Re: [PATCH] x86/sev: Skip DR7 write during kexec when it would trigger an unserviceable #VC
From: Pankaj Gupta
Date: Fri Nov 13 2026 - 10:49:40 EST
> 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.
>
> Skip the DR7 write in this case. Its value is not needed across kexec
> because the new kernel re-initializes DR7. Guests with DebugSwap enabled
> context-switch DR7 in hardware and do not intercept the write, and
> non-encrypted guests are unaffected, so both continue to call
> hw_breakpoint_disable() as before.
>
> Add a CC_ATTR_GUEST_DEBUG_VIRT confidential-computing attribute, so the
> debug-register-virtualization state (AMD DebugSwap) is queried through
> cc_platform_has().
>
> Reported-by: Srikanth Aithal <Srikanth.Aithal@xxxxxxx>
> Suggested-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
> Fixes: 3074152e56c9 ("x86/sev: Convert shared memory back to private on kexec")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Ashish Kalra <ashish.kalra@xxxxxxx>
> Reviewed-by: Nikunj A Dadhania <nikunj@xxxxxxx>
> Reviewed-by: Tom Lendacky <thomas.lendacky@xxxxxxx>
> Tested-by: Srikanth Aithal <Srikanth.Aithal@xxxxxxx>
I stumbled upon this issue while testing kexec on SNP on 7.4rc2.
I confirm this patch fixes issue for me.
Reviewed-by: Pankaj Gupta <pankaj.gupta@xxxxxxx>
Tested-by: Pankaj Gupta <pankaj.gupta@xxxxxxx>
Best regards,
Pankaj