[PATCH v4 0/6] KVM: nVMX: Synthesize SHUTDOWN on RSM with bad state
From: Sean Christopherson
Date: Mon Jul 27 2026 - 20:44:26 EST
Synthesize SHUTDOWN if invalid guest state is detected a RSM, i.e. if SMRAM
is clobbered by L1 (or host userspace) while handling an SMI that occurred
while L2 was active. This fixes yet another case of syzkaller tripping KVM's
sanity check that KVM doesn't cancel a pending nested VM-Enter.
Hao, can you provide your Signed-off-by for the selftest, assuming it looks
good to you? Thanks!
v4:
- Synthesize SHUTDOWN instead of trying to suppress the KVM_BUG_ON().
- Add a selftest.
v3:
- https://lore.kernel.org/all/al8M4gCwsWXS_jMs@192.168.1.215
- Retain KVM_NESTED_RUN_PENDING_UNTRUSTED until after
sync_vmcs02_to_vmcs12(), to avoid saving VMCS12 fields that are valid
only after L2 has actually run.
- Clear the untrusted pending state before restoring L1 state to avoid
leaking nested_run_pending into L1 and blocking event injection.
- Clarify the VMX pending-run BUG comment and update the changelog.
- Tested with the syzkaller repro on the fixed kernel, no WARNING/KVM_BUG
in the repro log
v2:
- https://lore.kernel.org/all/al8M4gCwsWXS_jMs@192.168.1.215
- Mark nested state restored by RSM from SMRAM as KVM_NESTED_RUN_PENDING_UNTRUSTED.
- Keep the BUG check in __vmx_handle_exit(), but make it apply only to KVM_NESTED_RUN_PENDING.
v1: https://lore.kernel.org/all/al3Qbq-jUYE-_72N@192.168.1.215
Hao Zhang (1):
KVM: selftests: Extend the invalid nVMX guest state test to cover RSM
Sean Christopherson (5):
KVM: x86: Extract VMX's unhandleable emulation check to common x86
KVM: nVMX: Synthesize SHUTDOWN on RSM if L2 requires emulation
KVM: x86: Rework kvm_x86_ops.vcpu_pre_run() into
.vcpu_needs_initialization()
KVM: selftests: Use port 0x80 in invalid nVMX guest state test
KVM: selftests: Refactor invalid nVMX state test to prepare for RSM
testcase
arch/x86/include/asm/kvm-x86-ops.h | 3 +-
arch/x86/include/asm/kvm_host.h | 4 +-
arch/x86/kvm/smm.c | 4 +
arch/x86/kvm/svm/sev.c | 5 +
arch/x86/kvm/svm/svm.c | 12 +-
arch/x86/kvm/svm/svm.h | 1 +
arch/x86/kvm/vmx/main.c | 21 +++-
arch/x86/kvm/vmx/tdx.c | 9 +-
arch/x86/kvm/vmx/vmx.c | 12 +-
arch/x86/kvm/vmx/x86_ops.h | 4 +-
arch/x86/kvm/x86.c | 10 +-
.../kvm/x86/vmx_invalid_nested_guest_state.c | 118 ++++++++++++++----
12 files changed, 143 insertions(+), 60 deletions(-)
base-commit: 271255273d5ff348fe29d89fe4712b2f7f7907c3
--
2.55.0.229.g6434b31f56-goog