diff mbox series

[RFC,2/2] virtio-pci: check if the configure interrupt enable

Message ID 20240327012905.70188-3-lulu@redhat.com (mailing list archive)
State New, archived
Headers show
Series disable the configuration interrupt for the unsupported device | expand

Commit Message

Cindy Lu March 27, 2024, 1:22 a.m. UTC
If config_irq_enabled is not true, it means that configure interrupt is
not supported. Therefore, the config vector will not be handled during
the interrupt process.

Signed-off-by: Cindy Lu <lulu@redhat.com>
---
 hw/virtio/virtio-pci.c | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index e433879542..36ad7da206 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1065,7 +1065,7 @@  static int virtio_pci_vector_unmask(PCIDevice *dev, unsigned vector,
         vq = virtio_vector_next_queue(vq);
     }
     /* unmask config intr */
-    if (vector == vdev->config_vector) {
+    if ((vector == vdev->config_vector) && (true == vdev->config_irq_enabled)) {
         n = virtio_config_get_guest_notifier(vdev);
         ret = virtio_pci_one_vector_unmask(proxy, VIRTIO_CONFIG_IRQ_IDX, vector,
                                            msg, n);
@@ -1111,7 +1111,7 @@  static void virtio_pci_vector_mask(PCIDevice *dev, unsigned vector)
         vq = virtio_vector_next_queue(vq);
     }
 
-    if (vector == vdev->config_vector) {
+    if ((vector == vdev->config_vector) && (true == vdev->config_irq_enabled)) {
         n = virtio_config_get_guest_notifier(vdev);
         virtio_pci_one_vector_mask(proxy, VIRTIO_CONFIG_IRQ_IDX, vector, n);
     }
@@ -1147,21 +1147,24 @@  static void virtio_pci_vector_poll(PCIDevice *dev,
         }
     }
     /* poll the config intr */
-    ret = virtio_pci_get_notifier(proxy, VIRTIO_CONFIG_IRQ_IDX, &notifier,
-                                  &vector);
-    if (ret < 0) {
-        return;
-    }
-    if (vector < vector_start || vector >= vector_end ||
-        !msix_is_masked(dev, vector)) {
-        return;
-    }
-    if (k->guest_notifier_pending) {
-        if (k->guest_notifier_pending(vdev, VIRTIO_CONFIG_IRQ_IDX)) {
+    if (true == vdev->config_irq_enabled) {
+        ret = virtio_pci_get_notifier(proxy, VIRTIO_CONFIG_IRQ_IDX, &notifier,
+                                      &vector);
+        if (ret < 0) {
+            return;
+        }
+
+        if (vector < vector_start || vector >= vector_end ||
+            !msix_is_masked(dev, vector)) {
+            return;
+        }
+        if (k->guest_notifier_pending) {
+            if (k->guest_notifier_pending(vdev, VIRTIO_CONFIG_IRQ_IDX)) {
+                msix_set_pending(dev, vector);
+            }
+        } else if (event_notifier_test_and_clear(notifier)) {
             msix_set_pending(dev, vector);
         }
-    } else if (event_notifier_test_and_clear(notifier)) {
-        msix_set_pending(dev, vector);
     }
 }
 
@@ -1282,9 +1285,11 @@  static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign)
             if (r < 0) {
                 goto config_assign_error;
             }
-            r = kvm_virtio_pci_vector_config_use(proxy);
-            if (r < 0) {
-                goto config_error;
+            if (true == vdev->config_irq_enabled) {
+                r = kvm_virtio_pci_vector_config_use(proxy);
+                if (r < 0) {
+                    goto config_error;
+                }
             }
         }