Skip to contentSkip to conversation

pci, vhost-user: Fix two incorrectly applied patches

PATCH In review Philippe Mathieu-Daudé 2 participants 5 messages Feb 12, 2019 – Feb 13, 2019 KVM

lore
Share & tools
lore
#0 lore raw

cover pci, vhost-user: Fix two incorrectly applied patches

Commit a56de056c91f8 squashed two unrelated commits at once. Revert it and reapply the two commits to avoid confusion.

See: https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg02966.html

Changpeng Liu (1):
contrib/vhost-user-blk: fix the compilation issue

Peter Xu (1):
i386/kvm: ignore masked irqs when update msi routes

Philippe Mathieu-Daudé (1):
Revert "contrib/vhost-user-blk: fix the compilation issue"

Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 Revert "contrib/vhost-user-blk: fix the compilation issue"

Commit a56de056c91f8 squashed the following two unrelated commits at once:

- "contrib/vhost-user-blk: fix the compilation issue" (Message-Id: [email protected])
- "i386/kvm: ignore masked irqs when update msi routes" (Message-Id: [email protected])

While the git history remains bisectable, having a commit that changes MSI/MSIX code but describes it as "fix vhost-user-blk compilation" is rather confusing.
Revert the offending commit to properly apply both patches separately.

---
 contrib/vhost-user-blk/vhost-user-blk.c |  6 +-----
 target/i386/kvm.c                       | 14 +++-----------
 2 files changed, 4 insertions(+), 16 deletions(-)
contrib/vhost-user-blk/vhost-user-blk.c +1 -5
index 43583f2659..5c2092e13a 100644
@@ -20,10 +20,6 @@
 #include "contrib/libvhost-user/libvhost-user-glib.h"
 #include "contrib/libvhost-user/libvhost-user.h"
 
-#if defined(__linux__)
-#include <linux/fs.h>
-#include <sys/ioctl.h>
-#endif
 
 struct virtio_blk_inhdr {
     unsigned char status;
@@ -525,7 +521,7 @@ vub_get_blocksize(int fd)
 
 #if defined(__linux__) && defined(BLKSSZGET)
     if (ioctl(fd, BLKSSZGET, &blocksize) == 0) {
-        return blocksize;
+        return blocklen;
     }
 #endif
 
target/i386/kvm.c +3 -11
index beae1b99da..9af4542fb8 100644
@@ -3894,7 +3894,7 @@ static QLIST_HEAD(, MSIRouteEntry) msi_route_list = \
 static void kvm_update_msi_routes_all(void *private, bool global,
                                       uint32_t index, uint32_t mask)
 {
-    int cnt = 0, vector;
+    int cnt = 0;
     MSIRouteEntry *entry;
     MSIMessage msg;
     PCIDevice *dev;
@@ -3902,19 +3902,11 @@ static void kvm_update_msi_routes_all(void *private, bool global,
     /* TODO: explicit route update */
     QLIST_FOREACH(entry, &msi_route_list, list) {
         cnt++;
-        vector = entry->vector;
         dev = entry->dev;
-        if (msix_enabled(dev) && !msix_is_masked(dev, vector)) {
-            msg = msix_get_message(dev, vector);
-        } else if (msi_enabled(dev) && !msi_is_masked(dev, vector)) {
-            msg = msi_get_message(dev, vector);
-        } else {
-            /*
-             * Either MSI/MSIX is disabled for the device, or the
-             * specific message was masked out.  Skip this one.
-             */
+        if (!msix_enabled(dev) && !msi_enabled(dev)) {
             continue;
         }
+        msg = pci_get_msi_message(dev, entry->vector);
         kvm_irqchip_update_msi_route(kvm_state, entry->virq, msg, dev);
     }
     kvm_irqchip_commit_routes(kvm_state);
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/3 contrib/vhost-user-blk: fix the compilation issue

In reply to Philippe Mathieu-Daudé

From: Changpeng Liu <[email protected]>

Message-Id: <[email protected]>

[PMD: this patch was first (incorrectly) introduced as a56de056c91f8]
---
 contrib/vhost-user-blk/vhost-user-blk.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
contrib/vhost-user-blk/vhost-user-blk.c +5 -1
index 5c2092e13a..43583f2659 100644
@@ -20,6 +20,10 @@
 #include "contrib/libvhost-user/libvhost-user-glib.h"
 #include "contrib/libvhost-user/libvhost-user.h"
 
+#if defined(__linux__)
+#include <linux/fs.h>
+#include <sys/ioctl.h>
+#endif
 
 struct virtio_blk_inhdr {
     unsigned char status;
@@ -521,7 +525,7 @@ vub_get_blocksize(int fd)
 
 #if defined(__linux__) && defined(BLKSSZGET)
     if (ioctl(fd, BLKSSZGET, &blocksize) == 0) {
-        return blocklen;
+        return blocksize;
     }
 #endif
 
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/3 i386/kvm: ignore masked irqs when update msi routes

In reply to Philippe Mathieu-Daudé

From: Peter Xu <[email protected]>

When we are with intel-iommu device and with IR on, KVM will register an IEC notifier to detect interrupt updates from the guest and we'll kick off kvm_update_msi_routes_all() when it happens to make sure kernel IRQ cache is matching the latest.

Though, kvm_update_msi_routes_all() is buggy in that it ignored the mask bit of either MSI/MSIX messages and it tries to translate the message even if the corresponding message was already masked by the guest driver (hence the MSI/MSIX message will be invalid).

Without this patch, we can receive an error message when we reboot a guest with both an assigned vfio-pci device and intel-iommu enabled:

qemu-system-x86_64: vtd_interrupt_remap_msi: MSI address low 32 bit invalid: 0x0

The error does not affect functionality of the guest since when we failed to translate we'll just silently continue (which makes sense since crashing the VM for this seems even worse), but still it's better to fix it up.

Message-Id: <[email protected]>

[PMD: this patch was first (incorrectly) introduced as a56de056c91f8]
---
 target/i386/kvm.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
target/i386/kvm.c +11 -3
index 9af4542fb8..beae1b99da 100644
@@ -3894,7 +3894,7 @@ static QLIST_HEAD(, MSIRouteEntry) msi_route_list = \
 static void kvm_update_msi_routes_all(void *private, bool global,
                                       uint32_t index, uint32_t mask)
 {
-    int cnt = 0;
+    int cnt = 0, vector;
     MSIRouteEntry *entry;
     MSIMessage msg;
     PCIDevice *dev;
@@ -3902,11 +3902,19 @@ static void kvm_update_msi_routes_all(void *private, bool global,
     /* TODO: explicit route update */
     QLIST_FOREACH(entry, &msi_route_list, list) {
         cnt++;
+        vector = entry->vector;
         dev = entry->dev;
-        if (!msix_enabled(dev) && !msi_enabled(dev)) {
+        if (msix_enabled(dev) && !msix_is_masked(dev, vector)) {
+            msg = msix_get_message(dev, vector);
+        } else if (msi_enabled(dev) && !msi_is_masked(dev, vector)) {
+            msg = msi_get_message(dev, vector);
+        } else {
+            /*
+             * Either MSI/MSIX is disabled for the device, or the
+             * specific message was masked out.  Skip this one.
+             */
             continue;
         }
-        msg = pci_get_msi_message(dev, entry->vector);
         kvm_irqchip_update_msi_route(kvm_state, entry->virq, msg, dev);
     }
     kvm_irqchip_commit_routes(kvm_state);
Signature · 1 line
2.20.1