yeahuh / rpms / qemu-kvm

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