From patchwork Mon Feb 27 22:29:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 13154234 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B934C64ED6 for ; Mon, 27 Feb 2023 22:31:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F2346B0078; Mon, 27 Feb 2023 17:31:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A4FD6B007B; Mon, 27 Feb 2023 17:31:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E371A6B007D; Mon, 27 Feb 2023 17:31:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D50B56B0078 for ; Mon, 27 Feb 2023 17:31:33 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9969E40A27 for ; Mon, 27 Feb 2023 22:31:33 +0000 (UTC) X-FDA: 80514519666.03.FFA8BCF Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf28.hostedemail.com (Postfix) with ESMTP id 9D005C000F for ; Mon, 27 Feb 2023 22:31:31 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LV4qOqFY; spf=pass (imf28.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677537091; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=m82UYX5aQssRgl8psmBP9zJk+xjZFbSau758VDt+A0c=; b=OhmSwWbdMUoN4FtyEIt0IwUy/CdfnvuC3aVjWoP4ylUdCIM7deaFNc4gE901q04En8vMiI ec8Y7kGX/fI3H1FknbM6hGpcJVE/ZQhafZridzX1ey/r+76/sTCJ4AaUnM9qwVZe0X4Ds8 gv/7fJOJpKFlxJqkT8lFn2w7gKApgow= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LV4qOqFY; spf=pass (imf28.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677537091; a=rsa-sha256; cv=none; b=8oAAlECNNEZ57UO7YJH4reeDojuN9qvhtsgpDCRFVldbMIh+lPtNpCAmaBLPuSxEzRKJEA CXzIIfCK2HxllKTpQeROlDtz+JZtqoUqwJX9LVqq5jHpj7CuNMR5KOcQrkGVg9BSRlcED/ xC7Qp9Cv7C14O7iN9YWXJbWjeRnBBTQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677537091; x=1709073091; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=9fd4C/mVhbbyV9RlyDxCvsqphPPcMSnaWW7TQtu1kzU=; b=LV4qOqFY1LOQS6MRtaXtSF2F8GOfsuwIa93bqgUdxrqb0ONKhlXuVXe7 2Dn3SU4h34ECi4DtHHorWS150pT8yg4lc6Ou6so61luRnptR+YRsZeldo +gEOK30b7+lWV/5AiHsK6pAMhKV9Xs0ga1QkgOuO42nNBXU+HHgdTZmYF aybdl2mt75spd7uOs2+WFHA14mzC+/dTwi1IQmMA3ZmPLydIwKE5gu2Tq t1MSytdf44fv8NR5Pg5DE52uqVVWVENAPoH4rC3JKyv97Qbo7zEDMhC/h MePYbHQY1cFtl9/Q1R7Kxge3Id1+uxmqgwLJM5+WyclqDhjr3Pehwl9wB w==; X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="313657051" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="313657051" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:09 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10634"; a="848024349" X-IronPort-AV: E=Sophos;i="5.98,220,1673942400"; d="scan'208";a="848024349" Received: from leonqu-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.72.19]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 14:31:08 -0800 From: Rick Edgecombe To: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, debug@rivosinc.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH v7 03/41] x86/cpufeatures: Add CPU feature flags for shadow stacks Date: Mon, 27 Feb 2023 14:29:19 -0800 Message-Id: <20230227222957.24501-4-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230227222957.24501-1-rick.p.edgecombe@intel.com> References: <20230227222957.24501-1-rick.p.edgecombe@intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9D005C000F X-Stat-Signature: xwzwb71e7rjw5oytbit7mf1zu9qy31kb X-Rspam-User: X-HE-Tag: 1677537091-668506 X-HE-Meta: U2FsdGVkX1/sNtNsrfOLOoiUBoatk0ftzzyHn4L/MXp/VE+/P73KMVIdFVxrzr4kWw95IDVdxoRqQMUvoe+c4RrFy7n4PpFAaohQDSX6Vf4bL+G1gWs8vzxhGBqk6fcHo6itgvneHGxWsWr+d9uq28t0ASSW/mjDGcAHsFFcwqpv70vijVdlAjstd87ckB0/175jUUGRk4wsIFc259keIvZv1umm2Pt2k1Vs4g76w6TC5jiThzYyZTmZ20rHX6JvV+fUyGVXk09FU6e/Rmv1dCIQE9KMsrYHc/JAqbG2x799R9kMtxO/sxmerrsuLAyz1PfrH5IUnyooPXVvKrjKMn7cqvhMKAPOngZ01DdRHGDTSWvIswgogMiEYGS52bkSshgmv+2gxDYUO7MkN/icr0Nv3u3f/SmdImUYHear4MU5nDI6vOTyFg9UWPDh9d3rZKPpap6fv1PX+UJN9rnGzGmG+y3pmUdWkyQs+gwqH5OllqlEPzuELz3CydB4i0DaqfTkqInI4+oRJRK19qBtmPcIK+KuoSkKNW5IEOCJSnxFwGO/20buw0cWUi8NX/kS4jSTDhk9LpECygL1pEUNZLaJnoIK2tfHLs4hGh1PlYsZrYUa6BbPEmYyjw+SgEjgjrdfbkbfDM1xOK9OSxGih3uXvE0xZ1++pOUhvyWXucEGDXW8OMgjXdybA4k34qp7gqb3Rgwvd5KjhtdImcONJpLBOwZ8mtiItMO8g0P3GLM/pIKSkFOPZosRp74DqJqrFLXj9qGDPN2/Ms+sPxDPFu9FIsM47IG0b2IIq/DYsmHY2DllPaLJQbGoLlg2U9g+NdzOWB0IIHzCVQs6TUW+aRrqi2tBHkqK1gxNz75wLNHRxJvBtV0LDkXVtSVeIkoMHKljNGM2TopsZXFkVk9UKc5B6oC+l0ExJTdyIqkg06gaNgswHDcE0cgOe6M/LLIrgkQVeVc4G8WiVfOMz/f ID24nsn6 yX729RctneAGXR7u6qga9jYpLjSqxeXlU6So4wK5Ns7pfxBKHl4+zizAfPxvTsqizlgIL6xNKP8NAGZuECuegCe0vtwlP9QqRsu39hKzIKiHLpNiCr7FfbHzK3J3LOYCfdRlf+RJzyx0memGAPliieBWl9O4YxM9sjklh1Z5OffW3nlVd4/AXwj5BIM9jf2umf7ckn67EQKuiX9E0HkDu44Xwhru1g4XzRuQgVDn7DfVjMRI2pxfJ/o93QRJEho07LJSm6dCMQy0I0hxslKATjCyO85BuwWGBIz5IE6yXUXDBcb4N5/Sq/e/KQUY2OYtoXJQD3weqEu595DbYZV9GxPAT0FMPE+JbQCMh X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Yu-cheng Yu The Control-Flow Enforcement Technology contains two related features, one of which is Shadow Stacks. Future patches will utilize this feature for shadow stack support in KVM, so add a CPU feature flags for Shadow Stacks (CPUID.(EAX=7,ECX=0):ECX[bit 7]). To protect shadow stack state from malicious modification, the registers are only accessible in supervisor mode. This implementation context-switches the registers with XSAVES. Make X86_FEATURE_SHSTK depend on XSAVES. The shadow stack feature, enumerated by the CPUID bit described above, encompasses both supervisor and userspace support for shadow stack. In near future patches, only userspace shadow stack will be enabled. In expectation of future supervisor shadow stack support, create a software CPU capability to enumerate kernel utilization of userspace shadow stack support. This user shadow stack bit should depend on the HW "shstk" capability and that logic will be implemented in future patches. Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Acked-by: Mike Rapoport (IBM) Reviewed-by: Kees Cook Signed-off-by: Yu-cheng Yu Co-developed-by: Rick Edgecombe Signed-off-by: Rick Edgecombe Cc: Kees Cook --- v5: - Drop "shstk" from cpuinfo (Boris) - Remove capitalization on shadow stack (Boris) v3: - Add user specific shadow stack cpu cap (Andrew Cooper) - Drop reviewed-bys from Boris and Kees due to the above change. v2: - Remove IBT reference in commit log (Kees) - Describe xsaves dependency using text from (Dave) v1: - Remove IBT, can be added in a follow on IBT series. --- arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/include/asm/disabled-features.h | 8 +++++++- arch/x86/kernel/cpu/cpuid-deps.c | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 389ea336258f..d01afabcf03e 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -309,6 +309,7 @@ #define X86_FEATURE_MSR_TSX_CTRL (11*32+20) /* "" MSR IA32_TSX_CTRL (Intel) implemented */ #define X86_FEATURE_SMBA (11*32+21) /* "" Slow Memory Bandwidth Allocation */ #define X86_FEATURE_BMEC (11*32+22) /* "" Bandwidth Monitoring Event Configuration */ +#define X86_FEATURE_USER_SHSTK (11*32+23) /* Shadow stack support for user mode applications */ /* Intel-defined CPU features, CPUID level 0x00000007:1 (EAX), word 12 */ #define X86_FEATURE_AVX_VNNI (12*32+ 4) /* AVX VNNI instructions */ @@ -375,6 +376,7 @@ #define X86_FEATURE_OSPKE (16*32+ 4) /* OS Protection Keys Enable */ #define X86_FEATURE_WAITPKG (16*32+ 5) /* UMONITOR/UMWAIT/TPAUSE Instructions */ #define X86_FEATURE_AVX512_VBMI2 (16*32+ 6) /* Additional AVX512 Vector Bit Manipulation Instructions */ +#define X86_FEATURE_SHSTK (16*32+ 7) /* "" Shadow stack */ #define X86_FEATURE_GFNI (16*32+ 8) /* Galois Field New Instructions */ #define X86_FEATURE_VAES (16*32+ 9) /* Vector AES */ #define X86_FEATURE_VPCLMULQDQ (16*32+10) /* Carry-Less Multiplication Double Quadword */ diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h index 5dfa4fb76f4b..505f78ddca82 100644 --- a/arch/x86/include/asm/disabled-features.h +++ b/arch/x86/include/asm/disabled-features.h @@ -99,6 +99,12 @@ # define DISABLE_TDX_GUEST (1 << (X86_FEATURE_TDX_GUEST & 31)) #endif +#ifdef CONFIG_X86_USER_SHADOW_STACK +#define DISABLE_USER_SHSTK 0 +#else +#define DISABLE_USER_SHSTK (1 << (X86_FEATURE_USER_SHSTK & 31)) +#endif + /* * Make sure to add features to the correct mask */ @@ -114,7 +120,7 @@ #define DISABLED_MASK9 (DISABLE_SGX) #define DISABLED_MASK10 0 #define DISABLED_MASK11 (DISABLE_RETPOLINE|DISABLE_RETHUNK|DISABLE_UNRET| \ - DISABLE_CALL_DEPTH_TRACKING) + DISABLE_CALL_DEPTH_TRACKING|DISABLE_USER_SHSTK) #define DISABLED_MASK12 0 #define DISABLED_MASK13 0 #define DISABLED_MASK14 0 diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c index f6748c8bd647..e462c1d3800a 100644 --- a/arch/x86/kernel/cpu/cpuid-deps.c +++ b/arch/x86/kernel/cpu/cpuid-deps.c @@ -81,6 +81,7 @@ static const struct cpuid_dep cpuid_deps[] = { { X86_FEATURE_XFD, X86_FEATURE_XSAVES }, { X86_FEATURE_XFD, X86_FEATURE_XGETBV1 }, { X86_FEATURE_AMX_TILE, X86_FEATURE_XFD }, + { X86_FEATURE_SHSTK, X86_FEATURE_XSAVES }, {} };