Re: [PATCH v2 2/3] KVM: TDX: Fix the exit reason handling

From: Sean Christopherson

Date: Tue Aug 11 2026 - 14:09:21 EST


On Tue, Aug 11, 2026, Xiaoyao Li wrote:
> On 8/11/2026 8:03 AM, Sean Christopherson wrote:
> > The shortlog is way too generic, and the changelog is light on details. Over
> > the weekend, I managed to forget why this was necessary, and it took me a few
> > seconds to recall why we need to avoid setting bits 31:16. Of course, one could
> > argue that says as much about me as it does the shortlog+changelog...
> >
> > Oh, and shortlogs like "Fix the exit reason handling" sometimes lead to amusing
> > follow-ups like "Really fix the exit reason handling". Don't be that person :-)
> >
> > Something like:
> >
> > KVM: TDX: Don't clobber exit_reason[31:16] when TDX-Module didn't try VM-Entry
>
> 1. It's not only about clobbering the exit_reason[31:16], but also about how
> to interpret the basic exit, e.g.. the change
>
> - switch (exit_reason) {
> + switch (exit_reason.basic) {

But the current TDX code doesn't care. The switch in tdx_to_vmx_exit_reason()
operates on the raw vp_enter_ret value, not a synthesized/clobbered exit reason.

And the switch in tdx_handle_exit() isn't reachable for the clobbering case
thanks to this check.

if (unlikely(vp_enter_ret == EXIT_REASON_EPT_MISCONFIG)) {
KVM_BUG_ON(1, vcpu->kvm);
return -EIO;
}

I agree that not clobbering exit_reason[31:16] is useful for additional cleanups,
but that isn't the main motiviation for the patch. The precision matters, because
it changes this patch from a "nice to have cleanup" to "this is 100% mandatory to
enable Instruction Timeout VM-Exits on TDX".

> 2. It's not only about TDX module doesn't try VM entry, bus also about a
> valid VM exit after successful VM entry. This patch also preserves the
> exit_reason[31:16] for a valid VM exit. (One could argue that existing code
> cannot clobber exit_reason[31;16] because the code to clobber it requires
> the [31:16] to be 0, because of switch (exit_reason))
>
> 3. For the case where TDX module doesn't try VM-Entry, I'm not sure if
> "clobber" is the correct word. There is no valid exit reason, so nothing to
> be really clobbered. Just don't synthesize a exit reason with non-zero bit
> 31:16.
>
> My intent was just using one patch to handle them all, so as to make KVM
> behave correctly after enabling Bus Lock VM exit for TDX in the next patch.
> Because they are targeted for stable kernels.
>
> What's your advice then? What do you think of spliting it into multiple so
> that it's easier to write a shortlog and changelog for each one.

Heh, my advice is pretty much always the same: when in doubt, split. Squashing
patches together is trivial, disentangling changes after the fact is not.