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

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