@@ -613,9 +613,18 @@ int msix_set_mask_notifier(PCIDevice *dev, unsigned vector, void *opaque)
if (vector >= dev->msix_entries_nr || !dev->msix_entry_used[vector])
return 0;
- if (dev->msix_mask_notifier)
- r = dev->msix_mask_notifier(dev, vector, opaque,
- msix_is_masked(dev, vector));
+ if (dev->msix_mask_notifier && !msix_is_masked(dev, vector)) {
+ /* Switching notifiers while vector is unmasked:
+ * mask the old one, unmask the new one. */
+ if (dev->msix_mask_notifier_opaque[vector]) {
+ r = dev->msix_mask_notifier(dev, vector,
+ dev->msix_mask_notifier_opaque[vector],
+ 1);
+ }
+ if (r >= 0 && opaque) {
+ r = dev->msix_mask_notifier(dev, vector, opaque, 0);
+ }
+ }
if (r >= 0)
dev->msix_mask_notifier_opaque[vector] = opaque;
return r;