vDPA devices has dedicated backed hardware like
passthrough-ed devices. Then it is possible to setup irq
offloading to vCPU for vDPA devices. Thus this patch tries to
manipulated assigned device counters by
kvm_arch_start/end_assignment() in irqbypass manager, so that
assigned devices could be detected in update_pi_irte()

We will increase/decrease the assigned device counter in kvm/x86.
Both vDPA and VFIO would go through this code path.

Only X86 uses these counters and kvm_arch_start/end_assignment(),
so this code path only affect x86 for now.

Signed-off-by: Zhu Lingshan <lingshan....@intel.com>
---
 arch/x86/kvm/x86.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 88c593f83b28..b2bf17f808b6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10630,11 +10630,17 @@ int kvm_arch_irq_bypass_add_producer(struct 
irq_bypass_consumer *cons,
 {
        struct kvm_kernel_irqfd *irqfd =
                container_of(cons, struct kvm_kernel_irqfd, consumer);
+       int ret;
 
        irqfd->producer = prod;
+       kvm_arch_start_assignment(irqfd->kvm);
+       ret = kvm_x86_ops.update_pi_irte(irqfd->kvm,
+                                        prod->irq, irqfd->gsi, 1);
+
+       if (ret)
+               kvm_arch_end_assignment(irqfd->kvm);
 
-       return kvm_x86_ops.update_pi_irte(irqfd->kvm,
-                                          prod->irq, irqfd->gsi, 1);
+       return ret;
 }
 
 void kvm_arch_irq_bypass_del_producer(struct irq_bypass_consumer *cons,
@@ -10645,6 +10651,7 @@ void kvm_arch_irq_bypass_del_producer(struct 
irq_bypass_consumer *cons,
                container_of(cons, struct kvm_kernel_irqfd, consumer);
 
        WARN_ON(irqfd->producer != prod);
+       kvm_arch_end_assignment(irqfd->kvm);
        irqfd->producer = NULL;
 
        /*
-- 
2.18.4

Reply via email to