c1c534
From fd981b46a6729b5d5dac4923b860f888b0c193b9 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <fd981b46a6729b5d5dac4923b860f888b0c193b9@dist-git>
c1c534
From: Andrea Bolognani <abologna@redhat.com>
c1c534
Date: Wed, 29 Nov 2017 16:23:12 +0100
c1c534
Subject: [PATCH] conf: Add target type and model for spapr-vty
c1c534
c1c534
We can finally introduce a specific target model for the spapr-vty
c1c534
device used by pSeries guests, which means isa-serial will no longer
c1c534
show 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 spapr-vty is
c1c534
not used for non-pSeries guests and add a bunch of test cases.
c1c534
c1c534
This commit is best viewed with 'git show -w'.
c1c534
c1c534
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1511421
c1c534
c1c534
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c1c534
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
c1c534
(cherry picked from commit c498a8921e447715189c8c6d22b7ca24cc810830)
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                             |  6 +-
c1c534
 src/conf/domain_conf.h                             |  2 +
c1c534
 src/qemu/qemu_command.c                            | 67 +++++++++------------
c1c534
 src/qemu/qemu_domain.c                             | 69 ++++++++++++++++++----
c1c534
 src/qemu/qemu_domain_address.c                     |  1 +
c1c534
 .../qemuxml2argv-pseries-basic.args                |  2 +-
c1c534
 .../qemuxml2argv-pseries-console-native.args       |  1 +
c1c534
 .../qemuxml2argv-pseries-console-native.xml        | 17 ++++++
c1c534
 .../qemuxml2argv-pseries-console-virtio.args       | 23 ++++++++
c1c534
 .../qemuxml2argv-pseries-console-virtio.xml        | 19 ++++++
c1c534
 .../qemuxml2argv-pseries-cpu-compat-power9.args    |  2 +-
c1c534
 .../qemuxml2argv-pseries-cpu-compat.args           |  2 +-
c1c534
 .../qemuxml2argv-pseries-cpu-exact.args            |  2 +-
c1c534
 .../qemuxml2argv-pseries-cpu-le.args               |  2 +-
c1c534
 .../qemuxml2argv-pseries-panic-missing.args        |  2 +-
c1c534
 .../qemuxml2argv-pseries-panic-no-address.args     |  2 +-
c1c534
 ...qemuxml2argv-pseries-serial+console-native.args |  1 +
c1c534
 .../qemuxml2argv-pseries-serial+console-native.xml | 18 ++++++
c1c534
 .../qemuxml2argv-pseries-serial-compat.args        |  1 +
c1c534
 .../qemuxml2argv-pseries-serial-compat.xml         | 19 ++++++
c1c534
 ...qemuxml2argv-pseries-serial-invalid-machine.xml | 19 ++++++
c1c534
 .../qemuxml2argv-pseries-serial-native.args        | 22 +++++++
c1c534
 .../qemuxml2argv-pseries-serial-native.xml         | 16 +++++
c1c534
 .../qemuxml2argv-pseries-usb-default.args          |  2 +-
c1c534
 .../qemuxml2argv-pseries-usb-kbd.args              |  2 +-
c1c534
 .../qemuxml2argv-pseries-usb-multi.args            |  2 +-
c1c534
 .../qemuxml2argv-pseries-vio-user-assigned.args    |  4 +-
c1c534
 .../qemuxml2argvdata/qemuxml2argv-pseries-vio.args |  4 +-
c1c534
 tests/qemuxml2argvtest.c                           | 16 +++++
c1c534
 .../qemuxml2xmlout-panic-pseries.xml               |  4 +-
c1c534
 .../qemuxml2xmlout-pseries-console-native.xml      |  1 +
c1c534
 .../qemuxml2xmlout-pseries-console-virtio.xml      | 31 ++++++++++
c1c534
 .../qemuxml2xmlout-pseries-cpu-compat-power9.xml   |  4 +-
c1c534
 .../qemuxml2xmlout-pseries-cpu-compat.xml          |  4 +-
c1c534
 .../qemuxml2xmlout-pseries-cpu-exact.xml           |  4 +-
c1c534
 .../qemuxml2xmlout-pseries-panic-missing.xml       |  4 +-
c1c534
 .../qemuxml2xmlout-pseries-panic-no-address.xml    |  4 +-
c1c534
 ...emuxml2xmlout-pseries-serial+console-native.xml |  1 +
c1c534
 .../qemuxml2xmlout-pseries-serial-compat.xml       |  1 +
c1c534
 .../qemuxml2xmlout-pseries-serial-native.xml       | 35 +++++++++++
c1c534
 tests/qemuxml2xmltest.c                            | 15 +++++
c1c534
 43 files changed, 386 insertions(+), 82 deletions(-)
c1c534
 create mode 120000 tests/qemuxml2argvdata/qemuxml2argv-pseries-console-native.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-console-native.xml
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-console-virtio.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-console-virtio.xml
c1c534
 create mode 120000 tests/qemuxml2argvdata/qemuxml2argv-pseries-serial+console-native.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-serial+console-native.xml
c1c534
 create mode 120000 tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-compat.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-compat.xml
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-invalid-machine.xml
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-native.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-native.xml
c1c534
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-console-native.xml
c1c534
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-console-virtio.xml
c1c534
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial+console-native.xml
c1c534
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial-compat.xml
c1c534
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial-native.xml
c1c534
c1c534
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
c1c534
index cf1167b9c6..0634f3396a 100644
c1c534
--- a/docs/formatdomain.html.in
c1c534
+++ b/docs/formatdomain.html.in
c1c534
@@ -6462,7 +6462,9 @@ qemu-kvm -net nic,model=? /dev/null
c1c534
       since 1.0.2, isa-serial (usable
c1c534
       with x86 guests), usb-serial (usable whenever USB support
c1c534
       is available) and pci-serial (usable whenever PCI support
c1c534
-      is available).
c1c534
+      is available); since 3.10.0,
c1c534
+      spapr-vio-serial (usable with ppc64/pseries guests)
c1c534
+      is available as well.
c1c534
     

c1c534
 
c1c534
     

c1c534
@@ -6472,7 +6474,9 @@ qemu-kvm -net nic,model=? /dev/null
c1c534
       isa-serial (usable with the isa-serial target
c1c534
       type); usb-serial (usable with the usb-serial
c1c534
       target type); pci-serial
c1c534
-      (usable with the pci-serial target type).
c1c534
+      (usable with the pci-serial target type);
c1c534
+      spapr-vty (usable with the spapr-vio-serial
c1c534
+      target type).
c1c534
     

c1c534
 
c1c534
     

c1c534
@@ -6484,8 +6488,9 @@ qemu-kvm -net nic,model=? /dev/null
c1c534
       All of the 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
-      and pci (for pci-serial).
c1c534
+      isa-serial), usb (for usb-serial),
c1c534
+      pci (for pci-serial) and spapr-vio
c1c534
+      (for spapr-vio-serial).
c1c534
     

c1c534
 
c1c534
     

c1c534
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
c1c534
index 3630e539e6..027d9ae7a1 100644
c1c534
--- a/docs/schemas/domaincommon.rng
c1c534
+++ b/docs/schemas/domaincommon.rng
c1c534
@@ -3571,6 +3571,7 @@
c1c534
         <value>isa-serial</value>
c1c534
         <value>usb-serial</value>
c1c534
         <value>pci-serial</value>
c1c534
+        <value>spapr-vio-serial</value>
c1c534
       </choice>
c1c534
     </attribute>
c1c534
   </define>
c1c534
@@ -3582,6 +3583,7 @@
c1c534
           <value>isa-serial</value>
c1c534
           <value>usb-serial</value>
c1c534
           <value>pci-serial</value>
c1c534
+          <value>spapr-vty</value>
c1c534
         </choice>
c1c534
       </attribute>
c1c534
     </element>
c1c534
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
c1c534
index 692b9d9414..97c7a66b5b 100644
c1c534
--- a/src/conf/domain_conf.c
c1c534
+++ b/src/conf/domain_conf.c
c1c534
@@ -444,7 +444,9 @@ VIR_ENUM_IMPL(virDomainChrSerialTarget,
c1c534
               "none",
c1c534
               "isa-serial",
c1c534
               "usb-serial",
c1c534
-              "pci-serial")
c1c534
+              "pci-serial",
c1c534
+              "spapr-vio-serial",
c1c534
+);
c1c534
 
c1c534
 VIR_ENUM_IMPL(virDomainChrChannelTarget,
c1c534
               VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_LAST,
c1c534
@@ -471,6 +473,7 @@ VIR_ENUM_IMPL(virDomainChrSerialTargetModel,
c1c534
               "isa-serial",
c1c534
               "usb-serial",
c1c534
               "pci-serial",
c1c534
+              "spapr-vty",
c1c534
 );
c1c534
 
c1c534
 VIR_ENUM_IMPL(virDomainChrDevice, VIR_DOMAIN_CHR_DEVICE_TYPE_LAST,
c1c534
@@ -4059,6 +4062,7 @@ virDomainDefAddConsoleCompat(virDomainDefPtr def)
c1c534
 
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_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 9dfe9388cd..979e8cca00 100644
c1c534
--- a/src/conf/domain_conf.h
c1c534
+++ b/src/conf/domain_conf.h
c1c534
@@ -1077,6 +1077,7 @@ typedef enum {
c1c534
     VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA,
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
 
c1c534
     VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST
c1c534
 } virDomainChrSerialTargetType;
c1c534
@@ -1109,6 +1110,7 @@ typedef enum {
c1c534
     VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL,
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
 
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 f8d5d317cd..91083dc73d 100644
c1c534
--- a/src/qemu/qemu_command.c
c1c534
+++ b/src/qemu/qemu_command.c
c1c534
@@ -9227,6 +9227,8 @@ qemuChrSerialTargetModelToCaps(virDomainChrSerialTargetModel targetModel)
c1c534
         return QEMU_CAPS_DEVICE_USB_SERIAL;
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
c1c534
         return QEMU_CAPS_DEVICE_PCI_SERIAL;
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_NONE:
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
c1c534
@@ -10354,52 +10356,39 @@ qemuBuildSerialChrDeviceStr(char **deviceStr,
c1c534
     virBuffer cmd = VIR_BUFFER_INITIALIZER;
c1c534
     virQEMUCapsFlags caps;
c1c534
 
c1c534
-    if (qemuDomainIsPSeries(def)) {
c1c534
-        if (serial->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
c1c534
-            serial->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO) {
c1c534
-            if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SPAPR_VTY)) {
c1c534
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
c1c534
-                               _("spapr-vty not supported in this QEMU binary"));
c1c534
-                goto error;
c1c534
-            }
c1c534
+    switch ((virDomainChrSerialTargetModel) serial->targetModel) {
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
 
c1c534
-            virBufferAsprintf(&cmd, "spapr-vty,chardev=char%s",
c1c534
-                              serial->info.alias);
c1c534
-        }
c1c534
-    } else {
c1c534
-        switch ((virDomainChrSerialTargetModel) serial->targetModel) {
c1c534
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL:
c1c534
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
c1c534
+        caps = qemuChrSerialTargetModelToCaps(serial->targetModel);
c1c534
 
c1c534
-            caps = qemuChrSerialTargetModelToCaps(serial->targetModel);
c1c534
-
c1c534
-            if (caps && !virQEMUCapsGet(qemuCaps, caps)) {
c1c534
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c1c534
-                               _("'%s' is not supported in this QEMU binary"),
c1c534
-                               virDomainChrSerialTargetModelTypeToString(serial->targetModel));
c1c534
-                goto error;
c1c534
-            }
c1c534
-            break;
c1c534
-
c1c534
-        case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
c1c534
-            break;
c1c534
-
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
-             * be used, all of the above are platform devices, which means
c1c534
-             * qemuBuildSerialCommandLine() will have taken the appropriate
c1c534
-             * branch and we will not have ended up here. */
c1c534
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
c1c534
-                           _("Invalid target model for serial device"));
c1c534
+        if (caps && !virQEMUCapsGet(qemuCaps, caps)) {
c1c534
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c1c534
+                           _("'%s' is not supported in this QEMU binary"),
c1c534
+                           virDomainChrSerialTargetModelTypeToString(serial->targetModel));
c1c534
             goto error;
c1c534
         }
c1c534
+        break;
c1c534
 
c1c534
-        virBufferAsprintf(&cmd, "%s,chardev=char%s,id=%s",
c1c534
-                          virDomainChrSerialTargetModelTypeToString(serial->targetModel),
c1c534
-                          serial->info.alias, serial->info.alias);
c1c534
+    case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
c1c534
+        break;
c1c534
+
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
+         * be used, all of the above are platform devices, which means
c1c534
+         * qemuBuildSerialCommandLine() will have taken the appropriate
c1c534
+         * branch and we will not have ended up here. */
c1c534
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
c1c534
+                       _("Invalid target model for serial device"));
c1c534
+        goto error;
c1c534
     }
c1c534
 
c1c534
+    virBufferAsprintf(&cmd, "%s,chardev=char%s,id=%s",
c1c534
+                      virDomainChrSerialTargetModelTypeToString(serial->targetModel),
c1c534
+                      serial->info.alias, serial->info.alias);
c1c534
+
c1c534
     if (qemuBuildDeviceAddressStr(&cmd, def, &serial->info, qemuCaps) < 0)
c1c534
         goto error;
c1c534
 
c1c534
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
c1c534
index 7b5bc97de6..17c898896d 100644
c1c534
--- a/src/qemu/qemu_domain.c
c1c534
+++ b/src/qemu/qemu_domain.c
c1c534
@@ -3466,6 +3466,8 @@ qemuDomainChrSerialTargetTypeToAddressType(int targetType)
c1c534
         return VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB;
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
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_LAST:
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
c1c534
         break;
c1c534
@@ -3485,6 +3487,8 @@ qemuDomainChrSerialTargetModelToTargetType(int targetModel)
c1c534
         return VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB;
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL:
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_NONE:
c1c534
     case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST:
c1c534
         break;
c1c534
@@ -3495,8 +3499,7 @@ qemuDomainChrSerialTargetModelToTargetType(int targetModel)
c1c534
 
c1c534
 
c1c534
 static int
c1c534
-qemuDomainChrTargetDefValidate(const virDomainDef *def,
c1c534
-                               const virDomainChrDef *chr)
c1c534
+qemuDomainChrTargetDefValidate(const virDomainChrDef *chr)
c1c534
 {
c1c534
     int expected;
c1c534
 
c1c534
@@ -3508,11 +3511,7 @@ qemuDomainChrTargetDefValidate(const virDomainDef *def,
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_PCI:
c1c534
-
c1c534
-            /* Hack required until we have a proper type for pSeries
c1c534
-             * serial consoles */
c1c534
-            if (qemuDomainIsPSeries(def))
c1c534
-                return 0;
c1c534
+        case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO:
c1c534
 
c1c534
             expected = qemuDomainChrSerialTargetTypeToAddressType(chr->targetType);
c1c534
 
c1c534
@@ -3536,6 +3535,7 @@ qemuDomainChrTargetDefValidate(const virDomainDef *def,
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL:
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
 
c1c534
             expected = qemuDomainChrSerialTargetModelToTargetType(chr->targetModel);
c1c534
 
c1c534
@@ -3573,7 +3573,7 @@ qemuDomainChrDefValidate(const virDomainChrDef *dev,
c1c534
     if (qemuDomainChrSourceDefValidate(dev->source) < 0)
c1c534
         return -1;
c1c534
 
c1c534
-    if (qemuDomainChrTargetDefValidate(def, dev) < 0)
c1c534
+    if (qemuDomainChrTargetDefValidate(dev) < 0)
c1c534
         return -1;
c1c534
 
c1c534
     if (dev->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL &&
c1c534
@@ -3583,6 +3583,26 @@ qemuDomainChrDefValidate(const virDomainChrDef *dev,
c1c534
             return -1;
c1c534
     }
c1c534
 
c1c534
+    if (dev->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL) {
c1c534
+        bool isCompatible = true;
c1c534
+
c1c534
+        if (!qemuDomainIsPSeries(def) &&
c1c534
+            (dev->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO ||
c1c534
+             dev->targetModel == VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_SPAPR_VTY)) {
c1c534
+            isCompatible = false;
c1c534
+        }
c1c534
+
c1c534
+        if (!isCompatible) {
c1c534
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
c1c534
+                           _("Serial device with target type '%s' and "
c1c534
+                             "target model '%s' not compatible with guest "
c1c534
+                             "architecture or machine type"),
c1c534
+                           virDomainChrSerialTargetTypeToString(dev->targetType),
c1c534
+                           virDomainChrSerialTargetModelTypeToString(dev->targetModel));
c1c534
+            return -1;
c1c534
+        }
c1c534
+    }
c1c534
+
c1c534
     return 0;
c1c534
 }
c1c534
 
c1c534
@@ -4222,10 +4242,7 @@ qemuDomainChrDefPostParse(virDomainChrDefPtr chr,
c1c534
         if (ARCH_IS_X86(def->os.arch)) {
c1c534
             chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA;
c1c534
         } else if (qemuDomainIsPSeries(def)) {
c1c534
-            /* Setting TYPE_ISA here is just a temporary hack to reduce test
c1c534
-             * suite churn. Later on we will have a proper serial type for
c1c534
-             * pSeries and this line will be updated accordingly. */
c1c534
-            chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA;
c1c534
+            chr->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO;
c1c534
         }
c1c534
     }
c1c534
 
c1c534
@@ -4242,6 +4259,9 @@ qemuDomainChrDefPostParse(virDomainChrDefPtr chr,
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
c1c534
             chr->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL;
c1c534
             break;
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_NONE:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
c1c534
             /* Nothing to do */
c1c534
@@ -5147,6 +5167,31 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver,
c1c534
                 goto cleanup;
c1c534
         }
c1c534
 
c1c534
+        for (i = 0; i < def->nserials; i++) {
c1c534
+            virDomainChrDefPtr serial = def->serials[i];
c1c534
+
c1c534
+            /* Historically, the native console type for some machine types
c1c534
+             * was not set at all, which means it defaulted to ISA even
c1c534
+             * though that was not even remotely accurate. To ensure migration
c1c534
+             * towards older libvirt versions works for such guests, we switch
c1c534
+             * it back to the default here */
c1c534
+            if (flags & VIR_DOMAIN_XML_MIGRATABLE) {
c1c534
+                switch ((virDomainChrSerialTargetType) serial->targetType) {
c1c534
+                case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_SPAPR_VIO:
c1c534
+                    serial->targetType = VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE;
c1c534
+                    serial->targetModel = VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE;
c1c534
+                    break;
c1c534
+                case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_ISA:
c1c534
+                case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_PCI:
c1c534
+                case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB:
c1c534
+                case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_NONE:
c1c534
+                case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
c1c534
+                    /* Nothing to do */
c1c534
+                    break;
c1c534
+                }
c1c534
+            }
c1c534
+        }
c1c534
+
c1c534
         /* Replace the CPU definition updated according to QEMU with the one
c1c534
          * used for starting the domain. The updated def will be sent
c1c534
          * separately for backward compatibility.
c1c534
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
c1c534
index 989c0e6c93..2319e503eb 100644
c1c534
--- a/src/qemu/qemu_domain_address.c
c1c534
+++ b/src/qemu/qemu_domain_address.c
c1c534
@@ -782,6 +782,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
c1c534
 
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_NONE:
c1c534
         case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
c1c534
             return 0;
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-basic.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-basic.args
c1c534
index 97a7057ba0..789d9f679e 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-basic.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-basic.args
c1c534
@@ -20,4 +20,4 @@ server,nowait \
c1c534
 -boot c \
c1c534
 -usb \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x30000000
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-console-native.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-console-native.args
c1c534
new file mode 120000
c1c534
index 0000000000..d6c830ecdf
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-console-native.args
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2argv-pseries-serial-native.args
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-console-native.xml b/tests/qemuxml2argvdata/qemuxml2argv-pseries-console-native.xml
c1c534
new file mode 100644
c1c534
index 0000000000..9f37bf0dec
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-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='ppc64' machine='pseries'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-ppc64</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-pseries-console-virtio.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-console-virtio.args
c1c534
new file mode 100644
c1c534
index 0000000000..343018fb3e
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-console-virtio.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-ppc64 \
c1c534
+-name guest \
c1c534
+-S \
c1c534
+-M pseries \
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
+-boot c \
c1c534
+-device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x1 \
c1c534
+-chardev pty,id=charconsole0 \
c1c534
+-device virtconsole,chardev=charconsole0,id=console0
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-console-virtio.xml b/tests/qemuxml2argvdata/qemuxml2argv-pseries-console-virtio.xml
c1c534
new file mode 100644
c1c534
index 0000000000..0190ab63ac
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-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='ppc64' machine='pseries'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-ppc64</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-pseries-cpu-compat-power9.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-compat-power9.args
c1c534
index af93d63dc9..9bb375aeba 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-compat-power9.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-compat-power9.args
c1c534
@@ -21,4 +21,4 @@ server,nowait \
c1c534
 -boot c \
c1c534
 -usb \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x30000000
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-compat.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-compat.args
c1c534
index 7740e2f5a9..5174aa760e 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-compat.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-compat.args
c1c534
@@ -21,4 +21,4 @@ server,nowait \
c1c534
 -boot c \
c1c534
 -usb \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x30000000
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-exact.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-exact.args
c1c534
index d2c99a7fa3..3790deca8c 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-exact.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-exact.args
c1c534
@@ -21,4 +21,4 @@ server,nowait \
c1c534
 -boot c \
c1c534
 -usb \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x30000000
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-le.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-le.args
c1c534
index 97a7057ba0..789d9f679e 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-le.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-cpu-le.args
c1c534
@@ -20,4 +20,4 @@ server,nowait \
c1c534
 -boot c \
c1c534
 -usb \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x30000000
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-panic-missing.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-panic-missing.args
c1c534
index 97a7057ba0..789d9f679e 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-panic-missing.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-panic-missing.args
c1c534
@@ -20,4 +20,4 @@ server,nowait \
c1c534
 -boot c \
c1c534
 -usb \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x30000000
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-panic-no-address.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-panic-no-address.args
c1c534
index 97a7057ba0..789d9f679e 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-panic-no-address.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-panic-no-address.args
c1c534
@@ -20,4 +20,4 @@ server,nowait \
c1c534
 -boot c \
c1c534
 -usb \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x30000000
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial+console-native.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial+console-native.args
c1c534
new file mode 120000
c1c534
index 0000000000..d6c830ecdf
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial+console-native.args
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2argv-pseries-serial-native.args
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial+console-native.xml b/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial+console-native.xml
c1c534
new file mode 100644
c1c534
index 0000000000..2733baa980
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-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='ppc64' machine='pseries'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-ppc64</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-pseries-serial-compat.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-compat.args
c1c534
new file mode 120000
c1c534
index 0000000000..d6c830ecdf
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-compat.args
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2argv-pseries-serial-native.args
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-compat.xml b/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-compat.xml
c1c534
new file mode 100644
c1c534
index 0000000000..2e182edbd0
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-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='ppc64' machine='pseries'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-ppc64</emulator>
c1c534
+    <controller type='usb' model='none'/>
c1c534
+    
c1c534
+         but should get converted to the proper type (spapr-vty-serial) -->
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-pseries-serial-invalid-machine.xml b/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-invalid-machine.xml
c1c534
new file mode 100644
c1c534
index 0000000000..5482146a57
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-invalid-machine.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='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
+         guests, so this should be rejected -->
c1c534
+    <serial type='pty'>
c1c534
+      <target type='spapr-vio-serial'/>
c1c534
+    </serial>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-native.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-native.args
c1c534
new file mode 100644
c1c534
index 0000000000..f72b8b6259
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-native.args
c1c534
@@ -0,0 +1,22 @@
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-ppc64 \
c1c534
+-name guest \
c1c534
+-S \
c1c534
+-M pseries \
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
+-boot c \
c1c534
+-chardev pty,id=charserial0 \
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-native.xml b/tests/qemuxml2argvdata/qemuxml2argv-pseries-serial-native.xml
c1c534
new file mode 100644
c1c534
index 0000000000..6cec4bc9d3
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-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='ppc64' machine='pseries'>hvm</type>
c1c534
+  </os>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-ppc64</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-pseries-usb-default.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-default.args
c1c534
index a92b1e01b1..37c0594032 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-default.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-default.args
c1c534
@@ -20,4 +20,4 @@ server,nowait \
c1c534
 -boot c \
c1c534
 -device pci-ohci,id=usb,bus=pci.0,addr=0x1 \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x30000000
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args
c1c534
index caaccdbb8e..838b80453a 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args
c1c534
@@ -20,5 +20,5 @@ server,nowait \
c1c534
 -boot c \
c1c534
 -device pci-ohci,id=usb,bus=pci.0,addr=0x1 \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x30000000 \
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000 \
c1c534
 -device usb-kbd,id=input0,bus=usb.0,port=1
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-multi.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-multi.args
c1c534
index b9bd905a5d..56bc1d67ef 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-multi.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-multi.args
c1c534
@@ -21,4 +21,4 @@ server,nowait \
c1c534
 -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1 \
c1c534
 -device pci-ohci,id=usb1,bus=pci.0,addr=0x2 \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x30000000
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-vio-user-assigned.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-vio-user-assigned.args
c1c534
index 63cf3c1830..0fcfbe3796 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-vio-user-assigned.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-vio-user-assigned.args
c1c534
@@ -25,6 +25,6 @@ server,nowait \
c1c534
 -device scsi-disk,bus=scsi1.0,channel=0,scsi-id=0,lun=0,\
c1c534
 drive=drive-scsi1-0-0-0,id=scsi1-0-0-0 \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x20000000 \
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x20000000 \
c1c534
 -chardev pty,id=charserial1 \
c1c534
--device spapr-vty,chardev=charserial1,reg=0x30001000
c1c534
+-device spapr-vty,chardev=charserial1,id=serial1,reg=0x30001000
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pseries-vio.args b/tests/qemuxml2argvdata/qemuxml2argv-pseries-vio.args
c1c534
index 0294067bc8..8a9bdcc4cd 100644
c1c534
--- a/tests/qemuxml2argvdata/qemuxml2argv-pseries-vio.args
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pseries-vio.args
c1c534
@@ -25,6 +25,6 @@ server,nowait \
c1c534
 -device scsi-disk,bus=scsi1.0,channel=0,scsi-id=0,lun=0,\
c1c534
 drive=drive-scsi1-0-0-0,id=scsi1-0-0-0 \
c1c534
 -chardev pty,id=charserial0 \
c1c534
--device spapr-vty,chardev=charserial0,reg=0x30000000 \
c1c534
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x30000000 \
c1c534
 -chardev pty,id=charserial1 \
c1c534
--device spapr-vty,chardev=charserial1,reg=0x30001000
c1c534
+-device spapr-vty,chardev=charserial1,id=serial1,reg=0x30001000
c1c534
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
c1c534
index 747ad24663..4b63dd141d 100644
c1c534
--- a/tests/qemuxml2argvtest.c
c1c534
+++ b/tests/qemuxml2argvtest.c
c1c534
@@ -1875,6 +1875,22 @@ mymain(void)
c1c534
                         QEMU_CAPS_MACHINE_OPT,
c1c534
                         QEMU_CAPS_MACHINE_PSERIES_RESIZE_HPT);
c1c534
 
c1c534
+    DO_TEST("pseries-serial-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_DEVICE_SPAPR_VTY);
c1c534
+    DO_TEST("pseries-serial+console-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_DEVICE_SPAPR_VTY);
c1c534
+    DO_TEST("pseries-serial-compat",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_DEVICE_SPAPR_VTY);
c1c534
+    DO_TEST("pseries-console-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_DEVICE_SPAPR_VTY);
c1c534
+    DO_TEST("pseries-console-virtio",
c1c534
+            QEMU_CAPS_NODEFCONFIG);
c1c534
+    DO_TEST_PARSE_ERROR("pseries-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-panic-pseries.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-panic-pseries.xml
c1c534
index 496df0696c..484fe4cfa6 100644
c1c534
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-panic-pseries.xml
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-panic-pseries.xml
c1c534
@@ -22,8 +22,8 @@
c1c534
       <target index='0'/>
c1c534
     </controller>
c1c534
     <serial type='pty'>
c1c534
-      <target type='isa-serial' port='0'>
c1c534
-        <model name='isa-serial'/>
c1c534
+      <target type='spapr-vio-serial' port='0'>
c1c534
+        <model name='spapr-vty'/>
c1c534
       </target>
c1c534
       <address type='spapr-vio' reg='0x30000000'/>
c1c534
     </serial>
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-console-native.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-console-native.xml
c1c534
new file mode 120000
c1c534
index 0000000000..b0e645fc03
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-console-native.xml
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2xmlout-pseries-serial-native.xml
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-console-virtio.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-console-virtio.xml
c1c534
new file mode 100644
c1c534
index 0000000000..48760f2824
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-console-virtio.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='ppc64' machine='pseries'>hvm</type>
c1c534
+    <boot dev='hd'/>
c1c534
+  </os>
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-ppc64</emulator>
c1c534
+    <controller type='usb' index='0' model='none'/>
c1c534
+    <controller type='pci' index='0' model='pci-root'>
c1c534
+      <model name='spapr-pci-host-bridge'/>
c1c534
+      <target index='0'/>
c1c534
+    </controller>
c1c534
+    <controller type='virtio-serial' index='0'>
c1c534
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
c1c534
+    </controller>
c1c534
+    <console type='pty'>
c1c534
+      <target type='virtio' port='0'/>
c1c534
+    </console>
c1c534
+    <memballoon model='none'/>
c1c534
+    <panic model='pseries'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-compat-power9.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-compat-power9.xml
c1c534
index 9d4c5efe67..404bb0c768 100644
c1c534
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-compat-power9.xml
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-compat-power9.xml
c1c534
@@ -25,8 +25,8 @@
c1c534
       <target index='0'/>
c1c534
     </controller>
c1c534
     <serial type='pty'>
c1c534
-      <target type='isa-serial' port='0'>
c1c534
-        <model name='isa-serial'/>
c1c534
+      <target type='spapr-vio-serial' port='0'>
c1c534
+        <model name='spapr-vty'/>
c1c534
       </target>
c1c534
       <address type='spapr-vio' reg='0x30000000'/>
c1c534
     </serial>
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-compat.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-compat.xml
c1c534
index 6059859abd..1891fa5f48 100644
c1c534
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-compat.xml
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-compat.xml
c1c534
@@ -25,8 +25,8 @@
c1c534
       <target index='0'/>
c1c534
     </controller>
c1c534
     <serial type='pty'>
c1c534
-      <target type='isa-serial' port='0'>
c1c534
-        <model name='isa-serial'/>
c1c534
+      <target type='spapr-vio-serial' port='0'>
c1c534
+        <model name='spapr-vty'/>
c1c534
       </target>
c1c534
       <address type='spapr-vio' reg='0x30000000'/>
c1c534
     </serial>
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-exact.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-exact.xml
c1c534
index f3216523ed..f08f3e005f 100644
c1c534
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-exact.xml
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-cpu-exact.xml
c1c534
@@ -26,8 +26,8 @@
c1c534
       <target index='0'/>
c1c534
     </controller>
c1c534
     <serial type='pty'>
c1c534
-      <target type='isa-serial' port='0'>
c1c534
-        <model name='isa-serial'/>
c1c534
+      <target type='spapr-vio-serial' port='0'>
c1c534
+        <model name='spapr-vty'/>
c1c534
       </target>
c1c534
       <address type='spapr-vio' reg='0x30000000'/>
c1c534
     </serial>
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-missing.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-missing.xml
c1c534
index 496df0696c..484fe4cfa6 100644
c1c534
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-missing.xml
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-missing.xml
c1c534
@@ -22,8 +22,8 @@
c1c534
       <target index='0'/>
c1c534
     </controller>
c1c534
     <serial type='pty'>
c1c534
-      <target type='isa-serial' port='0'>
c1c534
-        <model name='isa-serial'/>
c1c534
+      <target type='spapr-vio-serial' port='0'>
c1c534
+        <model name='spapr-vty'/>
c1c534
       </target>
c1c534
       <address type='spapr-vio' reg='0x30000000'/>
c1c534
     </serial>
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-no-address.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-no-address.xml
c1c534
index 496df0696c..484fe4cfa6 100644
c1c534
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-no-address.xml
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-panic-no-address.xml
c1c534
@@ -22,8 +22,8 @@
c1c534
       <target index='0'/>
c1c534
     </controller>
c1c534
     <serial type='pty'>
c1c534
-      <target type='isa-serial' port='0'>
c1c534
-        <model name='isa-serial'/>
c1c534
+      <target type='spapr-vio-serial' port='0'>
c1c534
+        <model name='spapr-vty'/>
c1c534
       </target>
c1c534
       <address type='spapr-vio' reg='0x30000000'/>
c1c534
     </serial>
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial+console-native.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial+console-native.xml
c1c534
new file mode 120000
c1c534
index 0000000000..b0e645fc03
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial+console-native.xml
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2xmlout-pseries-serial-native.xml
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial-compat.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial-compat.xml
c1c534
new file mode 120000
c1c534
index 0000000000..b0e645fc03
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial-compat.xml
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2xmlout-pseries-serial-native.xml
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial-native.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial-native.xml
c1c534
new file mode 100644
c1c534
index 0000000000..fae7c54d5b
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-pseries-serial-native.xml
c1c534
@@ -0,0 +1,35 @@
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='ppc64' machine='pseries'>hvm</type>
c1c534
+    <boot dev='hd'/>
c1c534
+  </os>
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-ppc64</emulator>
c1c534
+    <controller type='usb' index='0' model='none'/>
c1c534
+    <controller type='pci' index='0' model='pci-root'>
c1c534
+      <model name='spapr-pci-host-bridge'/>
c1c534
+      <target index='0'/>
c1c534
+    </controller>
c1c534
+    <serial type='pty'>
c1c534
+      <target type='spapr-vio-serial' port='0'>
c1c534
+        <model name='spapr-vty'/>
c1c534
+      </target>
c1c534
+      <address type='spapr-vio' reg='0x30000000'/>
c1c534
+    </serial>
c1c534
+    <console type='pty'>
c1c534
+      <target type='serial' port='0'/>
c1c534
+      <address type='spapr-vio' reg='0x30000000'/>
c1c534
+    </console>
c1c534
+    <memballoon model='none'/>
c1c534
+    <panic model='pseries'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
c1c534
index 6687997900..ad429ead4d 100644
c1c534
--- a/tests/qemuxml2xmltest.c
c1c534
+++ b/tests/qemuxml2xmltest.c
c1c534
@@ -766,6 +766,21 @@ mymain(void)
c1c534
             QEMU_CAPS_MACHINE_OPT,
c1c534
             QEMU_CAPS_MACHINE_PSERIES_RESIZE_HPT);
c1c534
 
c1c534
+    DO_TEST("pseries-serial-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_DEVICE_SPAPR_VTY);
c1c534
+    DO_TEST("pseries-serial+console-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_DEVICE_SPAPR_VTY);
c1c534
+    DO_TEST("pseries-serial-compat",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_DEVICE_SPAPR_VTY);
c1c534
+    DO_TEST("pseries-console-native",
c1c534
+            QEMU_CAPS_NODEFCONFIG,
c1c534
+            QEMU_CAPS_DEVICE_SPAPR_VTY);
c1c534
+    DO_TEST("pseries-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