From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010026.outbound.protection.outlook.com [52.101.201.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D50F3DFC9F for ; Thu, 23 Apr 2026 09:20:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.201.26 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776936046; cv=fail; b=WX2l5Lp5Bhks54ZOeqaB/av/19nhpHzGTS3rawqnmMcLlf1nQD71C8QPwWnjWBQ/yqKlWP6NxXJPXqoNKOJm3KZw8qma6vtOsm82TI7eqYc3nyouRxKhvtE/IOUznaUGC3cnJtVywtdAfjlbG3kjADWXeoFNgrydk37+TBXU1NM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776936046; c=relaxed/simple; bh=qXSJSO9u+2vfxWavxKS0GvLK9oThoDu2cKs+5NnCEeY=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=a7csRFuR+FaAfidifkx6Kw2w45No7a2rKwo62DBoGEFEWXXwrzsanSe2gRX47oBimJ+6AbCrwjsnpAbZ/6x1SOEjiqaRSFfK0HznecAqQLip6NELAq0QhdalQR1uHcFLxsUggJrs90OItYKrc/vkyxPmAmmdcLScLYP/AHg3tNA= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=BwwxGQqP; arc=fail smtp.client-ip=52.101.201.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="BwwxGQqP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Yi0HJLd+bFDVwilOV6yVt8TbXMWWL8ms7kQmj0c547mDNCa0RKYSh6mbdvV3e1VLIsbYA/ppPm4iX5R0YgGmKPbJYjrMIDOcPtR1iqvKRkUCwcaKJE/tEvzE4QmYeuqfgcDnrWeS02ZhFeM5skZcQDqpSv5qG1JVkFNGV71h4IptvNidzkiZXeW4df6e40mv63gwy1tzkzN0k+Ds8H0m6gZdZ49wUlhaIBa70DKggy3DvWhqsXeqdvxgWTY6p/hJ0IJmrz3uc1x4IDkcfEnG3mAUniuG0x3Hl7DJyN1UyGiEsGEWrijR1jrZp5UwSzS/OI1a7DtunvBKw9vn173+pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ys4BFXB6ujPdGnjtGM+/s4tCSup98eqlYkfbG8WmFfI=; b=XG/9c8LtagemUv8J5SEEf6LgGTW3iKR9/1OiKUunCM8zl8zT0h+P6I2JyYvSStzAbkIurUu2vWe3RW1zKeAtdhoxG0yHoKDt7+Yd25nUqCGyFmonuUetPv7pEYnpTUny86EqibSh8QIXK9ORnIl7ZOQiywxsg7OFYZ1Trtszg4kmaWTs3QEzP1LTtFDJzurTAZ/35FBjbeslulqI9Aqxb/elWQP/L9eXTHmJOSedzzgMCbP1IQUhn7rCplGEj0GDQ26R8PsfYuoM9TONsP2wtMn0zkeGLDYfbaEO+bHMSuHCHlAF25wbnfm0YmdAG8gu14qhnjZGB6hAZZTexStX2w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 165.204.55.251) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=fail (p=quarantine sp=quarantine pct=100) action=quarantine header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ys4BFXB6ujPdGnjtGM+/s4tCSup98eqlYkfbG8WmFfI=; b=BwwxGQqPLtJ7Kxx+TA5jxAKE5Vo4LUlg0GVW0TlTMZed49RFdCeOXKHINgbznvsc5of2tSr0q7+To/EfxFufLpYJgGY160XctQoGEWyrAo1cGeXrdpBKoxQPAOIpc6UcaD94hPmTCOd2ne6UBxFqcKGA9Mvd794yMK2QN2xxxK8= Received: from DS7PR03CA0350.namprd03.prod.outlook.com (2603:10b6:8:55::27) by BY5PR12MB4209.namprd12.prod.outlook.com (2603:10b6:a03:20d::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.15; Thu, 23 Apr 2026 09:20:39 +0000 Received: from CY4PEPF0000E9DC.namprd05.prod.outlook.com (2603:10b6:8:55:cafe::ab) by DS7PR03CA0350.outlook.office365.com (2603:10b6:8:55::27) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9846.22 via Frontend Transport; Thu, 23 Apr 2026 09:20:38 +0000 X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 165.204.55.251) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=fail action=quarantine header.from=amd.com; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning amd.com discourages use of 165.204.55.251 as permitted sender) Received: from satlexmb08.amd.com (165.204.55.251) by CY4PEPF0000E9DC.mail.protection.outlook.com (10.167.241.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.18 via Frontend Transport; Thu, 23 Apr 2026 09:20:38 +0000 Received: from satlexmb07.amd.com (10.181.42.216) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Thu, 23 Apr 2026 04:20:38 -0500 Received: from [10.252.210.85] (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Thu, 23 Apr 2026 04:20:35 -0500 Message-ID: <9eb1fb40-5af3-4c20-a15e-2acd2cf81fce@amd.com> Date: Thu, 23 Apr 2026 14:50:34 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] x86/entry: Zap the #VC entry user and kernel macros To: Borislav Petkov , Tom Lendacky , Joerg Roedel CC: X86 ML , LKML , "Borislav Petkov (AMD)" References: <20260420164352.32129-1-bp@kernel.org> Content-Language: en-US From: "Nikunj A. Dadhania" In-Reply-To: <20260420164352.32129-1-bp@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9DC:EE_|BY5PR12MB4209:EE_ X-MS-Office365-Filtering-Correlation-Id: a2ee1dcb-7373-47d7-eb8e-08dea1199580 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|36860700016|82310400026|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: f5nPR9L8k2Z4xaUwQy+Z9C/V6AzP8JtFaXkQ2Z6gtBSlf+AaX5phUxBl+OO52OQVRUcmdu+qiAEhcP1G5nr0+9XZN+MLG/VsQnFDjXvDW8YykYVrL1qkZ8/bEIDfRfFY1I9wa5hTIqMOBT/v9l1Ii1L4t5oN0enlNLGvT7rLkAsLhrH2j2mV5bDGNz7y24hHmibvm104Fylji8jl3giP8OS33znqhxGiuR0ke/NSFZpFK8nHzVL1hMxnNFViEbcJRLu1ze7INyv6aOrhZUiSNWoqw5+bY744qeHEcaiSBUTF/1Jpo/uUYj8ty/t8Ef3/n0aS37iDZyolbccZh+Wiho22eYgHwC1KABsl2/kYyKwTNAj7GcjzoAi7JLk1pk/OY+Y8NnbI52QT0ot8njunzXxhtuL+zUnNNA0n0le0Xb7op4NTrGKFQ6L//Y67jQeiy9RJGLsQQCHN3TbBMZam/al0yKhw1TPM+Erwi/FMonV2QBHeiLGXUFWEzGU1DKp906yUNwAKtQcA0idDfSVtEYKmSf5QZQZ9MSe3rS7c2sj3+t19EQ1c6bdV2nUsQM2j9lnr6QQNQI7AOfCrl2WjpeQQZ0pIBaGoyogHNwFz30bQ2POA86XufXBrC9XXiZBZtfJ0pnUyqMxEc3oiYBXz++q/fyuF45SJb0HxGB0zJOM4yy7AxiBTNXkTnlHZhaWOYmw+ytg+HujrjI9abYwkzpp8UDSDw1cxHvNSff0QKFRBFMEd5RAtcxbsh4C6e2AGF+9Qc9gXHY4OeOKY4MRM9w== X-Forefront-Antispam-Report: CIP:165.204.55.251;CTRY:CA;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb08.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(376014)(1800799024)(36860700016)(82310400026)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: i9/58AwrSDi85CV7nygVrrQ2QEaEPsONgSNpQXuPwCXuR5vbI3+UPTI1OIe7FCxrGXrDahBENZtyQGK9pbyFLOZiborwYP89FX999bCnP//D2zG2q1LDQwESoY6+9QXFVCkYAm88Tkjp3gCYVrW3yopTdBTgcIM2EuM3uvXGZP7Ua9XMx21h+5APvdYky8vv68lkHd0yhW4n/W07dZqp39+LrKXXJynlKG5s0qNBmbqiAS683fbhi2npI7TMRRRSc45BnIpPI2Dy9XtIUFjjXeQl6U4Bq2imPa3d/xn42DCzuVblL5gHKohPoDT4N+vJOLe2CGuxJ+DnP1YhlxVYG7iKmU28rDUVTzOvVmuG9aqUR4NCjGuwKQsbzHkb9f5zN+t63qrF3pWcWFGq1w5BIm+450ezfy5GL2Qjr7OQlrQDew5v/Smg7ShqINL9NFK2 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2026 09:20:38.5837 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a2ee1dcb-7373-47d7-eb8e-08dea1199580 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.55.251];Helo=[satlexmb08.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000E9DC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4209 On 4/20/2026 10:13 PM, Borislav Petkov wrote: > From: "Borislav Petkov (AMD)" > > Drop the separate kernel and user macros in favor of calling a single #VC > C handler which multiplexes between the kernel and user #VC entry points > by looking at CS's RPL. > > Zap unused DEFINE_IDTENTRY_VC while at it. > > There should be no functionality change resulting from this - just code > simplification. > > Signed-off-by: Borislav Petkov (AMD) Boot tested with and without FRED on various guest combination (SVM, SEV, ES and SNP) Tested-by: Nikunj A. Dadhania Reviewed-by: Nikunj A. Dadhania > --- > arch/x86/coco/sev/internal.h | 3 +++ > arch/x86/coco/sev/vc-handle.c | 12 ++++++++++-- > arch/x86/entry/entry_64.S | 4 ++-- > arch/x86/entry/entry_fred.c | 10 ---------- > arch/x86/include/asm/idtentry.h | 29 +++-------------------------- > 5 files changed, 18 insertions(+), 40 deletions(-) > > diff --git a/arch/x86/coco/sev/internal.h b/arch/x86/coco/sev/internal.h > index b1d0c66a651a..b9632c0fc391 100644 > --- a/arch/x86/coco/sev/internal.h > +++ b/arch/x86/coco/sev/internal.h > @@ -70,6 +70,9 @@ void svsm_pval_pages(struct snp_psc_desc *desc); > int svsm_perform_call_protocol(struct svsm_call *call); > bool snp_svsm_vtpm_probe(void); > > +noinstr void kernel_exc_vmm_communication(struct pt_regs *regs, unsigned long error_code); > +noinstr void user_exc_vmm_communication(struct pt_regs *regs, unsigned long error_code); > + > static inline u64 sev_es_rd_ghcb_msr(void) > { > return native_rdmsrq(MSR_AMD64_SEV_ES_GHCB); > diff --git a/arch/x86/coco/sev/vc-handle.c b/arch/x86/coco/sev/vc-handle.c > index d98b5c08ef00..96b62b49b2b5 100644 > --- a/arch/x86/coco/sev/vc-handle.c > +++ b/arch/x86/coco/sev/vc-handle.c > @@ -954,7 +954,7 @@ static __always_inline bool vc_is_db(unsigned long error_code) > * Runtime #VC exception handler when raised from kernel mode. Runs in NMI mode > * and will panic when an error happens. > */ > -DEFINE_IDTENTRY_VC_KERNEL(exc_vmm_communication) > +noinstr void kernel_exc_vmm_communication(struct pt_regs *regs, unsigned long error_code) > { > irqentry_state_t irq_state; > > @@ -1006,7 +1006,7 @@ DEFINE_IDTENTRY_VC_KERNEL(exc_vmm_communication) > * Runtime #VC exception handler when raised from user mode. Runs in IRQ mode > * and will kill the current task with SIGBUS when an error happens. > */ > -DEFINE_IDTENTRY_VC_USER(exc_vmm_communication) > +noinstr void user_exc_vmm_communication(struct pt_regs *regs, unsigned long error_code) > { > /* > * Handle #DB before calling into !noinstr code to avoid recursive #DB. > @@ -1032,6 +1032,14 @@ DEFINE_IDTENTRY_VC_USER(exc_vmm_communication) > irqentry_exit_to_user_mode(regs); > } > > +DEFINE_IDTENTRY_RAW_ERRORCODE(exc_vmm_communication) > +{ > + if (user_mode(regs)) > + return user_exc_vmm_communication(regs, error_code); > + else > + return kernel_exc_vmm_communication(regs, error_code); > +} > + > bool __init handle_vc_boot_ghcb(struct pt_regs *regs) > { > unsigned long exit_code = regs->orig_ax; > diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S > index 42447b1e1dff..c6d996593f32 100644 > --- a/arch/x86/entry/entry_64.S > +++ b/arch/x86/entry/entry_64.S > @@ -492,7 +492,7 @@ SYM_CODE_START(\asmsym) > > movq %rsp, %rdi /* pt_regs pointer */ > > - call kernel_\cfunc > + call \cfunc > > /* > * No need to switch back to the IST stack. The current stack is either > @@ -503,7 +503,7 @@ SYM_CODE_START(\asmsym) > > /* Switch to the regular task stack */ > .Lfrom_usermode_switch_stack_\@: > - idtentry_body user_\cfunc, has_error_code=1 > + idtentry_body \cfunc, has_error_code=1 > > _ASM_NOKPROBE(\asmsym) > SYM_CODE_END(\asmsym) > diff --git a/arch/x86/entry/entry_fred.c b/arch/x86/entry/entry_fred.c > index fbe2d10dd737..fb3594ddf731 100644 > --- a/arch/x86/entry/entry_fred.c > +++ b/arch/x86/entry/entry_fred.c > @@ -177,16 +177,6 @@ static noinstr void fred_extint(struct pt_regs *regs) > } > } > > -#ifdef CONFIG_AMD_MEM_ENCRYPT > -noinstr void exc_vmm_communication(struct pt_regs *regs, unsigned long error_code) > -{ > - if (user_mode(regs)) > - return user_exc_vmm_communication(regs, error_code); > - else > - return kernel_exc_vmm_communication(regs, error_code); > -} > -#endif > - > static noinstr void fred_hwexc(struct pt_regs *regs, unsigned long error_code) > { > /* Optimize for #PF. That's the only exception which matters performance wise */ > diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm/idtentry.h > index 42bf6a58ec36..20f548702404 100644 > --- a/arch/x86/include/asm/idtentry.h > +++ b/arch/x86/include/asm/idtentry.h > @@ -340,17 +340,14 @@ static __always_inline void __##func(struct pt_regs *regs) > __visible void noist_##func(struct pt_regs *regs) > > /** > - * DECLARE_IDTENTRY_VC - Declare functions for the VC entry point > + * DECLARE_IDTENTRY_VC - Declare a function for the VC entry point > * @vector: Vector number (ignored for C) > * @func: Function name of the entry point > * > - * Maps to DECLARE_IDTENTRY_RAW_ERRORCODE, but declares also the > - * safe_stack C handler. > + * Maps to DECLARE_IDTENTRY_RAW_ERRORCODE. > */ > #define DECLARE_IDTENTRY_VC(vector, func) \ > - DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func); \ > - __visible noinstr void kernel_##func(struct pt_regs *regs, unsigned long error_code); \ > - __visible noinstr void user_##func(struct pt_regs *regs, unsigned long error_code) > + DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func); > > /** > * DEFINE_IDTENTRY_IST - Emit code for IST entry points > @@ -391,26 +388,6 @@ static __always_inline void __##func(struct pt_regs *regs) > #define DEFINE_IDTENTRY_DF(func) \ > DEFINE_IDTENTRY_RAW_ERRORCODE(func) > > -/** > - * DEFINE_IDTENTRY_VC_KERNEL - Emit code for VMM communication handler > - * when raised from kernel mode > - * @func: Function name of the entry point > - * > - * Maps to DEFINE_IDTENTRY_RAW_ERRORCODE > - */ > -#define DEFINE_IDTENTRY_VC_KERNEL(func) \ > - DEFINE_IDTENTRY_RAW_ERRORCODE(kernel_##func) > - > -/** > - * DEFINE_IDTENTRY_VC_USER - Emit code for VMM communication handler > - * when raised from user mode > - * @func: Function name of the entry point > - * > - * Maps to DEFINE_IDTENTRY_RAW_ERRORCODE > - */ > -#define DEFINE_IDTENTRY_VC_USER(func) \ > - DEFINE_IDTENTRY_RAW_ERRORCODE(user_##func) > - > #else /* CONFIG_X86_64 */ > > /**