Commit f7f39c50 authored by Sean Christopherson's avatar Sean Christopherson
Browse files

KVM: x86: Exit to userspace if fastpath triggers one on instruction skip

Exit to userspace if a fastpath handler triggers such an exit, which can
happen when skipping the instruction, e.g. due to userspace
single-stepping the guest via KVM_GUESTDBG_SINGLESTEP or because of an
emulation failure.

Fixes: 404d5d7b ("KVM: X86: Introduce more exit_fastpath_completion enum values")
Link: https://lore.kernel.org/r/20240802195120.325560-4-seanjc@google.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent ea60229a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -211,6 +211,7 @@ enum exit_fastpath_completion {
	EXIT_FASTPATH_NONE,
	EXIT_FASTPATH_REENTER_GUEST,
	EXIT_FASTPATH_EXIT_HANDLED,
	EXIT_FASTPATH_EXIT_USERSPACE,
};
typedef enum exit_fastpath_completion fastpath_t;

+7 −2
Original line number Diff line number Diff line
@@ -2206,7 +2206,9 @@ fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu)
	}

	if (handled) {
		kvm_skip_emulated_instruction(vcpu);
		if (!kvm_skip_emulated_instruction(vcpu))
			ret = EXIT_FASTPATH_EXIT_USERSPACE;
		else
			ret = EXIT_FASTPATH_REENTER_GUEST;
		trace_kvm_msr_write(msr, data);
	} else {
@@ -11196,6 +11198,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
	if (vcpu->arch.apic_attention)
		kvm_lapic_sync_from_vapic(vcpu);

	if (unlikely(exit_fastpath == EXIT_FASTPATH_EXIT_USERSPACE))
		return 0;

	r = kvm_x86_call(handle_exit)(vcpu, exit_fastpath);
	return r;