From: Michael S. Tsirkin <[email protected]>

Sridhar Samudrala reported hitting the following assertions
in msix.c when doing a guest reboot or live migration using vhost.
qemu-kvm/hw/msix.c:375: msix_mask_all: Assertion `r >= 0' failed.
qemu-kvm/hw/msix.c:640: msix_unset_mask_notifier:
Assertion `dev->msix_mask_notifier_opaque[vector]' failed.

The issue is that we didn't clear/set the opaque pointer
when vector is masked. The following patch fixes this.

Signed-off-by: Sridhar Samudrala <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Tested-by: Sridhar Samudrala <[email protected]>
Signed-off-by: Marcelo Tosatti <[email protected]>

diff --git a/hw/msix.c b/hw/msix.c
index 59c7407..a52338e 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -601,7 +601,7 @@ void msix_unuse_all_vectors(PCIDevice *dev)
 
 int msix_set_mask_notifier(PCIDevice *dev, unsigned vector, void *opaque)
 {
-    int r;
+    int r = 0;
     if (vector >= dev->msix_entries_nr || !dev->msix_entry_used[vector])
         return 0;
 
@@ -610,13 +610,11 @@ int msix_set_mask_notifier(PCIDevice *dev, unsigned 
vector, void *opaque)
     assert(!dev->msix_mask_notifier_opaque[vector]);
 
     /* Unmask the new notifier unless vector is masked. */
-    if (msix_is_masked(dev, vector)) {
-        return 0;
-    }
-    r = dev->msix_mask_notifier(dev, vector, opaque,
-                                msix_is_masked(dev, vector));
-    if (r < 0) {
-        return r;
+    if (!msix_is_masked(dev, vector)) {
+        r = dev->msix_mask_notifier(dev, vector, opaque, false);
+        if (r < 0) {
+            return r;
+        }
     }
     dev->msix_mask_notifier_opaque[vector] = opaque;
     return r;
@@ -625,21 +623,21 @@ int msix_set_mask_notifier(PCIDevice *dev, unsigned 
vector, void *opaque)
 int msix_unset_mask_notifier(PCIDevice *dev, unsigned vector)
 {
     int r = 0;
+    void *opaque;
     if (vector >= dev->msix_entries_nr || !dev->msix_entry_used[vector])
         return 0;
 
+    opaque = dev->msix_mask_notifier_opaque[vector];
+
     assert(dev->msix_mask_notifier);
-    assert(dev->msix_mask_notifier_opaque[vector]);
+    assert(opaque);
 
     /* Mask the old notifier unless it is already masked. */
-    if (msix_is_masked(dev, vector)) {
-        return 0;
-    }
-    r = dev->msix_mask_notifier(dev, vector,
-                                dev->msix_mask_notifier_opaque[vector],
-                                !msix_is_masked(dev, vector));
-    if (r < 0) {
-        return r;
+    if (!msix_is_masked(dev, vector)) {
+        r = dev->msix_mask_notifier(dev, vector, opaque, true);
+        if (r < 0) {
+            return r;
+        }
     }
     dev->msix_mask_notifier_opaque[vector] = NULL;
     return r;
--
To unsubscribe from this list: send the line "unsubscribe kvm-commits" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to