[PATCH v2 4/9] KVM: mips, x86: do not rely on KVM_REQ_UNHALT

From: Paolo Bonzini
Date: Thu Aug 11 2022 - 17:06:55 EST


KVM_REQ_UNHALT is now available as the return value from kvm_vcpu_halt
or kvm_vcpu_block, so the request can be simply cleared just like all
other architectures do.

No functional change intended.

Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
arch/mips/kvm/emulate.c | 8 ++++----
arch/x86/kvm/x86.c | 8 +++++---
2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index b494d8d39290..77d760d45c48 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -944,6 +944,7 @@ enum hrtimer_restart kvm_mips_count_timeout(struct kvm_vcpu *vcpu)

enum emulation_result kvm_mips_emul_wait(struct kvm_vcpu *vcpu)
{
+ int r;
kvm_debug("[%#lx] !!!WAIT!!! (%#lx)\n", vcpu->arch.pc,
vcpu->arch.pending_exceptions);

@@ -952,16 +953,15 @@ enum emulation_result kvm_mips_emul_wait(struct kvm_vcpu *vcpu)
if (!vcpu->arch.pending_exceptions) {
kvm_vz_lose_htimer(vcpu);
vcpu->arch.wait = 1;
- kvm_vcpu_halt(vcpu);
+ r = kvm_vcpu_halt(vcpu);

/*
* We we are runnable, then definitely go off to user space to
* check if any I/O interrupts are pending.
*/
- if (kvm_check_request(KVM_REQ_UNHALT, vcpu)) {
- kvm_clear_request(KVM_REQ_UNHALT, vcpu);
+ kvm_clear_request(KVM_REQ_UNHALT, vcpu);
+ if (r > 0)
vcpu->run->exit_reason = KVM_EXIT_IRQ_WINDOW_OPEN;
- }
}

return EMULATE_DONE;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index c44348bb6ef2..416df0fc7fda 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10611,6 +10611,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
static inline int vcpu_block(struct kvm_vcpu *vcpu)
{
bool hv_timer;
+ int r;

if (!kvm_arch_vcpu_runnable(vcpu)) {
/*
@@ -10626,15 +10627,16 @@ static inline int vcpu_block(struct kvm_vcpu *vcpu)

kvm_vcpu_srcu_read_unlock(vcpu);
if (vcpu->arch.mp_state == KVM_MP_STATE_HALTED)
- kvm_vcpu_halt(vcpu);
+ r = kvm_vcpu_halt(vcpu);
else
- kvm_vcpu_block(vcpu);
+ r = kvm_vcpu_block(vcpu);
kvm_vcpu_srcu_read_lock(vcpu);

if (hv_timer)
kvm_lapic_switch_to_hv_timer(vcpu);

- if (!kvm_check_request(KVM_REQ_UNHALT, vcpu))
+ kvm_clear_request(KVM_REQ_UNHALT, vcpu);
+ if (r <= 0)
return 1;
}

--
2.31.1