Skip to content

Commit b4eef9b

Browse files
TiejunChenbonzini
authored andcommitted
kvm: x86: vmx: NULL out hwapic_isr_update() in case of !enable_apicv
In most cases calling hwapic_isr_update(), we always check if kvm_apic_vid_enabled() == 1, but actually, kvm_apic_vid_enabled() -> kvm_x86_ops->vm_has_apicv() -> vmx_vm_has_apicv() or '0' in svm case -> return enable_apicv && irqchip_in_kernel(kvm) So its a little cost to recall vmx_vm_has_apicv() inside hwapic_isr_update(), here just NULL out hwapic_isr_update() in case of !enable_apicv inside hardware_setup() then make all related stuffs follow this. Note we don't check this under that condition of irqchip_in_kernel() since we should make sure definitely any caller don't work without in-kernel irqchip. Signed-off-by: Tiejun Chen <tiejun.chen@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 5ff22e7 commit b4eef9b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

arch/x86/kvm/lapic.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static inline void apic_set_isr(int vec, struct kvm_lapic *apic)
402402
* because the processor can modify ISR under the hood. Instead
403403
* just set SVI.
404404
*/
405-
if (unlikely(kvm_apic_vid_enabled(vcpu->kvm)))
405+
if (unlikely(kvm_x86_ops->hwapic_isr_update))
406406
kvm_x86_ops->hwapic_isr_update(vcpu->kvm, vec);
407407
else {
408408
++apic->isr_count;
@@ -450,7 +450,7 @@ static inline void apic_clear_isr(int vec, struct kvm_lapic *apic)
450450
* on the other hand isr_count and highest_isr_cache are unused
451451
* and must be left alone.
452452
*/
453-
if (unlikely(kvm_apic_vid_enabled(vcpu->kvm)))
453+
if (unlikely(kvm_x86_ops->hwapic_isr_update))
454454
kvm_x86_ops->hwapic_isr_update(vcpu->kvm,
455455
apic_find_highest_isr(apic));
456456
else {
@@ -1742,7 +1742,9 @@ void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu,
17421742
if (kvm_x86_ops->hwapic_irr_update)
17431743
kvm_x86_ops->hwapic_irr_update(vcpu,
17441744
apic_find_highest_irr(apic));
1745-
kvm_x86_ops->hwapic_isr_update(vcpu->kvm, apic_find_highest_isr(apic));
1745+
if (unlikely(kvm_x86_ops->hwapic_isr_update))
1746+
kvm_x86_ops->hwapic_isr_update(vcpu->kvm,
1747+
apic_find_highest_isr(apic));
17461748
kvm_make_request(KVM_REQ_EVENT, vcpu);
17471749
kvm_rtc_eoi_tracking_restore_one(vcpu);
17481750
}

arch/x86/kvm/vmx.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5895,6 +5895,7 @@ static __init int hardware_setup(void)
58955895
kvm_x86_ops->update_cr8_intercept = NULL;
58965896
else {
58975897
kvm_x86_ops->hwapic_irr_update = NULL;
5898+
kvm_x86_ops->hwapic_isr_update = NULL;
58985899
kvm_x86_ops->deliver_posted_interrupt = NULL;
58995900
kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
59005901
}
@@ -7478,9 +7479,6 @@ static void vmx_hwapic_isr_update(struct kvm *kvm, int isr)
74787479
u16 status;
74797480
u8 old;
74807481

7481-
if (!vmx_vm_has_apicv(kvm))
7482-
return;
7483-
74847482
if (isr == -1)
74857483
isr = 0;
74867484

0 commit comments

Comments
 (0)