Re: [PATCH v2] x86/sev: Skip DR7 write during kexec when it would trigger an unserviceable #VC

From: Borislav Petkov

Date: Thu Nov 26 2026 - 12:13:41 EST


On November 25, 2026 8:29:49 PM UTC, "Kalra, Ashish" <ashish.kalra@xxxxxxx> wrote:
>Hello Boris,
>
>On 11/24/2026 10:19 PM, Borislav Petkov wrote:
>> On Mon, Nov 23, 2026 at 06:22:09PM -0600, Kalra, Ashish wrote:
>>> On the "bogus VMGEXIT": before Nikunj's change, __sev_get_ghcb() returned
>>> the per-CPU GHCB, which snp_kexec_finish() had already converted back to
>>> private. The host mapped that GPA, read ciphertext (exit code 0) and
>>> returned GHCB_ERR_MISSING_INPUT, but couldn't write the result into the
>>> private page, so the guest saw its own stale contents, treated the call as
>>> successful and moved on. The DR7 write was simply dropped. It worked by
>>> accident.
>>
>> Oh lovely.
>>
>>> As for using do_vc_no_ghcb(): the GHCB MSR protocol requests are meant for
>>> specific guest-initiated operations (protocol negotiation, GHCB
>>> registration, page state changes, termination, etc.). The only one that
>>> corresponds to an intercepted instruction is CPUID, which is why
>>> do_vc_no_ghcb() handles only the CPUID exit code and terminates the guest
>>> for anything else. There's no MSR-protocol equivalent of a DR7 write, so the
>>> no-GHCB #VC handler can't handle it.
>>
>> Well, can you fashion something with VMEXIT_DR7_WRITE and a dummy GHCB MSR request
>> to the HV which is innocuous, just so that it can satisfy the flow?
>>
>
>We could issue a harmless MSR-protocol request and then skip the instruction, but the request wouldn't carry anything about the DR7 write. The hypervisor would end up in exactly the same state as if we just skipped it, so it would be an extra exit that doesn't actually communicate anything.
>

Which doesn't matter on the kexec path.

>So how about doing it in the #VC handler: once the GHCBs have been torn down, route the #VC to a GHCB-less path that decodes and skips DR7 accesses, completing them locally, and the kexec then proceeds normally. This is safe: without DebugSwap, KVM intercepts DR7 accesses and only tracks the value, it can't load it into the encrypted VMSA, and the kexec'ed kernel writes DR7 again in cpu_init() anyway. Any other #VC in that window, which can't be completed without the hypervisor, would terminate the guest with a specific reason code instead of dereferencing a NULL GHCB, so it gets caught explicitly rather than silently skipped.
>

Sure, that sounds fine too.

Thx.

--
Small device. Typos and formatting crap