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

404507
 
404507
     

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

404507
 
404507
     

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

404507
 
404507
     

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

404507
 
404507
     

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