Skip to content

Commit e3e64fd

Browse files
committed
KVM: x86: Track required APICv inhibits with variable, not callback
jira LE-1907 Rebuild_History Non-Buildable kernel-5.14.0-284.30.1.el9_2 commit-author Sean Christopherson <seanjc@google.com> commit b3f257a Track the per-vendor required APICv inhibits with a variable instead of calling into vendor code every time KVM wants to query the set of required inhibits. The required inhibits are a property of the vendor's virtualization architecture, i.e. are 100% static. Using a variable allows the compiler to inline the check, e.g. generate a single-uop TEST+Jcc, and thus eliminates any desire to avoid checking inhibits for performance reasons. No functional change intended. Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20230106011306.85230-32-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> (cherry picked from commit b3f257a) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 4429822 commit e3e64fd

File tree

7 files changed

+29
-36
lines changed

7 files changed

+29
-36
lines changed

arch/x86/include/asm/kvm-x86-ops.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ KVM_X86_OP(set_nmi_mask)
7676
KVM_X86_OP(enable_nmi_window)
7777
KVM_X86_OP(enable_irq_window)
7878
KVM_X86_OP_OPTIONAL(update_cr8_intercept)
79-
KVM_X86_OP(check_apicv_inhibit_reasons)
8079
KVM_X86_OP(refresh_apicv_exec_ctrl)
8180
KVM_X86_OP_OPTIONAL(hwapic_irr_update)
8281
KVM_X86_OP_OPTIONAL(hwapic_isr_update)

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,7 @@ struct kvm_x86_ops {
15591559
void (*enable_irq_window)(struct kvm_vcpu *vcpu);
15601560
void (*update_cr8_intercept)(struct kvm_vcpu *vcpu, int tpr, int irr);
15611561
bool (*check_apicv_inhibit_reasons)(enum kvm_apicv_inhibit reason);
1562+
const unsigned long required_apicv_inhibits;
15621563
bool allow_apicv_in_x2apic_without_x2apic_virtualization;
15631564
void (*refresh_apicv_exec_ctrl)(struct kvm_vcpu *vcpu);
15641565
void (*hwapic_irr_update)(struct kvm_vcpu *vcpu, int max_irr);

arch/x86/kvm/svm/avic.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -963,25 +963,6 @@ int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq,
963963
return ret;
964964
}
965965

966-
bool avic_check_apicv_inhibit_reasons(enum kvm_apicv_inhibit reason)
967-
{
968-
ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) |
969-
BIT(APICV_INHIBIT_REASON_ABSENT) |
970-
BIT(APICV_INHIBIT_REASON_HYPERV) |
971-
BIT(APICV_INHIBIT_REASON_NESTED) |
972-
BIT(APICV_INHIBIT_REASON_IRQWIN) |
973-
BIT(APICV_INHIBIT_REASON_PIT_REINJ) |
974-
BIT(APICV_INHIBIT_REASON_BLOCKIRQ) |
975-
BIT(APICV_INHIBIT_REASON_SEV) |
976-
BIT(APICV_INHIBIT_REASON_PHYSICAL_ID_ALIASED) |
977-
BIT(APICV_INHIBIT_REASON_APIC_ID_MODIFIED) |
978-
BIT(APICV_INHIBIT_REASON_APIC_BASE_MODIFIED) |
979-
BIT(APICV_INHIBIT_REASON_LOGICAL_ID_ALIASED);
980-
981-
return supported & BIT(reason);
982-
}
983-
984-
985966
static inline int
986967
avic_update_iommu_vcpu_affinity(struct kvm_vcpu *vcpu, int cpu, bool r)
987968
{

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4814,8 +4814,8 @@ static struct kvm_x86_ops svm_x86_ops __initdata = {
48144814
.update_cr8_intercept = svm_update_cr8_intercept,
48154815
.set_virtual_apic_mode = avic_refresh_virtual_apic_mode,
48164816
.refresh_apicv_exec_ctrl = avic_refresh_apicv_exec_ctrl,
4817-
.check_apicv_inhibit_reasons = avic_check_apicv_inhibit_reasons,
48184817
.apicv_post_state_restore = avic_apicv_post_state_restore,
4818+
.required_apicv_inhibits = AVIC_REQUIRED_APICV_INHIBITS,
48194819

48204820
.get_exit_info = svm_get_exit_info,
48214821

arch/x86/kvm/svm/svm.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,21 @@ void svm_switch_vmcb(struct vcpu_svm *svm, struct kvm_vmcb_info *target_vmcb);
619619
extern struct kvm_x86_nested_ops svm_nested_ops;
620620

621621
/* avic.c */
622+
#define AVIC_REQUIRED_APICV_INHIBITS \
623+
( \
624+
BIT(APICV_INHIBIT_REASON_DISABLE) | \
625+
BIT(APICV_INHIBIT_REASON_ABSENT) | \
626+
BIT(APICV_INHIBIT_REASON_HYPERV) | \
627+
BIT(APICV_INHIBIT_REASON_NESTED) | \
628+
BIT(APICV_INHIBIT_REASON_IRQWIN) | \
629+
BIT(APICV_INHIBIT_REASON_PIT_REINJ) | \
630+
BIT(APICV_INHIBIT_REASON_BLOCKIRQ) | \
631+
BIT(APICV_INHIBIT_REASON_SEV) | \
632+
BIT(APICV_INHIBIT_REASON_PHYSICAL_ID_ALIASED) | \
633+
BIT(APICV_INHIBIT_REASON_APIC_ID_MODIFIED) | \
634+
BIT(APICV_INHIBIT_REASON_APIC_BASE_MODIFIED) | \
635+
BIT(APICV_INHIBIT_REASON_LOGICAL_ID_ALIASED) \
636+
)
622637

623638
bool avic_hardware_setup(struct kvm_x86_ops *ops);
624639
int avic_ga_log_notifier(u32 ga_tag);
@@ -632,7 +647,6 @@ void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
632647
void avic_vcpu_put(struct kvm_vcpu *vcpu);
633648
void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu);
634649
void avic_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu);
635-
bool avic_check_apicv_inhibit_reasons(enum kvm_apicv_inhibit reason);
636650
int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq,
637651
uint32_t guest_irq, bool set);
638652
void avic_vcpu_blocking(struct kvm_vcpu *vcpu);

arch/x86/kvm/vmx/vmx.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7965,18 +7965,16 @@ static void vmx_hardware_unsetup(void)
79657965
free_kvm_area();
79667966
}
79677967

7968-
static bool vmx_check_apicv_inhibit_reasons(enum kvm_apicv_inhibit reason)
7969-
{
7970-
ulong supported = BIT(APICV_INHIBIT_REASON_DISABLE) |
7971-
BIT(APICV_INHIBIT_REASON_ABSENT) |
7972-
BIT(APICV_INHIBIT_REASON_HYPERV) |
7973-
BIT(APICV_INHIBIT_REASON_BLOCKIRQ) |
7974-
BIT(APICV_INHIBIT_REASON_PHYSICAL_ID_ALIASED) |
7975-
BIT(APICV_INHIBIT_REASON_APIC_ID_MODIFIED) |
7976-
BIT(APICV_INHIBIT_REASON_APIC_BASE_MODIFIED);
7977-
7978-
return supported & BIT(reason);
7979-
}
7968+
#define VMX_REQUIRED_APICV_INHIBITS \
7969+
( \
7970+
BIT(APICV_INHIBIT_REASON_DISABLE)| \
7971+
BIT(APICV_INHIBIT_REASON_ABSENT) | \
7972+
BIT(APICV_INHIBIT_REASON_HYPERV) | \
7973+
BIT(APICV_INHIBIT_REASON_BLOCKIRQ) | \
7974+
BIT(APICV_INHIBIT_REASON_PHYSICAL_ID_ALIASED) | \
7975+
BIT(APICV_INHIBIT_REASON_APIC_ID_MODIFIED) | \
7976+
BIT(APICV_INHIBIT_REASON_APIC_BASE_MODIFIED) \
7977+
)
79807978

79817979
static void vmx_vm_destroy(struct kvm *kvm)
79827980
{
@@ -8060,7 +8058,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata = {
80608058
.refresh_apicv_exec_ctrl = vmx_refresh_apicv_exec_ctrl,
80618059
.load_eoi_exitmap = vmx_load_eoi_exitmap,
80628060
.apicv_post_state_restore = vmx_apicv_post_state_restore,
8063-
.check_apicv_inhibit_reasons = vmx_check_apicv_inhibit_reasons,
8061+
.required_apicv_inhibits = VMX_REQUIRED_APICV_INHIBITS,
80648062
.hwapic_irr_update = vmx_hwapic_irr_update,
80658063
.hwapic_isr_update = vmx_hwapic_isr_update,
80668064
.guest_apic_has_interrupt = vmx_guest_apic_has_interrupt,

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9847,7 +9847,7 @@ void __kvm_set_or_clear_apicv_inhibit(struct kvm *kvm,
98479847

98489848
lockdep_assert_held_write(&kvm->arch.apicv_update_lock);
98499849

9850-
if (!static_call(kvm_x86_check_apicv_inhibit_reasons)(reason))
9850+
if (!(kvm_x86_ops.required_apicv_inhibits & BIT(reason)))
98519851
return;
98529852

98539853
old = new = kvm->arch.apicv_inhibit_reasons;

0 commit comments

Comments
 (0)