[libvirt] [PATCHv4 1/6] conf: add <ioapic driver> to <features>

Ján Tomko posted 6 patches 8 years, 7 months ago
[libvirt] [PATCHv4 1/6] conf: add <ioapic driver> to <features>
Posted by Ján Tomko 8 years, 7 months ago
Add a new <ioapic> element with a driver attribute.

Possible values are qemu and kvm. With 'qemu', the I/O
APIC can be put in the userspace even for KVM domains.

https://bugzilla.redhat.com/show_bug.cgi?id=1427005
---
 docs/formatdomain.html.in                          |  8 ++++++
 docs/schemas/domaincommon.rng                      | 15 ++++++++++
 src/conf/domain_conf.c                             | 33 +++++++++++++++++++++-
 src/conf/domain_conf.h                             | 11 ++++++++
 .../qemuxml2argv-intel-iommu-ioapic.xml            | 29 +++++++++++++++++++
 .../qemuxml2xmlout-intel-iommu-ioapic.xml          |  1 +
 tests/qemuxml2xmltest.c                            |  1 +
 7 files changed, 97 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-ioapic.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8c884f4..6669e71 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1678,6 +1678,7 @@
   &lt;/kvm&gt;
   &lt;pvspinlock state='on'/&gt;
   &lt;gic version='2'/&gt;
+  &lt;ioapic driver='qemu'/&gt;
 
 &lt;/features&gt;
 ...</pre>
@@ -1839,6 +1840,13 @@
           for hypervisor to decide.
           <span class="since">Since 2.1.0</span>
       </dd>
+      <dt><code>ioapic</code></dt>
+      <dd>Tune the I/O APIC. Possible values for the
+          <code>driver</code> attribute are:
+          <code>kvm</code> (default for KVM domains)
+          and <code>qemu</code> which puts I/O APIC in userspace.
+          <span class="since">Since 3.4.0</span> (KVM only)
+      </dd>
     </dl>
 
     <h3><a name="elementsTime">Time keeping</a></h3>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 281309e..64f718b 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4569,6 +4569,9 @@
               </optional>
             </element>
           </optional>
+          <optional>
+            <ref name="ioapic"/>
+          </optional>
         </interleave>
       </element>
     </optional>
@@ -4747,6 +4750,18 @@
     </element>
   </define>
 
+  <define name="ioapic">
+    <element name="ioapic">
+      <attribute name="driver">
+        <choice>
+          <value>qemu</value>
+          <value>kvm</value>
+        </choice>
+      </attribute>
+      <empty/>
+    </element>
+  </define>
+
   <define name="address">
     <element name="address">
       <choice>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0ff216e..29b04d3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -141,7 +141,8 @@ VIR_ENUM_IMPL(virDomainFeature, VIR_DOMAIN_FEATURE_LAST,
               "pmu",
               "vmport",
               "gic",
-              "smm")
+              "smm",
+              "ioapic")
 
 VIR_ENUM_IMPL(virDomainCapabilitiesPolicy, VIR_DOMAIN_CAPABILITIES_POLICY_LAST,
               "default",
@@ -859,6 +860,11 @@ VIR_ENUM_IMPL(virDomainLoader,
               "rom",
               "pflash")
 
+VIR_ENUM_IMPL(virDomainIOAPIC,
+              VIR_DOMAIN_IOAPIC_LAST,
+              "qemu",
+              "kvm")
+
 /* Internal mapping: subset of block job types that can be present in
  * <mirror> XML (remaining types are not two-phase). */
 VIR_ENUM_DECL(virDomainBlockJob)
@@ -17527,6 +17533,24 @@ virDomainDefParseXML(xmlDocPtr xml,
             ctxt->node = node;
             break;
 
+        case VIR_DOMAIN_FEATURE_IOAPIC:
+            node = ctxt->node;
+            ctxt->node = nodes[i];
+            tmp = virXPathString("string(./@driver)", ctxt);
+            if (tmp) {
+                int value = virDomainIOAPICTypeFromString(tmp);
+                if (value < 0) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("Unknown driver mode: %s"),
+                                   tmp);
+                    goto error;
+                }
+                def->ioapic = value;
+                def->features[val] = VIR_TRISTATE_SWITCH_ON;
+            }
+            ctxt->node = node;
+            break;
+
         /* coverity[dead_error_begin] */
         case VIR_DOMAIN_FEATURE_LAST:
             break;
@@ -24627,6 +24651,13 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                 }
                 break;
 
+            case VIR_DOMAIN_FEATURE_IOAPIC:
+                if (def->features[i] == VIR_TRISTATE_SWITCH_ON) {
+                    virBufferAsprintf(buf, "<ioapic driver='%s'/>\n",
+                                      virDomainIOAPICTypeToString(def->ioapic));
+                }
+                break;
+
             /* coverity[dead_error_begin] */
             case VIR_DOMAIN_FEATURE_LAST:
                 break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 09fb7aa..82b4785 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1670,6 +1670,7 @@ typedef enum {
     VIR_DOMAIN_FEATURE_VMPORT,
     VIR_DOMAIN_FEATURE_GIC,
     VIR_DOMAIN_FEATURE_SMM,
+    VIR_DOMAIN_FEATURE_IOAPIC,
 
     VIR_DOMAIN_FEATURE_LAST
 } virDomainFeature;
@@ -1809,6 +1810,15 @@ struct _virDomainLoaderDef {
 
 void virDomainLoaderDefFree(virDomainLoaderDefPtr loader);
 
+typedef enum {
+    VIR_DOMAIN_IOAPIC_QEMU = 0,
+    VIR_DOMAIN_IOAPIC_KVM,
+
+    VIR_DOMAIN_IOAPIC_LAST
+} virDomainIOAPIC;
+
+VIR_ENUM_DECL(virDomainIOAPIC);
+
 /* Operating system configuration data & machine / arch */
 typedef struct _virDomainOSDef virDomainOSDef;
 typedef virDomainOSDef *virDomainOSDefPtr;
@@ -2258,6 +2268,7 @@ struct _virDomainDef {
     unsigned int hyperv_spinlocks;
     virGICVersion gic_version;
     char *hyperv_vendor_id;
+    virDomainIOAPIC ioapic;
 
     /* These options are of type virTristateSwitch: ON = keep, OFF = drop */
     int caps_features[VIR_DOMAIN_CAPS_FEATURE_LAST];
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml
new file mode 100644
index 0000000..284d63a
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml
@@ -0,0 +1,29 @@
+<domain type='kvm'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219100</memory>
+  <currentMemory unit='KiB'>219100</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='q35'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <features>
+    <ioapic driver='qemu'/>
+  </features>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <controller type='pci' index='0' model='pcie-root'/>
+    <controller type='sata' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
+    </controller>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='none'/>
+    <iommu model='intel'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-ioapic.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-ioapic.xml
new file mode 120000
index 0000000..42d17b2
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-ioapic.xml
@@ -0,0 +1 @@
+../qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml
\ No newline at end of file
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 2dccde7..0f00b20 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -1122,6 +1122,7 @@ mymain(void)
     DO_TEST("intel-iommu-machine",
             QEMU_CAPS_MACHINE_OPT,
             QEMU_CAPS_MACHINE_IOMMU);
+    DO_TEST("intel-iommu-ioapic", NONE);
 
     DO_TEST("cpu-check-none", NONE);
     DO_TEST("cpu-check-partial", NONE);
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv4 1/6] conf: add <ioapic driver> to <features>
Posted by John Ferlan 8 years, 7 months ago

On 05/03/2017 10:05 AM, Ján Tomko wrote:
> Add a new <ioapic> element with a driver attribute.
> 
> Possible values are qemu and kvm. With 'qemu', the I/O
> APIC can be put in the userspace even for KVM domains.
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1427005
> ---
>  docs/formatdomain.html.in                          |  8 ++++++
>  docs/schemas/domaincommon.rng                      | 15 ++++++++++
>  src/conf/domain_conf.c                             | 33 +++++++++++++++++++++-
>  src/conf/domain_conf.h                             | 11 ++++++++
>  .../qemuxml2argv-intel-iommu-ioapic.xml            | 29 +++++++++++++++++++
>  .../qemuxml2xmlout-intel-iommu-ioapic.xml          |  1 +
>  tests/qemuxml2xmltest.c                            |  1 +
>  7 files changed, 97 insertions(+), 1 deletion(-)
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml
>  create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-ioapic.xml
> 
> diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> index 8c884f4..6669e71 100644
> --- a/docs/formatdomain.html.in
> +++ b/docs/formatdomain.html.in
> @@ -1678,6 +1678,7 @@
>    &lt;/kvm&gt;
>    &lt;pvspinlock state='on'/&gt;
>    &lt;gic version='2'/&gt;
> +  &lt;ioapic driver='qemu'/&gt;
>  
>  &lt;/features&gt;
>  ...</pre>
> @@ -1839,6 +1840,13 @@
>            for hypervisor to decide.
>            <span class="since">Since 2.1.0</span>
>        </dd>
> +      <dt><code>ioapic</code></dt>
> +      <dd>Tune the I/O APIC. Possible values for the
> +          <code>driver</code> attribute are:
> +          <code>kvm</code> (default for KVM domains)
> +          and <code>qemu</code> which puts I/O APIC in userspace.

s/./which is also known as a split I/O APIC mode.

> +          <span class="since">Since 3.4.0</span> (KVM only)

should this be QEMU/KVM like patch 3 ?

> +      </dd>
>      </dl>
>  
>      <h3><a name="elementsTime">Time keeping</a></h3>

[...]

ACK w/ slight adjustments.

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv4 1/6] conf: add <ioapic driver> to <features>
Posted by Andrea Bolognani 8 years, 7 months ago
On Wed, 2017-05-03 at 16:05 +0200, Ján Tomko wrote:
> Add a new <ioapic> element with a driver attribute.
> 
> Possible values are qemu and kvm. With 'qemu', the I/O
> APIC can be put in the userspace even for KVM domains.
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1427005
> ---
>  docs/formatdomain.html.in                          |  8 ++++++
>  docs/schemas/domaincommon.rng                      | 15 ++++++++++
>  src/conf/domain_conf.c                             | 33 +++++++++++++++++++++-
>  src/conf/domain_conf.h                             | 11 ++++++++
>  .../qemuxml2argv-intel-iommu-ioapic.xml            | 29 +++++++++++++++++++
>  .../qemuxml2xmlout-intel-iommu-ioapic.xml          |  1 +
>  tests/qemuxml2xmltest.c                            |  1 +
>  7 files changed, 97 insertions(+), 1 deletion(-)
>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml
>  create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-ioapic.xml

Please make sure that only x86 guests can use the <ioapic/>
feature, and all other guests get an error instead.

Also I didn't check whether this is the case already, but
the feature should be advertised the same way <apic/> is,
and in particular it should show up in the capabilities XML.

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv4 1/6] conf: add <ioapic driver> to <features>
Posted by Ján Tomko 8 years, 7 months ago
On Tue, May 09, 2017 at 01:08:55PM +0200, Andrea Bolognani wrote:
>On Wed, 2017-05-03 at 16:05 +0200, Ján Tomko wrote:
>> Add a new <ioapic> element with a driver attribute.
>> 
>> Possible values are qemu and kvm. With 'qemu', the I/O
>> APIC can be put in the userspace even for KVM domains.
>> 
>> https://bugzilla.redhat.com/show_bug.cgi?id=1427005
>> ---
>>  docs/formatdomain.html.in                          |  8 ++++++
>>  docs/schemas/domaincommon.rng                      | 15 ++++++++++
>>  src/conf/domain_conf.c                             | 33 +++++++++++++++++++++-
>>  src/conf/domain_conf.h                             | 11 ++++++++
>>  .../qemuxml2argv-intel-iommu-ioapic.xml            | 29 +++++++++++++++++++
>>  .../qemuxml2xmlout-intel-iommu-ioapic.xml          |  1 +
>>  tests/qemuxml2xmltest.c                            |  1 +
>>  7 files changed, 97 insertions(+), 1 deletion(-)
>>  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-intel-iommu-ioapic.xml
>>  create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-intel-iommu-ioapic.xml
>
>Please make sure that only x86 guests can use the <ioapic/>
>feature, and all other guests get an error instead.
>
>Also I didn't check whether this is the case already, but
>the feature should be advertised the same way <apic/> is,
>and in particular it should show up in the capabilities XML.
>

I have sent the capabilites as a separate patch.

Re: x86-only: would squashing this in do?

Jan

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index cc02c80..7805b76 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2807,6 +2807,22 @@ qemuDomainDefCPUPostParse(virDomainDefPtr def)
 
 
 static int
+qemuDomainDefVerifyFeatures(const virDomainDef *def)
+{
+    if (def->features[VIR_DOMAIN_FEATURE_IOAPIC] == VIR_TRISTATE_SWITCH_ON &&
+        !ARCH_IS_X86(def->os.arch)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("I/O APIC tuning is not supported "
+                         "for '%s' architecture"),
+                       virArchToString(def->os.arch));
+        return -1;
+    }
+
+    return 0;
+}
+
+
+static int
 qemuDomainDefPostParse(virDomainDefPtr def,
                        virCapsPtr caps,
                        unsigned int parseFlags,
@@ -2861,6 +2877,9 @@ qemuDomainDefPostParse(virDomainDefPtr def,
 
     qemuDomainDefEnableDefaultFeatures(def, qemuCaps);
 
+    if (qemuDomainDefVerifyFeatures(def) < 0)
+        goto cleanup;
+
     if (qemuDomainRecheckInternalPaths(def, cfg, parseFlags) < 0)
         goto cleanup;
 
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv4 1/6] conf: add <ioapic driver> to <features>
Posted by Andrea Bolognani 8 years, 7 months ago
On Fri, 2017-05-12 at 16:42 +0200, Ján Tomko wrote:
> Re: x86-only: would squashing this in do?

Yup, looks reasonable enough :)

-- 
Andrea Bolognani / Red Hat / Virtualization

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