Skip to content

Commit f7f39c5

Browse files
committed
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: 404d5d7 ("KVM: X86: Introduce more exit_fastpath_completion enum values") Link: https://lore.kernel.org/r/20240802195120.325560-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent ea60229 commit f7f39c5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ enum exit_fastpath_completion {
211211
EXIT_FASTPATH_NONE,
212212
EXIT_FASTPATH_REENTER_GUEST,
213213
EXIT_FASTPATH_EXIT_HANDLED,
214+
EXIT_FASTPATH_EXIT_USERSPACE,
214215
};
215216
typedef enum exit_fastpath_completion fastpath_t;
216217

arch/x86/kvm/x86.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,8 +2206,10 @@ fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu)
22062206
}
22072207

22082208
if (handled) {
2209-
kvm_skip_emulated_instruction(vcpu);
2210-
ret = EXIT_FASTPATH_REENTER_GUEST;
2209+
if (!kvm_skip_emulated_instruction(vcpu))
2210+
ret = EXIT_FASTPATH_EXIT_USERSPACE;
2211+
else
2212+
ret = EXIT_FASTPATH_REENTER_GUEST;
22112213
trace_kvm_msr_write(msr, data);
22122214
} else {
22132215
ret = EXIT_FASTPATH_NONE;
@@ -11196,6 +11198,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
1119611198
if (vcpu->arch.apic_attention)
1119711199
kvm_lapic_sync_from_vapic(vcpu);
1119811200

11201+
if (unlikely(exit_fastpath == EXIT_FASTPATH_EXIT_USERSPACE))
11202+
return 0;
11203+
1119911204
r = kvm_x86_call(handle_exit)(vcpu, exit_fastpath);
1120011205
return r;
1120111206

0 commit comments

Comments
 (0)