Re: [PATCH v4 13/17] kvm: i8254: Deactivate APICv when using in-kernel PIT re-injection mode.

From: Roman Kagan
Date: Tue Nov 12 2019 - 07:23:04 EST


On Mon, Nov 11, 2019 at 11:37:53AM -0600, Suravee Suthikulpanit wrote:
> On 11/5/2019 4:47 PM, Paolo Bonzini wrote:
> > On 05/11/19 00:17, Roman Kagan wrote:
> > > > This is not too nice for Intel which does support (through the EOI exit
> > > > mask) APICv even if PIT reinjection active.
> > > Hmm, it's tempting to just make svm_load_eoi_exitmap() disable AVIC when
> > > given a non-empty eoi_exit_bitmap, and enable it back on a clear
> > > eoi_exit_bitmap. This may remove the need to add special treatment to
> > > PIT etc.
> >
> > That is a very nice idea---we can make that a single disable reason,
> > like APICV_DEACTIVATE_REASON_EOI, and Intel can simply never use it.
>
> I took at look at the svm_load_eoi_exitmap() and it is called via:
> kvm_make_scan_ioapic_request() ->
> KVM_REQ_SCAN_IOAPIC -> vcpu_scan_ioapic() ->
> KVM_REQ_LOAD_EOI_EXITMAP -> vcpu_load_eoi_exitmap()
>
> The kvm_make_scan_ioapic_request() is called from multiple places:
>
> arch/x86/kvm/irq_comm.c:
> * kvm_arch_post_irq_routing_update() : Called from kvm_set_irq_routing()
>
> arch/x86/kvm/ioapic.c:
> * kvm_arch_post_irq_ack_notifier_list_update() : (Un)registering irq ack notifier
> * kvm_set_ioapic() : Setting ioapic irqchip
> * ioapic_mmio_write() -> ioapic_write_indirect()
>
> arch/x86/kvm/lapic.c:
> * recalculate_apic_map()
>
> Most calls would be from ioapic_mmio_write()->ioapic_write_indirect().
>
> In case of AMD AVIC, the svm_load_e::vsoi_exitmap() is called several times, and requesting
> APICV (de)activate from here when the eoi_exit_bitmap is set/clear would introduce
> large overhead especially with SMP machine.

This doesn't look like a hot path, so I'm not sure it needs to be
optimized for performance. Especially so since
kvm_make_scan_ioapic_request does kvm_make_all_cpus_request which isn't
particularly fast by definition, and I guess the extra overhead there
won't be noticable.

OTOH introducing extra code paths has its maintenance costs, so sticking
the simple logic in svm_load_eoi_exitmap looks attractive.

Just my 2c,
Roman.