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

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