On Mon, Oct 03, 2016 at 02:37:57PM +0100, Daniel P. Berrange wrote:
The intel-iommu device has existed since QEMU 2.2.0, but
it was only possible to create it with -device since
QEMU 2.7.0, thanks to:

 commit 621d983a1f9051f4cfc3f402569b46b77d8449fc
 Author: Marcel Apfelbaum <mar...@redhat.com>
 Date:   Mon Jun 27 18:38:34 2016 +0300

   hw/iommu: enable iommu with -device

   Use the standard '-device intel-iommu' to create the IOMMU device.
   The legacy '-machine,iommu=on' can still be used.

The libvirt capability check & command line formatting code
is thus broken for all QEMU versions 2.2.0 -> 2.6.0 inclusive.

This fixes it to use iommu=on instead.

Signed-off-by: Daniel P. Berrange <berra...@redhat.com>
---
src/qemu/qemu_capabilities.c                       | 13 ++++++++
src/qemu/qemu_capabilities.h                       |  3 ++
src/qemu/qemu_command.c                            | 22 +++++++++++++
tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml   |  2 +-
tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  2 +-
tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  2 +-
tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  2 +-
.../qemuxml2argv-intel-iommu-machine.args          | 21 ++++++++++++
.../qemuxml2argv-intel-iommu-machine.xml           | 37 ++++++++++++++++++++++
tests/qemuxml2argvtest.c                           |  2 ++
10 files changed, 102 insertions(+), 4 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-machine.xml


This patch won't apply for me:
Applying: qemu: fix command line building for iommu devices
error: src/qemu/qemu_capabilities.c: does not match index
error: patch failed: src/qemu/qemu_capabilities.h:376
error: src/qemu/qemu_capabilities.h: patch does not apply
error: patch failed:
tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml:190
error: tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml: patch does not
apply
Patch failed at 0001 qemu: fix command line building for iommu devices

@@ -3633,6 +3635,17 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
    if (virQEMUCapsProbeQMPMigrationCapabilities(qemuCaps, mon) < 0)
        goto cleanup;

+    /* 'intel-iommu' shows up as a device since 2.2.0, but can
+     * not be used with -device until 2.7.0. Before that it
+     * requires -machine iommu=on. So we must clear the device
+     * capability we detected on older QEMUs
+     */
+    if (qemuCaps->version < 2007000 &&
+        virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_INTEL_IOMMU)) {
+        virQEMUCapsClear(qemuCaps, QEMU_CAPS_DEVICE_INTEL_IOMMU);
+        virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_IOMMU);

Works for upstream QEMU, but not for distros that have backported the
fix.

Sadly, with 2.7.0 "iommu" still shows in the "machine" section
of "query-command-line-options", despite:
commit 10d01f73e39100701028c7badd6ece52990cf758
   machine: remove iommu property
http://git.qemu.org/?p=qemu.git;a=commitdiff;h=10d01f73

But an attempt to use it fails:
# qemu-git -machine q35,iommu=on
qemu-git: Property '.iommu' not found

So the version check looks like the only way :(

+    }
+
    /* GIC capabilities, eg. available GIC versions */
    if ((qemuCaps->arch == VIR_ARCH_AARCH64 ||
         qemuCaps->arch == VIR_ARCH_ARMV7L) &&

diff --git a/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml 
b/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml
index 7a54040..b8b79ab 100644
--- a/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml
@@ -190,10 +190,10 @@
  <flag name='drive-detect-zeroes'/>
  <flag name='tls-creds-x509'/>
  <flag name='display'/>
-  <flag name='intel-iommu'/>

Strange. For 2.7.0 we should have kept the original capability,
according to the code above.

Jan

  <flag name='smm'/>
  <flag name='virtio-pci-disable-legacy'/>
  <flag name='query-hotpluggable-cpus'/>
+  <flag name='machine-iommu'/>
  <version>2006091</version>
  <kvmVersion>0</kvmVersion>
  <package> (v2.7.0-rc1-52-g42e0d60)</package>

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to