mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 16:24:13 +08:00
KVM: x86: Rename and expose helper to detect if INIT/SIPI are allowed
Rename and invert kvm_vcpu_latch_init() to kvm_apic_init_sipi_allowed() so as to match the behavior of {interrupt,nmi,smi}_allowed(), and expose the helper so that it can be used by kvm_vcpu_has_events() to determine whether or not an INIT or SIPI is pending _and_ can be taken immediately. Opportunistically replaced usage of the "latch" terminology with "blocked" and/or "allowed", again to align with KVM's terminology used for all other event types. No functional change intended. Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20220921003201.1441511-4-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
2ea89c7f7f
commit
1b7a1b78d6
@ -3051,14 +3051,14 @@ int kvm_apic_accept_events(struct kvm_vcpu *vcpu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* INITs are latched while CPU is in specific states
|
* INITs are blocked while CPU is in specific states
|
||||||
* (SMM, VMX root mode, SVM with GIF=0).
|
* (SMM, VMX root mode, SVM with GIF=0).
|
||||||
* Because a CPU cannot be in these states immediately
|
* Because a CPU cannot be in these states immediately
|
||||||
* after it has processed an INIT signal (and thus in
|
* after it has processed an INIT signal (and thus in
|
||||||
* KVM_MP_STATE_INIT_RECEIVED state), just eat SIPIs
|
* KVM_MP_STATE_INIT_RECEIVED state), just eat SIPIs
|
||||||
* and leave the INIT pending.
|
* and leave the INIT pending.
|
||||||
*/
|
*/
|
||||||
if (kvm_vcpu_latch_init(vcpu)) {
|
if (!kvm_apic_init_sipi_allowed(vcpu)) {
|
||||||
WARN_ON_ONCE(vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED);
|
WARN_ON_ONCE(vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED);
|
||||||
if (test_bit(KVM_APIC_SIPI, &pe))
|
if (test_bit(KVM_APIC_SIPI, &pe))
|
||||||
clear_bit(KVM_APIC_SIPI, &apic->pending_events);
|
clear_bit(KVM_APIC_SIPI, &apic->pending_events);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <linux/kvm_host.h>
|
#include <linux/kvm_host.h>
|
||||||
|
|
||||||
#include "hyperv.h"
|
#include "hyperv.h"
|
||||||
|
#include "kvm_cache_regs.h"
|
||||||
|
|
||||||
#define KVM_APIC_INIT 0
|
#define KVM_APIC_INIT 0
|
||||||
#define KVM_APIC_SIPI 1
|
#define KVM_APIC_SIPI 1
|
||||||
@ -228,6 +229,12 @@ static inline bool kvm_apic_has_events(struct kvm_vcpu *vcpu)
|
|||||||
return lapic_in_kernel(vcpu) && vcpu->arch.apic->pending_events;
|
return lapic_in_kernel(vcpu) && vcpu->arch.apic->pending_events;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool kvm_apic_init_sipi_allowed(struct kvm_vcpu *vcpu)
|
||||||
|
{
|
||||||
|
return !is_smm(vcpu) &&
|
||||||
|
!static_call(kvm_x86_apic_init_signal_blocked)(vcpu);
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool kvm_lowest_prio_delivery(struct kvm_lapic_irq *irq)
|
static inline bool kvm_lowest_prio_delivery(struct kvm_lapic_irq *irq)
|
||||||
{
|
{
|
||||||
return (irq->delivery_mode == APIC_DM_LOWEST ||
|
return (irq->delivery_mode == APIC_DM_LOWEST ||
|
||||||
|
@ -11295,11 +11295,12 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* KVM_MP_STATE_INIT_RECEIVED means the processor is in
|
* Pending INITs are reported using KVM_SET_VCPU_EVENTS, disallow
|
||||||
* INIT state; latched init should be reported using
|
* forcing the guest into INIT/SIPI if those events are supposed to be
|
||||||
* KVM_SET_VCPU_EVENTS, so reject it here.
|
* blocked. KVM prioritizes SMI over INIT, so reject INIT/SIPI state
|
||||||
|
* if an SMI is pending as well.
|
||||||
*/
|
*/
|
||||||
if ((kvm_vcpu_latch_init(vcpu) || vcpu->arch.smi_pending) &&
|
if ((!kvm_apic_init_sipi_allowed(vcpu) || vcpu->arch.smi_pending) &&
|
||||||
(mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED ||
|
(mp_state->mp_state == KVM_MP_STATE_SIPI_RECEIVED ||
|
||||||
mp_state->mp_state == KVM_MP_STATE_INIT_RECEIVED))
|
mp_state->mp_state == KVM_MP_STATE_INIT_RECEIVED))
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -275,11 +275,6 @@ static inline bool kvm_check_has_quirk(struct kvm *kvm, u64 quirk)
|
|||||||
return !(kvm->arch.disabled_quirks & quirk);
|
return !(kvm->arch.disabled_quirks & quirk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool kvm_vcpu_latch_init(struct kvm_vcpu *vcpu)
|
|
||||||
{
|
|
||||||
return is_smm(vcpu) || static_call(kvm_x86_apic_init_signal_blocked)(vcpu);
|
|
||||||
}
|
|
||||||
|
|
||||||
void kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip);
|
void kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip);
|
||||||
|
|
||||||
u64 get_kvmclock_ns(struct kvm *kvm);
|
u64 get_kvmclock_ns(struct kvm *kvm);
|
||||||
|
Loading…
Reference in New Issue
Block a user