Skip to contentSkip to conversation

*** Add SCLP event type CPI ***

PATCH Superseded Shalini Chellathurai Saroja 3 participants 15 messages Mar 31, 2025 – Apr 9, 2025 Arm/Amlogic Meson SoC support

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover *** Add SCLP event type CPI ***

Implement the Service-Call Logical Processor (SCLP) event type Control-Program Identification (CPI) in QEMU.

Changed since v2:
- Add SPDX license tag in the new file hw/s390x/sclpcpi.c
- Store the control-program Identification data in the sclpcpi device
- Update the description of CPI attributes
- Use ldq_be_p() intead of be64_to_cpu()
- Return the CPI attribute system-level as an integer in QMP
- Add compat handling for backward migration
- Other minor changes

Shalini Chellathurai Saroja (4):
hw/s390x: add SCLP event type CPI
hw/s390x: add Control-Program Identification to QOM hw/s390x: support migration of CPI data hw/s390x: compat handling for backward migration

 hw/s390x/event-facility.c         |  28 ++++-
 hw/s390x/meson.build              |   1 +
 hw/s390x/s390-virtio-ccw.c        |   1 +
 hw/s390x/sclpcpi.c                | 196 ++++++++++++++++++++++++++++++
 include/hw/s390x/event-facility.h |  12 ++
 qapi/machine.json                 |  58 +++++++++
 6 files changed, 295 insertions(+), 1 deletion(-)
 create mode 100644 hw/s390x/sclpcpi.c
Signature · 1 line
2.47.0
#1 lore raw

PATCH v3 1/4 hw/s390x: add SCLP event type CPI

Implement the Service-Call Logical Processor (SCLP) event type Control-Program Identification (CPI) in QEMU. This event is used to send CPI identifiers from the guest to the host. The CPI identifiers are: system type, system name, system level and sysplex name.

System type: operating system of the guest (e.g. "LINUX"). System name: user configurable name of the guest (e.g. "TESTVM"). System level: distribution and kernel version, if the system type is Linux (e.g. 0x50e00).
Sysplex name: name of the cluster which the guest belongs to (if any) (e.g. "PLEX").

---
 hw/s390x/event-facility.c         |  12 ++-
 hw/s390x/meson.build              |   1 +
 hw/s390x/sclpcpi.c                | 133 ++++++++++++++++++++++++++++++
 include/hw/s390x/event-facility.h |   3 +
 4 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 hw/s390x/sclpcpi.c
hw/s390x/event-facility.c +11 -1
index 2b0332c20e..c0fb6e098c 100644
@@ -39,7 +39,7 @@ typedef struct SCLPEventsBus {
 struct SCLPEventFacility {
     SysBusDevice parent_obj;
     SCLPEventsBus sbus;
-    SCLPEvent quiesce, cpu_hotplug;
+    SCLPEvent quiesce, cpu_hotplug, cpi;
     /* guest's receive mask */
     union {
         uint32_t receive_mask_pieces[2];
@@ -436,6 +436,10 @@ static void init_event_facility(Object *obj)
     object_initialize_child(obj, TYPE_SCLP_CPU_HOTPLUG,
                             &event_facility->cpu_hotplug,
                             TYPE_SCLP_CPU_HOTPLUG);
+
+    object_initialize_child(obj, TYPE_SCLP_CPI,
+                            &event_facility->cpi,
+                            TYPE_SCLP_CPI);
 }
 
 static void realize_event_facility(DeviceState *dev, Error **errp)
@@ -451,6 +455,12 @@ static void realize_event_facility(DeviceState *dev, Error **errp)
         qdev_unrealize(DEVICE(&event_facility->quiesce));
         return;
     }
+    if (!qdev_realize(DEVICE(&event_facility->cpi),
+                      BUS(&event_facility->sbus), errp)) {
+        qdev_unrealize(DEVICE(&event_facility->quiesce));
+        qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
+        return;
+    }
 }
 
 static void reset_event_facility(DeviceState *dev)
hw/s390x/meson.build +1 -0
index 3bbebfd817..eb7950489c 100644
@@ -13,6 +13,7 @@ s390x_ss.add(files(
   's390-skeys.c',
   's390-stattrib.c',
   'sclp.c',
+  'sclpcpi.c',
   'sclpcpu.c',
   'sclpquiesce.c',
   'tod.c',
hw/s390x/sclpcpi.c new file +133 -0

133 lines not on this page · raw message

include/hw/s390x/event-facility.h +3 -0
index ff874e792d..f445d2f9f5 100644
@@ -25,6 +25,7 @@
 #define SCLP_EVENT_MESSAGE                      0x02
 #define SCLP_EVENT_CONFIG_MGT_DATA              0x04
 #define SCLP_EVENT_PMSGCMD                      0x09
+#define SCLP_EVENT_CPI                          0x0b
 #define SCLP_EVENT_ASCII_CONSOLE_DATA           0x1a
 #define SCLP_EVENT_SIGNAL_QUIESCE               0x1d
 
@@ -35,6 +36,7 @@
 #define SCLP_EVENT_MASK_MSG             SCLP_EVMASK(SCLP_EVENT_MESSAGE)
 #define SCLP_EVENT_MASK_CONFIG_MGT_DATA SCLP_EVMASK(SCLP_EVENT_CONFIG_MGT_DATA)
 #define SCLP_EVENT_MASK_PMSGCMD         SCLP_EVMASK(SCLP_EVENT_PMSGCMD)
+#define SCLP_EVENT_MASK_CPI             SCLP_EVMASK(SCLP_EVENT_CPI)
 #define SCLP_EVENT_MASK_MSG_ASCII       SCLP_EVMASK(SCLP_EVENT_ASCII_CONSOLE_DATA)
 #define SCLP_EVENT_MASK_SIGNAL_QUIESCE  SCLP_EVMASK(SCLP_EVENT_SIGNAL_QUIESCE)
 
@@ -46,6 +48,7 @@ OBJECT_DECLARE_TYPE(SCLPEvent, SCLPEventClass,
                     SCLP_EVENT)
 
 #define TYPE_SCLP_CPU_HOTPLUG "sclp-cpu-hotplug"
+#define TYPE_SCLP_CPI "sclpcpi"
 #define TYPE_SCLP_QUIESCE "sclpquiesce"
 
 #define SCLP_EVENT_MASK_LEN_MAX 1021
Signature · 1 line
2.47.0
Reviewed-by on v3 1/4
#2 lore raw

Re: [PATCH v3 1/4] hw/s390x: add SCLP event type CPI

Quoted 13 lines · Shalini Chellathurai Saroja

Implement the Service-Call Logical Processor (SCLP) event type Control-Program Identification (CPI) in QEMU. This event is used to send CPI identifiers from the guest to the host. The CPI identifiers are: system type, system name, system level and sysplex name.

System type: operating system of the guest (e.g. "LINUX"). System name: user configurable name of the guest (e.g. "TESTVM"). System level: distribution and kernel version, if the system type is Linux (e.g. 0x50e00).
Sysplex name: name of the cluster which the guest belongs to (if any) (e.g. "PLEX").

Quoted 3 lines

---

#3 lore raw

Re: [PATCH v3 1/4] hw/s390x: add SCLP event type CPI

Quoted 14 lines · Thomas Huth
Quoted 13 lines · Shalini Chellathurai Saroja

Implement the Service-Call Logical Processor (SCLP) event type Control-Program Identification (CPI) in QEMU. This event is used to send CPI identifiers from the guest to the host. The CPI identifiers are: system type, system name, system level and sysplex name.

System type: operating system of the guest (e.g. "LINUX"). System name: user configurable name of the guest (e.g. "TESTVM"). System level: distribution and kernel version, if the system type is Linux (e.g. 0x50e00).
Sysplex name: name of the cluster which the guest belongs to (if any) (e.g. "PLEX").

Quoted 5 lines
Quoted 3 lines

---

Hello Thomas,

Thank you very much.

Signature · 9 lines
Mit freundlichen Grüßen / Kind regards
Shalini Chellathurai Saroja
Software Developer
Linux on IBM Z & KVM Development
IBM Deutschland Research & Development GmbH
Dept 1419, Schoenaicher Str. 220, 71032 Boeblingen
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
#4 lore raw

PATCH v3 2/4 hw/s390x: add Control-Program Identification to QOM

In reply to Shalini Chellathurai Saroja

Add Control-Program Identification data to the QEMU Object Model (QOM), along with the timestamp in which the data was received.

Example:
virsh # qemu-monitor-command vm --pretty '{ "execute": "qom-get",
"arguments": {
"path": "/machine/sclp/s390-sclp-event-facility/sclpcpi", "property": "control-program-id" }}'
{

  "return": {
    "timestamp": 1742390410685762000,
    "system-level": 74872343805430528,
    "sysplex-name": "PLEX ",
    "system-name": "TESTVM  ",
    "system-type": "LINUX   "

},
"id": "libvirt-15"
}

---
 hw/s390x/sclpcpi.c                | 38 ++++++++++++++++++++
 include/hw/s390x/event-facility.h |  9 +++++
 qapi/machine.json                 | 58 +++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+)
hw/s390x/sclpcpi.c +38 -0
index 7ace5dd64e..969c15e43d 100644
@@ -57,8 +57,11 @@
   */
 
 #include "qemu/osdep.h"
+#include "qemu/timer.h"
 #include "hw/s390x/sclp.h"
 #include "hw/s390x/event-facility.h"
+#include "hw/s390x/ebcdic.h"
+#include "qapi/qapi-visit-machine.h"
 
 typedef struct Data {
     uint8_t id_format;
@@ -99,10 +102,37 @@ static int write_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr)
     ControlProgramIdMsg *cpim = container_of(evt_buf_hdr, ControlProgramIdMsg,
                                              ebh);
 
+    ascii_put(event->cpi.system_type, (char *)cpim->data.system_type, 8);
+    ascii_put(event->cpi.system_name, (char *)cpim->data.system_name, 8);
+    ascii_put(event->cpi.sysplex_name, (char *)cpim->data.sysplex_name, 8);
+    event->cpi.system_level = ldq_be_p(&cpim->data.system_level);
+    event->cpi.timestamp = qemu_clock_get_ns(QEMU_CLOCK_HOST);
+
     cpim->ebh.flags = SCLP_EVENT_BUFFER_ACCEPTED;
     return SCLP_RC_NORMAL_COMPLETION;
 }
 
+static void get_control_program_id(Object *obj, Visitor *v,
+                                   const char *name, void *opaque,
+                                   Error **errp)
+{
+    SCLPEvent *event = (SCLPEvent *)(obj);
+    S390ControlProgramId *cpi;
+
+    cpi = &(S390ControlProgramId){
+        .system_type = g_strndup((char *) event->cpi.system_type,
+                                 sizeof(event->cpi.system_type)),
+        .system_name = g_strndup((char *) event->cpi.system_name,
+                                 sizeof(event->cpi.system_name)),
+        .system_level = event->cpi.system_level,
+        .sysplex_name = g_strndup((char *) event->cpi.sysplex_name,
+                                  sizeof(event->cpi.sysplex_name)),
+        .timestamp = event->cpi.timestamp
+    };
+
+    visit_type_S390ControlProgramId(v, name, &cpi, errp);
+}
+
 static void cpi_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -114,6 +144,14 @@ static void cpi_class_init(ObjectClass *klass, void *data)
     k->get_send_mask = send_mask;
     k->get_receive_mask = receive_mask;
     k->write_event_data = write_event_data;
+
+    object_class_property_add(klass, "control-program-id",
+                              "S390ControlProgramId",
+                              get_control_program_id,
+                              NULL, NULL, NULL);
+    object_class_property_set_description(klass, "control-program-id",
+        "Control-program identifiers provide data about the guest "
+        "operating system");
 }
 
 static const TypeInfo sclp_cpi_info = {
include/hw/s390x/event-facility.h +9 -0
index f445d2f9f5..39e589ed44 100644
@@ -169,10 +169,19 @@ typedef struct ReadEventData {
     };
 } QEMU_PACKED ReadEventData;
 
+typedef struct ControlProgramId {
+    uint8_t system_type[8];
+    uint8_t system_name[8];
+    uint64_t system_level;
+    uint8_t sysplex_name[8];
+    uint64_t timestamp;
+} QEMU_PACKED ControlProgramId;
+
 struct SCLPEvent {
     DeviceState qdev;
     bool event_pending;
     char *name;
+    ControlProgramId cpi;
 };
 
 struct SCLPEventClass {
qapi/machine.json +58 -0

61 lines not on this page · raw message

Signature · 1 line
2.47.0
#5 lore raw

Re: [PATCH v3 2/4] hw/s390x: add Control-Program Identification to QOM

Quoted 52 lines · Shalini Chellathurai Saroja

Add Control-Program Identification data to the QEMU Object Model (QOM), along with the timestamp in which the data was received.

Example:
virsh # qemu-monitor-command vm --pretty '{ "execute": "qom-get",
"arguments": {
"path": "/machine/sclp/s390-sclp-event-facility/sclpcpi", "property": "control-program-id" }}'
{

  "return": {
    "timestamp": 1742390410685762000,
    "system-level": 74872343805430528,
    "sysplex-name": "PLEX ",
    "system-name": "TESTVM  ",
    "system-type": "LINUX   "

},
"id": "libvirt-15"
}

---
 hw/s390x/sclpcpi.c                | 38 ++++++++++++++++++++
 include/hw/s390x/event-facility.h |  9 +++++
 qapi/machine.json                 | 58 +++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+)
hw/s390x/sclpcpi.c +8 -0
index 7ace5dd64e..969c15e43d 100644
@@ -57,8 +57,11 @@
   */
 
 #include "qemu/osdep.h"
+#include "qemu/timer.h"
 #include "hw/s390x/sclp.h"
 #include "hw/s390x/event-facility.h"
+#include "hw/s390x/ebcdic.h"
+#include "qapi/qapi-visit-machine.h"
 
 typedef struct Data {
     uint8_t id_format;
@@ -99,10 +102,37 @@ static int write_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr)
     ControlProgramIdMsg *cpim = container_of(evt_buf_hdr, ControlProgramIdMsg,
                                              ebh);
 
+    ascii_put(event->cpi.system_type, (char *)cpim->data.system_type, 8);
+    ascii_put(event->cpi.system_name, (char *)cpim->data.system_name, 8);
+    ascii_put(event->cpi.sysplex_name, (char *)cpim->data.sysplex_name, 8);
+    event->cpi.system_level = ldq_be_p(&cpim->data.system_level);
+    event->cpi.timestamp = qemu_clock_get_ns(QEMU_CLOCK_HOST);

hw/s390x/sclpcpi.c static int write_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr) · line 119

Quoted 10 lines
hw/s390x/sclpcpi.c +6 -0
+
     cpim->ebh.flags = SCLP_EVENT_BUFFER_ACCEPTED;
     return SCLP_RC_NORMAL_COMPLETION;
 }
 
+static void get_control_program_id(Object *obj, Visitor *v,
+                                   const char *name, void *opaque,
+                                   Error **errp)
+{
+    SCLPEvent *event = (SCLPEvent *)(obj);

Do a checked cast with SCLP_EVENT(obj).

Quoted 45 lines
hw/s390x/sclpcpi.c +24 -0
+    S390ControlProgramId *cpi;
+
+    cpi = &(S390ControlProgramId){
+        .system_type = g_strndup((char *) event->cpi.system_type,
+                                 sizeof(event->cpi.system_type)),
+        .system_name = g_strndup((char *) event->cpi.system_name,
+                                 sizeof(event->cpi.system_name)),
+        .system_level = event->cpi.system_level,
+        .sysplex_name = g_strndup((char *) event->cpi.sysplex_name,
+                                  sizeof(event->cpi.sysplex_name)),
+        .timestamp = event->cpi.timestamp
+    };
+
+    visit_type_S390ControlProgramId(v, name, &cpi, errp);
+}
+
 static void cpi_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -114,6 +144,14 @@ static void cpi_class_init(ObjectClass *klass, void *data)
     k->get_send_mask = send_mask;
     k->get_receive_mask = receive_mask;
     k->write_event_data = write_event_data;
+
+    object_class_property_add(klass, "control-program-id",
+                              "S390ControlProgramId",
+                              get_control_program_id,
+                              NULL, NULL, NULL);
+    object_class_property_set_description(klass, "control-program-id",
+        "Control-program identifiers provide data about the guest "
+        "operating system");
 }
 
 static const TypeInfo sclp_cpi_info = {
include/hw/s390x/event-facility.h +3 -0
index f445d2f9f5..39e589ed44 100644
@@ -169,10 +169,19 @@ typedef struct ReadEventData {
     };
 } QEMU_PACKED ReadEventData;
 
+typedef struct ControlProgramId {
+    uint8_t system_type[8];
+    uint8_t system_name[8];

include/hw/s390x/event-facility.h typedef struct ReadEventData { · line 184

Quoted 10 lines
include/hw/s390x/event-facility.h +6 -0
+    uint64_t system_level;
+    uint8_t sysplex_name[8];
+    uint64_t timestamp;
+} QEMU_PACKED ControlProgramId;
+
 struct SCLPEvent {
     DeviceState qdev;
     bool event_pending;
     char *name;
+    ControlProgramId cpi;

I don't think this should go into SCLPEvent.
Rather SCLPEventFacility or SCLPDevice. Otherwise all events, so also quiesce and cpu_hotplug have a cpi field.

Quoted 1 line
include/hw/s390x/event-facility.h +0 -0
 };

[...]

Signature · 4 lines
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
#6 lore raw

Re: [PATCH v3 2/4] hw/s390x: add Control-Program Identification to QOM

In reply to Shalini Chellathurai Saroja
Quoted 101 lines · Shalini Chellathurai Saroja

Add Control-Program Identification data to the QEMU Object Model (QOM), along with the timestamp in which the data was received.

Example:
virsh # qemu-monitor-command vm --pretty '{ "execute": "qom-get",
"arguments": {
"path": "/machine/sclp/s390-sclp-event-facility/sclpcpi", "property": "control-program-id" }}'

{
   "return": {
     "timestamp": 1742390410685762000,
     "system-level": 74872343805430528,
     "sysplex-name": "PLEX ",
     "system-name": "TESTVM  ",
     "system-type": "LINUX   "
   },
   "id": "libvirt-15"
}
---
  hw/s390x/sclpcpi.c                | 38 ++++++++++++++++++++
  include/hw/s390x/event-facility.h |  9 +++++
  qapi/machine.json                 | 58 +++++++++++++++++++++++++++++++
  3 files changed, 105 insertions(+)
hw/s390x/sclpcpi.c +38 -0
index 7ace5dd64e..969c15e43d 100644
@@ -57,8 +57,11 @@
    */
 
  #include "qemu/osdep.h"
+#include "qemu/timer.h"
  #include "hw/s390x/sclp.h"
  #include "hw/s390x/event-facility.h"
+#include "hw/s390x/ebcdic.h"
+#include "qapi/qapi-visit-machine.h"
 
  typedef struct Data {
      uint8_t id_format;
@@ -99,10 +102,37 @@ static int write_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr)
      ControlProgramIdMsg *cpim = container_of(evt_buf_hdr, ControlProgramIdMsg,
                                               ebh);
 
+    ascii_put(event->cpi.system_type, (char *)cpim->data.system_type, 8);
+    ascii_put(event->cpi.system_name, (char *)cpim->data.system_name, 8);
+    ascii_put(event->cpi.sysplex_name, (char *)cpim->data.sysplex_name, 8);
+    event->cpi.system_level = ldq_be_p(&cpim->data.system_level);
+    event->cpi.timestamp = qemu_clock_get_ns(QEMU_CLOCK_HOST);
+
      cpim->ebh.flags = SCLP_EVENT_BUFFER_ACCEPTED;
      return SCLP_RC_NORMAL_COMPLETION;
  }
 
+static void get_control_program_id(Object *obj, Visitor *v,
+                                   const char *name, void *opaque,
+                                   Error **errp)
+{
+    SCLPEvent *event = (SCLPEvent *)(obj);
+    S390ControlProgramId *cpi;
+
+    cpi = &(S390ControlProgramId){
+        .system_type = g_strndup((char *) event->cpi.system_type,
+                                 sizeof(event->cpi.system_type)),
+        .system_name = g_strndup((char *) event->cpi.system_name,
+                                 sizeof(event->cpi.system_name)),
+        .system_level = event->cpi.system_level,
+        .sysplex_name = g_strndup((char *) event->cpi.sysplex_name,
+                                  sizeof(event->cpi.sysplex_name)),
+        .timestamp = event->cpi.timestamp
+    };
+
+    visit_type_S390ControlProgramId(v, name, &cpi, errp);
+}
+
  static void cpi_class_init(ObjectClass *klass, void *data)
  {
      DeviceClass *dc = DEVICE_CLASS(klass);
@@ -114,6 +144,14 @@ static void cpi_class_init(ObjectClass *klass, void *data)
      k->get_send_mask = send_mask;
      k->get_receive_mask = receive_mask;
      k->write_event_data = write_event_data;
+
+    object_class_property_add(klass, "control-program-id",
+                              "S390ControlProgramId",
+                              get_control_program_id,
+                              NULL, NULL, NULL);
+    object_class_property_set_description(klass, "control-program-id",
+        "Control-program identifiers provide data about the guest "
+        "operating system");
  }
 
  static const TypeInfo sclp_cpi_info = {
include/hw/s390x/event-facility.h +0 -0
index f445d2f9f5..39e589ed44 100644

include/hw/s390x/event-facility.h typedef struct ReadEventData { · line 178

Quoted 10 lines
include/hw/s390x/event-facility.h +7 -0
@@ -169,10 +169,19 @@ typedef struct ReadEventData {
      };
  } QEMU_PACKED ReadEventData;
 
+typedef struct ControlProgramId {
+    uint8_t system_type[8];
+    uint8_t system_name[8];
+    uint64_t system_level;
+    uint8_t sysplex_name[8];
+    uint64_t timestamp;
+} QEMU_PACKED ControlProgramId;

Do we need the QEMU_PACKED here? The members seem naturally aligned, and the struct does not seem to be involved in the communication with the guest directly, so if you don't need it, please drop the QEMU_PACKED here. (without PACKED, the compiler can optimize the code in a better way, and this causes less trouble on exotic platforms like SPARC that cannot access unaligned memory addresses)

Quoted 42 lines
include/hw/s390x/event-facility.h +1 -0
  struct SCLPEvent {
      DeviceState qdev;
      bool event_pending;
      char *name;
+    ControlProgramId cpi;
  };
 
  struct SCLPEventClass {
qapi/machine.json +26 -0
index a6b8795b09..cd2bcd2d13 100644
@@ -1898,3 +1898,61 @@
  { 'command': 'x-query-interrupt-controllers',
    'returns': 'HumanReadableText',
    'features': [ 'unstable' ]}
+
+##
+# @S390ControlProgramId:
+#
+# Control-program identifiers provide data about the guest operating system.
+# The control-program identifiers are: system type, system name, system level
+# and sysplex name.
+#
+# In Linux, all the control-program identifiers are user configurable. The
+# system type, system name, and sysplex name use EBCDIC characters from
+# this set: capital A-Z, 0-9, $, @, #, and blank.  In Linux, the system type,
+# system name and sysplex name are arbitrary free-form texts.
+#
+# In Linux, the 8-byte hexadecimal system-level has the format
+# 0x<a><b><cc><dd><eeee><ff><gg><hh>, where:
+# <a>: is one hexadecimal byte, its most significant bit indicates hypervisor
+# use
+# <b>: is one digit that represents Linux distributions as follows
+# 0: generic Linux
+# 1: Red Hat Enterprise Linux
+# 2: SUSE Linux Enterprise Server
+# 3: Canonical Ubuntu
+# 4: Fedora
+# 5: openSUSE Leap
+# 6: Debian GNU/Linux
+# 7: Red Hat Enterprise Linux CoreOS

qapi/machine.json line 1936

Quoted 10 lines
qapi/machine.json +10 -0
+# <cc>: are two digits for a distribution-specific encoding of the major version
+# of the distribution
+# <dd>: are two digits for a distribution-specific encoding of the minor version
+# of the distribution
+# <eeee>: are four digits for the patch level of the distribution
+# <ff>: are two digits for the major version of the kernel
+# <gg>: are two digits for the minor version of the kernel
+# <hh>: are two digits for the stable version of the kernel
+# (e.g. 74872343805430528, when converted to hex is 0x010a000000060b00). On
+# machines prior to z16, some of the values are not available to display.

You've got the same information in the comment at the beginning of the sclpcpi.c file already ... maybe it would be good to have it in one place only to avoid double maintenance in case it needs to be changed in the future. I'd suggest to change the comment at the beginning of sclpcpi.c to say something like "for a detailed description of the contents of the CPI, please see the S390ControlProgramId QOM-type description." or something similar?

Thomas

#7 lore raw

PATCH v3 3/4 hw/s390x: support migration of CPI data

In reply to Shalini Chellathurai Saroja

Register Control-Program Identification data with the live migration infrastructure.

---
 hw/s390x/sclpcpi.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
hw/s390x/sclpcpi.c +27 -0
index 969c15e43d..0b1b5293ea 100644
@@ -62,6 +62,7 @@
 #include "hw/s390x/event-facility.h"
 #include "hw/s390x/ebcdic.h"
 #include "qapi/qapi-visit-machine.h"
+#include "migration/vmstate.h"
 
 typedef struct Data {
     uint8_t id_format;
@@ -133,12 +134,38 @@ static void get_control_program_id(Object *obj, Visitor *v,
     visit_type_S390ControlProgramId(v, name, &cpi, errp);
 }
 
+static const VMStateDescription vmstate_control_program_id = {
+    .name = "s390_control_program_id",
+    .version_id = 0,
+    .minimum_version_id = 0,
+    .fields = (const VMStateField[]) {
+        VMSTATE_UINT8_ARRAY(system_type, ControlProgramId, 8),
+        VMSTATE_UINT8_ARRAY(system_name, ControlProgramId, 8),
+        VMSTATE_UINT64(system_level, ControlProgramId),
+        VMSTATE_UINT8_ARRAY(sysplex_name, ControlProgramId, 8),
+        VMSTATE_UINT64(timestamp, ControlProgramId),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_sclpcpi = {
+    .name = "s390_sclpcpi",
+    .version_id = 0,
+    .minimum_version_id = 0,
+    .fields = (const VMStateField[]) {
+        VMSTATE_STRUCT(cpi, SCLPEvent, 0, vmstate_control_program_id,
+                       ControlProgramId),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void cpi_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     SCLPEventClass *k = SCLP_EVENT_CLASS(klass);
 
     dc->user_creatable = false;
+    dc->vmsd =  &vmstate_sclpcpi;
 
     k->can_handle_event = can_handle_event;
     k->get_send_mask = send_mask;
Signature · 1 line
2.47.0
#8 lore raw

Re: [PATCH v3 3/4] hw/s390x: support migration of CPI data

Quoted 22 lines · Shalini Chellathurai Saroja

Register Control-Program Identification data with the live migration infrastructure.

---
  hw/s390x/sclpcpi.c | 27 +++++++++++++++++++++++++++
  1 file changed, 27 insertions(+)
hw/s390x/sclpcpi.c +1 -0
index 969c15e43d..0b1b5293ea 100644
@@ -62,6 +62,7 @@
  #include "hw/s390x/event-facility.h"
  #include "hw/s390x/ebcdic.h"
  #include "qapi/qapi-visit-machine.h"
+#include "migration/vmstate.h"
 
  typedef struct Data {
      uint8_t id_format;

hw/s390x/sclpcpi.c static void get_control_program_id(Object *obj, Visitor *v, · line 140

Quoted 7 lines
hw/s390x/sclpcpi.c +4 -0
@@ -133,12 +134,38 @@ static void get_control_program_id(Object *obj, Visitor *v,
      visit_type_S390ControlProgramId(v, name, &cpi, errp);
  }
 
+static const VMStateDescription vmstate_control_program_id = {
+    .name = "s390_control_program_id",
+    .version_id = 0,
+    .minimum_version_id = 0,

Nit: As long as it is 0, I think you could simply omit the minimum_version_id field here.

Quoted 4 lines
hw/s390x/sclpcpi.c +4 -0
+    .fields = (const VMStateField[]) {
+        VMSTATE_UINT8_ARRAY(system_type, ControlProgramId, 8),
+        VMSTATE_UINT8_ARRAY(system_name, ControlProgramId, 8),
+        VMSTATE_UINT64(system_level, ControlProgramId),

hw/s390x/sclpcpi.c static void get_control_program_id(Object *obj, Visitor *v, · line 154

Quoted 10 lines
hw/s390x/sclpcpi.c +10 -0
+        VMSTATE_UINT8_ARRAY(sysplex_name, ControlProgramId, 8),
+        VMSTATE_UINT64(timestamp, ControlProgramId),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_sclpcpi = {
+    .name = "s390_sclpcpi",
+    .version_id = 0,
+    .minimum_version_id = 0,

dito

hw/s390x/sclpcpi.c static void get_control_program_id(Object *obj, Visitor *v, · line 160

Quoted 6 lines
hw/s390x/sclpcpi.c +6 -0
+    .fields = (const VMStateField[]) {
+        VMSTATE_STRUCT(cpi, SCLPEvent, 0, vmstate_control_program_id,
+                       ControlProgramId),
+        VMSTATE_END_OF_LIST()
+    }
+};

Thomas

#9 lore raw

Re: [PATCH v3 3/4] hw/s390x: support migration of CPI data

Quoted 24 lines · Thomas Huth
Quoted 23 lines · Shalini Chellathurai Saroja

Register Control-Program Identification data with the live migration infrastructure.

---
  hw/s390x/sclpcpi.c | 27 +++++++++++++++++++++++++++
  1 file changed, 27 insertions(+)
hw/s390x/sclpcpi.c +1 -0
index 969c15e43d..0b1b5293ea 100644
@@ -62,6 +62,7 @@
  #include "hw/s390x/event-facility.h"
  #include "hw/s390x/ebcdic.h"
  #include "qapi/qapi-visit-machine.h"
+#include "migration/vmstate.h"
    typedef struct Data {
      uint8_t id_format;
@@ -133,12 +134,38 @@ static void get_control_program_id(Object *obj, 
 Visitor *v,
      visit_type_S390ControlProgramId(v, name, &cpi, errp);
Quoted 9 lines

hw/s390x/sclpcpi.c static void get_control_program_id(Object *obj, Visitor *v, · line 140

Quoted 5 lines
hw/s390x/sclpcpi.c +3 -0
  }
  +static const VMStateDescription vmstate_control_program_id = {
+    .name = "s390_control_program_id",
+    .version_id = 0,
+    .minimum_version_id = 0,

Nit: As long as it is 0, I think you could simply omit the minimum_version_id field here.

Ok, I will omit the minimum_version_id field in both, thank you.

Quoted 24 lines
Quoted 4 lines
hw/s390x/sclpcpi.c +4 -0
+    .fields = (const VMStateField[]) {
+        VMSTATE_UINT8_ARRAY(system_type, ControlProgramId, 8),
+        VMSTATE_UINT8_ARRAY(system_name, ControlProgramId, 8),
+        VMSTATE_UINT64(system_level, ControlProgramId),

hw/s390x/sclpcpi.c static void get_control_program_id(Object *obj, Visitor *v, · line 154

Quoted 10 lines
hw/s390x/sclpcpi.c +10 -0
+        VMSTATE_UINT8_ARRAY(sysplex_name, ControlProgramId, 8),
+        VMSTATE_UINT64(timestamp, ControlProgramId),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_sclpcpi = {
+    .name = "s390_sclpcpi",
+    .version_id = 0,
+    .minimum_version_id = 0,

dito

hw/s390x/sclpcpi.c static void get_control_program_id(Object *obj, Visitor *v, · line 160

Quoted 6 lines
hw/s390x/sclpcpi.c +6 -0
+    .fields = (const VMStateField[]) {
+        VMSTATE_STRUCT(cpi, SCLPEvent, 0, vmstate_control_program_id,
+                       ControlProgramId),
+        VMSTATE_END_OF_LIST()
+    }
+};

Thomas

Signature · 9 lines
Mit freundlichen Grüßen / Kind regards
Shalini Chellathurai Saroja
Software Developer
Linux on IBM Z & KVM Development
IBM Deutschland Research & Development GmbH
Dept 1419, Schoenaicher Str. 220, 71032 Boeblingen
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
#10 lore raw

PATCH v3 4/4 hw/s390x: compat handling for backward migration

In reply to Shalini Chellathurai Saroja

Add Control-Program Identification (CPI) device to QOM only when the virtual machine supports CPI. CPI is supported from "s390-ccw-virtio-10.0" machine and higher.

---
 hw/s390x/event-facility.c  | 27 ++++++++++++++++++++++-----
 hw/s390x/s390-virtio-ccw.c |  1 +
 2 files changed, 23 insertions(+), 5 deletions(-)
hw/s390x/event-facility.c +22 -5
index c0fb6e098c..cb23bbc54b 100644
@@ -22,6 +22,7 @@
 #include "hw/s390x/sclp.h"
 #include "migration/vmstate.h"
 #include "hw/s390x/event-facility.h"
+#include "hw/qdev-properties.h"
 
 typedef struct SCLPEventsBus {
     BusState qbus;
@@ -54,6 +55,7 @@ struct SCLPEventFacility {
     bool allow_all_mask_sizes;
     /* length of the receive mask */
     uint16_t mask_length;
+    bool use_cpi;
 };
 
 /* return true if any child has event pending set */
@@ -455,11 +457,20 @@ static void realize_event_facility(DeviceState *dev, Error **errp)
         qdev_unrealize(DEVICE(&event_facility->quiesce));
         return;
     }
-    if (!qdev_realize(DEVICE(&event_facility->cpi),
-                      BUS(&event_facility->sbus), errp)) {
-        qdev_unrealize(DEVICE(&event_facility->quiesce));
-        qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
-        return;
+    /*
+     * Add sclpcpi device to QOM only when the virtual machine supports
+     * Control-Program Identification. It is supported by "s390-ccw-virtio-10.0"
+     * machine and higher.
+     */
+    if (!event_facility->use_cpi) {
+        object_unparent(OBJECT(&event_facility->cpi));
+    } else {
+        if (!qdev_realize(DEVICE(&event_facility->cpi),
+                          BUS(&event_facility->sbus), errp)) {
+            qdev_unrealize(DEVICE(&event_facility->quiesce));
+            qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
+            return;
+        }
     }
 }
 
@@ -470,12 +481,18 @@ static void reset_event_facility(DeviceState *dev)
     sdev->receive_mask = 0;
 }
 
+static const Property qemu_event_facility_properties[] = {
+    DEFINE_PROP_BOOL("use-cpi", SCLPEventFacility,
+                     use_cpi, true),
+};
+
 static void init_event_facility_class(ObjectClass *klass, void *data)
 {
     SysBusDeviceClass *sbdc = SYS_BUS_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(sbdc);
     SCLPEventFacilityClass *k = EVENT_FACILITY_CLASS(dc);
 
+    device_class_set_props(dc, qemu_event_facility_properties);
     dc->realize = realize_event_facility;
     device_class_set_legacy_reset(dc, reset_event_facility);
     dc->vmsd = &vmstate_event_facility;
hw/s390x/s390-virtio-ccw.c +1 -0
index 75b32182eb..c1001322e0 100644
@@ -939,6 +939,7 @@ static void ccw_machine_9_2_class_options(MachineClass *mc)
 {
     static GlobalProperty compat[] = {
         { TYPE_S390_PCI_DEVICE, "relaxed-translation", "off", },
+        { TYPE_SCLP_EVENT_FACILITY, "use-cpi", "off", },
     };
 
     ccw_machine_10_0_class_options(mc);
Signature · 1 line
2.47.0
#11 lore raw

Re: [PATCH v3 4/4] hw/s390x: compat handling for backward migration

Quoted 43 lines · Shalini Chellathurai Saroja

Add Control-Program Identification (CPI) device to QOM only when the virtual machine supports CPI. CPI is supported from "s390-ccw-virtio-10.0" machine and higher.

---
  hw/s390x/event-facility.c  | 27 ++++++++++++++++++++++-----
  hw/s390x/s390-virtio-ccw.c |  1 +
  2 files changed, 23 insertions(+), 5 deletions(-)
hw/s390x/event-facility.c +6 -5
index c0fb6e098c..cb23bbc54b 100644
@@ -22,6 +22,7 @@
  #include "hw/s390x/sclp.h"
  #include "migration/vmstate.h"
  #include "hw/s390x/event-facility.h"
+#include "hw/qdev-properties.h"
 
  typedef struct SCLPEventsBus {
      BusState qbus;
@@ -54,6 +55,7 @@ struct SCLPEventFacility {
      bool allow_all_mask_sizes;
      /* length of the receive mask */
      uint16_t mask_length;
+    bool use_cpi;
  };
 
  /* return true if any child has event pending set */
@@ -455,11 +457,20 @@ static void realize_event_facility(DeviceState *dev, Error **errp)
          qdev_unrealize(DEVICE(&event_facility->quiesce));
          return;
      }
-    if (!qdev_realize(DEVICE(&event_facility->cpi),
-                      BUS(&event_facility->sbus), errp)) {
-        qdev_unrealize(DEVICE(&event_facility->quiesce));
-        qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
-        return;
+    /*
+     * Add sclpcpi device to QOM only when the virtual machine supports
+     * Control-Program Identification. It is supported by "s390-ccw-virtio-10.0"
+     * machine and higher.

hw/s390x/event-facility.c static void realize_event_facility(DeviceState *dev, Error **errp) · line 473

Quoted 10 lines
hw/s390x/event-facility.c +10 -0
+     */
+    if (!event_facility->use_cpi) {
+        object_unparent(OBJECT(&event_facility->cpi));
+    } else {
+        if (!qdev_realize(DEVICE(&event_facility->cpi),
+                          BUS(&event_facility->sbus), errp)) {
+            qdev_unrealize(DEVICE(&event_facility->quiesce));
+            qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
+            return;
+        }

Hmm, first doing object_initialize_child() in init_event_facility() and then unparenting it here again in case we are running with an older machine type is a little bit ugly. I wonder whether it would be nicer to add the QOM object from ccw_init() init instead, similar to what we do with the SCLP-console in s390_create_sclpconsole() ? If you've got some spare minutes, could you please give it a try whether that looks nicer?

Thanks,
Thomas

#12 lore raw

Re: [PATCH v3 4/4] hw/s390x: compat handling for backward migration

Quoted 56 lines · Thomas Huth
Quoted 44 lines · Shalini Chellathurai Saroja

Add Control-Program Identification (CPI) device to QOM only when the virtual machine supports CPI. CPI is supported from "s390-ccw-virtio-10.0" machine and higher.

---
  hw/s390x/event-facility.c  | 27 ++++++++++++++++++++++-----
  hw/s390x/s390-virtio-ccw.c |  1 +
  2 files changed, 23 insertions(+), 5 deletions(-)
hw/s390x/event-facility.c +4 -5
index c0fb6e098c..cb23bbc54b 100644
@@ -22,6 +22,7 @@
  #include "hw/s390x/sclp.h"
  #include "migration/vmstate.h"
  #include "hw/s390x/event-facility.h"
+#include "hw/qdev-properties.h"
    typedef struct SCLPEventsBus {
      BusState qbus;
@@ -54,6 +55,7 @@ struct SCLPEventFacility {
      bool allow_all_mask_sizes;
      /* length of the receive mask */
      uint16_t mask_length;
+    bool use_cpi;
  };
    /* return true if any child has event pending set */
@@ -455,11 +457,20 @@ static void realize_event_facility(DeviceState 
 *dev, Error **errp)
          qdev_unrealize(DEVICE(&event_facility->quiesce));
          return;
      }
-    if (!qdev_realize(DEVICE(&event_facility->cpi),
-                      BUS(&event_facility->sbus), errp)) {
-        qdev_unrealize(DEVICE(&event_facility->quiesce));
-        qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
-        return;
+    /*
+     * Add sclpcpi device to QOM only when the virtual machine 

supports
+ * Control-Program Identification. It is supported by
"s390-ccw-virtio-10.0"

hw/s390x/event-facility.c +1 -0
+     * machine and higher.

hw/s390x/event-facility.c

Quoted 10 lines
hw/s390x/event-facility.c +10 -0
+     */
+    if (!event_facility->use_cpi) {
+        object_unparent(OBJECT(&event_facility->cpi));
+    } else {
+        if (!qdev_realize(DEVICE(&event_facility->cpi),
+                          BUS(&event_facility->sbus), errp)) {
+            qdev_unrealize(DEVICE(&event_facility->quiesce));
+            qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
+            return;
+        }
Quoted 8 lines

Hmm, first doing object_initialize_child() in init_event_facility() and then unparenting it here again in case we are running with an older machine type is a little bit ugly. I wonder whether it would be nicer to add the QOM object from ccw_init() init instead, similar to what we do with the SCLP-console in s390_create_sclpconsole() ? If you've got some spare minutes, could you please give it a try whether that looks nicer?

Hello Thomas,

Sure. Did you mean like the code below?, if yes, the use_cpi is always true when adding the sclpcpi device from ccw_init(). The use_cpi is set to false at a later point, when the machine type is 9.2 or older. This means the sclpcpi device is always added, the output and the code are provided below. Please let me know how to proceed, thank you very much.

virsh # qemu-monitor-command vm --pretty '{"execute":"qom-get", "arguments":{"path":"/machine/sclp/s390-sclp-event-facility", "property":"use-cpi"}}' {
"return": false,
"id": "libvirt-16"
}
virsh # qemu-monitor-command vm --pretty '{"execute":"qom-get", "arguments":{"path":"/machine/sclp/s390-sclp-event-facility/sclpcpi", "property":"control-program-id"}}' {

  "return": {
    "timestamp": 1743681889538425000,
    "system-level": 74872343805430528,
    "sysplex-name": "        ",
    "system-name": "        ",
    "system-type": "LINUX   "

},
"id": "libvirt-17"
}

hw/s390x/event-facility.c +6 -18
index cb23bbc54b..15d9f94845 100644
@@ -76,6 +76,11 @@ static bool event_pending(SCLPEventFacility *ef)
     return false;
 }
 
+static bool use_cpi(SCLPEventFacility *ef)
+{
+    return ef->use_cpi;
+}
+
 static sccb_mask_t get_host_send_mask(SCLPEventFacility *ef)
 {
     sccb_mask_t mask;
@@ -438,10 +443,6 @@ static void init_event_facility(Object *obj)
     object_initialize_child(obj, TYPE_SCLP_CPU_HOTPLUG,
                             &event_facility->cpu_hotplug,
                             TYPE_SCLP_CPU_HOTPLUG);
-
-    object_initialize_child(obj, TYPE_SCLP_CPI,
-                            &event_facility->cpi,
-                            TYPE_SCLP_CPI);
 }
 
 static void realize_event_facility(DeviceState *dev, Error **errp)
@@ -457,21 +458,6 @@ static void realize_event_facility(DeviceState *dev, Error **errp)
         qdev_unrealize(DEVICE(&event_facility->quiesce));
         return;
     }
-    /*
-     * Add sclpcpi device to QOM only when the virtual machine supports
-     * Control-Program Identification. It is supported by "s390-ccw-virtio-10.0"
-     * machine and higher.
-     */
-    if (!event_facility->use_cpi) {
-        object_unparent(OBJECT(&event_facility->cpi));
-    } else {
-        if (!qdev_realize(DEVICE(&event_facility->cpi),
-                          BUS(&event_facility->sbus), errp)) {
-            qdev_unrealize(DEVICE(&event_facility->quiesce));
-            qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
-            return;
-        }
 }
 
 static void reset_event_facility(DeviceState *dev)
@@ -499,6 +485,7 @@ static void init_event_facility_class(ObjectClass *klass, void *data)
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
     k->command_handler = command_handler;
     k->event_pending = event_pending;
+    k->use_cpi = use_cpi;
 }
 
 static const TypeInfo sclp_event_facility_info = {
hw/s390x/s390-virtio-ccw.c +19 -0
index c1001322e0..f077ecaee1 100644
@@ -260,6 +260,21 @@ static void s390_create_sclpconsole(SCLPDevice *sclp,
     qdev_realize_and_unref(dev, ev_fac_bus, &error_fatal);
 }
 
+static void s390_create_sclpcpi(SCLPDevice *sclp)
+{
+    SCLPEventFacility *ef = sclp->event_facility;
+    SCLPEventFacilityClass *efc = EVENT_FACILITY_GET_CLASS(ef);
+    BusState *ev_fac_bus = sclp_get_event_facility_bus(ef);
+    DeviceState *dev;
+
+    if(efc->use_cpi) {
+        dev = qdev_new(TYPE_SCLP_CPI);
+        object_property_add_child(OBJECT(ef), "sclpcpi", OBJECT(dev));
+        object_unref(OBJECT(dev));
+        qdev_realize_and_unref(dev, ev_fac_bus, &error_fatal);
+    }
+}
+
 static void ccw_init(MachineState *machine)
 {
     MachineClass *mc = MACHINE_GET_CLASS(machine);
@@ -323,6 +338,10 @@ static void ccw_init(MachineState *machine)
 
     /* init the TOD clock */
     s390_init_tod();
+
+    /* init SCLP event Control-Program Identification */
+    s390_create_sclpcpi(ms->sclp);
+
 }
 
 static void s390_cpu_plug(HotplugHandler *hotplug_dev,
include/hw/s390x/event-facility.h +0 -0
index f445d2f9f5..ba20161023 100644
@@ -204,6 +204,7 @@ struct SCLPEventFacilityClass {
     SysBusDeviceClass parent_class;
     void (*command_handler)(SCLPEventFacility *ef, SCCB *sccb, uint64_t 
code);
     bool (*event_pending)(SCLPEventFacility *ef);

+ bool (*use_cpi)(SCLPEventFacility *ef);
};

BusState *sclp_get_event_facility_bus(SCLPEventFacility *ef);

Quoted 2 lines

Thanks,
Thomas

Signature · 9 lines
Mit freundlichen Grüßen / Kind regards
Shalini Chellathurai Saroja
Software Developer
Linux on IBM Z & KVM Development
IBM Deutschland Research & Development GmbH
Dept 1419, Schoenaicher Str. 220, 71032 Boeblingen
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
#13 lore raw

Re: [PATCH v3 4/4] hw/s390x: compat handling for backward migration

Quoted 68 lines · Shalini Chellathurai Saroja
Quoted 55 lines · Thomas Huth
Quoted 45 lines · Shalini Chellathurai Saroja

Add Control-Program Identification (CPI) device to QOM only when the virtual machine supports CPI. CPI is supported from "s390-ccw-virtio-10.0" machine and higher.

---
  hw/s390x/event-facility.c  | 27 ++++++++++++++++++++++----- hw/s390x/s390-virtio-ccw.c |  1 +

  2 files changed, 23 insertions(+), 5 deletions(-)
hw/s390x/event-facility.c +5 -5
index c0fb6e098c..cb23bbc54b 100644
@@ -22,6 +22,7 @@
   #include "hw/s390x/sclp.h"
   #include "migration/vmstate.h"
   #include "hw/s390x/event-facility.h"
+#include "hw/qdev-properties.h"
     typedef struct SCLPEventsBus {
       BusState qbus;
@@ -54,6 +55,7 @@ struct SCLPEventFacility {
       bool allow_all_mask_sizes;
       /* length of the receive mask */
       uint16_t mask_length;
+    bool use_cpi;
   };
     /* return true if any child has event pending set */
@@ -455,11 +457,20 @@ static void realize_event_facility(DeviceState 
 *dev, Error **errp)
           qdev_unrealize(DEVICE(&event_facility->quiesce));
           return;
       }
-    if (!qdev_realize(DEVICE(&event_facility->cpi),
-                      BUS(&event_facility->sbus), errp)) {
-        qdev_unrealize(DEVICE(&event_facility->quiesce));
-        qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
-        return;
+    /*
+     * Add sclpcpi device to QOM only when the virtual machine supports
+     * Control-Program Identification. It is supported by "s390-ccw- 

virtio-10.0"
+     * machine and higher.
+     */
+    if (!event_facility->use_cpi) {

Quoted 8 lines

+        object_unparent(OBJECT(&event_facility->cpi)); +    } else {
+        if (!qdev_realize(DEVICE(&event_facility->cpi), +                          BUS(&event_facility->sbus), errp)) { +            qdev_unrealize(DEVICE(&event_facility->quiesce)); +            qdev_unrealize(DEVICE(&event_facility->cpu_hotplug)); +            return;
+        }

Quoted 8 lines

Hmm, first doing object_initialize_child() in init_event_facility() and then unparenting it here again in case we are running with an older machine type is a little bit ugly. I wonder whether it would be nicer to add the QOM object from ccw_init() init instead, similar to what we do with the SCLP-console in s390_create_sclpconsole() ? If you've got some spare minutes, could you please give it a try whether that looks nicer?

Hello Thomas,

Sure. Did you mean like the code below?, if yes, the use_cpi is always true when adding the sclpcpi device from ccw_init(). The use_cpi is set to false at a later point, when the machine type is 9.2 or older. This means the sclpcpi device is always added, the output and the code are provided below. Please let me know how to proceed, thank you very much.

...

Quoted 7 lines
hw/s390x/event-facility.c +1 -0
@@ -499,6 +485,7 @@ static void init_event_facility_class(ObjectClass 
 *klass, void *data)
      set_bit(DEVICE_CATEGORY_MISC, dc->categories);
      k->command_handler = command_handler;
      k->event_pending = event_pending;
+    k->use_cpi = use_cpi;
  }

...

include/hw/s390x/event-facility.h struct SCLPEventFacilityClass { · line 209

Quoted 11 lines
include/hw/s390x/event-facility.h +1 -0
index f445d2f9f5..ba20161023 100644
@@ -204,6 +204,7 @@ struct SCLPEventFacilityClass {
      SysBusDeviceClass parent_class;
      void (*command_handler)(SCLPEventFacility *ef, SCCB *sccb, uint64_t 
 code);
      bool (*event_pending)(SCLPEventFacility *ef);
+    bool (*use_cpi)(SCLPEventFacility *ef);
  };

Hi,

you certainly don't need the (*use_cpi) callback here.

I'd suggest to:

1) Add a boolean flag to S390CcwMachineClass in s390-virtio-ccw.h called "use_cpi", "cpi_allowed", "has_cpi" or whatever.

2) Set that flag to true in ccw_machine_class_init() (similar to that hpage_1m_allowed flag)

3) Set that flag to false in ccw_machine_9_2_class_options() so that it gets disabled for older machine type classes. Important: use the class_options() function here, not the instance_options()! Also not that this should go into the ccw_machine_10_0_class_options() functions instead once v10.0 has been released.

4) In ccw_init() you should now be able to use "S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc)" to query the flag from the machine class.

HTH,
Thomas

#14 lore raw

Re: [PATCH v3 4/4] hw/s390x: compat handling for backward migration

Quoted 109 lines · Thomas Huth
Quoted 69 lines · Shalini Chellathurai Saroja
Quoted 56 lines · Thomas Huth
Quoted 46 lines · Shalini Chellathurai Saroja

Add Control-Program Identification (CPI) device to QOM only when the virtual machine supports CPI. CPI is supported from "s390-ccw-virtio-10.0" machine and higher.

---
  hw/s390x/event-facility.c  | 27 ++++++++++++++++++++++----- hw/s390x/s390-virtio-ccw.c |  1 +

  2 files changed, 23 insertions(+), 5 deletions(-)
hw/s390x/event-facility.c +4 -5
index c0fb6e098c..cb23bbc54b 100644
@@ -22,6 +22,7 @@
   #include "hw/s390x/sclp.h"
   #include "migration/vmstate.h"
   #include "hw/s390x/event-facility.h"
+#include "hw/qdev-properties.h"
     typedef struct SCLPEventsBus {
       BusState qbus;
@@ -54,6 +55,7 @@ struct SCLPEventFacility {
       bool allow_all_mask_sizes;
       /* length of the receive mask */
       uint16_t mask_length;
+    bool use_cpi;
   };
     /* return true if any child has event pending set */
@@ -455,11 +457,20 @@ static void realize_event_facility(DeviceState 
 *dev, Error **errp)
           qdev_unrealize(DEVICE(&event_facility->quiesce));
           return;
       }
-    if (!qdev_realize(DEVICE(&event_facility->cpi),
-                      BUS(&event_facility->sbus), errp)) {
-        qdev_unrealize(DEVICE(&event_facility->quiesce));
-        qdev_unrealize(DEVICE(&event_facility->cpu_hotplug));
-        return;
+    /*
+     * Add sclpcpi device to QOM only when the virtual machine 

supports
+     * Control-Program Identification. It is supported by "s390-ccw- virtio-10.0"
+     * machine and higher.
+     */
+    if (!event_facility->use_cpi) {

Quoted 8 lines

+        object_unparent(OBJECT(&event_facility->cpi)); +    } else {
+        if (!qdev_realize(DEVICE(&event_facility->cpi), +                          BUS(&event_facility->sbus), errp)) { +            qdev_unrealize(DEVICE(&event_facility->quiesce)); +            qdev_unrealize(DEVICE(&event_facility->cpu_hotplug)); +            return;
+        }

Quoted 8 lines

Hmm, first doing object_initialize_child() in init_event_facility() and then unparenting it here again in case we are running with an older machine type is a little bit ugly. I wonder whether it would be nicer to add the QOM object from ccw_init() init instead, similar to what we do with the SCLP-console in s390_create_sclpconsole() ? If you've got some spare minutes, could you please give it a try whether that looks nicer?

Hello Thomas,

Sure. Did you mean like the code below?, if yes, the use_cpi is always true when adding the sclpcpi device from ccw_init(). The use_cpi is set to false at a later point, when the machine type is 9.2 or older. This means the sclpcpi device is always added, the output and the code are provided below. Please let me know how to proceed, thank you very much.

...

Quoted 7 lines
hw/s390x/event-facility.c +1 -0
@@ -499,6 +485,7 @@ static void init_event_facility_class(ObjectClass 
 *klass, void *data)
      set_bit(DEVICE_CATEGORY_MISC, dc->categories);
      k->command_handler = command_handler;
      k->event_pending = event_pending;
+    k->use_cpi = use_cpi;
  }

...

include/hw/s390x/event-facility.h struct SCLPEventFacilityClass { · line 209

Quoted 11 lines
include/hw/s390x/event-facility.h +1 -0
index f445d2f9f5..ba20161023 100644
@@ -204,6 +204,7 @@ struct SCLPEventFacilityClass {
      SysBusDeviceClass parent_class;
      void (*command_handler)(SCLPEventFacility *ef, SCCB *sccb, 
 uint64_t code);
      bool (*event_pending)(SCLPEventFacility *ef);
+    bool (*use_cpi)(SCLPEventFacility *ef);
  };

Hi,

you certainly don't need the (*use_cpi) callback here.

I'd suggest to:

1) Add a boolean flag to S390CcwMachineClass in s390-virtio-ccw.h called "use_cpi", "cpi_allowed", "has_cpi" or whatever.

2) Set that flag to true in ccw_machine_class_init() (similar to that hpage_1m_allowed flag)

3) Set that flag to false in ccw_machine_9_2_class_options() so that it gets disabled for older machine type classes. Important: use the class_options() function here, not the instance_options()! Also not that this should go into the ccw_machine_10_0_class_options() functions instead once v10.0 has been released.

Quoted 6 lines

4) In ccw_init() you should now be able to use "S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc)" to query the flag from the machine class.

HTH,
Thomas

Hi Thomas,

I will do this, Thank you.

Signature · 9 lines
Mit freundlichen Grüßen / Kind regards
Shalini Chellathurai Saroja
Software Developer
Linux on IBM Z & KVM Development
IBM Deutschland Research & Development GmbH
Dept 1419, Schoenaicher Str. 220, 71032 Boeblingen
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294