From patchwork Fri Jun 16 19:17:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 109346 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1571854vqr; Fri, 16 Jun 2023 12:37:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gR9CwnhH9d9VCflJQW38zNQ39QnoXqe76SQ1afAR+XWnX/nZT+6zkI47Znnm6EWSdG/TZ X-Received: by 2002:a05:6a21:6da9:b0:10e:786c:8219 with SMTP id wl41-20020a056a216da900b0010e786c8219mr4323256pzb.3.1686944261406; Fri, 16 Jun 2023 12:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686944261; cv=none; d=google.com; s=arc-20160816; b=EmtcC+z5Mch+XVQezG7I2LBPPaoN0tyO4Blo8IP8aplE9hgR9rFdydQwZ7nkCib/aY ZHSfEdYIj/0xgkBzOzP8LiQyHMIXbFIkHVkMA92ckS+FQeiKpY0wBuQyYIKAuxaSF+ww Yowizny4mEy1IQEPmIZ5XwrxUcnD25HtWQxHxpbcZq9RQHXJs0M3JspmA0yWP3zpX/zK sOoESp2Xt/kOdy0kWw6AwJnMvvAeKLO+0v/3mYmUbNXjm/IZcNZiZ6po9aokk3K86JlS L5WeihDFzj1IMm4KPyC2oyZMYsNprg8hsVVCXyiXhFYAo2LxLaxPIlYDf5VstnnpTy8B fZHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=xWg1vfAn/a5e9mEDL8K8oblZzS9YfIzE1QPniwf5F/k=; b=OmXlzinBrdE3r/AXt5eRTK40I//5HFNJWDG13gSNYavQKNOtmvOEhrurk1caukWjMb r6Lmvn2biSy8N57fhs8di9PuNIoYJV8uoT8Zm47g2w5RMaO22BO63wX3x2JwZnspLcth VOiEw075pxE/JR50xaiS3KFE9VUYHLXPDfpEidRP6ivaYcp1+q5XZ851vvVTWMJMMzKF eVikTtktusrPhB9j047TRBQZhYKbnNJADnYjspgjKD3ouTsMnXcoPsYsXIfX30+DUkhn Q0zBZ2MaSqtaumomLIZ+5zcQKukmVwcgX0KPjwDJz05Z3ibcqk6cDRklxRfg9O7isc+w swAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=HACMsuAR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=VJjhn3Pv; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d8-20020a621d08000000b00666adf7816esi2886820pfd.179.2023.06.16.12.37.27; Fri, 16 Jun 2023 12:37:41 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b=HACMsuAR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=VJjhn3Pv; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345813AbjFPTTa (ORCPT + 99 others); Fri, 16 Jun 2023 15:19:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345060AbjFPTRQ (ORCPT ); Fri, 16 Jun 2023 15:17:16 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3E533AB7; Fri, 16 Jun 2023 12:17:06 -0700 (PDT) Date: Fri, 16 Jun 2023 19:17:04 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686943025; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xWg1vfAn/a5e9mEDL8K8oblZzS9YfIzE1QPniwf5F/k=; b=HACMsuARlv0zkvNdMtb9zHYr2ItjWd/mzpnyFpjAIEb93a3jig0OSbLgATA1t59J9ZTmEH 9YwPbbPhx1TmCtGUMb7Sk8FIT6PBWiL60igeEsnNkgbMdcPA70BGG67i3G9QFZWv05zXV5 aLNfSN2w0NQ0aCLgE38MTHnGI0qlliWsWrarhr8sHwPhcqNF9XdhHhBWPQgz8vDNGyYfUW kSI0AO4r5g6y/jYlQhSK1n/U+/6dO07JgVb1VdwxfbcVGFL77iZ/rrW3fhbkTL303vF1Wk 845Fb7cOIKNAdUlgFrp5h7Qs2DH2ekasoaVuzKe/rNcrRx8DgrnQgO7YjJOvyQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686943025; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xWg1vfAn/a5e9mEDL8K8oblZzS9YfIzE1QPniwf5F/k=; b=VJjhn3PvbNoEaG0nht+0PoeDD/HhZ768XO6tftMwIpLNhZHL17mPG6LkPAAj1qlbLWPujr 8IZ4CFpcT5u+9JCQ== From: "tip-bot2 for Rick Edgecombe" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/shstk] x86/cpufeatures: Add CPU feature flags for shadow stacks Cc: "Yu-cheng Yu" , Rick Edgecombe , Dave Hansen , "Borislav Petkov (AMD)" , Kees Cook , "Mike Rapoport (IBM)" , Pengfei Xu , John Allen , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <168694302458.404.13075251894613638564.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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?1768889265814014604?= X-GMAIL-MSGID: =?utf-8?q?1768889265814014604?= The following commit has been merged into the x86/shstk branch of tip: Commit-ID: 5c43063e917a88fd4af07c118b7af954d593daad Gitweb: https://git.kernel.org/tip/5c43063e917a88fd4af07c118b7af954d593daad Author: Rick Edgecombe AuthorDate: Mon, 12 Jun 2023 17:10:34 -07:00 Committer: Dave Hansen CommitterDate: Thu, 15 Jun 2023 16:31:00 -07:00 x86/cpufeatures: Add CPU feature flags for shadow stacks 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. Co-developed-by: Yu-cheng Yu Signed-off-by: Yu-cheng Yu Signed-off-by: Rick Edgecombe Signed-off-by: Dave Hansen Reviewed-by: Borislav Petkov (AMD) Reviewed-by: Kees Cook Acked-by: Mike Rapoport (IBM) Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook Link: https://lore.kernel.org/all/20230613001108.3040476-9-rick.p.edgecombe%40intel.com --- 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 cb8ca46..d7215c8 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -308,6 +308,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 */ @@ -380,6 +381,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 fafe9be..b9c7eae 100644 --- a/arch/x86/include/asm/disabled-features.h +++ b/arch/x86/include/asm/disabled-features.h @@ -105,6 +105,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 */ @@ -120,7 +126,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 (DISABLE_LAM) #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 f6748c8..e462c1d 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 }, {} };