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=52.101.201.35 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796215590; b=omHkQ705+oecqE9nn5WxOjOpixw8zix7Akwa3CDfMwK5gubBmLj+AR9NSUPYi+jGN7ji 7HF3FDHws4lOQEl0z0i/SbIOI8TVKU0ER/bb84QlC5tsisPwyyrn+ngTirzywYA6zv/Bo l8aC4MiTZzj48G6Mm6OkokP4YXxiA904RT7lumagMqqBt434AMOn7KtO2ATWhv/VhhuDl GFQbjI1p2zxVbDQVuyyJ58IkWOxH6/r/ABHeVoejqoALNs3M8ylDbsOvSnl1tggDVzfTP P/hv7zhGFn01qLQDaKanpLtraXqA3H0DQdxEGJN+Rcy9ZCpppGPTcr2Rxn228+NQ3dA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796215590; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:Message-ID:Date:MIME-Version:User-Agent:Subject:To:CC: References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding: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=zjqMBPSXUc7Iz4/nuh8TpNHhs5r3r42IKg347YObnpw=; b=A0MLOXsF48TowyQ04TaFx9KQOp8NqaAUOU3mS5HzaGpTow8N7muzZgXa0XXuspp58YQM 0cQsH7aEYaBtrvHu1ZwqVVAdsWZt4ZkfQNrCCDriOfOWflxjLsxHukJwe+LS80krcQpnF psYBX/wgwlDBJImVEk6PRvgZHhj7gxB83EmoUpav80stFTWvOV8qz2C3PX+rYxgL+di05 iLDoE6QkB2vRJ/LX+zkrrUKqggcS+gVspKCPAqqYHOwBn0vzf0O2NQTaFatJUVERSZAzd AnUBvbEzDj7um57JBYfjTHXw3tGW5Wk6Pa6aS9zR8dPJUfbjE5im5d9QAC1Pxj0M3sw== 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=wOXUPx2Y; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.201.35 Received: from PH7PR06CU001.outbound.protection.outlook.com (mail-westus3azon11010035.outbound.protection.outlook.com [52.101.201.35]) (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 EB8DE606A31A; Wed, 2 Dec 2026 12:46:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EB8DE606A31A 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=wOXUPx2Y ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DiP4RmjTr2evugMFnKuKfWwVRTlvGuPnP66jYdv6VQV/NUy6ZBR0Ers71l22MzdaCX9dSZjEFQLCodLQSJJ87x75iw4AYzlsoHyvn2/+klwoKX2uS5rqtyCnbnJNbY8jwsWyBEYSG2lOqxclsrkqt+e/3dCZUJaXR9AB5mw5XzKAybcAYd3Lyi4nM1Wx9iyAZwUFxJL4+iBGJzhEq8sIUbdP0dEB/ZDRr6bsxRqBDv+cFO0jii604DHbzFcFauHF+gZ1QjFSZ57RMfuhghdpsTF5uPQZf5c6B2H0BcYPWA72quCtZh9+VnuQ5IU9i0Mi+kWhHZcuPuQVon9nhSni4w== 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=zjqMBPSXUc7Iz4/nuh8TpNHhs5r3r42IKg347YObnpw=; b=ONwlrPExGAFgFAAOoZzAHQpMgNqyIK3qFMvqGH12vk4aQ5l0vErr7DUAHQBHR4z7jP+SCNJobE+RurJTjX/qbS3fjYik96+3e3o6OaHkZ23OQhkn7TzWebNB3JfTO24TEcZzjPnJumxEXY+RFroHzcnhKx9K3kiq7BbZwok3T51ngyT8BBSKEEZnCbOff1gXPPsXVZd7TNL+eaiaa7P0yFGGe+wx851p6hcwIm5A1QBwDH6oPYYlJ1LoXO4sCRljG0zIGZkJt+zhQsNCbOW5hq+6uLViNVEBUk/6ps61nFi5yxidks+kED/clnrvfCa7v37pCnmCqrX8CXSkPPnMcw== 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=zjqMBPSXUc7Iz4/nuh8TpNHhs5r3r42IKg347YObnpw=; b=wOXUPx2YZ7bzmqlzX4KLfx3JeWNGSUyncpAfJ8yCVw4OlLyyh7kwW/sq7d89eG/vCqJeg7e4fSQyE/2feQRyLCsW3vkHBjEru9meUkFmDzOAy2TAS+7oZswI1WBTdmhIPLJe7jlKJKOkk0pTu7nUcTaYBUEcNQb57UyC514xd34= Received: from BN8PR04CA0059.namprd04.prod.outlook.com (2603:10b6:408:d4::33) by SA0PR12MB4496.namprd12.prod.outlook.com (2603:10b6:806:9b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Wed, 2 Dec 2026 12:46:26 +0000 Received: from BN3PEPF00022BD6.namprd03.prod.outlook.com (2603:10b6:408:d4:cafe::84) by BN8PR04CA0059.outlook.office365.com (2603:10b6:408:d4::33) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.11 via Frontend Transport; Wed, 2 Dec 2026 12:46:26 +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=satlexmb08.amd.com; pr=C Received: from satlexmb08.amd.com (165.204.84.17) by BN3PEPF00022BD6.mail.protection.outlook.com (10.167.248.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Wed, 2 Dec 2026 12:46:25 +0000 Received: from satlexmb08.amd.com (10.181.42.217) 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.57; Wed, 2 Dec 2026 06:46:25 -0600 Received: from [192.168.1.100] (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Wed, 2 Dec 2026 06:46:21 -0600 Message-ID: <7964c570-4f9b-4f19-bbfc-c0e52894f560@amd.com> Date: Wed, 2 Dec 2026 18:16:20 +0530 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4] x86/sev: Handle DR7 accesses in the #VC handler after GHCB teardown To: Ashish Kalra , , , , , , , , CC: , , References: <4f8dc645aafd49c65dfa5456f097b4d3122862e4.1796158168.git.ashish.kalra@amd.com> Content-Language: en-US From: "Aithal, Srikanth" In-Reply-To: <4f8dc645aafd49c65dfa5456f097b4d3122862e4.1796158168.git.ashish.kalra@amd.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF00022BD6:EE_|SA0PR12MB4496:EE_ X-MS-Office365-Filtering-Correlation-Id: eaa75a8a-91b0-4db7-b377-08df50724724 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|376014|1800799024|23010399003|82310400026|10067099003|261026140227099003|56012099006|261021121427099003|11063799006|261022075727099003|261009223027099003|261021123027099003|261102123227099003|261022105027099003|261026121527099003|261028144727099003|18002099003|22082099003|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: HYia1N9X8PgPiE705j2fFMFLXwki1YtjTbu1t/g4/DLc4BDB/ez4GI23PgS1kJlvSiQHnTO7k0BwHuwhxFrbc4qJI6NZfFAJd0JX5BSGabcG10w5jLuCmAKpyzjkCJtvLFwgXyi1OTjW5pDC5XkTyqqvIL7OI3FTga5x+WG39aXr9i2w3MatZKwPekW57BTaw6w/6VY5KA+HpF2t4FaQQ6wll2J1+aQTXVw3k2EhXlDE0h3EVT/XgOasKvTdHMT7k1neV5Nn+81atYU52jtQlMoHd5zKv5OGw3l2H56m8j7fOfJp6gp05NpShdQ7ZPJa9fIQvIZDM284HF4/9+fPsIbaEAQIhQBaXRN7ciaBDSkk952ZGMMgP5F5LW6HOhDAJQQ98/gYzC2uZKxWzNpNW4hXIQRsgWfc1M9FfdvTxA8uoWc4QqvRcZdJdzvT6/0vz2wSjhtFGNvkJbiWp4/MqUKx1YGpeQquNSF9F5m6vxcIbSFmIAwcr5TjLvbw5ERKC+mg8+CDTFq9NF+KFOPn3y2+4WPo1NzNQRWH8vMGd04gQ+crnRorGaHkeuwwzVBILnNaCDDA2V7MtsI1q4epTqqC5x/hY/G3htxsJEF9p8r28qQSAStRViT7XoFgshKOp5/1CMTDGK02Hwgwxm2PMjw+TAS0MPrYn4r6viPXgmKYbAo+32m0xeNl0vQz2ESse1SCRgWJ+XU6nUchpMT59Q== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:satlexmb08.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(376014)(1800799024)(23010399003)(82310400026)(10067099003)(261026140227099003)(56012099006)(261021121427099003)(11063799006)(261022075727099003)(261009223027099003)(261021123027099003)(261102123227099003)(261022105027099003)(261026121527099003)(261028144727099003)(18002099003)(22082099003)(6133799003)(3023799007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6pPvnqOT8AC6Avj5fMaCsBMegz6UI1KWMo7byZEFNIhdHlfo7AQDZxTYIiNcklkLu4Ssic2co7xVq7Yr/b9qwi/7eMybI+2bNxmVjw9RTdT2Pnwj2pLp20CHoECqS+s/HWcKGRB36qubmATCf4jonpB/3kG6PlZ5sBZZkyZ3fyLmT2lN9JtWe/Ak6Q/djx/eIuHTz6rsRE0b3tMZZJGKvhSCS+GlqsBI44zq8wcCXfJwQuAC0SetxJEDowOpKtlVwyEnvEsoRMtxxmwPh6UKux5jSllqrTjzaHOgWnt48DhnIizf8xptOoPbvMB8DPqEdaABu2MeQ44/R8/uSTD6I7IdNBZQ7CfCVtmgyidFs9G/rXW0Xyza9EC75MXqbAPq5YqdCSobvkf92kWoEK3Kb+2GE6jcNeDaxuJgvJZhGlJ8mfh6lEnYvI2YBUo89P0C X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 12:46:25.9545 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eaa75a8a-91b0-4db7-b377-08df50724724 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=[satlexmb08.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF00022BD6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4496 On 12/2/2026 2:30 AM, Ashish Kalra wrote: > 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 Tested v4 on top of 7.4.0-rc5[fe6ff8d]; kexec and kdump works fine with this patch. Reported-by: Srikanth Aithal Tested-by: Srikanth Aithal