Blame SOURCES/kvm-i386-kvm-ignore-masked-irqs-when-update-msi-routes.patch

ae23c9
From b33299faac2ed3e7757bf1a0c733a9abb2c6ed34 Mon Sep 17 00:00:00 2001
ae23c9
From: Peter Xu <peterx@redhat.com>
ae23c9
Date: Tue, 2 Apr 2019 07:25:31 +0100
ae23c9
Subject: [PATCH 7/7] i386/kvm: ignore masked irqs when update msi routes
ae23c9
MIME-Version: 1.0
ae23c9
Content-Type: text/plain; charset=UTF-8
ae23c9
Content-Transfer-Encoding: 8bit
ae23c9
ae23c9
RH-Author: Peter Xu <peterx@redhat.com>
ae23c9
Message-id: <20190402072531.23771-5-peterx@redhat.com>
ae23c9
Patchwork-id: 85301
ae23c9
O-Subject: [RHEL-8.1 qemu-kvm PATCH 4/4] i386/kvm: ignore masked irqs when update msi routes
ae23c9
Bugzilla: 1662272
ae23c9
RH-Acked-by: Wei Huang <wei@redhat.com>
ae23c9
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
ae23c9
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
ae23c9
When we are with intel-iommu device and with IR on, KVM will register
ae23c9
an IEC notifier to detect interrupt updates from the guest and we'll
ae23c9
kick off kvm_update_msi_routes_all() when it happens to make sure
ae23c9
kernel IRQ cache is matching the latest.
ae23c9
ae23c9
Though, kvm_update_msi_routes_all() is buggy in that it ignored the
ae23c9
mask bit of either MSI/MSIX messages and it tries to translate the
ae23c9
message even if the corresponding message was already masked by the
ae23c9
guest driver (hence the MSI/MSIX message will be invalid).
ae23c9
ae23c9
Without this patch, we can receive an error message when we reboot a
ae23c9
guest with both an assigned vfio-pci device and intel-iommu enabled:
ae23c9
ae23c9
  qemu-system-x86_64: vtd_interrupt_remap_msi: MSI address low 32 bit invalid: 0x0
ae23c9
ae23c9
The error does not affect functionality of the guest since when we
ae23c9
failed to translate we'll just silently continue (which makes sense
ae23c9
since crashing the VM for this seems even worse), but still it's
ae23c9
better to fix it up.
ae23c9
ae23c9
Signed-off-by: Peter Xu <peterx@redhat.com>
ae23c9
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
Message-Id: <20190116030815.27273-5-peterx@redhat.com>
ae23c9
[PMD: this patch was first (incorrectly) introduced as a56de056c91f8]
ae23c9
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ae23c9
Message-Id: <20190212140621.17009-4-philmd@redhat.com>
ae23c9
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
Reviewed-by: Peter Xu <peterx@redhat.com>
ae23c9
(cherry picked from commit 558e8c6139a5f517433b6f1779b2df8a0b4ff610)
ae23c9
Signed-off-by: Peter Xu <peterx@redhat.com>
ae23c9
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 target/i386/kvm.c | 14 +++++++++++---
ae23c9
 1 file changed, 11 insertions(+), 3 deletions(-)
ae23c9
ae23c9
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
ae23c9
index 87e4771..702e3bf 100644
ae23c9
--- a/target/i386/kvm.c
ae23c9
+++ b/target/i386/kvm.c
ae23c9
@@ -3590,7 +3590,7 @@ static QLIST_HEAD(, MSIRouteEntry) msi_route_list = \
ae23c9
 static void kvm_update_msi_routes_all(void *private, bool global,
ae23c9
                                       uint32_t index, uint32_t mask)
ae23c9
 {
ae23c9
-    int cnt = 0;
ae23c9
+    int cnt = 0, vector;
ae23c9
     MSIRouteEntry *entry;
ae23c9
     MSIMessage msg;
ae23c9
     PCIDevice *dev;
ae23c9
@@ -3598,11 +3598,19 @@ static void kvm_update_msi_routes_all(void *private, bool global,
ae23c9
     /* TODO: explicit route update */
ae23c9
     QLIST_FOREACH(entry, &msi_route_list, list) {
ae23c9
         cnt++;
ae23c9
+        vector = entry->vector;
ae23c9
         dev = entry->dev;
ae23c9
-        if (!msix_enabled(dev) && !msi_enabled(dev)) {
ae23c9
+        if (msix_enabled(dev) && !msix_is_masked(dev, vector)) {
ae23c9
+            msg = msix_get_message(dev, vector);
ae23c9
+        } else if (msi_enabled(dev) && !msi_is_masked(dev, vector)) {
ae23c9
+            msg = msi_get_message(dev, vector);
ae23c9
+        } else {
ae23c9
+            /*
ae23c9
+             * Either MSI/MSIX is disabled for the device, or the
ae23c9
+             * specific message was masked out.  Skip this one.
ae23c9
+             */
ae23c9
             continue;
ae23c9
         }
ae23c9
-        msg = pci_get_msi_message(dev, entry->vector);
ae23c9
         kvm_irqchip_update_msi_route(kvm_state, entry->virq, msg, dev);
ae23c9
     }
ae23c9
     kvm_irqchip_commit_routes(kvm_state);
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9