Skip to content

Commit 44428e4

Browse files
Binbin Wubonzini
authored andcommitted
KVM: x86: Move pv_unhalted check out of kvm_vcpu_has_events()
Move pv_unhalted check out of kvm_vcpu_has_events(), check pv_unhalted explicitly when handling PV unhalt and expose kvm_vcpu_has_events(). kvm_vcpu_has_events() returns true if pv_unhalted is set, and pv_unhalted is only cleared on transitions to KVM_MP_STATE_RUNNABLE. If the guest initiates a spurious wakeup, pv_unhalted could be left set in perpetuity. Currently, this is not problematic because kvm_vcpu_has_events() is only called when handling PV unhalt. However, if kvm_vcpu_has_events() is used for other purposes in the future, it could return the unexpected results. Export kvm_vcpu_has_events() for its usage in broader contexts. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Message-ID: <20250222014225.897298-3-binbin.wu@linux.intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 6162b37 commit 44428e4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

arch/x86/kvm/x86.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11143,7 +11143,7 @@ static bool kvm_vcpu_running(struct kvm_vcpu *vcpu)
1114311143
!vcpu->arch.apf.halted);
1114411144
}
1114511145

11146-
static bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu)
11146+
bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu)
1114711147
{
1114811148
if (!list_empty_careful(&vcpu->async_pf.done))
1114911149
return true;
@@ -11152,9 +11152,6 @@ static bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu)
1115211152
kvm_apic_init_sipi_allowed(vcpu))
1115311153
return true;
1115411154

11155-
if (vcpu->arch.pv.pv_unhalted)
11156-
return true;
11157-
1115811155
if (kvm_is_exception_pending(vcpu))
1115911156
return true;
1116011157

@@ -11192,10 +11189,12 @@ static bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu)
1119211189

1119311190
return false;
1119411191
}
11192+
EXPORT_SYMBOL_GPL(kvm_vcpu_has_events);
1119511193

1119611194
int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
1119711195
{
11198-
return kvm_vcpu_running(vcpu) || kvm_vcpu_has_events(vcpu);
11196+
return kvm_vcpu_running(vcpu) || vcpu->arch.pv.pv_unhalted ||
11197+
kvm_vcpu_has_events(vcpu);
1119911198
}
1120011199

1120111200
/* Called within kvm->srcu read side. */
@@ -11331,7 +11330,7 @@ static int __kvm_emulate_halt(struct kvm_vcpu *vcpu, int state, int reason)
1133111330
*/
1133211331
++vcpu->stat.halt_exits;
1133311332
if (lapic_in_kernel(vcpu)) {
11334-
if (kvm_vcpu_has_events(vcpu))
11333+
if (kvm_vcpu_has_events(vcpu) || vcpu->arch.pv.pv_unhalted)
1133511334
vcpu->arch.pv.pv_unhalted = false;
1133611335
else
1133711336
vcpu->arch.mp_state = state;

include/linux/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,7 @@ void kvm_arch_disable_virtualization(void);
16091609
int kvm_arch_enable_virtualization_cpu(void);
16101610
void kvm_arch_disable_virtualization_cpu(void);
16111611
#endif
1612+
bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu);
16121613
int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
16131614
bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu);
16141615
int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu);

0 commit comments

Comments
 (0)