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.85.69 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796294966; b=poEv4rYsQmObsZvMC5+lQzSb3jqfYMzlOzJ/S+FMNHHkJftEIIBq3iWyUk4Abgt8gVzC 572OJ+LIf8vxqltgIrEQgyxvME37pJBiD+5x/FyluCCC1+SGOd6GG14mltl+HrF+3zk7Z TlEOncP0azfNdKQ6rUsR+SV/yZuzk3Vg0/k5svyugvzC78bEEA0eeB+YIWQfKydh4AcvV xI0lHm4OCLip/thDBqdlQecBKfe7cMQybOfVKGjmrxDZGNgiYdz5PBFGjK9DOjRQTQo1q nsWOwMVPmAHNFDHhvB/wj4wsrZAlBzADf0tWUCLkEHU3T8GQJgDcKC9SRZ7o8KGiH8g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796294966; 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=QGmXhtV3MQfoNun2JGYQ1LqZnYO26iBVFiBRk2tCU3w=; b=KZ4OwKXXa0SBOWTpiHKNHA0ZUEWO1wz3Az5l8QtT86Whg5CH3CenpiEX6jG+C9nKIcs8 xmw50YrtaDu5Sf+XLLLuplGYLbREuR5HqSE9LI2alyTolrDFLm+MLEyzT7iLCJkM89VWs ecjk1PnqxLKloLqhWlRGzJyIUCUhmJAFku9/mjdvPQBJKLbQWNLE4NNVlCAKdgw7J3Au+ AdRUIblBWPlksUkquEH6plGJRDFdsYa7/10PPnNrkAK+OggJiNmiErnR8xHNaWTQOMACo vROUbEv/srALO/t0fCQWZ8Fl7/dnF+EhYqkuNCTvV5FUcOi+OmSgUaGhqrodGLMoDwg== 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=IOdCzG89; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.85.69 Received: from BYAPR05CU005.outbound.protection.outlook.com (mail-westusazon11010069.outbound.protection.outlook.com [52.101.85.69]) (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 A2FB6606A32D for ; Thu, 3 Dec 2026 10:49:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A2FB6606A32D 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=IOdCzG89 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=giXV+iTQcpjrM9nV3lL9dnie9L7UegAYYDDP2Q+DSkt/9jracDCVgdEyUuIXRtUe7e+XvC74JRCQRJNH3YxfgkWiYzgniFINRNz4ZJAnJaM8eOo128v6BSXbQv+hUHRGrZDGrtyPPSg0gTAak+12aeLAFA4FzJneXNuLMyzlz6sLJHNQYR34vhLh9KQ14fVMKNwE8J0kWuOp+dlyH4M8Fpx0tuAo6f9t6M0XiXsZZzwZ6KjuK4SQ0zJBqmwExd/jnKADkCuJLcuVzgN0iXIml5/Aat4Z/7BdRNWygdfjDWdblMtm0IrPdACxTEGZODh+7MuA5efSdR4WfVWdEfzEmw== 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=QGmXhtV3MQfoNun2JGYQ1LqZnYO26iBVFiBRk2tCU3w=; b=gLDiNj/MAxMI59RslZ6WZ3w2UdMObCzd5FTwkappP8SZOQ9zNECbkddwIHWSn3R/skHJlTn/ZRUNXpvQHs5HERbNTyzkNQ7d1LSBxlL+o6JZPqVS+65w/y5asZBdhdj1PGFKGTqNBg5xsYaLNcCU0VbfZVrfwqCb/6hIsx6adRQQszF0v3mzeNevd+jeMfIpNPQbciieRbD4ouTGTTUxiUHt7hZCuHXMjMKbwGW5EEEoYiL7XjzZ/5Luy7yxP0CxDyGZBpM0HK1ctwApweUSE0x813J0OyQBzK66rj7H3c50dfv6DsPGsLNhNdW6IyXu2BFEFRmSqpZW5CgzdSrtSg== 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=QGmXhtV3MQfoNun2JGYQ1LqZnYO26iBVFiBRk2tCU3w=; b=IOdCzG89hcG8ODHNb60c6LqrnqQvCUCErutgPJ2VSnRmtkNpaMn6j2TlSR9ZP+XGIPhOWl8g1WAoS9LXDm3Ipm68jJw8wKKKyNLjb6Iz/8muSUm1T5ciot/hkHd5zMsR5nrTbZET5Psvb5mI5VBUfIeVRz066DGadc6lH0pn9fE= Received: from CH0PR03CA0277.namprd03.prod.outlook.com (2603:10b6:610:e6::12) by MW4PR12MB7440.namprd12.prod.outlook.com (2603:10b6:303:223::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Thu, 3 Dec 2026 10:49:20 +0000 Received: from BN3PEPF0000B36F.namprd21.prod.outlook.com (2603:10b6:610:e6::4) by CH0PR03CA0277.outlook.office365.com (2603:10b6:610:e6::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.12 via Frontend Transport; Thu, 3 Dec 2026 10:49:17 +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 BN3PEPF0000B36F.mail.protection.outlook.com (10.167.243.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.2 via Frontend Transport; Thu, 3 Dec 2026 10:49:17 +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; Thu, 3 Dec 2026 04:49:17 -0600 Received: from [192.168.88.7] (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.57 via Frontend Transport; Thu, 3 Dec 2026 04:49:13 -0600 Message-ID: <896e1333-9407-4028-b188-160dd40f0c3e@amd.com> Date: Thu, 3 Dec 2026 16:19:12 +0530 X-Mailing-List: linux-coco@lists.linux.dev 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: "Nikunj A. Dadhania" In-Reply-To: <4f8dc645aafd49c65dfa5456f097b4d3122862e4.1796158168.git.ashish.kalra@amd.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B36F:EE_|MW4PR12MB7440:EE_ X-MS-Office365-Filtering-Correlation-Id: 366a67a0-2f48-48c9-6247-08df512b1453 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|1800799024|36860700016|23010399003|11063799006|22082099003|18002099003|3023799007|261026140227099003|56012099006|10067099003|261021121427099003|261026121527099003|261028144727099003|261022105027099003|261102123227099003|261021123027099003|261022075727099003; X-Microsoft-Antispam-Message-Info: 7qKWC0FTRGnFBj0XTf09QkQDOCddnnW1Adw4BduEIdQ4ShS3jkqMzIxP843cPJ/SLr/Q6NoOH7L43YHIB+B5X37swqNeP5uR6PY0qEnLp4tBr1H64HT1IKEmIS7yz/dwtKm90VBwzJbrbooSMAB9PBZ+wTx/w71gCt+fx5mFUx7FfwnVxoOWKRwVQCtoLuOjo6fotQ3qzaYJyxtxrJVqGqPg8IDTWtqIgmeJTQcNbgZbZt2emwGyKTRjR5cBaAPoWUj9NLNYB5tBJHtLVwEEDsdAS9ygPHtOEIF0W3Gd2fLA6ip1VN2tAcb0AcDDAlRPfDSKkr4d+ykNtAi9rp+eQzfNrYx7EwFf+VUx26htUuPJzsctjWlu9zjuUh66hEgpDrQdRApEchYXkjEr/hEu5dF3AMEGeiV5ucxcan4rYC3zbGvYR2+RtQZ4JGVCG9sBMuaZi9eaDCGnaiRZw+DKhYpOm3WGaelpwqe/UJeHf1k+BdOWmYDsep+4uHUhrBmcUZSebji2djFNA3UAYfXWrE9+S/U5INUpYUTmqPE8nk9fKWS04dH7LfuNLfMPpF0w9piRFwbhqnDLyMNbRp6bZ1RKacF4ZcJv2Wf4pnd5XgfhoN4H5ZH08rvsCYTKLNgHiCQhhTzzweRnxPmSPs5MN/cxZUw4eIb6P2EC3Z33faYF9ZCCoQeK6YAbVmj+PZO5haV9lZ68Ez3aCWXH3pkBfA== 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)(82310400026)(376014)(1800799024)(36860700016)(23010399003)(11063799006)(22082099003)(18002099003)(3023799007)(261026140227099003)(56012099006)(10067099003)(261021121427099003)(261026121527099003)(261028144727099003)(261022105027099003)(261102123227099003)(261021123027099003)(261022075727099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FwJl7w7b38/VXPBNTKGKFld6Lpb1sTktrwQZS1BdXH7WtI4yuaPvmr2oMgzFfs4pZhVYsOQGrQ20VrqCVi9akCe22Hp35Pj2+Vd1UWq7+EScQmeCi09eqfK2s8nehcArOHmsLgrwc2M/Xr7SbjgDobeiG1Ga1AxVlsXBEVlpWBJEyv04PoSU4fzeWFqsCbiYMwi+TiBty/O7gVQSnJmb8O1RI3g463OBJAXykS9+SOFQCK93p3NPaSI1YBhiZl5GJ5nEo7db2E1adRuCROHhPqd6O7q3LCcqpIwaO7Mm56LCffO/RkiV3w1BUT9mRJ6Vzhz+YmwSFqFZtXDHmLyUsArMfesPeXo0pn89CPCaoIcgwsccQtRA5bhFQXxW8ZK18DIWKaj77PBpreLugiHuctzAWNikMKHkx+FW20xJe6EIFC9r+dplaEupIJuJzMtN X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2026 10:49:17.5966 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 366a67a0-2f48-48c9-6247-08df512b1453 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: BN3PEPF0000B36F.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7440 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 Tested SEV-SNP guest with this patch, kexec kernel boots fine and the DR7 write is handled locally. I also built a test kernel that does an RDMSR after the GHCBs are torn down. The guest terminates with 0x1:0xd (GHCB_TERM_VC_NO_GHCB), as intended. Reviewed-by: Nikunj A Dadhania nikunj@amd.com Tested-by: Nikunj A Dadhania nikunj@amd.com