]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: default to vfio for nodedev-detach
authorLaine Stump <laine@laine.org>
Fri, 29 Nov 2013 11:19:26 +0000 (13:19 +0200)
committerLaine Stump <laine@laine.org>
Tue, 3 Dec 2013 09:58:26 +0000 (11:58 +0200)
This patch resolves:

  https://bugzilla.redhat.com/show_bug.cgi?id=1035188

Commit f094aaac48a6 changed the PCI device assignment in qemu domains
to default to using VFIO rather than legacy KVM device assignment
(when VFIO is available). It didn't change which driver was used by
default for virNodeDeviceDetachFlags(), though, so that API (and the
virsh nodedev-detach command) was still binding to the pci-stub
driver, used by legacy KVM assignment, by default.

This patch publicizes (only within the qemu module, though, so no
additions to the symbol exports are needed) the functions that check
for presence of KVM and VFIO device assignment, then uses those
functions to decide what to do when no driver is specified for
virNodeDeviceDetachFlags(); if the vfio driver is loaded, the device
will be bound to vfio-pci, or if legacy KVM assignment is supported on
this system, the device will be bound to pci-stub; if neither method
is available, the detach will fail.

src/qemu/qemu_driver.c
src/qemu/qemu_hostdev.c
src/qemu/qemu_hostdev.h

index a794e472096f9cbad524011dcb4316a9744f7f15..67b549c1f53c2c2ff5720ac94c59b958a3ed81b1 100644 (file)
@@ -10737,12 +10737,25 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
     if (!pci)
         goto cleanup;
 
-    if (!driverName || STREQ(driverName, "kvm")) {
-        if (virPCIDeviceSetStubDriver(pci, "pci-stub") < 0)
-            goto cleanup;
+    if (!driverName) {
+        /* prefer vfio */
+        if (qemuHostdevHostSupportsPassthroughVFIO())
+            driverName = "vfio";
+        else if (qemuHostdevHostSupportsPassthroughLegacy())
+            driverName = "kvm";
+    }
+
+    if (!driverName) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("neither VFIO nor kvm device assignment is "
+                         "currently supported on this system"));
+        goto cleanup;
     } else if (STREQ(driverName, "vfio")) {
         if (virPCIDeviceSetStubDriver(pci, "vfio-pci") < 0)
             goto cleanup;
+    } else if (STREQ(driverName, "kvm")) {
+        if (virPCIDeviceSetStubDriver(pci, "pci-stub") < 0)
+            goto cleanup;
     } else {
         virReportError(VIR_ERR_INVALID_ARG,
                        _("unknown driver name '%s'"), driverName);
index f5cad15cf917e6625f1297039831ea23e90dda27..dee61e742d318677b218c715a1bff4049c68f991 100644 (file)
@@ -501,7 +501,7 @@ qemuDomainHostdevNetConfigRestore(virDomainHostdevDefPtr hostdev,
 }
 
 
-static bool
+bool
 qemuHostdevHostSupportsPassthroughVFIO(void)
 {
     DIR *iommuDir = NULL;
@@ -541,7 +541,7 @@ cleanup:
 
 #if HAVE_LINUX_KVM_H
 # include <linux/kvm.h>
-static bool
+bool
 qemuHostdevHostSupportsPassthroughLegacy(void)
 {
     int kvmfd = -1;
@@ -563,7 +563,7 @@ cleanup:
     return ret;
 }
 #else
-static bool
+bool
 qemuHostdevHostSupportsPassthroughLegacy(void)
 {
     return false;
index 272086effa97ba1c34ad53b248ff09a6650930cf..ffb3167ca1aed3915ca65096170c31fb0571f876 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * qemu_hostdev.h: QEMU hostdev management
  *
- * Copyright (C) 2006-2007, 2009-2010 Red Hat, Inc.
+ * Copyright (C) 2006-2007, 2009-2013 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -33,6 +33,8 @@ int qemuUpdateActiveUsbHostdevs(virQEMUDriverPtr driver,
                                 virDomainDefPtr def);
 int qemuUpdateActiveScsiHostdevs(virQEMUDriverPtr driver,
                                  virDomainDefPtr def);
+bool qemuHostdevHostSupportsPassthroughLegacy(void);
+bool qemuHostdevHostSupportsPassthroughVFIO(void);
 int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
                                  const char *name,
                                  const unsigned char *uuid,