[RFC][PATCH 40/45] qemu-kvm: msix: Drop check for preexisting cap from msix_add_config

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

 



msix_add_config is called from msix_init which only supports init-once.
Moreover, msix_add_config performed no check if the provided parameters
were compatible with the existing capability entry, so was inconsistent
anyway.

Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
 hw/msix.c |   72 +++++++++++++++++++++++++++++-------------------------------
 1 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/hw/msix.c b/hw/msix.c
index f1b97b5..5f0fa6a 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -63,48 +63,46 @@ static int msix_add_config(struct PCIDevice *pdev, unsigned short nentries,
                            unsigned bar_nr, unsigned bar_size)
 {
     int config_offset;
+    uint32_t new_size;
     uint8_t *config;
 
-    pdev->msix_bar_size = bar_size;
-
-    config_offset = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
-
-    if (!config_offset) {
-        uint32_t new_size;
-
-        if (nentries < 1 || nentries > PCI_MSIX_FLAGS_QSIZE + 1)
-            return -EINVAL;
-        if (bar_size > 0x80000000)
-            return -ENOSPC;
+    if (nentries < 1 || nentries > PCI_MSIX_FLAGS_QSIZE + 1) {
+        return -EINVAL;
+    }
+    if (bar_size > 0x80000000) {
+        return -ENOSPC;
+    }
 
-        /* Add space for MSI-X structures */
-        if (!bar_size) {
-            new_size = MSIX_PAGE_SIZE;
-        } else if (bar_size < MSIX_PAGE_SIZE) {
-            bar_size = MSIX_PAGE_SIZE;
-            new_size = MSIX_PAGE_SIZE * 2;
-        } else {
-            new_size = bar_size * 2;
-        }
+    /* Add space for MSI-X structures */
+    if (!bar_size) {
+        new_size = MSIX_PAGE_SIZE;
+    } else if (bar_size < MSIX_PAGE_SIZE) {
+        bar_size = MSIX_PAGE_SIZE;
+        new_size = MSIX_PAGE_SIZE * 2;
+    } else {
+        new_size = bar_size * 2;
+    }
 
-        pdev->msix_bar_size = new_size;
-        config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX,
-                                           0, MSIX_CAP_LENGTH);
-        if (config_offset < 0)
-            return config_offset;
-        config = pdev->config + config_offset;
-
-        pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
-        /* Table on top of BAR */
-        pci_set_long(config + PCI_MSIX_TABLE, bar_size | bar_nr);
-        /* Pending bits on top of that */
-        pci_set_long(config + PCI_MSIX_PBA, (bar_size + MSIX_PAGE_PENDING) |
-                     bar_nr);
+    pdev->msix_bar_size = new_size;
+    config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX, 0,
+                                       MSIX_CAP_LENGTH);
+    if (config_offset < 0) {
+        return config_offset;
     }
     pdev->msix_cap = config_offset;
+
+    config = pdev->config + config_offset;
+    pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
+    /* Table on top of BAR */
+    pci_set_long(config + PCI_MSIX_TABLE, bar_size | bar_nr);
+    /* Pending bits on top of that */
+    pci_set_long(config + PCI_MSIX_PBA,
+                 (bar_size + MSIX_PAGE_PENDING) | bar_nr);
+
     /* Make flags bit writable. */
-    pdev->wmask[config_offset + MSIX_CONTROL_OFFSET] |= MSIX_ENABLE_MASK |
-	    MSIX_MASKALL_MASK;
+    pdev->wmask[config_offset + MSIX_CONTROL_OFFSET] |=
+        MSIX_ENABLE_MASK | MSIX_MASKALL_MASK;
+
     return 0;
 }
 
-- 
1.7.3.4

--
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