From patchwork Mon Jan 23 22:04:46 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: 47433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1837604wrn; Mon, 23 Jan 2023 14:06:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXuHSqnl9ebjX5iKdhgHN2F/tALR2ZHiNuPFjaQezlfPgevU2PiXO9ZvO0SJN6am/Jx4Sk1N X-Received: by 2002:a17:906:4094:b0:854:956:1438 with SMTP id u20-20020a170906409400b0085409561438mr56977729ejj.25.1674511604345; Mon, 23 Jan 2023 14:06:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674511604; cv=none; d=google.com; s=arc-20160816; b=aZ9N8fwzqZgcoG0lxqpWop+VZmzNZ1cY08BLGxQuWajxzUtzfJRZb4hOKLdqabRDJl knd/M7zuKdHDFlm4gKO1lxPSomkbOs0Ymx9a3I6VCHkLYVNq2DBir+uQl/Qr6kcDWTZF LSpyyh7eikRkYtTiKyLpnf1C7KFUz1+zrHAI4bsNt9LF8HNIlhTJxYKQaQovCw5hKlwm ywI4GThIWL8psjf0EqF4exslyAbEdHsfwZ3L4U+jwtHlg3FNJ7IphL4jxwvtqypEQ8UY FwMgHIaiQTeCcptgw6JvFojduQFSQWCLlFtnYVbX1s45U4SR8zyZion7Q7ORwT0sdObd sHnQ== 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=xExjoMkzN/P2NAoPJBM1R3czgTsyLyY3dlPRiGQ5Uxw=; b=W2K8kNJtDJjSDl74wFtC0G/a+Hbzhl1lfXPrCxUSrzdsRK1x4qjoChjWC4G7/1C6op pnOaHfuzVeQZCxP0Ja41egLOKyIcP3gOk5NU4g8GBkvFg/W/KUUniR9xUiZ/g81mjWRS mXm4m6tglfWjlI8554+sIOj6aukygMcGeYTlnEUSoKHjnxOVqSE8RGL0rMKUSo/faFE9 HOPjVYiVvRIbfXK3XuuQe7UfO4AH6pyz3GKzxB1tN0C7i1nUmBE3hu/IoOWBaxXkXY9s /d08sDWIaBs8reglZvTVuYAl5ztNcyW0JRgAb/VqnsavLRIzr4XhWJWF/thXvjI8uxg3 pzxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KCrfa8SE; 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 mq18-20020a170907831200b00873092fd3bdsi6751ejc.746.2023.01.23.14.06.20; Mon, 23 Jan 2023 14:06:44 -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=KCrfa8SE; 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 S232440AbjAWWFt (ORCPT + 99 others); Mon, 23 Jan 2023 17:05:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232422AbjAWWFo (ORCPT ); Mon, 23 Jan 2023 17:05:44 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 041956A7E for ; Mon, 23 Jan 2023 14:05:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674511529; x=1706047529; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Qaw9/4SUZhSsN7dpC0zn5y1iDL4Dr/tJI+fTv1FbMq0=; b=KCrfa8SER2bO6wuTyxbai8u1H4L6IWaiRWA+cRl6qyRLgX7CqGCD1/BR fcLVs61cW9N8CCL6cIIBqEfhNCr6G9h8LTRiN9gmsb+QlAl68bD9y6ICV 1y07uXHgtvf1a+Q0oU7yXs/gNKIZQDss1/5yAowEf9MX9GimvrZ1lVHDb 7PIV8MfYoeRuLmMhvMlbrYgFnw0DgGOer3DNRgFafxt1VP2b3ch5mulN5 sjjg/IeO5nj56sZ2mz9+S2hgCPvWjPMEOLMGoniA9ec7TM52XymfY/Iz2 Ruf9/kFln5Bg1wlf9REMdxnoZ6b//Bvo/sv1jANdMbzOoKYtVOdiv43Ig A==; X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="326198114" X-IronPort-AV: E=Sophos;i="5.97,240,1669104000"; d="scan'208";a="326198114" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2023 14:05:14 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10599"; a="694103344" X-IronPort-AV: E=Sophos;i="5.97,240,1669104000"; d="scan'208";a="694103344" Received: from ssauty-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.46.171]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2023 14:05:07 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 37E2510943A; Tue, 24 Jan 2023 01:05:03 +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: [PATCHv15 03/17] x86: CPUID and CR3/CR4 flags for Linear Address Masking Date: Tue, 24 Jan 2023 01:04:46 +0300 Message-Id: <20230123220500.21077-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230123220500.21077-1-kirill.shutemov@linux.intel.com> References: <20230123220500.21077-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?1755852680445636659?= X-GMAIL-MSGID: =?utf-8?q?1755852680445636659?= 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