b971b8
From 12892e0376be4dc07dc317b807f2ec86c27a94b2 Mon Sep 17 00:00:00 2001
b971b8
Message-Id: <12892e0376be4dc07dc317b807f2ec86c27a94b2@dist-git>
b971b8
From: Laine Stump <laine@redhat.com>
b971b8
Date: Sun, 26 Apr 2020 13:04:07 -0400
b971b8
Subject: [PATCH] conf: new attribute "hotplug" for pci controllers
b971b8
b971b8
a <controller type='pci'...> element can now have a "hotplug"
b971b8
attribute in the <target> subelement. This is intended to control
b971b8
whether or not the slot(s) of the controller support
b971b8
hotplugging/unplugging a device:
b971b8
b971b8
   <controller type='pci' model='pcie-root-port'>
b971b8
     <target hotplug='off'/>
b971b8
   </controller>
b971b8
b971b8
The default value of hotplug is "on".
b971b8
b971b8
Since support for configuring such an option is hypervisor-dependent
b971b8
(and will vary among different types of PCI controllers even on a
b971b8
single hypervisor), no validation is done in this patch - that
b971b8
validation will be done in the patch that wires support for the
b971b8
setting into the hypervisor.
b971b8
b971b8
Signed-off-by: Laine Stump <laine@redhat.com>
b971b8
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
b971b8
(cherry picked from commit 78f4d5e6f188a9f0f8d6da6b1fe78b9f4172d9ad)
b971b8
b971b8
https://bugzilla.redhat.com/1802592
b971b8
Signed-off-by: Laine Stump <laine@redhat.com>
b971b8
b971b8
Conflicts/Changes from upstread:
b971b8
b971b8
  tests/qemuxml2xmloutdata/pcie-root-port-nohotplug.x86_64-latest.xml:
b971b8
b971b8
    had to be modified to remove reference to the qemu64 CPU type.
b971b8
b971b8
Signed-off-by: Laine Stump <laine@redhat.com>
b971b8
Message-Id: <20200426170415.18328-5-laine@redhat.com>
b971b8
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
b971b8
---
b971b8
 docs/formatdomain.html.in                     | 11 +++
b971b8
 docs/schemas/domaincommon.rng                 |  5 ++
b971b8
 src/conf/domain_conf.c                        | 20 +++++-
b971b8
 src/conf/domain_conf.h                        |  1 +
b971b8
 .../pcie-root-port-nohotplug.xml              | 35 ++++++++++
b971b8
 ...pcie-root-port-nohotplug.x86_64-latest.xml | 67 +++++++++++++++++++
b971b8
 tests/qemuxml2xmltest.c                       |  2 +-
b971b8
 7 files changed, 139 insertions(+), 2 deletions(-)
b971b8
 create mode 100644 tests/qemuxml2argvdata/pcie-root-port-nohotplug.xml
b971b8
 create mode 100644 tests/qemuxml2xmloutdata/pcie-root-port-nohotplug.x86_64-latest.xml
b971b8
b971b8
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
b971b8
index 9c588185df..76799f5ffc 100644
b971b8
--- a/docs/formatdomain.html.in
b971b8
+++ b/docs/formatdomain.html.in
b971b8
@@ -4651,6 +4651,17 @@
b971b8
         which is visible to the virtual machine. If set, port must be
b971b8
         between 0 and 255.
b971b8
       
b971b8
+      
hotplug
b971b8
+      
b971b8
+        pcie-root-port and pcie-switch-downstream-port controllers can
b971b8
+        also have a hotplug attribute in
b971b8
+        the <target> subelement, which is used to
b971b8
+        disable hotplug/unplug of devices on a particular
b971b8
+        controller. The default setting of hotplug
b971b8
+        is on; it should be set to off to
b971b8
+        disable hotplug/unplug of devices on a particular controller.
b971b8
+        Since 6.3.0
b971b8
+      
b971b8
       
busNr
b971b8
       
b971b8
         pci-expander-bus and pcie-expander-bus controllers can have an
b971b8
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
b971b8
index dd8f27243a..9fda5f17e0 100644
b971b8
--- a/docs/schemas/domaincommon.rng
b971b8
+++ b/docs/schemas/domaincommon.rng
b971b8
@@ -2475,6 +2475,11 @@
b971b8
                     <ref name='uint8'/>
b971b8
                   </attribute>
b971b8
                 </optional>
b971b8
+                <optional>
b971b8
+                  <attribute name='hotplug'>
b971b8
+                    <ref name="virOnOff"/>
b971b8
+                  </attribute>
b971b8
+                </optional>
b971b8
                 <optional>
b971b8
                   <element name='node'>
b971b8
                     <ref name='unsignedInt'/>
b971b8
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
b971b8
index 28160a2967..ed9ca0e9d8 100644
b971b8
--- a/src/conf/domain_conf.c
b971b8
+++ b/src/conf/domain_conf.c
b971b8
@@ -10933,6 +10933,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
b971b8
     g_autofree char *port = NULL;
b971b8
     g_autofree char *busNr = NULL;
b971b8
     g_autofree char *targetIndex = NULL;
b971b8
+    g_autofree char *hotplug = NULL;
b971b8
     g_autofree char *ioeventfd = NULL;
b971b8
     g_autofree char *portsStr = NULL;
b971b8
     g_autofree char *iothread = NULL;
b971b8
@@ -11004,6 +11005,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
b971b8
                 chassis = virXMLPropString(cur, "chassis");
b971b8
                 port = virXMLPropString(cur, "port");
b971b8
                 busNr = virXMLPropString(cur, "busNr");
b971b8
+                hotplug = virXMLPropString(cur, "hotplug");
b971b8
                 targetIndex = virXMLPropString(cur, "index");
b971b8
                 processedTarget = true;
b971b8
             }
b971b8
@@ -11240,6 +11242,17 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
b971b8
             }
b971b8
             def->opts.pciopts.numaNode = numaNode;
b971b8
         }
b971b8
+        if (hotplug) {
b971b8
+            int val = virTristateSwitchTypeFromString(hotplug);
b971b8
+
b971b8
+            if (val <= 0) {
b971b8
+                virReportError(VIR_ERR_XML_ERROR,
b971b8
+                               _("PCI controller unrecognized hotplug setting '%s'"),
b971b8
+                               hotplug);
b971b8
+                goto error;
b971b8
+            }
b971b8
+            def->opts.pciopts.hotplug = val;
b971b8
+        }
b971b8
         break;
b971b8
     case VIR_DOMAIN_CONTROLLER_TYPE_XENBUS: {
b971b8
         g_autofree char *gntframes = virXMLPropString(node, "maxGrantFrames");
b971b8
@@ -25112,7 +25125,8 @@ virDomainControllerDefFormat(virBufferPtr buf,
b971b8
             def->opts.pciopts.port != -1 ||
b971b8
             def->opts.pciopts.busNr != -1 ||
b971b8
             def->opts.pciopts.targetIndex != -1 ||
b971b8
-            def->opts.pciopts.numaNode != -1) {
b971b8
+            def->opts.pciopts.numaNode != -1 ||
b971b8
+            def->opts.pciopts.hotplug != VIR_TRISTATE_SWITCH_ABSENT) {
b971b8
             virBufferAddLit(&childBuf, "
b971b8
             if (def->opts.pciopts.chassisNr != -1)
b971b8
                 virBufferAsprintf(&childBuf, " chassisNr='%d'",
b971b8
@@ -25129,6 +25143,10 @@ virDomainControllerDefFormat(virBufferPtr buf,
b971b8
             if (def->opts.pciopts.targetIndex != -1)
b971b8
                 virBufferAsprintf(&childBuf, " index='%d'",
b971b8
                                   def->opts.pciopts.targetIndex);
b971b8
+            if (def->opts.pciopts.hotplug != VIR_TRISTATE_SWITCH_ABSENT) {
b971b8
+                virBufferAsprintf(&childBuf, " hotplug='%s'",
b971b8
+                                  virTristateSwitchTypeToString(def->opts.pciopts.hotplug));
b971b8
+            }
b971b8
             if (def->opts.pciopts.numaNode == -1) {
b971b8
                 virBufferAddLit(&childBuf, "/>\n");
b971b8
             } else {
b971b8
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
b971b8
index 2a382ede72..118077edaa 100644
b971b8
--- a/src/conf/domain_conf.h
b971b8
+++ b/src/conf/domain_conf.h
b971b8
@@ -719,6 +719,7 @@ struct _virDomainPCIControllerOpts {
b971b8
      * item in memory target config) -1 == unspecified
b971b8
      */
b971b8
     int numaNode;
b971b8
+    virTristateSwitch hotplug; /* 'off' to prevent hotplug/unplug, default 'on' */
b971b8
 };
b971b8
 
b971b8
 struct _virDomainUSBControllerOpts {
b971b8
diff --git a/tests/qemuxml2argvdata/pcie-root-port-nohotplug.xml b/tests/qemuxml2argvdata/pcie-root-port-nohotplug.xml
b971b8
new file mode 100644
b971b8
index 0000000000..8a01494470
b971b8
--- /dev/null
b971b8
+++ b/tests/qemuxml2argvdata/pcie-root-port-nohotplug.xml
b971b8
@@ -0,0 +1,35 @@
b971b8
+<domain type='qemu'>
b971b8
+  <name>guest</name>
b971b8
+  <uuid>11dbdcdd-4c3b-482b-8903-9bdb8c0a2774</uuid>
b971b8
+  <memory unit='KiB'>2097152</memory>
b971b8
+  <currentMemory unit='KiB'>2097152</currentMemory>
b971b8
+  <vcpu placement='static'>2</vcpu>
b971b8
+  <os>
b971b8
+    <type arch='x86_64' machine='q35'>hvm</type>
b971b8
+  </os>
b971b8
+  <devices>
b971b8
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
b971b8
+    <controller type='pci' index='0' model='pcie-root'/>
b971b8
+    <controller type='pci' index='1' model='pcie-root-port'/>
b971b8
+    <controller type='pci' index='2' model='pcie-root-port'>
b971b8
+      <target hotplug='off'/>
b971b8
+    </controller>
b971b8
+    <controller type='pci' index='3' model='pcie-root-port'>
b971b8
+      <model name='ioh3420'/>
b971b8
+      <target hotplug='off'/>
b971b8
+    </controller>
b971b8
+    <controller type='pci' index='4' model='pcie-switch-upstream-port'/>
b971b8
+    <controller type='pci' index='5' model='pcie-switch-downstream-port'>
b971b8
+      <target hotplug='off'/>
b971b8
+    </controller>
b971b8
+    <controller type='pci' index='6' model='pcie-switch-downstream-port'>
b971b8
+      <target hotplug='on'/>
b971b8
+    </controller>
b971b8
+    <controller type='pci' index='7' model='pcie-switch-downstream-port'/>
b971b8
+    <controller type='pci' index='8' model='pcie-switch-downstream-port'>
b971b8
+      <model name='xio3130-downstream'/>
b971b8
+      <target chassis='30' port='0x27'/>
b971b8
+    </controller>
b971b8
+    <memballoon model='none'/>
b971b8
+  </devices>
b971b8
+</domain>
b971b8
diff --git a/tests/qemuxml2xmloutdata/pcie-root-port-nohotplug.x86_64-latest.xml b/tests/qemuxml2xmloutdata/pcie-root-port-nohotplug.x86_64-latest.xml
b971b8
new file mode 100644
b971b8
index 0000000000..f7dbaccae9
b971b8
--- /dev/null
b971b8
+++ b/tests/qemuxml2xmloutdata/pcie-root-port-nohotplug.x86_64-latest.xml
b971b8
@@ -0,0 +1,67 @@
b971b8
+<domain type='qemu'>
b971b8
+  <name>guest</name>
b971b8
+  <uuid>11dbdcdd-4c3b-482b-8903-9bdb8c0a2774</uuid>
b971b8
+  <memory unit='KiB'>2097152</memory>
b971b8
+  <currentMemory unit='KiB'>2097152</currentMemory>
b971b8
+  <vcpu placement='static'>2</vcpu>
b971b8
+  <os>
b971b8
+    <type arch='x86_64' machine='q35'>hvm</type>
b971b8
+    <boot dev='hd'/>
b971b8
+  </os>
b971b8
+  <clock offset='utc'/>
b971b8
+  <on_poweroff>destroy</on_poweroff>
b971b8
+  <on_reboot>restart</on_reboot>
b971b8
+  <on_crash>destroy</on_crash>
b971b8
+  <devices>
b971b8
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
b971b8
+    <controller type='pci' index='0' model='pcie-root'/>
b971b8
+    <controller type='pci' index='1' model='pcie-root-port'>
b971b8
+      <model name='pcie-root-port'/>
b971b8
+      <target chassis='1' port='0x8'/>
b971b8
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0' multifunction='on'/>
b971b8
+    </controller>
b971b8
+    <controller type='pci' index='2' model='pcie-root-port'>
b971b8
+      <model name='pcie-root-port'/>
b971b8
+      <target chassis='2' port='0x9' hotplug='off'/>
b971b8
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
b971b8
+    </controller>
b971b8
+    <controller type='pci' index='3' model='pcie-root-port'>
b971b8
+      <model name='ioh3420'/>
b971b8
+      <target chassis='3' port='0xa' hotplug='off'/>
b971b8
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
b971b8
+    </controller>
b971b8
+    <controller type='pci' index='4' model='pcie-switch-upstream-port'>
b971b8
+      <model name='x3130-upstream'/>
b971b8
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
b971b8
+    </controller>
b971b8
+    <controller type='pci' index='5' model='pcie-switch-downstream-port'>
b971b8
+      <model name='xio3130-downstream'/>
b971b8
+      <target chassis='5' port='0x0' hotplug='off'/>
b971b8
+      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
b971b8
+    </controller>
b971b8
+    <controller type='pci' index='6' model='pcie-switch-downstream-port'>
b971b8
+      <model name='xio3130-downstream'/>
b971b8
+      <target chassis='6' port='0x1' hotplug='on'/>
b971b8
+      <address type='pci' domain='0x0000' bus='0x04' slot='0x01' function='0x0'/>
b971b8
+    </controller>
b971b8
+    <controller type='pci' index='7' model='pcie-switch-downstream-port'>
b971b8
+      <model name='xio3130-downstream'/>
b971b8
+      <target chassis='7' port='0x2'/>
b971b8
+      <address type='pci' domain='0x0000' bus='0x04' slot='0x02' function='0x0'/>
b971b8
+    </controller>
b971b8
+    <controller type='pci' index='8' model='pcie-switch-downstream-port'>
b971b8
+      <model name='xio3130-downstream'/>
b971b8
+      <target chassis='30' port='0x27'/>
b971b8
+      <address type='pci' domain='0x0000' bus='0x04' slot='0x03' function='0x0'/>
b971b8
+    </controller>
b971b8
+    <controller type='usb' index='0' model='qemu-xhci'>
b971b8
+      <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
b971b8
+    </controller>
b971b8
+    <controller type='sata' index='0'>
b971b8
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
b971b8
+    </controller>
b971b8
+    <input type='mouse' bus='ps2'/>
b971b8
+    <input type='keyboard' bus='ps2'/>
b971b8
+    <memballoon model='none'/>
b971b8
+  </devices>
b971b8
+</domain>
b971b8
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
b971b8
index 15110dd104..c8218e423e 100644
b971b8
--- a/tests/qemuxml2xmltest.c
b971b8
+++ b/tests/qemuxml2xmltest.c
b971b8
@@ -953,7 +953,7 @@ mymain(void)
b971b8
             QEMU_CAPS_DEVICE_IOH3420);
b971b8
     DO_TEST("pcie-root-port-model-ioh3420",
b971b8
             QEMU_CAPS_DEVICE_IOH3420);
b971b8
-
b971b8
+    DO_TEST_CAPS_LATEST("pcie-root-port-nohotplug");
b971b8
     DO_TEST("pcie-switch-upstream-port",
b971b8
             QEMU_CAPS_DEVICE_IOH3420,
b971b8
             QEMU_CAPS_DEVICE_X3130_UPSTREAM,
b971b8
-- 
b971b8
2.26.2
b971b8