Blame SOURCES/kvm-qdev-Fix-assert-in-PCI-address-property-when-used-by.patch

5d360b
From f8553be3140a1f77ab3c4e218ecc79437534d1ea Mon Sep 17 00:00:00 2001
5d360b
From: Alex Williamson <alex.williamson@redhat.com>
5d360b
Date: Fri, 26 Jan 2018 02:21:25 +0100
5d360b
Subject: [PATCH 1/4] qdev: Fix assert in PCI address property when used by
5d360b
 vfio-pci
5d360b
5d360b
RH-Author: Alex Williamson <alex.williamson@redhat.com>
5d360b
Message-id: <20180126021938.25889.98354.stgit@gimli.home>
5d360b
Patchwork-id: 78707
5d360b
O-Subject: [RHEL-7.5 qemu-kvm PATCH] qdev: Fix assert in PCI address property when used by vfio-pci
5d360b
Bugzilla: 1538866
5d360b
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
5d360b
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
5d360b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
5d360b
5d360b
From: Daniel Oram <daniel.oram@gmail.com>
5d360b
5d360b
Allow the PCIHostDeviceAddress structure to work as the host property
5d360b
in vfio-pci when it has it's default value of all fields set to ~0. In
5d360b
this form the property indicates a non-existant device but given the
5d360b
field bit sizes gets asserted as excess (and invalid) precision
5d360b
overflows the string buffer. The BDF of an invalid device
5d360b
"FFFF:FF:FF.F" is returned instead.
5d360b
5d360b
Signed-off-by: Daniel Oram <daniel.oram@gmail.com>
5d360b
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
5d360b
Message-Id: <71f06765c4ba16dcd71cbf78e877619948f04ed9.1478777270.git.daniel.oram@gmail.com>
5d360b
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
5d360b
(cherry picked from commit 00b8702581f312aa46f797a8b3153d9b2892d967)
5d360b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
---
5d360b
 hw/core/qdev-properties.c | 14 ++++++++++----
5d360b
 1 file changed, 10 insertions(+), 4 deletions(-)
5d360b
5d360b
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
5d360b
index dc8ae69..a61250e 100644
5d360b
--- a/hw/core/qdev-properties.c
5d360b
+++ b/hw/core/qdev-properties.c
5d360b
@@ -728,13 +728,19 @@ static void get_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
5d360b
     DeviceState *dev = DEVICE(obj);
5d360b
     Property *prop = opaque;
5d360b
     PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
5d360b
-    char buffer[] = "xxxx:xx:xx.x";
5d360b
+    char buffer[] = "ffff:ff:ff.f";
5d360b
     char *p = buffer;
5d360b
     int rc = 0;
5d360b
 
5d360b
-    rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%d",
5d360b
-                  addr->domain, addr->bus, addr->slot, addr->function);
5d360b
-    assert(rc == sizeof(buffer) - 1);
5d360b
+    /*
5d360b
+     * Catch "invalid" device reference from vfio-pci and allow the
5d360b
+     * default buffer representing the non-existant device to be used.
5d360b
+     */
5d360b
+    if (~addr->domain || ~addr->bus || ~addr->slot || ~addr->function) {
5d360b
+        rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%0d",
5d360b
+                      addr->domain, addr->bus, addr->slot, addr->function);
5d360b
+        assert(rc == sizeof(buffer) - 1);
5d360b
+    }
5d360b
 
5d360b
     visit_type_str(v, &p, name, errp);
5d360b
 }
5d360b
-- 
5d360b
1.8.3.1
5d360b