3e5111
From d7a019948e1c1f0400ee174ef60bf0cb32d181f9 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <d7a019948e1c1f0400ee174ef60bf0cb32d181f9@dist-git>
3e5111
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
3e5111
Date: Fri, 26 May 2017 08:52:56 +0200
3e5111
Subject: [PATCH] conf: add eim attribute to <iommu><driver>
3e5111
MIME-Version: 1.0
3e5111
Content-Type: text/plain; charset=UTF-8
3e5111
Content-Transfer-Encoding: 8bit
3e5111
3e5111
Add an attribute to control extended interrupt mode.
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1451282
3e5111
3e5111
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3e5111
(cherry picked from commit dc61d927589b2b122868e6abea86b73caa682226)
3e5111
3e5111
Signed-off-by: Ján Tomko <jtomko@redhat.com>
3e5111
3e5111
Also:
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1289153
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 docs/formatdomain.html.in                          | 13 +++++++++
3e5111
 docs/schemas/domaincommon.rng                      |  5 ++++
3e5111
 src/conf/domain_conf.c                             | 21 +++++++++++++++
3e5111
 src/conf/domain_conf.h                             |  1 +
3e5111
 .../qemuxml2argv-intel-iommu-eim.xml               | 31 ++++++++++++++++++++++
3e5111
 .../qemuxml2xmlout-intel-iommu-eim.xml             |  1 +
3e5111
 tests/qemuxml2xmltest.c                            |  1 +
3e5111
 7 files changed, 73 insertions(+)
3e5111
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-eim.xml
3e5111
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-eim.xml
3e5111
3e5111
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
3e5111
index 43a75c1ee..e886e4e17 100644
3e5111
--- a/docs/formatdomain.html.in
3e5111
+++ b/docs/formatdomain.html.in
3e5111
@@ -7433,6 +7433,19 @@ qemu-kvm -net nic,model=? /dev/null
3e5111
               Since 3.4.0 (QEMU/KVM only)
3e5111
             

3e5111
           
3e5111
+          
eim
3e5111
+          
3e5111
+            

3e5111
+              The eim attribute (with possible values
3e5111
+              on and off) can be used to
3e5111
+              configure Extended Interrupt Mode. A q35 domain with
3e5111
+              split I/O APIC (as described in
3e5111
+              hypervisor features),
3e5111
+              and both interrupt remapping and EIM turned on for
3e5111
+              the IOMMU, will be able to use more than 255 vCPUs.
3e5111
+              Since 3.4.0 (QEMU/KVM only)
3e5111
+            

3e5111
+          
3e5111
         
3e5111
       
3e5111
     
3e5111
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
3e5111
index 12ccbd4e2..af7824aa0 100644
3e5111
--- a/docs/schemas/domaincommon.rng
3e5111
+++ b/docs/schemas/domaincommon.rng
3e5111
@@ -3905,6 +3905,11 @@
3e5111
               <ref name="virOnOff"/>
3e5111
             </attribute>
3e5111
           </optional>
3e5111
+          <optional>
3e5111
+            <attribute name="eim">
3e5111
+              <ref name="virOnOff"/>
3e5111
+            </attribute>
3e5111
+          </optional>
3e5111
         </element>
3e5111
       </optional>
3e5111
     </element>
3e5111
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
3e5111
index 370916396..4404b8f73 100644
3e5111
--- a/src/conf/domain_conf.c
3e5111
+++ b/src/conf/domain_conf.c
3e5111
@@ -14176,6 +14176,15 @@ virDomainIOMMUDefParseXML(xmlNodePtr node,
3e5111
         iommu->caching_mode = val;
3e5111
     }
3e5111
 
3e5111
+    VIR_FREE(tmp);
3e5111
+    if ((tmp = virXPathString("string(./driver/@eim)", ctxt))) {
3e5111
+        if ((val = virTristateSwitchTypeFromString(tmp)) < 0) {
3e5111
+            virReportError(VIR_ERR_XML_ERROR, _("unknown eim value: %s"), tmp);
3e5111
+            goto cleanup;
3e5111
+        }
3e5111
+        iommu->eim = val;
3e5111
+    }
3e5111
+
3e5111
     ret = iommu;
3e5111
     iommu = NULL;
3e5111
 
3e5111
@@ -19847,6 +19856,14 @@ virDomainIOMMUDefCheckABIStability(virDomainIOMMUDefPtr src,
3e5111
                        virTristateSwitchTypeToString(src->caching_mode));
3e5111
         return false;
3e5111
     }
3e5111
+    if (src->eim != dst->eim) {
3e5111
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
+                       _("Target domain IOMMU device eim value '%s' "
3e5111
+                         "does not match source '%s'"),
3e5111
+                       virTristateSwitchTypeToString(dst->eim),
3e5111
+                       virTristateSwitchTypeToString(src->eim));
3e5111
+        return false;
3e5111
+    }
3e5111
     return true;
3e5111
 }
3e5111
 
3e5111
@@ -24170,6 +24187,10 @@ virDomainIOMMUDefFormat(virBufferPtr buf,
3e5111
             virBufferAsprintf(&childBuf, " caching_mode='%s'",
3e5111
                               virTristateSwitchTypeToString(iommu->caching_mode));
3e5111
         }
3e5111
+        if (iommu->eim != VIR_TRISTATE_SWITCH_ABSENT) {
3e5111
+            virBufferAsprintf(&childBuf, " eim='%s'",
3e5111
+                              virTristateSwitchTypeToString(iommu->eim));
3e5111
+        }
3e5111
         virBufferAddLit(&childBuf, "/>\n");
3e5111
     }
3e5111
 
3e5111
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
3e5111
index 825158a7d..980aafa66 100644
3e5111
--- a/src/conf/domain_conf.h
3e5111
+++ b/src/conf/domain_conf.h
3e5111
@@ -2211,6 +2211,7 @@ struct _virDomainIOMMUDef {
3e5111
     virDomainIOMMUModel model;
3e5111
     virTristateSwitch intremap;
3e5111
     virTristateSwitch caching_mode;
3e5111
+    virTristateSwitch eim;
3e5111
 };
3e5111
 /*
3e5111
  * Guest VM main configuration
3e5111
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-eim.xml b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-eim.xml
3e5111
new file mode 100644
3e5111
index 000000000..8642ed349
3e5111
--- /dev/null
3e5111
+++ b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-eim.xml
3e5111
@@ -0,0 +1,31 @@
3e5111
+<domain type='kvm'>
3e5111
+  <name>QEMUGuest1</name>
3e5111
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
3e5111
+  <memory unit='KiB'>219100</memory>
3e5111
+  <currentMemory unit='KiB'>219100</currentMemory>
3e5111
+  <vcpu placement='static'>288</vcpu>
3e5111
+  <os>
3e5111
+    <type arch='x86_64' machine='q35'>hvm</type>
3e5111
+    <boot dev='hd'/>
3e5111
+  </os>
3e5111
+  <features>
3e5111
+    <ioapic driver='qemu'/>
3e5111
+  </features>
3e5111
+  <clock offset='utc'/>
3e5111
+  <on_poweroff>destroy</on_poweroff>
3e5111
+  <on_reboot>restart</on_reboot>
3e5111
+  <on_crash>destroy</on_crash>
3e5111
+  <devices>
3e5111
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
3e5111
+    <controller type='pci' index='0' model='pcie-root'/>
3e5111
+    <controller type='sata' index='0'>
3e5111
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
3e5111
+    </controller>
3e5111
+    <input type='mouse' bus='ps2'/>
3e5111
+    <input type='keyboard' bus='ps2'/>
3e5111
+    <memballoon model='none'/>
3e5111
+    <iommu model='intel'>
3e5111
+      <driver intremap='on' eim='on'/>
3e5111
+    </iommu>
3e5111
+  </devices>
3e5111
+</domain>
3e5111
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-eim.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-eim.xml
3e5111
new file mode 120000
3e5111
index 000000000..9fbec36dc
3e5111
--- /dev/null
3e5111
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-eim.xml
3e5111
@@ -0,0 +1 @@
3e5111
+../qemuxml2argvdata/qemuxml2argv-intel-iommu-eim.xml
3e5111
\ No newline at end of file
3e5111
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
3e5111
index e1938421a..6283da409 100644
3e5111
--- a/tests/qemuxml2xmltest.c
3e5111
+++ b/tests/qemuxml2xmltest.c
3e5111
@@ -1130,6 +1130,7 @@ mymain(void)
3e5111
             QEMU_CAPS_MACHINE_IOMMU);
3e5111
     DO_TEST("intel-iommu-ioapic", NONE);
3e5111
     DO_TEST("intel-iommu-caching-mode", NONE);
3e5111
+    DO_TEST("intel-iommu-eim", NONE);
3e5111
 
3e5111
     DO_TEST("cpu-check-none", NONE);
3e5111
     DO_TEST("cpu-check-partial", NONE);
3e5111
-- 
3e5111
2.13.0
3e5111