Skip to contentSkip to conversation

libqos: Solve bug in interrupt checking when using MSIX in virtio-pci.c

PATCH In review Marc Marí 3 participants 5 messages Feb 24, 2015 – Mar 10, 2015

lore
Share & tools
lore

Marc Marí

author
#0 lore raw

PATCH 1/1 libqos: Solve bug in interrupt checking when using MSIX in virtio-pci.c

The MSIX interrupt was always acked without checking its value, which caused a race condition. If the ISR was raised between the read and the acking, the ISR was never detected and it timed out.

---
 tests/libqos/virtio-pci.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
tests/libqos/virtio-pci.c +12 -4
index 788ebaf..c74a669 100644
@@ -140,8 +140,12 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
             return qpci_msix_pending(dev->pdev, vqpci->msix_entry);
         } else {
             data = readl(vqpci->msix_addr);
-            writel(vqpci->msix_addr, 0);
-            return data == vqpci->msix_data;
+            if (data == vqpci->msix_data) {
+                writel(vqpci->msix_addr, 0);
+                return true;
+            } else {
+                return false;
+            }
         }
     } else {
         return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_ISR_STATUS) & 1;
@@ -160,8 +164,12 @@ static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d)
             return qpci_msix_pending(dev->pdev, dev->config_msix_entry);
         } else {
             data = readl(dev->config_msix_addr);
-            writel(dev->config_msix_addr, 0);
-            return data == dev->config_msix_data;
+            if (data == dev->config_msix_data) {
+                writel(dev->config_msix_addr, 0);
+                return true;
+            } else {
+                return false;
+            }
         }
     } else {
         return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_ISR_STATUS) & 2;
Signature · 1 line
1.7.10.4
Tested-by Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines · Marc Marí

The MSIX interrupt was always acked without checking its value, which caused a race condition. If the ISR was raised between the read and the acking, the ISR was never detected and it timed out.

---
  tests/libqos/virtio-pci.c |   16 ++++++++++++----
  1 file changed, 12 insertions(+), 4 deletions(-)
tests/libqos/virtio-pci.c +6 -3
index 788ebaf..c74a669 100644
@@ -140,8 +140,12 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
              return qpci_msix_pending(dev->pdev, vqpci->msix_entry);
          } else {
              data = readl(vqpci->msix_addr);
-            writel(vqpci->msix_addr, 0);
-            return data == vqpci->msix_data;
+            if (data == vqpci->msix_data) {
+                writel(vqpci->msix_addr, 0);
+                return true;
+            } else {
+                return false;
+            }
          }
      } else {
          return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_ISR_STATUS) & 1;
@@ -160,8 +164,12 @@ static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d)
              return qpci_msix_pending(dev->pdev, dev->config_msix_entry);
          } else {
              data = readl(dev->config_msix_addr);
-            writel(dev->config_msix_addr, 0);

tests/libqos/virtio-pci.c static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d) · line 175

Quoted 10 lines
tests/libqos/virtio-pci.c +6 -1
-            return data == dev->config_msix_data;
+            if (data == dev->config_msix_data) {
+                writel(dev->config_msix_addr, 0);
+                return true;
+            } else {
+                return false;
+            }
          }
      } else {
          return qpci_io_readb(dev->pdev, dev->addr + QVIRTIO_ISR_STATUS) & 2;

1,600+ runs and no hang, thanks :)

#2 lore raw
Quoted 57 lines · John Snow
Quoted 49 lines · Marc Marí

The MSIX interrupt was always acked without checking its value, which caused a
race condition. If the ISR was raised between the read and the acking, the ISR
was never detected and it timed out.

---
  tests/libqos/virtio-pci.c |   16 ++++++++++++----
  1 file changed, 12 insertions(+), 4 deletions(-)
tests/libqos/virtio-pci.c +6 -2
index 788ebaf..c74a669 100644
@@ -140,8 +140,12 @@ static bool
 qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
              return qpci_msix_pending(dev->pdev, vqpci->msix_entry);
          } else {
              data = readl(vqpci->msix_addr);
-            writel(vqpci->msix_addr, 0);
-            return data == vqpci->msix_data;
+            if (data == vqpci->msix_data) {
+                writel(vqpci->msix_addr, 0);
+                return true;
+            } else {
+                return false;
+            }
          }
      } else {
          return qpci_io_readb(dev->pdev, dev->addr +

QVIRTIO_ISR_STATUS) & 1;

tests/libqos/virtio-pci.c +6 -2
@@ -160,8 +164,12 @@ static bool
 qvirtio_pci_get_config_isr_status(QVirtioDevice *d)
              return qpci_msix_pending(dev->pdev,
 dev->config_msix_entry);
          } else {
              data = readl(dev->config_msix_addr);
-            writel(dev->config_msix_addr, 0);
-            return data == dev->config_msix_data;
+            if (data == dev->config_msix_data) {
+                writel(dev->config_msix_addr, 0);
+                return true;
+            } else {
+                return false;
+            }
          }
      } else {
          return qpci_io_readb(dev->pdev, dev->addr +
Quoted 2 lines

QVIRTIO_ISR_STATUS) & 2;

1,600+ runs and no hang, thanks :)

Quoted 3 lines

Ping?

Still hitting this failure upstream.

author
#3 lore raw
Quoted 60 lines · El Tue, 10 Mar 2015 16:50:48 -0400 John Snow <[email protected]> escribió:
Quoted 57 lines · John Snow
Quoted 49 lines · Marc Marí

The MSIX interrupt was always acked without checking its value, which caused a
race condition. If the ISR was raised between the read and the acking, the ISR
was never detected and it timed out.

---
  tests/libqos/virtio-pci.c |   16 ++++++++++++----
  1 file changed, 12 insertions(+), 4 deletions(-)
tests/libqos/virtio-pci.c +6 -2
index 788ebaf..c74a669 100644
@@ -140,8 +140,12 @@ static bool
 qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
              return qpci_msix_pending(dev->pdev,
 vqpci->msix_entry); } else {
              data = readl(vqpci->msix_addr);
-            writel(vqpci->msix_addr, 0);
-            return data == vqpci->msix_data;
+            if (data == vqpci->msix_data) {
+                writel(vqpci->msix_addr, 0);
+                return true;
+            } else {
+                return false;
+            }
          }
      } else {
          return qpci_io_readb(dev->pdev, dev->addr +

QVIRTIO_ISR_STATUS) & 1;

tests/libqos/virtio-pci.c +6 -2
@@ -160,8 +164,12 @@ static bool
 qvirtio_pci_get_config_isr_status(QVirtioDevice *d)
              return qpci_msix_pending(dev->pdev,
 dev->config_msix_entry);
          } else {
              data = readl(dev->config_msix_addr);
-            writel(dev->config_msix_addr, 0);
-            return data == dev->config_msix_data;
+            if (data == dev->config_msix_data) {
+                writel(dev->config_msix_addr, 0);
+                return true;
+            } else {
+                return false;
+            }
          }
      } else {
          return qpci_io_readb(dev->pdev, dev->addr +
Quoted 2 lines

QVIRTIO_ISR_STATUS) & 2;

1,600+ runs and no hang, thanks :)

Quoted 7 lines
Quoted 3 lines

Ping?

Still hitting this failure upstream.

I think this is in Stefan's pull request, which has issues merging.

Marc

#4 lore raw
In reply to John Snow

Am 10.03.2015 um 21:50 schrieb John Snow:

Quoted 56 lines · John Snow
Quoted 55 lines · Marc Marí
Quoted 49 lines

The MSIX interrupt was always acked without checking its value, which caused a
race condition. If the ISR was raised between the read and the acking, the ISR
was never detected and it timed out.

---
  tests/libqos/virtio-pci.c |   16 ++++++++++++----
  1 file changed, 12 insertions(+), 4 deletions(-)
tests/libqos/virtio-pci.c +6 -2
index 788ebaf..c74a669 100644
@@ -140,8 +140,12 @@ static bool
 qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)
              return qpci_msix_pending(dev->pdev, vqpci->msix_entry);
          } else {
              data = readl(vqpci->msix_addr);
-            writel(vqpci->msix_addr, 0);
-            return data == vqpci->msix_data;
+            if (data == vqpci->msix_data) {
+                writel(vqpci->msix_addr, 0);
+                return true;
+            } else {
+                return false;
+            }
          }
      } else {
          return qpci_io_readb(dev->pdev, dev->addr +

QVIRTIO_ISR_STATUS) & 1;

tests/libqos/virtio-pci.c +6 -2
@@ -160,8 +164,12 @@ static bool
 qvirtio_pci_get_config_isr_status(QVirtioDevice *d)
              return qpci_msix_pending(dev->pdev,
 dev->config_msix_entry);
          } else {
              data = readl(dev->config_msix_addr);
-            writel(dev->config_msix_addr, 0);
-            return data == dev->config_msix_data;
+            if (data == dev->config_msix_data) {
+                writel(dev->config_msix_addr, 0);
+                return true;
+            } else {
+                return false;
+            }
          }
      } else {
          return qpci_io_readb(dev->pdev, dev->addr +
Quoted 2 lines

QVIRTIO_ISR_STATUS) & 2;

1,600+ runs and no hang, thanks :)

Quoted 7 lines
Quoted 3 lines

Ping?

Still hitting this failure upstream.

CC'ing the PCI/virtio maintainer might help. ;)

Cheers,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)