Re: [PATCH v2] x86/sev: Skip DR7 write during kexec when it would trigger an unserviceable #VC
From: Nikunj A. Dadhania
Date: Tue Nov 24 2026 - 03:56:11 EST
Hi Boris,
On 11/24/2026 5:13 AM, Borislav Petkov wrote:
> On Mon, Nov 16, 2026 at 11:03:35PM +0000, Ashish Kalra wrote:
>> From: Ashish Kalra <ashish.kalra@xxxxxxx>
>>
>> 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 must be
>> 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 and set boot_ghcb to NULL, tearing down the
>> GHCB infrastructure. The DR7 write therefore raises a #VC that
>> dereferences a NULL GHCB pointer, causing a page fault and the kexec to
>> fail.
>>
>> The NULL boot_ghcb pointer is a result of commit 3645eb7e3915 ("x86/fred:
>> Fix early boot failures on SEV-ES/SNP guests"): that change makes
>> __sev_get_ghcb() return the now-NULL boot_ghcb in this window, turning
>> the previously-benign teardown-window #VC (a bogus VMGEXIT the host
>> rejected but survived) into a NULL dereference.
>
> So, before that patch from Nikunj, __sev_get_ghcb() would return the per-CPU
> GHCBs which are not initialized. That was fine for the kexec case - I don't
> understand the bogus VMGEXIT thing - but apparently it worked there.
Before 3645eb7e3915, the DR7 write during kexec was silently dropped by the
hypervisor because the GHCB had already been converted back to private. The
guest did not notice and carried on, so kexec only worked because nothing
depended on that write.
Regards,
Nikunj