Re: [PATCH v3 0/7] KVM: x86: never write to memory from kvm_vcpu_check_block

From: Sean Christopherson
Date: Fri Sep 16 2022 - 21:03:09 EST


On Thu, Sep 08, 2022, Sean Christopherson wrote:
> On Mon, Aug 22, 2022, Paolo Bonzini wrote:
> > The following backtrace:
> > Paolo Bonzini (6):
> > KVM: x86: check validity of argument to KVM_SET_MP_STATE
>
> Skipping this one since it's already in 6.0 and AFAICT isn't strictly necessary
> for the rest of the series (shouldn't matter anyways?).
>
> > KVM: x86: make vendor code check for all nested events
> > KVM: x86: lapic does not have to process INIT if it is blocked
> > KVM: x86: never write to memory from kvm_vcpu_check_block
> > KVM: mips, x86: do not rely on KVM_REQ_UNHALT
> > KVM: remove KVM_REQ_UNHALT
> >
> > Sean Christopherson (1):
> > KVM: nVMX: Make an event request when pending an MTF nested VM-Exit
>
> Pushed to branch `for_paolo/6.1` at:
>
> https://github.com/sean-jc/linux.git
>
> with a cosmetic cleanup to kvm_apic_has_events() and the MTF migration fix squashed
> in.

Oh the irony about complaining that people waste maintainers' time by not running
existing tests :-) I suppose it's not technically ironic since I was the one doing
the actual complaining, but it's still hilarious.

The eponymous patch breaks handling of INITs (and SIPIs) that are "latched"[1]
and later become unblocked, e.g. due to entering VMX non-root mode or because SVM's
GIF is set. vmx_init_signal_test fails because KVM fails to re-evaluate pending
events after entering guest/non-root. It passes now because KVM always checks
nested events in the outer run loop.

I have fixes, I'll (temporarily) drop this from the queue and post a new version of
this series on Monday. As a reward to myself for bisecting and debugging, I'm going
to tweak "KVM: x86: lapic does not have to process INIT if it is blocked" to incorporate
my suggestions[2] from v2 so that the VMX and SVM code can check only for pending
INIT/SIPI and not include the blocking check to align with related checks that also
trigger KVM_REQ_EVENT (and because the resulting SVM GIF code would be quite fragile
if the blocking were incorporated).

[1] It annoys me to no end that KVM uses different terminology for INIT/SIPI versus
everything else.
[2] https://lore.kernel.org/all/YvwxJzHC5xYnc7CJ@xxxxxxxxxx