[PATCH 7/9] msix: Move kvm_enabled() guards to kvm-all.c functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Simplifies the msix code.

Signed-off-by: Avi Kivity <avi@xxxxxxxxxx>
---
 hw/msix.c  |   22 ++++++++--------------
 kvm-all.c  |   18 ++++++++++++++++++
 kvm-stub.c |    2 +-
 3 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/hw/msix.c b/hw/msix.c
index bdec0b3..fc4cbb1 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -159,9 +159,7 @@ static void msix_mmio_writel(void *opaque, target_phys_addr_t addr,
     int vector = offset / MSIX_ENTRY_SIZE;
     int was_masked = msix_is_masked(dev, vector);
     pci_set_long(dev->msix_table_page + offset, val);
-    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
-        kvm_msix_update(dev, vector, was_masked, msix_is_masked(dev, vector));
-    }
+    kvm_msix_update(dev, vector, was_masked, msix_is_masked(dev, vector));
     if (was_masked != msix_is_masked(dev, vector) &&
         dev->msix_mask_notifier && dev->msix_mask_notifier_opaque[vector]) {
         int r = dev->msix_mask_notifier(dev, vector,
@@ -276,9 +274,7 @@ static void msix_free_irq_entries(PCIDevice *dev)
 {
     int vector;
 
-    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
-        kvm_msix_free(dev);
-    }
+    kvm_msix_free(dev);
 
     for (vector = 0; vector < dev->msix_entries_nr; ++vector) {
         dev->msix_entry_used[vector] = 0;
@@ -413,12 +409,12 @@ int msix_vector_use(PCIDevice *dev, unsigned vector)
     if (dev->msix_entry_used[vector]) {
         return 0;
     }
-    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
-        ret = kvm_msix_add(dev, vector);
-        if (ret) {
-            return ret;
-        }
+
+    ret = kvm_msix_add(dev, vector);
+    if (ret) {
+        return ret;
     }
+
     ++dev->msix_entry_used[vector];
     return 0;
 }
@@ -432,9 +428,7 @@ void msix_vector_unuse(PCIDevice *dev, unsigned vector)
     if (--dev->msix_entry_used[vector]) {
         return;
     }
-    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
-        kvm_msix_del(dev, vector);
-    }
+    kvm_msix_del(dev, vector);
     msix_clr_pending(dev, vector);
 }
 
diff --git a/kvm-all.c b/kvm-all.c
index 0860a16..a5e7545 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1353,6 +1353,11 @@ void kvm_msix_init(PCIDevice *dev)
 void kvm_msix_free(PCIDevice *dev)
 {
     int vector, changed = 0;
+
+    if (!(kvm_enabled() && kvm_irqchip_in_kernel())) {
+        return;
+    }
+
     for (vector = 0; vector < dev->msix_entries_nr; ++vector) {
         if (dev->msix_entry_used[vector]) {
             kvm_del_routing_entry(kvm_context, &dev->msix_irq_entries[vector]);
@@ -1380,6 +1385,11 @@ void kvm_msix_update(PCIDevice *dev, int vector,
 {
     struct kvm_irq_routing_entry e = {}, *entry;
     int mask_cleared = was_masked && !is_masked;
+
+    if (!(kvm_enabled() && kvm_irqchip_in_kernel())) {
+        return;
+    }
+
     /* It is only legal to change an entry when it is masked. Therefore, it is
      * enough to update the routing in kernel when mask is being cleared. */
     if (!mask_cleared) {
@@ -1414,6 +1424,10 @@ int kvm_msix_add(PCIDevice *dev, unsigned vector)
     struct kvm_irq_routing_entry *entry = dev->msix_irq_entries + vector;
     int r;
 
+    if (!(kvm_enabled() && kvm_irqchip_in_kernel())) {
+        return 0;
+    }
+
     if (!kvm_has_gsi_routing(kvm_context)) {
         fprintf(stderr, "Warning: no MSI-X support found. "
                 "At least kernel 2.6.30 is required for MSI-X support.\n"
@@ -1444,6 +1458,10 @@ int kvm_msix_add(PCIDevice *dev, unsigned vector)
 
 void kvm_msix_del(PCIDevice *dev, unsigned vector)
 {
+    if (!(kvm_enabled() && kvm_irqchip_in_kernel())) {
+        return;
+    }
+
     if (dev->msix_entry_used[vector]) {
         return;
     }
diff --git a/kvm-stub.c b/kvm-stub.c
index 1c54020..37d2b7a 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -158,7 +158,7 @@ void kvm_msix_update(PCIDevice *dev, int vector,
 
 int kvm_msix_add(PCIDevice *dev, unsigned vector)
 {
-    return -1;
+    return 0;
 }
 
 void kvm_msix_del(PCIDevice *dev, unsigned vector)
-- 
1.7.2.3

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux