c1c534
From 623a617e8199a9c7abd1903399fdbeccf4e85add Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <623a617e8199a9c7abd1903399fdbeccf4e85add@dist-git>
c1c534
From: Andrea Bolognani <abologna@redhat.com>
c1c534
Date: Wed, 29 Nov 2017 16:23:14 +0100
c1c534
Subject: [PATCH] conf: Add target type and model for pl011
c1c534
c1c534
We can finally introduce a specific target model for the pl011 device
c1c534
used by mach-virt guests, which means isa-serial will no longer show
c1c534
up to confuse users.
c1c534
c1c534
We make sure migration works in both directions by interpreting the
c1c534
isa-serial target type, or the lack of target type, appropriately
c1c534
when parsing the guest XML, and skipping the newly-introduced type
c1c534
when formatting if for migration. We also verify that pl011 is not
c1c534
used for non-mach-virt guests and add a bunch of test cases.
c1c534
c1c534
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1512929
c1c534
c1c534
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c1c534
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
c1c534
(cherry picked from commit eccdcb81fcfd1641960d397c82986b4517841794)
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 docs/formatdomain.html.in                          | 13 ++++---
c1c534
 docs/schemas/domaincommon.rng                      |  2 +
c1c534
 src/conf/domain_conf.c                             |  3 ++
c1c534
 src/conf/domain_conf.h                             |  2 +
c1c534
 src/qemu/qemu_command.c                            |  9 ++++-
c1c534
 src/qemu/qemu_domain.c                             | 26 +++++++++++++
c1c534
 src/qemu/qemu_domain_address.c                     |  1 +
c1c534
 .../qemuxml2argv-mach-virt-console-native.args     |  1 +
c1c534
 .../qemuxml2argv-mach-virt-console-native.xml      | 17 +++++++++
c1c534
 .../qemuxml2argv-mach-virt-console-virtio.args     | 24 ++++++++++++
c1c534
 .../qemuxml2argv-mach-virt-console-virtio.xml      | 19 ++++++++++
c1c534
 ...muxml2argv-mach-virt-serial+console-native.args |  1 +
c1c534
 ...emuxml2argv-mach-virt-serial+console-native.xml | 18 +++++++++
c1c534
 .../qemuxml2argv-mach-virt-serial-compat.args      |  1 +
c1c534
 .../qemuxml2argv-mach-virt-serial-compat.xml       | 19 ++++++++++
c1c534
 ...muxml2argv-mach-virt-serial-invalid-machine.xml | 21 +++++++++++
c1c534
 .../qemuxml2argv-mach-virt-serial-native.args      | 23 +++++++++++
c1c534
 .../qemuxml2argv-mach-virt-serial-native.xml       | 16 ++++++++
c1c534
 .../qemuxml2argv-mach-virt-serial-pci.args         | 26 +++++++++++++
c1c534
 .../qemuxml2argv-mach-virt-serial-pci.xml          | 18 +++++++++
c1c534
 .../qemuxml2argv-mach-virt-serial-usb.args         | 27 +++++++++++++
c1c534
 .../qemuxml2argv-mach-virt-serial-usb.xml          | 21 +++++++++++
c1c534
 tests/qemuxml2argvtest.c                           | 27 +++++++++++++
c1c534
 .../qemuxml2xmlout-aarch64-virtio-pci-default.xml  |  4 +-
c1c534
 .../qemuxml2xmlout-mach-virt-console-native.xml    |  1 +
c1c534
 .../qemuxml2xmlout-mach-virt-console-virtio.xml    | 27 +++++++++++++
c1c534
 ...uxml2xmlout-mach-virt-serial+console-native.xml |  1 +
c1c534
 .../qemuxml2xmlout-mach-virt-serial-compat.xml     | 31 +++++++++++++++
c1c534
 .../qemuxml2xmlout-mach-virt-serial-native.xml     |  1 +
c1c534
 .../qemuxml2xmlout-mach-virt-serial-pci.xml        | 44 ++++++++++++++++++++++
c1c534
 .../qemuxml2xmlout-mach-virt-serial-usb.xml        | 41 ++++++++++++++++++++
c1c534
 tests/qemuxml2xmltest.c                            | 26 +++++++++++++
c1c534
 32 files changed, 503 insertions(+), 8 deletions(-)
c1c534
 create mode 120000 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-native.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-native.xml
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-virtio.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-virtio.xml
c1c534
 create mode 120000 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial+console-native.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial+console-native.xml
c1c534
 create mode 120000 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-compat.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-compat.xml
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-invalid-machine.xml
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-native.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-native.xml
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-pci.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-pci.xml
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-usb.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-usb.xml
c1c534
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-console-native.xml
c1c534
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-console-virtio.xml
c1c534
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial+console-native.xml
c1c534
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-compat.xml
c1c534
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-native.xml
c1c534
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-pci.xml
c1c534
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-usb.xml
c1c534
c1c534
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
c1c534
index 0634f3396a..87389f4e73 100644
c1c534
--- a/docs/formatdomain.html.in
c1c534
+++ b/docs/formatdomain.html.in
c1c534
@@ -6463,8 +6463,9 @@ qemu-kvm -net nic,model=? /dev/null
c1c534
       with x86 guests), usb-serial (usable whenever USB support
c1c534
       is available) and pci-serial (usable whenever PCI support
c1c534
       is available); since 3.10.0,
c1c534
-      spapr-vio-serial (usable with ppc64/pseries guests)
c1c534
-      is available as well.
c1c534
+      spapr-vio-serial (usable with ppc64/pseries guests) and
c1c534
+      system-serial (usable with aarch64/virt guests) are
c1c534
+      available as well.
c1c534
     

c1c534
 
c1c534
     

c1c534
@@ -6476,7 +6477,8 @@ qemu-kvm -net nic,model=? /dev/null
c1c534
       target type); pci-serial
c1c534
       (usable with the pci-serial target type);
c1c534
       spapr-vty (usable with the spapr-vio-serial
c1c534
-      target type).
c1c534
+      target type); pl011 (usable with the
c1c534
+      system-serial target type).
c1c534
     

c1c534
 
c1c534
     

c1c534
@@ -6485,12 +6487,13 @@ qemu-kvm -net nic,model=? /dev/null
c1c534
     

c1c534
 
c1c534
     

c1c534
-      All of the target types support configuring the guest-visible device
c1c534
+      Most target types support configuring the guest-visible device
c1c534
       address as documented above; more
c1c534
       specifically, acceptable address types are isa (for
c1c534
       isa-serial), usb (for usb-serial),
c1c534
       pci (for pci-serial) and spapr-vio
c1c534
-      (for spapr-vio-serial).
c1c534
+      (for spapr-vio-serial). The system-serial
c1c534
+      target type doesn't support specifying an address.
c1c534
     

c1c534
 
c1c534
     

c1c534
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
c1c534
index 027d9ae7a1..957eae2832 100644
c1c534
--- a/docs/schemas/domaincommon.rng
c1c534
+++ b/docs/schemas/domaincommon.rng
c1c534
@@ -3572,6 +3572,7 @@
c1c534
         <value>usb-serial</value>
c1c534
         <value>pci-serial</value>
c1c534
         <value>spapr-vio-serial</value>
c1c534
+        <value>system-serial</value>
c1c534
       </choice>
c1c534
     </attribute>
c1c534
   </define>
c1c534
@@ -3584,6 +3585,7 @@
c1c534
           <value>usb-serial</value>
c1c534
           <value>pci-serial</value>
c1c534
           <value>spapr-vty</value>
c1c534
+          <value>pl011</value>
c1c534
         </choice>
c1c534
       </attribute>
c1c534
     </element>
c1c534
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
c1c534
index 97c7a66b5b..32089df3c2 100644
c1c534
--- a/src/conf/domain_conf.c
c1c534
+++ b/src/conf/domain_conf.c
c1c534
@@ -446,6 +446,7 @@ VIR_ENUM_IMPL(virDomainChrSerialTarget,
c1c534
               "usb-serial",
c1c534
               "pci-serial",
c1c534
               "spapr-vio-serial",
c1c534
+              "system-serial",
c1c534
 );
c1c534
 
c1c534
 VIR_ENUM_IMPL(virDomainChrChannelTarget,
c1c534
@@ -474,6 +475,7 @@ VIR_ENUM_IMPL(virDomainChrSerialTargetModel,
c1c534
               "usb-serial",
c1c534
               "pci-serial",
c1c534
               "spapr-vty",
c1c534
+              "pl011",
c1c534
 );
c1c534
 
c1c534
 VIR_ENUM_IMPL(virDomainChrDevice, VIR_DOMAIN_CHR_DEVICE_TYPE_LAST,
c1c534
@@ -4063,6 +4065,7 @@ virDomainDefAddConsoleCompat(virDomainDefPtr def)
c1c534
         switch ((virDomainChrSerialTargetType) def->serials[0]->targetType) {
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO:
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE: {
c1c534
 
c1c534
             /* Create a stub console to match the serial port.
c1c534
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
c1c534
index 979e8cca00..d6febf3059 100644
c1c534
--- a/src/conf/domain_conf.h
c1c534
+++ b/src/conf/domain_conf.h
c1c534
@@ -1078,6 +1078,7 @@ typedef enum {
c1c534
     VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB,
c1c534
     VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI,
c1c534
     VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO,
c1c534
+    VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM,
c1c534
 
c1c534
     VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST
c1c534
 } virDomainChrSerialTargetType;
c1c534
@@ -1111,6 +1112,7 @@ typedef enum {
c1c534
     VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL,
c1c534
     VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL,
c1c534
     VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_SPAPR_VTY,
c1c534
+    VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011,
c1c534
 
c1c534
     VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST
c1c534
 } virDomainChrSerialTargetModel;
c1c534
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
c1c534
index 056dafea39..483eee6056 100644
c1c534
--- a/src/qemu/qemu_command.c
c1c534
+++ b/src/qemu/qemu_command.c
c1c534
@@ -9230,6 +9230,7 @@ qemuChrSerialTargetModelToCaps(virDomainChrSerialTargetModel targetModel)
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_SPAPR_VTY:
c1c534
         return QEMU_CAPS_DEVICE_SPAPR_VTY;
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011:
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE:
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
c1c534
         break;
c1c534
@@ -9261,10 +9262,13 @@ qemuChrIsPlatformDevice(const virDomainDef *def,
c1c534
                         virDomainChrDefPtr chr)
c1c534
 {
c1c534
     if (def->os.arch == VIR_ARCH_ARMV7L || def->os.arch == VIR_ARCH_AARCH64) {
c1c534
-        /* TARGET_TYPE_ISA here really means 'the default platform device' */
c1c534
+
c1c534
+        /* pl011 (used on mach-virt) is a platform device */
c1c534
         if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
c1c534
-            chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA)
c1c534
+            chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM &&
c1c534
+            chr->targetModel == VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011) {
c1c534
             return true;
c1c534
+        }
c1c534
     }
c1c534
 
c1c534
     /* If we got all the way here and we're still stuck with the default
c1c534
@@ -10365,6 +10369,7 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
c1c534
         break;
c1c534
 
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011:
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE:
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
c1c534
         /* Except from _LAST, which is just a guard value and will never
c1c534
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
c1c534
index 17c898896d..2fc173fa45 100644
c1c534
--- a/src/qemu/qemu_domain.c
c1c534
+++ b/src/qemu/qemu_domain.c
c1c534
@@ -3468,6 +3468,7 @@ qemuDomainChrSerialTargetTypeToAddressType(int targetType)
c1c534
         return VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO:
c1c534
         return VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO;
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM:
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
c1c534
         break;
c1c534
@@ -3489,6 +3490,8 @@ qemuDomainChrSerialTargetModelToTargetType(int targetModel)
c1c534
         return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI;
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_SPAPR_VTY:
c1c534
         return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO;
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011:
c1c534
+        return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM;
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE:
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
c1c534
         break;
c1c534
@@ -3525,6 +3528,16 @@ qemuDomainChrTargetDefValidate(const virDomainChrDef *chr)
c1c534
             }
c1c534
             break;
c1c534
 
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM:
c1c534
+            if (chr->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
c1c534
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c1c534
+                               _("Target type '%s' cannot have an "
c1c534
+                                 "associated address"),
c1c534
+                               virDomainChrSerialTargetTypeToString(chr->targetType));
c1c534
+                return -1;
c1c534
+            }
c1c534
+            break;
c1c534
+
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
c1c534
             break;
c1c534
@@ -3536,6 +3549,7 @@ qemuDomainChrTargetDefValidate(const virDomainChrDef *chr)
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_SPAPR_VTY:
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011:
c1c534
 
c1c534
             expected = qemuDomainChrSerialTargetModelToTargetType(chr->targetModel);
c1c534
 
c1c534
@@ -3592,6 +3606,12 @@ qemuDomainChrDefValidate(const virDomainChrDef *dev,
c1c534
             isCompatible = false;
c1c534
         }
c1c534
 
c1c534
+        if (!qemuDomainIsVirt(def) &&
c1c534
+            (dev->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM ||
c1c534
+             dev->targetModel == VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011)) {
c1c534
+            isCompatible = false;
c1c534
+        }
c1c534
+
c1c534
         if (!isCompatible) {
c1c534
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c1c534
                            _("Serial device with target type '%s' and "
c1c534
@@ -4243,6 +4263,8 @@ qemuDomainChrDefPostParse(virDomainChrDefPtr chr,
c1c534
             chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA;
c1c534
         } else if (qemuDomainIsPSeries(def)) {
c1c534
             chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO;
c1c534
+        } else if (qemuDomainIsVirt(def)) {
c1c534
+            chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM;
c1c534
         }
c1c534
     }
c1c534
 
c1c534
@@ -4262,6 +4284,9 @@ qemuDomainChrDefPostParse(virDomainChrDefPtr chr,
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO:
c1c534
             chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_SPAPR_VTY;
c1c534
             break;
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM:
c1c534
+            chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PL011;
c1c534
+            break;
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
c1c534
             /* Nothing to do */
c1c534
@@ -5178,6 +5203,7 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver,
c1c534
             if (flags & VIR_DOMAIN_XML_MIGRATABLE) {
c1c534
                 switch ((virDomainChrSerialTargetType) serial->targetType) {
c1c534
                 case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO:
c1c534
+                case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM:
c1c534
                     serial->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE;
c1c534
                     serial->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE;
c1c534
                     break;
c1c534
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
c1c534
index f62bb2f97e..db9656a3a5 100644
c1c534
--- a/src/qemu/qemu_domain_address.c
c1c534
+++ b/src/qemu/qemu_domain_address.c
c1c534
@@ -784,6 +784,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO:
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SYSTEM:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
c1c534
             return 0;
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-native.args b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-native.args
c1c534
new file mode 120000
c1c534
index 0000000000..1a90484d3b
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-native.args
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2argv-mach-virt-serial-native.args
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-native.xml b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-native.xml
c1c534
new file mode 100644
c1c534
index 0000000000..6aba864d0b
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-native.xml
c1c534
@@ -0,0 +1,17 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='aarch64' machine='virt'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-aarch64</emulator>
c1c534
+    <controller type='usb' model='none'/>
c1c534
+    
c1c534
+         <serial> element being created -->
c1c534
+    <console type='pty'/>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-virtio.args b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-virtio.args
c1c534
new file mode 100644
c1c534
index 0000000000..2a862bff18
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-virtio.args
c1c534
@@ -0,0 +1,24 @@
c1c534
+LC_ALL=C \
c1c534
+PATH=/bin \
c1c534
+HOME=/home/test \
c1c534
+USER=test \
c1c534
+LOGNAME=test \
c1c534
+QEMU_AUDIO_DRV=none \
c1c534
+/usr/bin/qemu-system-aarch64 \
c1c534
+-name guest \
c1c534
+-S \
c1c534
+-M virt \
c1c534
+-m 512 \
c1c534
+-smp 1,sockets=1,cores=1,threads=1 \
c1c534
+-uuid 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 \
c1c534
+-nographic \
c1c534
+-nodefconfig \
c1c534
+-nodefaults \
c1c534
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-guest/monitor.sock,\
c1c534
+server,nowait \
c1c534
+-mon chardev=charmonitor,id=monitor,mode=readline \
c1c534
+-no-acpi \
c1c534
+-boot c \
c1c534
+-device virtio-serial,id=virtio-serial0 \
c1c534
+-chardev pty,id=charconsole0 \
c1c534
+-device virtconsole,chardev=charconsole0,id=console0
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-virtio.xml b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-virtio.xml
c1c534
new file mode 100644
c1c534
index 0000000000..92704504c8
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-console-virtio.xml
c1c534
@@ -0,0 +1,19 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='aarch64' machine='virt'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-aarch64</emulator>
c1c534
+    <controller type='usb' model='none'/>
c1c534
+    
c1c534
+         matching <serial> element being created -->
c1c534
+    <console type='pty'>
c1c534
+      <target type='virtio'/>
c1c534
+    </console>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial+console-native.args b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial+console-native.args
c1c534
new file mode 120000
c1c534
index 0000000000..1a90484d3b
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial+console-native.args
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2argv-mach-virt-serial-native.args
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial+console-native.xml b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial+console-native.xml
c1c534
new file mode 100644
c1c534
index 0000000000..549b764e98
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial+console-native.xml
c1c534
@@ -0,0 +1,18 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='aarch64' machine='virt'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-aarch64</emulator>
c1c534
+    <controller type='usb' model='none'/>
c1c534
+    
c1c534
+         be matched and end up representing the same native serial console -->
c1c534
+    <serial type='pty'/>
c1c534
+    <console type='pty'/>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-compat.args b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-compat.args
c1c534
new file mode 120000
c1c534
index 0000000000..1a90484d3b
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-compat.args
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2argv-mach-virt-serial-native.args
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-compat.xml b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-compat.xml
c1c534
new file mode 100644
c1c534
index 0000000000..9e6be3ffeb
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-compat.xml
c1c534
@@ -0,0 +1,19 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='aarch64' machine='virt'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-aarch64</emulator>
c1c534
+    <controller type='usb' model='none'/>
c1c534
+    
c1c534
+         but should get converted to the proper type (pl011) -->
c1c534
+    <serial type='pty'>
c1c534
+      <target type='isa-serial'/>
c1c534
+    </serial>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-invalid-machine.xml b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-invalid-machine.xml
c1c534
new file mode 100644
c1c534
index 0000000000..a8de76abf9
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-invalid-machine.xml
c1c534
@@ -0,0 +1,21 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='x86_64' machine='pc'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
c1c534
+    <controller type='usb' model='none'/>
c1c534
+    
c1c534
+         so this should be rejected -->
c1c534
+    <serial type='pty'>
c1c534
+      <target type='system-serial'>
c1c534
+        <model name='pl011'/>
c1c534
+      </target>
c1c534
+    </serial>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-native.args b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-native.args
c1c534
new file mode 100644
c1c534
index 0000000000..f4bfce376a
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-native.args
c1c534
@@ -0,0 +1,23 @@
c1c534
+LC_ALL=C \
c1c534
+PATH=/bin \
c1c534
+HOME=/home/test \
c1c534
+USER=test \
c1c534
+LOGNAME=test \
c1c534
+QEMU_AUDIO_DRV=none \
c1c534
+/usr/bin/qemu-system-aarch64 \
c1c534
+-name guest \
c1c534
+-S \
c1c534
+-M virt \
c1c534
+-m 512 \
c1c534
+-smp 1,sockets=1,cores=1,threads=1 \
c1c534
+-uuid 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 \
c1c534
+-nographic \
c1c534
+-nodefconfig \
c1c534
+-nodefaults \
c1c534
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-guest/monitor.sock,\
c1c534
+server,nowait \
c1c534
+-mon chardev=charmonitor,id=monitor,mode=readline \
c1c534
+-no-acpi \
c1c534
+-boot c \
c1c534
+-chardev pty,id=charserial0 \
c1c534
+-serial chardev:charserial0
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-native.xml b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-native.xml
c1c534
new file mode 100644
c1c534
index 0000000000..817f606eea
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-native.xml
c1c534
@@ -0,0 +1,16 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='aarch64' machine='virt'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-aarch64</emulator>
c1c534
+    <controller type='usb' model='none'/>
c1c534
+    
c1c534
+    <serial type='pty'/>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-pci.args b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-pci.args
c1c534
new file mode 100644
c1c534
index 0000000000..334194efe1
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-pci.args
c1c534
@@ -0,0 +1,26 @@
c1c534
+LC_ALL=C \
c1c534
+PATH=/bin \
c1c534
+HOME=/home/test \
c1c534
+USER=test \
c1c534
+LOGNAME=test \
c1c534
+QEMU_AUDIO_DRV=none \
c1c534
+/usr/bin/qemu-system-aarch64 \
c1c534
+-name guest \
c1c534
+-S \
c1c534
+-M virt \
c1c534
+-m 512 \
c1c534
+-smp 1,sockets=1,cores=1,threads=1 \
c1c534
+-uuid 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 \
c1c534
+-nographic \
c1c534
+-nodefconfig \
c1c534
+-nodefaults \
c1c534
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-guest/monitor.sock,\
c1c534
+server,nowait \
c1c534
+-mon chardev=charmonitor,id=monitor,mode=readline \
c1c534
+-no-acpi \
c1c534
+-boot c \
c1c534
+-device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1 \
c1c534
+-device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 \
c1c534
+-device pcie-root-port,port=0x10,chassis=3,id=pci.3,bus=pcie.0,addr=0x2 \
c1c534
+-chardev pty,id=charserial0 \
c1c534
+-device pci-serial,chardev=charserial0,id=serial0,bus=pci.2,addr=0x1
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-pci.xml b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-pci.xml
c1c534
new file mode 100644
c1c534
index 0000000000..29aa7664b1
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-pci.xml
c1c534
@@ -0,0 +1,18 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='aarch64' machine='virt'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-aarch64</emulator>
c1c534
+    <controller type='usb' model='none'/>
c1c534
+    
c1c534
+    <serial type='pty'>
c1c534
+      <target type='pci-serial'/>
c1c534
+    </serial>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-usb.args b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-usb.args
c1c534
new file mode 100644
c1c534
index 0000000000..44c4027acc
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-usb.args
c1c534
@@ -0,0 +1,27 @@
c1c534
+LC_ALL=C \
c1c534
+PATH=/bin \
c1c534
+HOME=/home/test \
c1c534
+USER=test \
c1c534
+LOGNAME=test \
c1c534
+QEMU_AUDIO_DRV=none \
c1c534
+/usr/bin/qemu-system-aarch64 \
c1c534
+-name guest \
c1c534
+-S \
c1c534
+-M virt \
c1c534
+-m 512 \
c1c534
+-smp 1,sockets=1,cores=1,threads=1 \
c1c534
+-uuid 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 \
c1c534
+-nographic \
c1c534
+-nodefconfig \
c1c534
+-nodefaults \
c1c534
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-guest/monitor.sock,\
c1c534
+server,nowait \
c1c534
+-mon chardev=charmonitor,id=monitor,mode=readline \
c1c534
+-no-acpi \
c1c534
+-boot c \
c1c534
+-device pcie-root-port,port=0x8,chassis=1,id=pci.1,bus=pcie.0,multifunction=on,\
c1c534
+addr=0x1 \
c1c534
+-device pcie-root-port,port=0x9,chassis=2,id=pci.2,bus=pcie.0,addr=0x1.0x1 \
c1c534
+-device qemu-xhci,id=usb,bus=pci.1,addr=0x0 \
c1c534
+-chardev pty,id=charserial0 \
c1c534
+-device usb-serial,chardev=charserial0,id=serial0,bus=usb.0,port=1
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-usb.xml b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-usb.xml
c1c534
new file mode 100644
c1c534
index 0000000000..35f192a3e5
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mach-virt-serial-usb.xml
c1c534
@@ -0,0 +1,21 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='aarch64' machine='virt'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-aarch64</emulator>
c1c534
+    <controller type='usb' model='qemu-xhci'/>
c1c534
+    
c1c534
+         in the file generated by qemuxml2xmltest due to limitations in the
c1c534
+         test suite, but it will be there when actually running libvirt;
c1c534
+         moreover, the USB address will be present in the .args file -->
c1c534
+    <serial type='pty'>
c1c534
+      <target type='usb-serial'/>
c1c534
+    </serial>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
c1c534
index 2b3bbd1b8b..656b8c0995 100644
c1c534
--- a/tests/qemuxml2argvtest.c
c1c534
+++ b/tests/qemuxml2argvtest.c
c1c534
@@ -1898,6 +1898,33 @@ mymain(void)
c1c534
             QEMU_CAPS_NODEFCONFIG);
c1c534
     DO_TEST_PARSE_ERROR("pseries-serial-invalid-machine", NONE);
c1c534
 
c1c534
+    DO_TEST("mach-virt-serial-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG);
c1c534
+    DO_TEST("mach-virt-serial+console-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG);
c1c534
+    DO_TEST("mach-virt-serial-compat",
c1c534
+            QEMU_CAPS_NODEFCONFIG);
c1c534
+    DO_TEST("mach-virt-serial-pci",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_OBJECT_GPEX,
c1c534
+            QEMU_CAPS_PCI_MULTIFUNCTION,
c1c534
+            QEMU_CAPS_DEVICE_PCIE_ROOT_PORT,
c1c534
+            QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,
c1c534
+            QEMU_CAPS_DEVICE_PCI_BRIDGE,
c1c534
+            QEMU_CAPS_DEVICE_PCI_SERIAL);
c1c534
+    DO_TEST("mach-virt-serial-usb",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_OBJECT_GPEX,
c1c534
+            QEMU_CAPS_PCI_MULTIFUNCTION,
c1c534
+            QEMU_CAPS_DEVICE_PCIE_ROOT_PORT,
c1c534
+            QEMU_CAPS_DEVICE_QEMU_XHCI,
c1c534
+            QEMU_CAPS_DEVICE_USB_SERIAL);
c1c534
+    DO_TEST("mach-virt-console-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG);
c1c534
+    DO_TEST("mach-virt-console-virtio",
c1c534
+            QEMU_CAPS_NODEFCONFIG);
c1c534
+    DO_TEST_PARSE_ERROR("mach-virt-serial-invalid-machine", NONE);
c1c534
+
c1c534
     DO_TEST("disk-ide-drive-split",
c1c534
             QEMU_CAPS_NODEFCONFIG,
c1c534
             QEMU_CAPS_IDE_CD);
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-aarch64-virtio-pci-default.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-aarch64-virtio-pci-default.xml
c1c534
index e5496424b3..9796d7f637 100644
c1c534
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-aarch64-virtio-pci-default.xml
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-aarch64-virtio-pci-default.xml
c1c534
@@ -71,7 +71,9 @@
c1c534
       <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
c1c534
     </interface>
c1c534
     <serial type='pty'>
c1c534
-      <target port='0'/>
c1c534
+      <target type='system-serial' port='0'>
c1c534
+        <model name='pl011'/>
c1c534
+      </target>
c1c534
     </serial>
c1c534
     <console type='pty'>
c1c534
       <target type='serial' port='0'/>
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-console-native.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-console-native.xml
c1c534
new file mode 120000
c1c534
index 0000000000..a4768fcf86
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-console-native.xml
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2xmlout-mach-virt-serial-compat.xml
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-console-virtio.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-console-virtio.xml
c1c534
new file mode 100644
c1c534
index 0000000000..3e46cd2012
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-console-virtio.xml
c1c534
@@ -0,0 +1,27 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <currentMemory unit='KiB'>524288</currentMemory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='aarch64' machine='virt'>hvm</type>
c1c534
+    <boot dev='hd'/>
c1c534
+  </os>
c1c534
+  <features>
c1c534
+    <gic version='2'/>
c1c534
+  </features>
c1c534
+  <clock offset='utc'/>
c1c534
+  <on_poweroff>destroy</on_poweroff>
c1c534
+  <on_reboot>restart</on_reboot>
c1c534
+  <on_crash>destroy</on_crash>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-aarch64</emulator>
c1c534
+    <controller type='usb' index='0' model='none'/>
c1c534
+    <controller type='virtio-serial' index='0'/>
c1c534
+    <console type='pty'>
c1c534
+      <target type='virtio' port='0'/>
c1c534
+    </console>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial+console-native.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial+console-native.xml
c1c534
new file mode 120000
c1c534
index 0000000000..a4768fcf86
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial+console-native.xml
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2xmlout-mach-virt-serial-compat.xml
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-compat.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-compat.xml
c1c534
new file mode 100644
c1c534
index 0000000000..3d7325a8db
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-compat.xml
c1c534
@@ -0,0 +1,31 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <currentMemory unit='KiB'>524288</currentMemory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='aarch64' machine='virt'>hvm</type>
c1c534
+    <boot dev='hd'/>
c1c534
+  </os>
c1c534
+  <features>
c1c534
+    <gic version='2'/>
c1c534
+  </features>
c1c534
+  <clock offset='utc'/>
c1c534
+  <on_poweroff>destroy</on_poweroff>
c1c534
+  <on_reboot>restart</on_reboot>
c1c534
+  <on_crash>destroy</on_crash>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-aarch64</emulator>
c1c534
+    <controller type='usb' index='0' model='none'/>
c1c534
+    <serial type='pty'>
c1c534
+      <target type='system-serial' port='0'>
c1c534
+        <model name='pl011'/>
c1c534
+      </target>
c1c534
+    </serial>
c1c534
+    <console type='pty'>
c1c534
+      <target type='serial' port='0'/>
c1c534
+    </console>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-native.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-native.xml
c1c534
new file mode 120000
c1c534
index 0000000000..a4768fcf86
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-native.xml
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2xmlout-mach-virt-serial-compat.xml
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-pci.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-pci.xml
c1c534
new file mode 100644
c1c534
index 0000000000..4bcf69a3d1
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-pci.xml
c1c534
@@ -0,0 +1,44 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <currentMemory unit='KiB'>524288</currentMemory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='aarch64' machine='virt'>hvm</type>
c1c534
+    <boot dev='hd'/>
c1c534
+  </os>
c1c534
+  <features>
c1c534
+    <gic version='2'/>
c1c534
+  </features>
c1c534
+  <clock offset='utc'/>
c1c534
+  <on_poweroff>destroy</on_poweroff>
c1c534
+  <on_reboot>restart</on_reboot>
c1c534
+  <on_crash>destroy</on_crash>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-aarch64</emulator>
c1c534
+    <controller type='usb' index='0' model='none'/>
c1c534
+    <controller type='pci' index='0' model='pcie-root'/>
c1c534
+    <controller type='pci' index='1' model='dmi-to-pci-bridge'>
c1c534
+      <model name='i82801b11-bridge'/>
c1c534
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
c1c534
+    </controller>
c1c534
+    <controller type='pci' index='2' model='pci-bridge'>
c1c534
+      <model name='pci-bridge'/>
c1c534
+      <target chassisNr='2'/>
c1c534
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
c1c534
+    </controller>
c1c534
+    <controller type='pci' index='3' model='pcie-root-port'>
c1c534
+      <model name='pcie-root-port'/>
c1c534
+      <target chassis='3' port='0x10'/>
c1c534
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
c1c534
+    </controller>
c1c534
+    <serial type='pty'>
c1c534
+      <target type='pci-serial' port='0'>
c1c534
+        <model name='pci-serial'/>
c1c534
+      </target>
c1c534
+      <address type='pci' domain='0x0000' bus='0x02' slot='0x01' function='0x0'/>
c1c534
+    </serial>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-usb.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-usb.xml
c1c534
new file mode 100644
c1c534
index 0000000000..01c2a52555
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-mach-virt-serial-usb.xml
c1c534
@@ -0,0 +1,41 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>guest</name>
c1c534
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
c1c534
+  <memory unit='KiB'>524288</memory>
c1c534
+  <currentMemory unit='KiB'>524288</currentMemory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='aarch64' machine='virt'>hvm</type>
c1c534
+    <boot dev='hd'/>
c1c534
+  </os>
c1c534
+  <features>
c1c534
+    <gic version='2'/>
c1c534
+  </features>
c1c534
+  <clock offset='utc'/>
c1c534
+  <on_poweroff>destroy</on_poweroff>
c1c534
+  <on_reboot>restart</on_reboot>
c1c534
+  <on_crash>destroy</on_crash>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-aarch64</emulator>
c1c534
+    <controller type='usb' index='0' model='qemu-xhci'>
c1c534
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
c1c534
+    </controller>
c1c534
+    <controller type='pci' index='0' model='pcie-root'/>
c1c534
+    <controller type='pci' index='1' model='pcie-root-port'>
c1c534
+      <model name='pcie-root-port'/>
c1c534
+      <target chassis='1' port='0x8'/>
c1c534
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0' multifunction='on'/>
c1c534
+    </controller>
c1c534
+    <controller type='pci' index='2' model='pcie-root-port'>
c1c534
+      <model name='pcie-root-port'/>
c1c534
+      <target chassis='2' port='0x9'/>
c1c534
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
c1c534
+    </controller>
c1c534
+    <serial type='pty'>
c1c534
+      <target type='usb-serial' port='0'>
c1c534
+        <model name='usb-serial'/>
c1c534
+      </target>
c1c534
+    </serial>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
c1c534
index f76bd5a68d..bd18507bb6 100644
c1c534
--- a/tests/qemuxml2xmltest.c
c1c534
+++ b/tests/qemuxml2xmltest.c
c1c534
@@ -788,6 +788,32 @@ mymain(void)
c1c534
     DO_TEST("pseries-console-virtio",
c1c534
             QEMU_CAPS_NODEFCONFIG);
c1c534
 
c1c534
+    DO_TEST("mach-virt-serial-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG);
c1c534
+    DO_TEST("mach-virt-serial+console-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG);
c1c534
+    DO_TEST("mach-virt-serial-compat",
c1c534
+            QEMU_CAPS_NODEFCONFIG);
c1c534
+    DO_TEST("mach-virt-serial-pci",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_OBJECT_GPEX,
c1c534
+            QEMU_CAPS_PCI_MULTIFUNCTION,
c1c534
+            QEMU_CAPS_DEVICE_PCIE_ROOT_PORT,
c1c534
+            QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,
c1c534
+            QEMU_CAPS_DEVICE_PCI_BRIDGE,
c1c534
+            QEMU_CAPS_DEVICE_PCI_SERIAL);
c1c534
+    DO_TEST("mach-virt-serial-usb",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_OBJECT_GPEX,
c1c534
+            QEMU_CAPS_PCI_MULTIFUNCTION,
c1c534
+            QEMU_CAPS_DEVICE_PCIE_ROOT_PORT,
c1c534
+            QEMU_CAPS_DEVICE_QEMU_XHCI,
c1c534
+            QEMU_CAPS_DEVICE_USB_SERIAL);
c1c534
+    DO_TEST("mach-virt-console-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG);
c1c534
+    DO_TEST("mach-virt-console-virtio",
c1c534
+            QEMU_CAPS_NODEFCONFIG);
c1c534
+
c1c534
     DO_TEST("balloon-device-auto", NONE);
c1c534
     DO_TEST("balloon-device-period", NONE);
c1c534
     DO_TEST("channel-virtio-auto", NONE);
c1c534
-- 
c1c534
2.15.1
c1c534