Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: x86: Suppress MMIO that is triggered during task switch emulation

Explicitly suppress userspace emulated MMIO exits that are triggered when
emulating a task switch as KVM doesn't support userspace MMIO during
complex (multi-step) emulation. Silently ignoring the exit request can
result in the WARN_ON_ONCE(vcpu->mmio_needed) firing if KVM exits to
userspace for some other reason prior to purging mmio_needed.

See commit 0dc902267cb3 ("KVM: x86: Suppress pending MMIO write exits if
emulator detects exception") for more details on KVM's limitations with
respect to emulated MMIO during complex emulator flows.

Reported-by: syzbot+2fb9f8ed752c01bc9a3f@syzkaller.appspotmail.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-ID: <20240712144841.1230591-1-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Sean Christopherson and committed by
Paolo Bonzini
2a1fc7dc 9fe17d2a

+7 -1
+7 -1
arch/x86/kvm/x86.c
··· 11800 11800 11801 11801 ret = emulator_task_switch(ctxt, tss_selector, idt_index, reason, 11802 11802 has_error_code, error_code); 11803 - if (ret) { 11803 + 11804 + /* 11805 + * Report an error userspace if MMIO is needed, as KVM doesn't support 11806 + * MMIO during a task switch (or any other complex operation). 11807 + */ 11808 + if (ret || vcpu->mmio_needed) { 11809 + vcpu->mmio_needed = false; 11804 11810 vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; 11805 11811 vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; 11806 11812 vcpu->run->internal.ndata = 0;