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.93.195.60 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796158850; b=tG6AqiBX8ELFkKBGCxwaN7dMcK8rlEoWvO8jV+prfNPrLCTB7sv8t8j5FVxjtrvDGzQJ fYjUCF/Jxpsg7yE/e4FsV0cjC0ls+YFLq4PldN8RrEkHEjllLX6Fi5UmQqBitbdRF4DuF qbj3usryA6pyXIvbrYoi3l56EcZnoykg3Zag7ovD8IBwWUj0FzHxvrtcQ+FyM2xC/0pLu ofhtC4pFFow29fBpv4URz+tn3iLymQ0rjtS4yglToeyFBHNw6RCFEGQkQJW/Y6xbHVqZB i/CRHuSVuYdh6UfEug0A3JYpwfuvO2AkJJSFb0NJXGgJEQRJc0jMiDV6vJUMNn6ec9g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796158850; 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: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=4qysRt4QXv5pUtKcWT7AMpSxC8B+lTGyy5b5X0K9KoY=; b=bU6eqfzRnzB3orJ7mrBw/HeLVlMOgFY3JUNtxvbLDhFS0B1dXLemTEFhqkXrV0kLiHWD E0hAZbTd7p7O8dLymy1gZGop8REzLXzpIjH4f5WlfQSOLQyxH2DKwRqeB48Z8zvMAlQC3 rM4S4g3xrqMp1sgSzyL0CugpOWr7iaHphozepSslYnIceQE++d3GpcTtlFVWZs6jN5KJ5 ZEsI1W9krEEUm3JCvAnH3uW5eChFgMlg8+HtKPnyaBu592rxXJYiyiqlG1DGmXiNITomA FkmJlMOSUFBABIkgHqImXXG6ZSPUzu4f+9Bd8wrtTswWf98MCj51EiQJHQ05MVa16Qw== 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=syjxJa16; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.195.60 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012060.outbound.protection.outlook.com [40.93.195.60]) (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 7171B606A320; Tue, 1 Dec 2026 21:00:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7171B606A320 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=syjxJa16 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QJUXU99sbHKqgoGI8hKWTd9B7ioTtI28qps34g+wXfY0cvc4xiQlmrgk6OhxHkrlKHX1s/RwFNkFfULvxoqbMabdQckpXFNbe7rd2brxWD+ah1HZZuN3GC3SaecEIlrRLZcLS4fBxKOWN/lH4eXzJlXgojw5HJI1cgyoX1yJKHEsnAB/MZFCPvvutFtnxxJL6YAPTpfbLmlYD8106gfxbac+XeaPJaVB8duGjRT+73vq8wZBizb2yVtWn5uYhGpE2E5EHRYUkb88MNBbtUhTyRmu+aMia/k3kf2uLwQEAkHwg3gYAjZZh5cx2bUMfM/Nb+piptYULCqRICQfDsK0WA== 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=4qysRt4QXv5pUtKcWT7AMpSxC8B+lTGyy5b5X0K9KoY=; b=Tw6CvrUzWVfWBUAw10ivXXkY0K6cJbUsGHGnRdCs8J5rgep2Vljz/QMZ4XUKnLpx0Afp0xPU2kfFT4vBf8jQRsAe6ESfO34g5YjtcfUeZA+dv80/5+IJLI08WV/4UlOTznKhrwb0bz/DS7EV18OTh12fijdUUtCAsPTM9vYt7U0YFsQjJxPYeqpPxy6UxiIJNrGHaZmu1d+b9fcEL7vZGSBsP0zAdacrZ41m73X6ZTU4vNhn46dMgmaF+o/5olqtQaKEZv/l/rqN5bMeKv8iZ3OZ1S/7k+vg4BlzAEmjWw9mtB6rmpGgkbP6ng2Z4UGMOeApRqNMmCxc/CVepKCwAg== 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=4qysRt4QXv5pUtKcWT7AMpSxC8B+lTGyy5b5X0K9KoY=; b=syjxJa16RXL+wV4UqDBdwdmfgnBbkqtijuuySXBBoksjRwt9ro4cJkKQBJFjWXdhqm9DKQfaORRB2BsQggwAtRjauiDAz4c18eszKmRatZQJL6oAkv/Yr3yd+8q5AOiHlsrSMHOShiX5Q1aKrKmUqdieUBkgFEUeB/FMZUjs9Oo= Received: from CY5PR18CA0008.namprd18.prod.outlook.com (2603:10b6:930:5::11) by DS0PR12MB7772.namprd12.prod.outlook.com (2603:10b6:8:138::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Tue, 1 Dec 2026 21:00:41 +0000 Received: from CY8PEPF00000054.namprd05.prod.outlook.com (2603:10b6:930:5:cafe::86) by CY5PR18CA0008.outlook.office365.com (2603:10b6:930:5::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Tue, 1 Dec 2026 21:00:41 +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 CY8PEPF00000054.mail.protection.outlook.com (10.167.247.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 21:00:41 +0000 Received: from nigeria-2635-os.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; Tue, 1 Dec 2026 15:00:40 -0600 From: Ashish Kalra To: , , , , , , , , CC: , , Subject: [PATCH v4] x86/sev: Handle DR7 accesses in the #VC handler after GHCB teardown Date: Tue, 1 Dec 2026 21:00:30 +0000 Message-ID: <4f8dc645aafd49c65dfa5456f097b4d3122862e4.1796158168.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.43.0 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: CY8PEPF00000054:EE_|DS0PR12MB7772:EE_ X-MS-Office365-Filtering-Correlation-Id: 7b3a3038-ef72-4807-e49a-08df4fee28a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700016|376014|23010399003|6133799003|18002099003|3023799007|56012099006|10067099003|11063799006|261026140227099003|261022075727099003|261028144727099003|261022105027099003|261026121527099003|261021121427099003|261102123227099003|261021123027099003|261009223027099003; X-Microsoft-Antispam-Message-Info: BVlEyRU+8yy+FKCoFfFrTujQjmF0sKSXfOiGHWsMbnOVA8gUVw0DPuewCO/0yfxZKFv7WhN48gxFfdzoKIATryk4sgLmNM/l0etpL/ZIEe2SpkPN5FVL9nwbVMHGZsqGm0ObcHfRt6nsfWd/yR66wAqtSUsfhJP8j8UI7qAQyDmk92THDNL/wEqeHuSF3Qf2eg2mLOxAZ+jLncz2zgoy//JLmu8GTnE21js35/O4MSPa+D9eSkxuDLka5zVKIqzvxmSdynQM6sl7NPLPNSK/46OKE0VsLxv52LcMXf1PsG4YIDh0TkjeWHcMVidJrWOEPsW6Cwcz0LeZmYw1h6VR4FU35LQNaWocl5g4PgGryzQgA/WSsuW8WgjfvrmJAp2jyPpP5rLWAkjljkIu/GmSU3JwTU58skgo/ehzaXufNypJ29Ew85d5ajiSvU171avB+Wzf23L3/71cqovZtp4fvYQrzSFrHLiQgd/uB18AFG2L3Z5oyLvaAGmGxeOexnv9kF2TOLkWp/0tGDN0eb92luPWEkDWmklnrr8qOIkQsV/Mgj3IWa0Vky0d9a7HyYimR87JaBW0oLtUF9WNzZ/M2jhvZHYRaqtN2xg3Ys7wUYlpzIEghaOy0bppeqFU+MfLBrZUGKD229awdUGqzO4ok5xg+uFzmfbIC4AQCh38v6fqECZXbQdPuS1sV/JOuT29/R224vK0/9LyyuYGMLFH5g== 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)(1800799024)(36860700016)(376014)(23010399003)(6133799003)(18002099003)(3023799007)(56012099006)(10067099003)(11063799006)(261026140227099003)(261022075727099003)(261028144727099003)(261022105027099003)(261026121527099003)(261021121427099003)(261102123227099003)(261021123027099003)(261009223027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yB+fzKkZKJH7wEwyrao9LPASvm2+rVktb4PlKRy0TgrILlNfTfZhWWBODPXpL6jVrxnnjufgkbU1b783cjF3gHont56xmfrcM1qFejsFIvCidEzz7J3OowRHUWWZWocm+nPJG08UcLbs+4rovPld6273f3VxHiuUyoPHFJEor8Qb0Nz6l/PV7ROOWJWqN5c/ejcXg+89eSyHl72oEid6vugSeFzBondJh1uYb7lZH3j/pF1dYU7Q0TV8Ekt8RiuT29lqL2d/4t0ua5Z2f/kRKADx0t4hA0aoKxAp7XnTXeD3D1xeFxwr6nPsMVYizGGwAal2zUKRmf1CU80RZWmC8JfJvuEp8m2gHZTo6OS8CSmzvm2PlO4OpvRZU5eLSkvXPOrrmR4V4XEiI2pQW05UOy+FSolDyJdR38Fak9JqiN9TDF29n6qiIWsBq1RUBwga X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 21:00:41.1722 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7b3a3038-ef72-4807-e49a-08df4fee28a4 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: CY8PEPF00000054.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7772 From: Ashish Kalra machine_kexec() calls hw_breakpoint_disable(), which writes DR7. On SEV-ES/SNP guests that do not have DebugSwap enabled, DR7 accesses are intercepted and delivered to the guest as a #VC exception, which is normally serviced through the GHCB. By the time machine_kexec() runs, snp_kexec_finish() (called from native_machine_shutdown()) has already converted the per-CPU GHCBs and the boot GHCB back to private, set boot_ghcb to NULL and cleared sev_cfg.ghcbs_initialized. The DR7 write therefore raises a #VC that dereferences a NULL GHCB pointer and the kexec fails. Before commit 3645eb7e3915 ("x86/fred: Fix early boot failures on SEV-ES/SNP guests"), __sev_get_ghcb() returned the per-CPU GHCB in this window. That page had already been converted back to private, so the hypervisor could not read the request nor write a response, and the guest treated its own stale GHCB contents as a successful reply. The DR7 write was silently dropped and the kexec only worked by accident. Since that commit, __sev_get_ghcb() returns the now NULL boot_ghcb instead. The GHCB MSR protocol cannot help here: apart from CPUID, it has no request that corresponds to an intercepted instruction, so a DR7 access cannot be forwarded to the hypervisor without a GHCB. Instead, once the GHCBs have been torn down, handle the #VC without a GHCB: verify that it is a genuine DR7 access and complete it locally, returning the reset value for reads and dropping writes. This is safe because, without DebugSwap, the hypervisor only tracks the DR7 value and cannot load it into the encrypted VMSA, and the kexec'ed kernel writes DR7 again in cpu_init(). Only DR7 accesses are currently handled this way; any other #VC in that window terminates the guest with a new, specific reason code instead of dereferencing a NULL GHCB. Fixes: 3074152e56c9 ("x86/sev: Convert shared memory back to private on kexec") Cc: stable@vger.kernel.org Signed-off-by: Ashish Kalra --- v4: - Check that the instruction really is a DR7 access with vc_check_opcode_bytes(). (Tom, Sashiko AI review) - Terminate if DebugSwap is enabled, as DR7 accesses are not intercepted then. (Sashiko AI review) - Handle the NULL GHCB returned by __sev_get_ghcb() instead of open-coding the teardown check before it. (Tom) - Rename vc_handle_exception_no_ghcb() to vc_handle_no_ghcb() and make it return bool; vc_no_ghcb is already the early-boot #VC entry point. (Tom) - Rename GHCB_TERM_NO_GHCB to GHCB_TERM_VC_NO_GHCB. (Tom) v3: - Handle the DR7 access in the #VC handler once the GHCBs have been torn down (decode it and complete it locally) instead of skipping the DR7 write at the hw_breakpoint_disable() call site. Any other #VC in that window terminates the guest with a new reason code. (Boris, Nikunj) - Drop the Suggested-by/Reported-by/Tested-by tags since the fix was reworked. v2: - Move the check into hw_breakpoint_disable() through a new snp_hw_breakpoint_disable() helper. - Drop CC_ATTR_GUEST_DEBUG_VIRT and read DebugSwap from sev_status. arch/x86/coco/sev/vc-handle.c | 35 +++++++++++++++++++++++++++++++ arch/x86/include/asm/sev-common.h | 1 + 2 files changed, 36 insertions(+) diff --git a/arch/x86/coco/sev/vc-handle.c b/arch/x86/coco/sev/vc-handle.c index 954df836ac65..a233ea5c867e 100644 --- a/arch/x86/coco/sev/vc-handle.c +++ b/arch/x86/coco/sev/vc-handle.c @@ -873,6 +873,39 @@ static __always_inline bool vc_from_invalid_context(struct pt_regs *regs) return is_vc2_stack(sp) && !is_vc2_stack(prev_sp); } +static bool vc_handle_no_ghcb(struct pt_regs *regs, unsigned long exit_code) +{ + struct es_em_ctxt ctxt; + long *reg; + + /* Without a GHCB, only DR7 accesses are currently handled */ + if (exit_code != SVM_EXIT_READ_DR7 && exit_code != SVM_EXIT_WRITE_DR7) + goto fail; + + if (sev_status & MSR_AMD64_SNP_DEBUG_SWAP) + goto fail; + + if (vc_init_em_ctxt(&ctxt, regs, exit_code) != ES_OK) + goto fail; + + if (vc_check_opcode_bytes(&ctxt, exit_code) != ES_OK) + goto fail; + + reg = vc_insn_get_rm(&ctxt); + if (!reg) + goto fail; + + if (exit_code == SVM_EXIT_READ_DR7) + *reg = DR7_RESET_VALUE; + + vc_finish_insn(&ctxt); + + return true; + +fail: + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_VC_NO_GHCB); +} + static bool vc_raw_handle_exception(struct pt_regs *regs, unsigned long error_code) { struct ghcb_state state; @@ -882,6 +915,8 @@ static bool vc_raw_handle_exception(struct pt_regs *regs, unsigned long error_co bool ret = true; ghcb = __sev_get_ghcb(&state); + if (!ghcb) + return vc_handle_no_ghcb(regs, error_code); vc_ghcb_invalidate(ghcb); result = vc_init_em_ctxt(&ctxt, regs, error_code); diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-common.h index 01a6e4dbe423..b0a64a49875c 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -209,6 +209,7 @@ struct snp_psc_desc { #define GHCB_TERM_SECURE_TSC 10 /* Secure TSC initialization failed */ #define GHCB_TERM_SVSM_CA_REMAP_FAIL 11 /* SVSM is present but CA could not be remapped */ #define GHCB_TERM_SAVIC_FAIL 12 /* Secure AVIC-specific failure */ +#define GHCB_TERM_VC_NO_GHCB 13 /* #VC that can't be handled without a GHCB */ #define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK) base-commit: 75b8262a97abcb972ef897dad5f94d425157b635 -- 2.43.0