From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.209.23 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796534053; b=ToPbuG3POpBCye+Xi46ObarzBAGKe2lWEA9DHaPxfZOjiTEshOvX0RWreN27bEg5CjlG bwekax6yUUjpGZG/texgkAfmztdxcy8HT1yG0T9IiWIPmnfvn7EYe7B8kMFhEGjilVR1m NNVQzbY6Iq+w12y3M5Ji/LIOupvdCu8vKip96h5CxYv1Qo9FXe72c4hfZJq7GX6dbt6B4 2S/bXFIdSiEhAS3h45WXgh1Y4gRHTPQaB5Vqlwcby2ykZnzgrpx44dPTQQm0FoM64iYMs t1v6cLdK3oX2IpjuOCCItfhmJtR9zjITJNJ0UnPP+z9bllR4ytOI0whkmCe2z7W08ZQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796534053; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy:X-EOPAttributedMessage:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=cUQTQEkCYgu/1JDrifqkAMP716dj299/8jXkyqgHegE=; b=10/LS7g+bP32wTBosHHoL2jMe/R/PsSQlc0ZvXZ/TqBZWg2VY7BaZG1GbCotMzH7mDmB z9xR1BlM9Z8cbQu8ElC8M/R3he5SDacIUvm1Q38UZdGzW8s0W+7gmWRy9hXyRlOG+RQcK ea+dZag2TX7EMUfNCoJv5y5WbQp0M3drd5D9TdfUR9vtGwGrHnAFEsZKgUVQ5ruNZe/wF 7NXMZ+AhC/tKrJgyeAP0PL13nVHFWeKiQopXy8JbL4D4nkViQMKdPofC0svSRuClnDYel bSaIfNE+lUOOU1rlaCxehrp84KpZL8WYC/u7CnY2JhzKpSRZH9sHG64pmniEoDuzAvw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=G4tF0hpM; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.209.23 Received: from PH8PR06CU001.outbound.protection.outlook.com (mail-westus3azon11012023.outbound.protection.outlook.com [40.107.209.23]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B622606A321 for ; Sun, 6 Dec 2026 05:14:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3B622606A321 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, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=G4tF0hpM ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l06vpHam5lynn/ryzKEbhk93m2d8l+IoD0k3EE0uyeBCNbpD/q9UoqiwAjacp4S6VEVc7kP9KJ7OAkrZnRq7ftL5EIKuZgsyPmQccgKxOhwcyWzNrmv24l/kOPiTY+fdSJX8fh7+cVrVF+mIlqte+budi8MBBhdzSUpjpAS14N8MqLwqmfUiKHIRFAMV3rMZTlGudZTgwzdSeDymGiY4WbLcroM/2vKbqwbLTukKmDGsHWS9sOwjeJvHTcrKfuTKsz3yhH3AClwsFVzKb74ugabqLelcgA8xS6x/ZfEieiyDFtlLq5TwAAyrTCzC8y6sv52GSNLmyXMY8WjfSBwxug== 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=cUQTQEkCYgu/1JDrifqkAMP716dj299/8jXkyqgHegE=; b=kQDuQEuxhiNuRZE6jX7bxMINa+Rz3p08Oq22PgPMEa3LLmfAHuVBNGIg2LJQg/YHT2ZGgJJaMsgenFou88+hDfBOgHIcv0QEPKvO4oiSrTCsjX8Dol4DZa97RzUDAcxIn7uX0trqsKyw+kpuvZTGEugEABf/IPKpiakIBDNN447L+4NInfUt9L0wB8SquOCnKWen0LLWeanA6t71IdN8YzOu6L/MNeaxxlbbGsCiX/NSY9xTa088KWsN6LUk48YdW4j3nPBsU0vc9uuHzzUz7fUxk4jr0rfJwOGPxd9TXJ37TSWFJUqp0CbWz4xZItEGxWSa5n1RUbYp7Mpgly35QQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none 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=cUQTQEkCYgu/1JDrifqkAMP716dj299/8jXkyqgHegE=; b=G4tF0hpMvBYng2O2t0RX1i0LD2JN8fXVqhQ2FOGg+HWuvElKuIoI01CjB+hLeNFuSgDLb5t7wMSQYqi6Me4uSyFl+RQw/A2iM06H+7H5FNcBF8kGQoNo6+k0pU1xonVlucrlVFR2j44r6KLJdGVSKqVZIGuu1MMNXtlE6lV8OkI= Received: from CH0PR04CA0001.namprd04.prod.outlook.com (2603:10b6:610:76::6) by DS2PR12MB9776.namprd12.prod.outlook.com (2603:10b6:8:2bd::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.15; Sun, 6 Dec 2026 05:14:06 +0000 Received: from CH1PEPF0005BD62.namprd02.prod.outlook.com (2603:10b6:610:76:cafe::43) by CH0PR04CA0001.outlook.office365.com (2603:10b6:610:76::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.15 via Frontend Transport; Sun, 6 Dec 2026 05:14:06 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH1PEPF0005BD62.mail.protection.outlook.com (10.167.244.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.6 via Frontend Transport; Sun, 6 Dec 2026 05:14:05 +0000 Received: from purico-9dcchost.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Sat, 5 Dec 2026 23:14:05 -0600 From: Melody Wang To: CC: LKML , Tom Lendacky , , Melody Wang Subject: [PATCH v7 03/10] x86/sev: Implement backup CA Date: Sun, 6 Dec 2026 05:13:05 +0000 Message-ID: <66925daa93c05c5f2e23828f0af2c70aac5fbf4c.1796524449.git.huibo.wang@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0005BD62:EE_|DS2PR12MB9776:EE_ X-MS-Office365-Filtering-Correlation-Id: bbdcc7ca-42c5-4d65-41ac-08df5357c00d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|23010399003|1800799024|36860700016|5023799004|11063799006|261009223027099003|261021135927099003|261021121427099003|261021123027099003|22082099003|18002099003|56012099006|261102123227099003|261026121527099003|10067099003; X-Microsoft-Antispam-Message-Info: gDNkLC5yEb9NMRFp857zuCH+9K40L82KYjAGMZn8bYJsRy+SRh+AmoWFGR8/d0svSIIXtPFHzVGJXEMlhRU9CXkdDsSBpiYbela6weO7egfsLXDh6Hmo3gqsEe9ciZhRV1auYcAvUoWHl2BB6N13dparBbNXUF9/1pddyTmr4v9JdsIwBGg+onMjHUBIhdmbOtn0bSAwnDYEbrEcCYsauXXtGCawQFu+SUOrFf5YS8xhWi4A4qaDKMXXOHaQJMk2CULRKX3Ivqau4v2suS0rSBxXJIewGqjnULuGRC2fOzji+0USSi7Zrh8UtjtnyGsHnrg2IVsgRyK6/KBIDTNu0wdotueDLu55oHevzFLvJS9PWcRMjXiwC1fdXLdowe4HrJtLLbfiwTZ0V0DaxZjtu3d3TRrimgxTQVDCjkW7Rc75m0oCE8vZtWp2UeQi9wdv/i3XVm2fBbqPWGN3X50AcYlhMFaKCT76mAqBoj80yFV+TeOKJ6TxeRmOPjMlJ29hLzfRsPPIN2ilYUcK/guy6Emz/1kSearvD4i8euQ/mOHUlKBMQ4a9/7BqzPuLRFdhaHMQB0bCYKnPU5XL62zK07T0kE1EG2TXCxVxFp6cANFSTB7GH43dd4+qeuIgecU9w94lhu1iLqcIv1639E30bs/bmFvHwwfWXiKoUTMLTbRimvVKtcHRHaBzm13OV6nxg46slMVC3jHfZWqoDzcm1g== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb07.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(23010399003)(1800799024)(36860700016)(5023799004)(11063799006)(261009223027099003)(261021135927099003)(261021121427099003)(261021123027099003)(22082099003)(18002099003)(56012099006)(261102123227099003)(261026121527099003)(10067099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4FzE8jfRASC+JFCR8TOASQ6u4lOD1dRZ+CcR3tTkNJruGOKWjK08gykAntX3uoCCvjhBPBslj+Rya85w8pr7okomHWnBXYoatGPyIt/ts7YXMpjJuR7LUKt3TSIsy/n6fFMKQgp5YV+EplSq98L14ToMtJ48GiaOAuThgIIGeRjaF3oZECm1rZFDjO4JDo956/kaikiYOm4TBYJgvUfrmMKUrpcjkmg3vr0B+U97fscHHYAJGhYxxS0LES+iqjVaeD1rv2VTtO514yr1WAQ0nE3rg5pgwKzqhJVLxBNSvtC7PK0SbOH0bgHqyjTnW0qIKpOtFmOR7ckzvTG23y5x305DXfhfwrGop+Q2LIn7iSQKc2Hzt04eKXMAnFByM8Eq/a5o/9Lefon6zzMB9vRwH+zPMWMQSVXH1DqFPEQCnUUj6MhtrYq7jH4EYJzRgSkV X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2026 05:14:05.8976 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bbdcc7ca-42c5-4d65-41ac-08df5357c00d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0005BD62.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS2PR12MB9776 Give each CPU a backup CA so an interrupting call can save and restore the in-use CA around its own call. If both CAs are already in use there is no safe way to proceed, so panic, as the GHCB code does. No functional change for guests running without an SVSM. Signed-off-by: Melody Wang --- arch/x86/coco/sev/core.c | 4 +++- arch/x86/coco/sev/internal.h | 10 ++++++++++ arch/x86/coco/sev/noinstr.c | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index d4cd7a0d469f..91a3ff5b1f27 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -1237,8 +1237,10 @@ static void __init init_ghcb_and_ca(int cpu) data->ghcb_active = false; data->backup_ghcb_active = false; - if (snp_vmpl) + if (snp_vmpl) { data->ca_runtime_data->ca_active = false; + data->ca_runtime_data->backup_ca_active = false; + } } void __init sev_es_init_vc_handling(void) diff --git a/arch/x86/coco/sev/internal.h b/arch/x86/coco/sev/internal.h index 540b1a2b1946..8f5dd898b244 100644 --- a/arch/x86/coco/sev/internal.h +++ b/arch/x86/coco/sev/internal.h @@ -21,6 +21,15 @@ struct svsm_ca_runtime_data { struct svsm_ca *ca_page; u64 caa_pa; + /* + * Reserve one page per CPU as backup storage for CA. + * It is needed when an NMI happens while the SVSM call uses the real + * CA, and the NMI handler itself is causing another SVSM call. In + * that case the CA content of the first SVSM call needs to be backed up + * and restored. + */ + struct svsm_ca backup_ca; + /* * Mark the per-cpu CAs as in-use to detect a nested SVSM call. * There is no need for it to be atomic, because nothing is written to @@ -35,6 +44,7 @@ struct svsm_ca_runtime_data { * already. */ bool ca_active; + bool backup_ca_active; }; /* #VC handler runtime per-CPU data */ diff --git a/arch/x86/coco/sev/noinstr.c b/arch/x86/coco/sev/noinstr.c index fb178ee1e60a..9e85f64f07ac 100644 --- a/arch/x86/coco/sev/noinstr.c +++ b/arch/x86/coco/sev/noinstr.c @@ -215,6 +215,24 @@ noinstr struct svsm_ca *__svsm_get_caa(struct caa_state *state) if (unlikely(data->ca_active)) { /* CA is already in use - save its contents */ + if (unlikely(data->backup_ca_active)) { + /* + * Backup-CA is also already in use. There is no way + * to continue here so just kill the machine. + */ + data->ca_active = false; + data->backup_ca_active = false; + + instrumentation_begin(); + panic("CA and backup CA already in use. Giving up"); + instrumentation_end(); + } + + /* Mark backup_ca active before writing to it */ + data->backup_ca_active = true; + + state->caa = &data->backup_ca; + /* Backup CAA content */ *state->caa = *caa; } else { @@ -242,6 +260,7 @@ noinstr void __svsm_put_caa(struct caa_state *state) /* Restore CAA from backup */ *caa = *state->caa; + data->backup_ca_active = false; state->caa = NULL; } else { data->ca_active = false; -- 2.43.0