From patchwork Tue Dec 27 03:08:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 36744 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1200412wrt; Mon, 26 Dec 2022 19:09:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXuFSGOxlgkF4X/4AgWXvbY1HSjXTULQbbku7OPlzAWtybMhw1VyADmG12ocrgmXuQlQOeQW X-Received: by 2002:a17:90b:812:b0:219:f993:7f30 with SMTP id bk18-20020a17090b081200b00219f9937f30mr37814248pjb.32.1672110569335; Mon, 26 Dec 2022 19:09:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672110569; cv=none; d=google.com; s=arc-20160816; b=WTHs2VpnobQYlEy0574Rp8qFZrM17qPvws2sqBustayqGddYmP5A/rG0aRb/UNC54A XeaquHSas58XMSqq6KRYbAoOsvMCR2RITsB9is7K4zXYL96i04d13+GJklAADcgqv3ua zsU15Bfw3TMKq/EfKNXiJdE4dl6ePGIUmnAHjhE4Ct1U9Cl93bZJihBjOApDqeiIrqPD Z53y1BxeRudngl2pe8Cp+zNpJ1/pxp6rwnsJgJnTPfhyioNTtvk3zJIDCazrWmr7Oyvu pLJE59qvI8XHuYJeBnELgfkBeUUF2iNG4ToawAmu9cNqJD72VRF+9wQUZPjFcMwdSsiW Iw6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HiQmt79j+yP5ckm1kw0E99dGcnfCgkwWTWtqPyabNRA=; b=WCDzAiTASBubNFyBMn8OUfLlwxJkti9zITkvBJTpCeNzQWUxYVUdSzrcvoIbpmPRW5 YDHU23PdeJBArXGwYONr7tvpL8XFlGChk8H5Twmx1zanudcXINYeFjnkUwUcvoH1UD8g ZCJJbIt4kY65J04fHbTb7XSJviEde43TExQT2YZveB7ITNC7v49KE83o+oq07ALeEpRW i9T3s9Ystt6/adLTfRGCQJBaxuVsrJEcjNVBmufi0/18Ga0NJ6yWApNAqBjqW/w3mbLx NQori4OxGxIUNjqKsHsQPvKrvV9x5dTA55C4N/IsKumshAAD/1X56XNSskJnm+JV8eO9 LeFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lmrozRjP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lp5-20020a17090b4a8500b00218a9f90590si17884988pjb.2.2022.12.26.19.09.17; Mon, 26 Dec 2022 19:09:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lmrozRjP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229724AbiL0DIs (ORCPT + 99 others); Mon, 26 Dec 2022 22:08:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbiL0DIo (ORCPT ); Mon, 26 Dec 2022 22:08:44 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 042F3EA5 for ; Mon, 26 Dec 2022 19:08:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672110523; x=1703646523; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gEzeHerPaWTs/tIk/qtNJxiWNCV7jnSRQjRqxLLucY8=; b=lmrozRjPyLdejz0lZR9AtOCd7P7L7iyEWEhkk+yomB75eVxMiPno0k63 IBASRkKKhn7uWMPFJk10CrNVzGGt/wC1CDfFcMx49sIRNp12vGo6hh60i lkktvLo//Lu1Tzy5iU/vI4+mmknO/Er+ZEoSYoKZ7+7f3etPZFV0bg1SH dP4igVPzo8EtZa/YXLPCpwtnIJx8p7Ia+9QzN/l6ErSYlIt5783DY/8yo Qah7p8H1mJKyicHF9W732RSxeAEPeAp+Gw6PpZMo+Cuk/UAshro/1L0RM DU16TQvEIEvzMVmO1sMDnyPJJI0yBlYuILRoX3FARtIJw0+k1jv3l8OZ3 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10572"; a="300994650" X-IronPort-AV: E=Sophos;i="5.96,277,1665471600"; d="scan'208";a="300994650" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2022 19:08:43 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10572"; a="741605192" X-IronPort-AV: E=Sophos;i="5.96,277,1665471600"; d="scan'208";a="741605192" Received: from ppogotov-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.62.152]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2022 19:08:39 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 8FB6410BBAF; Tue, 27 Dec 2022 06:08:36 +0300 (+03) From: "Kirill A. Shutemov" To: Dave Hansen , Andy Lutomirski , Peter Zijlstra Cc: x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Taras Madan , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , Bharata B Rao , Jacob Pan , Ashok Raj , Linus Torvalds , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv13 02/16] x86: CPUID and CR3/CR4 flags for Linear Address Masking Date: Tue, 27 Dec 2022 06:08:15 +0300 Message-Id: <20221227030829.12508-3-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20221227030829.12508-1-kirill.shutemov@linux.intel.com> References: <20221227030829.12508-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753335012154746569?= X-GMAIL-MSGID: =?utf-8?q?1753335012154746569?= Enumerate Linear Address Masking and provide defines for CR3 and CR4 flags. Signed-off-by: Kirill A. Shutemov Reviewed-by: Alexander Potapenko Acked-by: Peter Zijlstra (Intel) Tested-by: Alexander Potapenko --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/processor-flags.h | 2 ++ arch/x86/include/uapi/asm/processor-flags.h | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 61012476d66e..bc662c80b99d 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -314,6 +314,7 @@ #define X86_FEATURE_CMPCCXADD (12*32+ 7) /* "" CMPccXADD instructions */ #define X86_FEATURE_AMX_FP16 (12*32+21) /* "" AMX fp16 Support */ #define X86_FEATURE_AVX_IFMA (12*32+23) /* "" Support for VPMADD52[H,L]UQ */ +#define X86_FEATURE_LAM (12*32+26) /* Linear Address Masking */ /* AMD-defined CPU features, CPUID level 0x80000008 (EBX), word 13 */ #define X86_FEATURE_CLZERO (13*32+ 0) /* CLZERO instruction */ diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h index a7f3d9100adb..d8cccadc83a6 100644 --- a/arch/x86/include/asm/processor-flags.h +++ b/arch/x86/include/asm/processor-flags.h @@ -28,6 +28,8 @@ * On systems with SME, one bit (in a variable position!) is stolen to indicate * that the top-level paging structure is encrypted. * + * On systemms with LAM, bits 61 and 62 are used to indicate LAM mode. + * * All of the remaining bits indicate the physical address of the top-level * paging structure. * diff --git a/arch/x86/include/uapi/asm/processor-flags.h b/arch/x86/include/uapi/asm/processor-flags.h index c47cc7f2feeb..d898432947ff 100644 --- a/arch/x86/include/uapi/asm/processor-flags.h +++ b/arch/x86/include/uapi/asm/processor-flags.h @@ -82,6 +82,10 @@ #define X86_CR3_PCID_BITS 12 #define X86_CR3_PCID_MASK (_AC((1UL << X86_CR3_PCID_BITS) - 1, UL)) +#define X86_CR3_LAM_U57_BIT 61 /* Activate LAM for userspace, 62:57 bits masked */ +#define X86_CR3_LAM_U57 _BITULL(X86_CR3_LAM_U57_BIT) +#define X86_CR3_LAM_U48_BIT 62 /* Activate LAM for userspace, 62:48 bits masked */ +#define X86_CR3_LAM_U48 _BITULL(X86_CR3_LAM_U48_BIT) #define X86_CR3_PCID_NOFLUSH_BIT 63 /* Preserve old PCID */ #define X86_CR3_PCID_NOFLUSH _BITULL(X86_CR3_PCID_NOFLUSH_BIT) @@ -132,6 +136,8 @@ #define X86_CR4_PKE _BITUL(X86_CR4_PKE_BIT) #define X86_CR4_CET_BIT 23 /* enable Control-flow Enforcement Technology */ #define X86_CR4_CET _BITUL(X86_CR4_CET_BIT) +#define X86_CR4_LAM_SUP_BIT 28 /* LAM for supervisor pointers */ +#define X86_CR4_LAM_SUP _BITUL(X86_CR4_LAM_SUP_BIT) /* * x86-64 Task Priority Register, CR8