cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
5d360b
From 9f8e26c9d8485647072b2cbe7848b8d0054597c6 Mon Sep 17 00:00:00 2001
5d360b
From: Alex Williamson <alex.williamson@redhat.com>
5d360b
Date: Fri, 29 Sep 2017 21:45:31 +0200
5d360b
Subject: [PATCH 11/27] vfio/pci: Handle host oversight
5d360b
5d360b
RH-Author: Alex Williamson <alex.williamson@redhat.com>
5d360b
Message-id: <20170929214531.16765.45212.stgit@gimli.home>
5d360b
Patchwork-id: 76769
5d360b
O-Subject: [RHEL-7.5 qemu-kvm PATCH 11/16] vfio/pci: Handle host oversight
5d360b
Bugzilla: 1494181
5d360b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
5d360b
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
5d360b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
5d360b
From: Eric Auger <eric.auger@redhat.com>
5d360b
5d360b
Upstream: 4a946268504e72fe0c547b9dda97adbe277a585f
5d360b
5d360b
In case the end-user calls qemu with -vfio-pci option without passing
5d360b
either sysfsdev or host property value, the device is interpreted as
5d360b
0000:00:00.0. Let's create a specific error message to guide the end-user.
5d360b
5d360b
Signed-off-by: Eric Auger <eric.auger@redhat.com>
5d360b
Reviewed-by: Markus Armbruster <armbru@redhat.com>
5d360b
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
5d360b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
5d360b
---
5d360b
 hw/misc/vfio.c | 13 +++++++++++++
5d360b
 1 file changed, 13 insertions(+)
5d360b
5d360b
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
5d360b
index 0af8613..a95bbaf 100644
5d360b
--- a/hw/misc/vfio.c
5d360b
+++ b/hw/misc/vfio.c
5d360b
@@ -3864,6 +3864,13 @@ static int vfio_initfn(PCIDevice *pdev)
5d360b
     }
5d360b
 
5d360b
     if (!vdev->vbasedev.sysfsdev) {
5d360b
+        if (!(~vdev->host.domain || ~vdev->host.bus ||
5d360b
+              ~vdev->host.slot || ~vdev->host.function)) {
5d360b
+            error_report("No provided host device - "
5d360b
+                         "Use -vfio-pci,host=DDDD:BB:DD.F "
5d360b
+                         "or -vfio-pci,sysfsdev=PATH_TO_DEVICE");
5d360b
+            return -EINVAL;
5d360b
+        }
5d360b
         vdev->vbasedev.sysfsdev =
5d360b
             g_strdup_printf("/sys/bus/pci/devices/%04x:%02x:%02x.%01x",
5d360b
                             vdev->host.domain, vdev->host.bus,
5d360b
@@ -4062,6 +4069,12 @@ post_reset:
5d360b
 
5d360b
 static void vfio_instance_init(Object *obj)
5d360b
 {
5d360b
+    VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, PCI_DEVICE(obj));
5d360b
+
5d360b
+    vdev->host.domain = ~0U;
5d360b
+    vdev->host.bus = ~0U;
5d360b
+    vdev->host.slot = ~0U;
5d360b
+    vdev->host.function = ~0U;
5d360b
 }
5d360b
 
5d360b
 static Property vfio_pci_dev_properties[] = {
5d360b
-- 
5d360b
1.8.3.1
5d360b