From patchwork Wed Jan 11 12:37:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 41989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3318783wrt; Wed, 11 Jan 2023 05:26:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXswQcmaoHqMKEwMgmxojTuWjglBQQMnQe1ExieaprhCc6njX6z7Raf3yW5Xwar4buhDhT0G X-Received: by 2002:a05:6a00:1d8e:b0:575:6a68:65f8 with SMTP id z14-20020a056a001d8e00b005756a6865f8mr73222178pfw.18.1673443615471; Wed, 11 Jan 2023 05:26:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673443615; cv=none; d=google.com; s=arc-20160816; b=Fu5WvgvDPAh6vBmt5/3pmZ7RTbjLmTEJ5E4Ag+WvMO1D7uTkhDgv/ylg2A0fkLq3IO NmyBfRRhPaSu077dxPxcoZMlh2qSVRyJj7/TttGG0lUfo+tISlTtVJl9mBz2kpWF2B6a faw5sADlui7iaukr3p8t9omXrXXsdDM4VnC51wY+Cqy8Ye3tzhh4BRI5LB+eMAaLyIzP G3w9/GVQ5B0Vj3ZzkZOksrvZlWfGfDbh8HJJNmfxpDvLmVUhg7gHJ6r0mSxachfKRQ8V bNmuuEAAxY1jpyaupWMbkNnw7NYgOBaZ+EpkS7CKgab8M/ebBKS+Bw6Z9LVcSgKrjxV8 1/Zw== 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=gtvQdR/tQF6edmArQpOLj1DCcO+bGxNE9riU66jpwoM=; b=iLgg3Y/ssiur4DfahnbRf11LEWjS2lRK7Qz+hZha6Rre9GTa1XO4VuDh8sW791Dzv7 2xYvBdi3djleC4T6zWSgWWrtWst46YOrPaG0PVMaWGR9AXkcFmiubG7tYz7U6e1uOeEX V7AyR/+jpkLIxyeU2wUevEjZyu06BuElPywBSBH1W0B4SLXY2AmhvOV1ofbgeFE7TdEI TWzHKhf6kKRZPzwUDbeX9qEqSRW3CQdo0rp9gN+mRPoVZA8kEuj50J4wcyPvV2ZbMvk9 i3wm1DIoWT1Pq3li+cPJWxAkfZH3vWFeTFEmf+JEpZlApIbvi5HYHJSHSXyu4OxAnEtd WXKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=oHiLIj3x; 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 e10-20020a056a001a8a00b0056aafb43783si15356222pfv.155.2023.01.11.05.26.42; Wed, 11 Jan 2023 05:26:55 -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=oHiLIj3x; 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 S231760AbjAKNZU (ORCPT + 99 others); Wed, 11 Jan 2023 08:25:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234100AbjAKNYC (ORCPT ); Wed, 11 Jan 2023 08:24:02 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA0BE389F for ; Wed, 11 Jan 2023 05:24:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673443441; x=1704979441; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q9S2rKMrsOnON3J2uWuzPapruoVCfa2fXWWpeKLEJbA=; b=oHiLIj3xjSU9LHsUO39p7ED3DOa/f0E2Zz5ysn/1IcaV9Nc7dSEitHS5 NzS2dpPnkf0tSftwvk24Jxvzb6EDHyqdGYcAbBQcWUHou2IRZsf3d++O5 QMa7CVTvotuxAAr2FUqbUUKM2n92RzCv7XuMB93OleNaj2/BH+tm9Nvr7 LQNQz+/tsWTu4ErGSKQYNfZ93gL0jG3AQK+AGzzAzKxf84Tf+ChO8i//O rWW5PS/ZK4hU+MjNv2HzRyyLcKsk1Z5HOWFwroCfgsu2ezWcrwxt9dA3u i7hi4oRT/uc4PwXzsJZ7BtzlaVOtm/FRnDWskDYHIrrbqH0PboOD1Zx8I w==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="324646109" X-IronPort-AV: E=Sophos;i="5.96,317,1665471600"; d="scan'208";a="324646109" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2023 05:23:55 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="720725488" X-IronPort-AV: E=Sophos;i="5.96,317,1665471600"; d="scan'208";a="720725488" Received: from bachaue1-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.37.250]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2023 05:23:50 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 1EC3E109C7D; Wed, 11 Jan 2023 15:37:41 +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: [PATCHv14 03/17] x86: CPUID and CR3/CR4 flags for Linear Address Masking Date: Wed, 11 Jan 2023 15:37:22 +0300 Message-Id: <20230111123736.20025-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20230111123736.20025-1-kirill.shutemov@linux.intel.com> References: <20230111123736.20025-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1754732812716894624?= X-GMAIL-MSGID: =?utf-8?q?1754732812716894624?= Enumerate Linear Address Masking and provide defines for CR3 and CR4 flags. The new CONFIG_ADDRESS_MASKING option enables the feature support in kernel. Signed-off-by: Kirill A. Shutemov Reviewed-by: Alexander Potapenko Acked-by: Peter Zijlstra (Intel) Tested-by: Alexander Potapenko --- arch/x86/Kconfig | 11 +++++++++++ arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/processor-flags.h | 2 ++ arch/x86/include/uapi/asm/processor-flags.h | 6 ++++++ 4 files changed, 20 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 3604074a878b..211869aa618d 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -2290,6 +2290,17 @@ config RANDOMIZE_MEMORY_PHYSICAL_PADDING If unsure, leave at the default value. +config ADDRESS_MASKING + bool "Linear Address Masking support" + depends on X86_64 + help + Linear Address Masking (LAM) modifies the checking that is applied + to 64-bit linear addresses, allowing software to use of the + untranslated address bits for metadata. + + The capability can be used for efficient address sanitizers (ASAN) + implementation and for optimizations in JITs. + config HOTPLUG_CPU def_bool y depends on SMP 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