Re: [PART1 RFC v4 07/11] svm: Add interrupt injection via AVIC

From: Radim KrÄmÃÅ
Date: Mon Apr 11 2016 - 16:52:12 EST


2016-04-07 03:20-0500, Suravee Suthikulpanit:
> This patch introduces a new mechanism to inject interrupt using AVIC.
> Since VINTR is not supported when enable AVIC, we need to inject
> interrupt via APIC backing page instead.
>
> This patch also adds support for AVIC doorbell, which is used by
> KVM to signal a running vcpu to check IRR for injected interrupts.
>
> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx>
> ---
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> @@ -216,6 +218,8 @@ static bool npt_enabled = true;
> +static struct kvm_x86_ops svm_x86_ops;
> @@ -963,6 +979,8 @@ static __init int svm_hardware_setup(void)
>
> if (avic) {
> printk(KERN_INFO "kvm: AVIC enabled\n");
> + } else {
> + svm_x86_ops.deliver_posted_interrupt = NULL;

(No need to NULL this. deliver_posted_interrupt cannot be used to
determine whether avic is should be used, so we can keep it !NULL.
Declaration of svm_x86_ops can be omitted then.)

> @@ -2883,8 +2901,10 @@ static int clgi_interception(struct vcpu_svm *svm)
> disable_gif(svm);
>
> /* After a CLGI no interrupts should come */
> - svm_clear_vintr(svm);
> - svm->vmcb->control.int_ctl &= ~V_IRQ_MASK;
> + if (!svm_vcpu_avic_enabled(svm)) {
> + svm_clear_vintr(svm);
> + svm->vmcb->control.int_ctl &= ~V_IRQ_MASK;
> + }
>
> mark_dirty(svm->vmcb, VMCB_INTR);

mark_dirty also belongs to the if, because avic doesn't touch vmcb.

> @@ -3854,6 +3875,20 @@ static void svm_sync_pir_to_irr(struct kvm_vcpu *vcpu)
> +static void svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec)
> +{
> + struct vcpu_svm *svm = to_svm(vcpu);
> +
> + kvm_lapic_set_irr(vec, svm->vcpu.arch.apic);

(vcpu->arch.apic would work too. ;])