From nobody Mon Feb 9 10:24:43 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B88FC6FD18 for ; Tue, 28 Mar 2023 20:18:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229655AbjC1USL (ORCPT ); Tue, 28 Mar 2023 16:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229489AbjC1USK (ORCPT ); Tue, 28 Mar 2023 16:18:10 -0400 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDFC44222 for ; Tue, 28 Mar 2023 13:17:50 -0700 (PDT) Received: from zn.tnic (p5de8e687.dip0.t-ipconnect.de [93.232.230.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 06D431EC067C; Tue, 28 Mar 2023 22:17:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1680034634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kj9ZMXdOiC4j+qhb1y+6eCUnrAvvjZYAJh8azvysCpQ=; b=ZzLFJ/E5RZZt1ohUTLM3czf8JkkIzDOoX4i5eRu+X7Faaeg6V0VCb0+jQcdQtoIl/uCasM qGlf3qVqO540sZpo8O5pSXIH1XpjIEEH97EuzYA/7VJlotoBFhRkFC6m3VYc2KGiNdBo5X 8CBXduL4/rAchWkbdYZwMAp3JbqLk3E= From: Borislav Petkov To: Joerg Roedel , Tom Lendacky Cc: X86 ML , LKML Subject: [PATCH v2 1/2] x86/coco: Mark cc_platform_has() and descendants noinstr Date: Tue, 28 Mar 2023 22:17:11 +0200 Message-Id: <20230328201712.25852-2-bp@alien8.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230328201712.25852-1-bp@alien8.de> References: <20230328201712.25852-1-bp@alien8.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Those will be used in code regions where instrumentation is not allowed so mark them as such. No functional changes. Signed-off-by: Borislav Petkov (AMD) Acked-by: Tom Lendacky --- arch/x86/coco/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c index 73f83233d25d..df10e75be085 100644 --- a/arch/x86/coco/core.c +++ b/arch/x86/coco/core.c @@ -16,7 +16,7 @@ enum cc_vendor cc_vendor __ro_after_init; static u64 cc_mask __ro_after_init; =20 -static bool intel_cc_platform_has(enum cc_attr attr) +static bool noinstr intel_cc_platform_has(enum cc_attr attr) { switch (attr) { case CC_ATTR_GUEST_UNROLL_STRING_IO: @@ -34,7 +34,7 @@ static bool intel_cc_platform_has(enum cc_attr attr) * the other levels of SME/SEV functionality, including C-bit * based SEV-SNP, are not enabled. */ -static __maybe_unused bool amd_cc_platform_vtom(enum cc_attr attr) +static __maybe_unused __always_inline bool amd_cc_platform_vtom(enum cc_at= tr attr) { switch (attr) { case CC_ATTR_GUEST_MEM_ENCRYPT: @@ -58,7 +58,7 @@ static __maybe_unused bool amd_cc_platform_vtom(enum cc_a= ttr attr) * the trampoline area must be encrypted. */ =20 -static bool amd_cc_platform_has(enum cc_attr attr) +static bool noinstr amd_cc_platform_has(enum cc_attr attr) { #ifdef CONFIG_AMD_MEM_ENCRYPT =20 @@ -97,7 +97,7 @@ static bool amd_cc_platform_has(enum cc_attr attr) #endif } =20 -bool cc_platform_has(enum cc_attr attr) +bool noinstr cc_platform_has(enum cc_attr attr) { switch (cc_vendor) { case CC_VENDOR_AMD: --=20 2.35.1 From nobody Mon Feb 9 10:24:43 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7A51C76196 for ; Tue, 28 Mar 2023 20:17:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229869AbjC1URw (ORCPT ); Tue, 28 Mar 2023 16:17:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229864AbjC1URp (ORCPT ); Tue, 28 Mar 2023 16:17:45 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2DBD4231 for ; Tue, 28 Mar 2023 13:17:16 -0700 (PDT) Received: from zn.tnic (p5de8e687.dip0.t-ipconnect.de [93.232.230.135]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 78C0E1EC068B; Tue, 28 Mar 2023 22:17:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1680034634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mVzCjBqiRJvpLljfR/3AfHJOhQrU6iN8fQ64FUXXH/A=; b=ocWa01MU62vpXKDULW1D4MEcbqWBBYZzDUJWwUhzVjHlwTmNOqgkpmOyc7GlCUcMPCXB0h 4yzvUVXgiaZzPE8AnlaZmCCPAUEELiKifsu3DFHlqffd7Ft9iZtCgVYAAS2sM2wYzrbw5b egozXtiU6d8EaOY/RRSMQ0SHDvHYF30= From: Borislav Petkov To: Joerg Roedel , Tom Lendacky Cc: X86 ML , LKML Subject: [PATCH v2 2/2] x86/sev: Get rid of special sev_es_enable_key Date: Tue, 28 Mar 2023 22:17:12 +0200 Message-Id: <20230328201712.25852-3-bp@alien8.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230328201712.25852-1-bp@alien8.de> References: <20230328201712.25852-1-bp@alien8.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" A SEV-ES guest is active on AMD when CC_ATTR_GUEST_STATE_ENCRYPT is set. I.e., MSR_AMD64_SEV, bit 1, SEV_ES_Enabled. So no need for a special static key. No functional changes. Signed-off-by: Borislav Petkov (AMD) Acked-by: Tom Lendacky --- arch/x86/include/asm/sev.h | 11 +++++++---- arch/x86/kernel/sev.c | 5 ----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 13dc2a9d23c1..f14060cbead2 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -14,6 +14,7 @@ #include #include #include +#include =20 #define GHCB_PROTOCOL_MIN 1ULL #define GHCB_PROTOCOL_MAX 2ULL @@ -136,24 +137,26 @@ struct snp_secrets_page_layout { } __packed; =20 #ifdef CONFIG_AMD_MEM_ENCRYPT -extern struct static_key_false sev_es_enable_key; extern void __sev_es_ist_enter(struct pt_regs *regs); extern void __sev_es_ist_exit(void); static __always_inline void sev_es_ist_enter(struct pt_regs *regs) { - if (static_branch_unlikely(&sev_es_enable_key)) + if (cc_vendor =3D=3D CC_VENDOR_AMD && + cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) __sev_es_ist_enter(regs); } static __always_inline void sev_es_ist_exit(void) { - if (static_branch_unlikely(&sev_es_enable_key)) + if (cc_vendor =3D=3D CC_VENDOR_AMD && + cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) __sev_es_ist_exit(); } extern int sev_es_setup_ap_jump_table(struct real_mode_header *rmh); extern void __sev_es_nmi_complete(void); static __always_inline void sev_es_nmi_complete(void) { - if (static_branch_unlikely(&sev_es_enable_key)) + if (cc_vendor =3D=3D CC_VENDOR_AMD && + cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)) __sev_es_nmi_complete(); } extern int __init sev_es_efi_map_ghcbs(pgd_t *pgd); diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index b031244d6d2d..0ec0d963b8b7 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -113,8 +113,6 @@ struct ghcb_state { }; =20 static DEFINE_PER_CPU(struct sev_es_runtime_data*, runtime_data); -DEFINE_STATIC_KEY_FALSE(sev_es_enable_key); - static DEFINE_PER_CPU(struct sev_es_save_area *, sev_vmsa); =20 struct sev_config { @@ -1395,9 +1393,6 @@ void __init sev_es_init_vc_handling(void) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); } =20 - /* Enable SEV-ES special handling */ - static_branch_enable(&sev_es_enable_key); - /* Initialize per-cpu GHCB pages */ for_each_possible_cpu(cpu) { alloc_runtime_data(cpu); --=20 2.35.1