Skip to contentSkip to conversation

s390x: kvm-unit-tests: a PONG device for Sub Channels tests

PATCH In review Pierre Morel 4 participants 14 messages Nov 13, 2019 – Nov 15, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x: kvm-unit-tests: a PONG device for Sub Channels tests

The PONG device accept two commands: PONG_READ and PONG_WRITE which allow to read from and write to an internal buffer of 1024 bytes.

The QEMU device is named ccw-pong.

---
 hw/s390x/Makefile.objs  |   1 +
 hw/s390x/ccw-pong.c     | 186 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/s390x/pong.h |  47 ++++++++++++
 3 files changed, 234 insertions(+)
 create mode 100644 hw/s390x/ccw-pong.c
 create mode 100644 include/hw/s390x/pong.h
hw/s390x/Makefile.objs +1 -0
index ee91152..3a83438 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_KVM) += tod-kvm.o
 obj-$(CONFIG_KVM) += s390-skeys-kvm.o
 obj-$(CONFIG_KVM) += s390-stattrib-kvm.o s390-mchk.o
 obj-y += s390-ccw.o
+obj-y += ccw-pong.o
 obj-y += ap-device.o
 obj-y += ap-bridge.o
 obj-y += s390-sei.o
hw/s390x/ccw-pong.c new file +186 -0

186 lines not on this page · raw message

include/hw/s390x/pong.h new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

Minor nit for $SUBJECT: this isn't a kvm-unit-tests patch, that's just one consumer :)

Quoted 20 lines

The PONG device accept two commands: PONG_READ and PONG_WRITE which allow to read from and write to an internal buffer of 1024 bytes.

The QEMU device is named ccw-pong.

---
 hw/s390x/Makefile.objs  |   1 +
 hw/s390x/ccw-pong.c     | 186 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/s390x/pong.h |  47 ++++++++++++
 3 files changed, 234 insertions(+)
 create mode 100644 hw/s390x/ccw-pong.c
 create mode 100644 include/hw/s390x/pong.h
hw/s390x/Makefile.objs +0 -0
index ee91152..3a83438 100644

hw/s390x/Makefile.objs obj-$(CONFIG_KVM) += tod-kvm.o · line 35

Quoted 4 lines
hw/s390x/Makefile.objs +1 -0
@@ -32,6 +32,7 @@ obj-$(CONFIG_KVM) += tod-kvm.o
 obj-$(CONFIG_KVM) += s390-skeys-kvm.o
 obj-$(CONFIG_KVM) += s390-stattrib-kvm.o s390-mchk.o
 obj-y += s390-ccw.o
+obj-y += ccw-pong.o

Not sure if unconditionally introducing a test device is a good idea.

Quoted 78 lines
hw/s390x/Makefile.objs +0 -0
 obj-y += ap-device.o
 obj-y += ap-bridge.o
 obj-y += s390-sei.o
hw/s390x/ccw-pong.c new file +69 -0
new file mode 100644
index 0000000..e7439d5
@@ -0,0 +1,186 @@
+/*
+ * CCW PING-PONG
+ *
+ * Copyright 2019 IBM Corp.
+ * Author(s): Pierre Morel <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/module.h"
+#include "cpu.h"
+#include "exec/address-spaces.h"
+#include "hw/s390x/css.h"
+#include "hw/s390x/css-bridge.h"
+#include "hw/qdev-properties.h"
+#include "hw/s390x/pong.h"
+
+#define PONG_BUF_SIZE 0x1000
+static char buf[PONG_BUF_SIZE] = "Hello world\n";
+
+static inline int pong_rw(CCW1 *ccw, char *p, int len, bool dir)
+{
+    int ret;
+
+    ret = address_space_rw(&address_space_memory, ccw->cda,
+                           MEMTXATTRS_UNSPECIFIED,
+                           (unsigned char *)buf, len, dir);
+
+    return (ret == MEMTX_OK) ? -EIO : 0;
+}
+
+/* Handle READ ccw commands from guest */
+static int handle_payload_read(CcwPONGDevice *dev, CCW1 *ccw)
+{
+    CcwDevice *ccw_dev = CCW_DEVICE(dev);
+    int len;
+
+    if (!ccw->cda) {
+        return -EFAULT;
+    }
+
+    if (ccw->count > PONG_BUF_SIZE) {
+        len = PONG_BUF_SIZE;
+        ccw_dev->sch->curr_status.scsw.count = ccw->count - PONG_BUF_SIZE;
+    } else {
+        len = ccw->count;
+        ccw_dev->sch->curr_status.scsw.count = 0;
+    }
+
+    return pong_rw(ccw, buf, len, 1);
+}
+
+/*
+ * Handle WRITE ccw commands to write data to client
+ * The SCSW count is set to the number of bytes not transfered.
+ */
+static int handle_payload_write(CcwPONGDevice *dev, CCW1 *ccw)
+{
+    CcwDevice *ccw_dev = CCW_DEVICE(dev);
+    int len;
+
+    if (!ccw->cda) {
+        ccw_dev->sch->curr_status.scsw.count = ccw->count;
+        return -EFAULT;
+    }

hw/s390x/ccw-pong.c line 79

Quoted 10 lines
hw/s390x/ccw-pong.c new file +10 -0
+
+    if (ccw->count > PONG_BUF_SIZE) {
+        len = PONG_BUF_SIZE;
+        ccw_dev->sch->curr_status.scsw.count = ccw->count - PONG_BUF_SIZE;
+    } else {
+        len = ccw->count;
+        ccw_dev->sch->curr_status.scsw.count = 0;
+    }
+
+    return pong_rw(ccw, buf, len, 0);

Can you please use the dstream infrastructure for read/write handling?

You also seem to miss some basic checks e.g. for short reads/writes with and without SLI set.

Quoted 15 lines
hw/s390x/ccw-pong.c new file +15 -0
+}
+
+static int pong_ccw_cb(SubchDev *sch, CCW1 ccw)
+{
+    int rc = 0;
+    CcwPONGDevice *dev = sch->driver_data;
+
+    switch (ccw.cmd_code) {
+    case PONG_WRITE:
+        rc = handle_payload_write(dev, &ccw);
+        break;
+    case PONG_READ:
+        rc = handle_payload_read(dev, &ccw);
+        break;
+    default:

hw/s390x/ccw-pong.c line 104

Quoted 10 lines
hw/s390x/ccw-pong.c new file +10 -0
+        rc = -ENOSYS;
+        break;
+    }
+
+    if (rc == -EIO) {
+        /* I/O error, specific devices generate specific conditions */
+        SCHIB *schib = &sch->curr_status;
+
+        sch->curr_status.scsw.dstat = SCSW_DSTAT_UNIT_CHECK;
+        sch->sense_data[0] = 0x40;    /* intervention-req */

This is really odd. If it succeeds, you generate a unit check with intervention required? Confused. At the very least, this requires some description as to how this device is supposed to interact with the driver.

Quoted 56 lines
hw/s390x/ccw-pong.c new file +56 -0
+        schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND;
+        schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL;
+        schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
+                   SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
+    }
+    return rc;
+}
+
+static void pong_ccw_realize(DeviceState *ds, Error **errp)
+{
+    uint16_t chpid;
+    CcwPONGDevice *dev = CCW_PONG(ds);
+    CcwDevice *cdev = CCW_DEVICE(ds);
+    CCWDeviceClass *cdk = CCW_DEVICE_GET_CLASS(cdev);
+    SubchDev *sch;
+    Error *err = NULL;
+
+    sch = css_create_sch(cdev->devno, errp);
+    if (!sch) {
+        return;
+    }
+
+    sch->driver_data = dev;
+    cdev->sch = sch;
+    chpid = css_find_free_chpid(sch->cssid);
+
+    if (chpid > MAX_CHPID) {
+        error_setg(&err, "No available chpid to use.");
+        goto out_err;
+    }
+
+    sch->id.reserved = 0xff;
+    sch->id.cu_type = CCW_PONG_CU_TYPE;
+    css_sch_build_virtual_schib(sch, (uint8_t)chpid,
+                                CCW_PONG_CHPID_TYPE);
+    sch->do_subchannel_work = do_subchannel_work_virtual;
+    sch->ccw_cb = pong_ccw_cb;
+
+    cdk->realize(cdev, &err);
+    if (err) {
+        goto out_err;
+    }
+
+    css_reset_sch(sch);
+    return;
+
+out_err:
+    error_propagate(errp, err);
+    css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
+    cdev->sch = NULL;
+    g_free(sch);
+}
+
+static Property pong_ccw_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};

hw/s390x/ccw-pong.c line 170

Quoted 10 lines
hw/s390x/ccw-pong.c new file +10 -0
+
+static void pong_ccw_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->props = pong_ccw_properties;
+    dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
+    dc->realize = pong_ccw_realize;
+    dc->hotpluggable = false;
+    set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);

Huh? misc seems like a better idea for this :)

Quoted 6 lines
hw/s390x/ccw-pong.c new file +6 -0
+}
+
+static const TypeInfo pong_ccw_info = {
+    .name = TYPE_CCW_PONG,
+    .parent = TYPE_CCW_DEVICE,
+    .instance_size = sizeof(CcwPONGDevice),

hw/s390x/ccw-pong.c line 186

Quoted 10 lines
hw/s390x/ccw-pong.c new file +10 -0
+    .class_init = pong_ccw_class_init,
+    .class_size = sizeof(CcwPONGClass),
+};
+
+static void pong_ccw_register(void)
+{
+    type_register_static(&pong_ccw_info);
+}
+
+type_init(pong_ccw_register)

Some questions regarding this device and its intended usage:

- What are you trying to test? Basic ccw processing, or something more specific? Is there any way you can use the kvm-unit-test infrastructure to test basic processing with an existing device?
- Who is instantiating this device? Only the kvm-unit-test?
- Can you instantiate multiple instances? Does that make sense? If yes, it should probably not request a new chpid every time :)
- What happens if someone instantiates this by hand? The only drawback is that it uses up a subchannel and a chpid, right?
- Do you plan to make this hotpluggable later?

#2 lore raw
Quoted 21 lines · Cornelia Huck

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

Minor nit for $SUBJECT: this isn't a kvm-unit-tests patch, that's just one consumer :)

Quoted 15 lines

The PONG device accept two commands: PONG_READ and PONG_WRITE which allow to read from and write to an internal buffer of 1024 bytes.

The QEMU device is named ccw-pong.

---
 hw/s390x/Makefile.objs  |   1 +
 hw/s390x/ccw-pong.c     | 186 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/s390x/pong.h |  47 ++++++++++++
 3 files changed, 234 insertions(+)
 create mode 100644 hw/s390x/ccw-pong.c
 create mode 100644 include/hw/s390x/pong.h
Quoted 11 lines

hw/s390x/Makefile.objs obj-$(CONFIG_KVM) += tod-kvm.o · line 35

Quoted 9 lines
hw/s390x/Makefile.objs +1 -0
index ee91152..3a83438 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_KVM) += tod-kvm.o
 obj-$(CONFIG_KVM) += s390-skeys-kvm.o
 obj-$(CONFIG_KVM) += s390-stattrib-kvm.o s390-mchk.o
 obj-y += s390-ccw.o
+obj-y += ccw-pong.o

Not sure if unconditionally introducing a test device is a good idea.

This definitely needs a CONFIG switch (which can be "y" by default, but still we should provide a possibility to disable it)

Quoted 11 lines

hw/s390x/ccw-pong.c line 2

Quoted 11 lines
hw/s390x/Makefile.objs +0 -0
 obj-y += ap-device.o
 obj-y += ap-bridge.o
 obj-y += s390-sei.o
hw/s390x/ccw-pong.c new file +2 -0
new file mode 100644
index 0000000..e7439d5
@@ -0,0 +1,186 @@
+/*
+ * CCW PING-PONG

Please add a short description here what this device is all about.

Quoted 22 lines
Quoted 22 lines
hw/s390x/ccw-pong.c new file +22 -0
+ * Copyright 2019 IBM Corp.
+ * Author(s): Pierre Morel <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/module.h"
+#include "cpu.h"
+#include "exec/address-spaces.h"
+#include "hw/s390x/css.h"
+#include "hw/s390x/css-bridge.h"
+#include "hw/qdev-properties.h"
+#include "hw/s390x/pong.h"
+
+#define PONG_BUF_SIZE 0x1000
+static char buf[PONG_BUF_SIZE] = "Hello world\n";
+
+static inline int pong_rw(CCW1 *ccw, char *p, int len, bool dir)
Quoted 8 lines

hw/s390x/ccw-pong.c line 33

Quoted 8 lines
hw/s390x/ccw-pong.c new file +8 -0
+{
+    int ret;
+
+    ret = address_space_rw(&address_space_memory, ccw->cda,
+                           MEMTXATTRS_UNSPECIFIED,
+                           (unsigned char *)buf, len, dir);
+
+    return (ret == MEMTX_OK) ? -EIO : 0;

If return code was OK, then you return an EIO error? That looks weird?

Quoted 90 lines
Quoted 36 lines
hw/s390x/ccw-pong.c new file +36 -0
+}
+
+/* Handle READ ccw commands from guest */
+static int handle_payload_read(CcwPONGDevice *dev, CCW1 *ccw)
+{
+    CcwDevice *ccw_dev = CCW_DEVICE(dev);
+    int len;
+
+    if (!ccw->cda) {
+        return -EFAULT;
+    }
+
+    if (ccw->count > PONG_BUF_SIZE) {
+        len = PONG_BUF_SIZE;
+        ccw_dev->sch->curr_status.scsw.count = ccw->count - PONG_BUF_SIZE;
+    } else {
+        len = ccw->count;
+        ccw_dev->sch->curr_status.scsw.count = 0;
+    }
+
+    return pong_rw(ccw, buf, len, 1);
+}
+
+/*
+ * Handle WRITE ccw commands to write data to client
+ * The SCSW count is set to the number of bytes not transfered.
+ */
+static int handle_payload_write(CcwPONGDevice *dev, CCW1 *ccw)
+{
+    CcwDevice *ccw_dev = CCW_DEVICE(dev);
+    int len;
+
+    if (!ccw->cda) {
+        ccw_dev->sch->curr_status.scsw.count = ccw->count;
+        return -EFAULT;
+    }

hw/s390x/ccw-pong.c line 79

Quoted 10 lines
hw/s390x/ccw-pong.c new file +10 -0
+
+    if (ccw->count > PONG_BUF_SIZE) {
+        len = PONG_BUF_SIZE;
+        ccw_dev->sch->curr_status.scsw.count = ccw->count - PONG_BUF_SIZE;
+    } else {
+        len = ccw->count;
+        ccw_dev->sch->curr_status.scsw.count = 0;
+    }
+
+    return pong_rw(ccw, buf, len, 0);

Can you please use the dstream infrastructure for read/write handling?

You also seem to miss some basic checks e.g. for short reads/writes with and without SLI set.

Quoted 15 lines
hw/s390x/ccw-pong.c new file +15 -0
+}
+
+static int pong_ccw_cb(SubchDev *sch, CCW1 ccw)
+{
+    int rc = 0;
+    CcwPONGDevice *dev = sch->driver_data;
+
+    switch (ccw.cmd_code) {
+    case PONG_WRITE:
+        rc = handle_payload_write(dev, &ccw);
+        break;
+    case PONG_READ:
+        rc = handle_payload_read(dev, &ccw);
+        break;
+    default:

hw/s390x/ccw-pong.c line 104

Quoted 10 lines
hw/s390x/ccw-pong.c new file +10 -0
+        rc = -ENOSYS;
+        break;
+    }
+
+    if (rc == -EIO) {
+        /* I/O error, specific devices generate specific conditions */
+        SCHIB *schib = &sch->curr_status;
+
+        sch->curr_status.scsw.dstat = SCSW_DSTAT_UNIT_CHECK;
+        sch->sense_data[0] = 0x40;    /* intervention-req */

This is really odd. If it succeeds, you generate a unit check with intervention required? Confused. At the very least, this requires some description as to how this device is supposed to interact with the driver.

Quoted 7 lines
hw/s390x/ccw-pong.c new file +7 -0
+        schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND;
+        schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL;
+        schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
+                   SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
+    }
+    return rc;
+}

[...]

Quoted 10 lines

hw/s390x/ccw-pong.c line 166

Quoted 10 lines
hw/s390x/ccw-pong.c new file +10 -0
+
+static Property pong_ccw_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void pong_ccw_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->props = pong_ccw_properties;

As long as there are no properties, I think you can simply drop that line.

Thomas

#3 lore raw
Quoted 32 lines · Thomas Huth
Quoted 21 lines · Cornelia Huck

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

Minor nit for $SUBJECT: this isn't a kvm-unit-tests patch, that's just one consumer :)

Quoted 15 lines

The PONG device accept two commands: PONG_READ and PONG_WRITE which allow to read from and write to an internal buffer of 1024 bytes.

The QEMU device is named ccw-pong.

---
  hw/s390x/Makefile.objs  |   1 +
  hw/s390x/ccw-pong.c     | 186 ++++++++++++++++++++++++++++++++++++++++++++++++
  include/hw/s390x/pong.h |  47 ++++++++++++
  3 files changed, 234 insertions(+)

create mode 100644 hw/s390x/ccw-pong.c
create mode 100644 include/hw/s390x/pong.h

Quoted 10 lines

hw/s390x/Makefile.objs obj-$(CONFIG_KVM) += tod-kvm.o · line 35

Quoted 9 lines
hw/s390x/Makefile.objs +1 -0
index ee91152..3a83438 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_KVM) += tod-kvm.o
  obj-$(CONFIG_KVM) += s390-skeys-kvm.o
  obj-$(CONFIG_KVM) += s390-stattrib-kvm.o s390-mchk.o
  obj-y += s390-ccw.o
+obj-y += ccw-pong.o

Not sure if unconditionally introducing a test device is a good idea.

Quoted 2 lines

This definitely needs a CONFIG switch (which can be "y" by default, but still we should provide a possibility to disable it)

yes, clearly

Quoted 13 lines
Quoted 12 lines

hw/s390x/ccw-pong.c line 2

Quoted 12 lines
hw/s390x/Makefile.objs +0 -0
  obj-y += ap-device.o
  obj-y += ap-bridge.o
  obj-y += s390-sei.o
hw/s390x/ccw-pong.c new file +2 -0
new file mode 100644
index 0000000..e7439d5
@@ -0,0 +1,186 @@
+/*
+ * CCW PING-PONG

Please add a short description here what this device is all about.

yes

Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
hw/s390x/ccw-pong.c new file +23 -0
+ * Copyright 2019 IBM Corp.
+ * Author(s): Pierre Morel <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/module.h"
+#include "cpu.h"
+#include "exec/address-spaces.h"
+#include "hw/s390x/css.h"
+#include "hw/s390x/css-bridge.h"
+#include "hw/qdev-properties.h"
+#include "hw/s390x/pong.h"
+
+#define PONG_BUF_SIZE 0x1000
+static char buf[PONG_BUF_SIZE] = "Hello world\n";
+
+static inline int pong_rw(CCW1 *ccw, char *p, int len, bool dir)
+{
Quoted 8 lines
Quoted 7 lines

hw/s390x/ccw-pong.c line 33

Quoted 7 lines
hw/s390x/ccw-pong.c new file +7 -0
+    int ret;
+
+    ret = address_space_rw(&address_space_memory, ccw->cda,
+                           MEMTXATTRS_UNSPECIFIED,
+                           (unsigned char *)buf, len, dir);
+
+    return (ret == MEMTX_OK) ? -EIO : 0;

If return code was OK, then you return an EIO error? That looks weird?

Totally weird. it is of course the oposite.

This explain the comment from Connie on the unit check.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/s390x/ccw-pong.c new file +3 -0
+}
+
+/* Handle READ ccw commands from guest */

...snip...

Quoted 12 lines
Quoted 10 lines

hw/s390x/ccw-pong.c line 166

Quoted 10 lines
hw/s390x/ccw-pong.c new file +10 -0
+
+static Property pong_ccw_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void pong_ccw_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->props = pong_ccw_properties;

As long as there are no properties, I think you can simply drop that line.

Quoted 1 line

Thomas

Yes, right.

Thanks for the comments,

Regards,

Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#4 lore raw
Quoted 35 lines · Pierre Morel
Quoted 33 lines · Thomas Huth
Quoted 32 lines · Cornelia Huck

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

Minor nit for $SUBJECT: this isn't a kvm-unit-tests patch, that's just one consumer :)

Quoted 21 lines

The PONG device accept two commands: PONG_READ and PONG_WRITE which allow to read from and write to an internal buffer of 1024 bytes.

The QEMU device is named ccw-pong.

---
  hw/s390x/Makefile.objs  |   1 +
  hw/s390x/ccw-pong.c     | 186
++++++++++++++++++++++++++++++++++++++++++++++++
  include/hw/s390x/pong.h |  47 ++++++++++++

  3 files changed, 234 insertions(+)

  create mode 100644 hw/s390x/ccw-pong.c
  create mode 100644 include/hw/s390x/pong.h

hw/s390x/Makefile.objs +0 -0
index ee91152..3a83438 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_KVM) += tod-kvm.o
Quoted 4 lines

  obj-$(CONFIG_KVM) += s390-skeys-kvm.o obj-$(CONFIG_KVM) += s390-stattrib-kvm.o s390-mchk.o obj-y += s390-ccw.o
+obj-y += ccw-pong.o

Not sure if unconditionally introducing a test device is a good idea.

Quoted 4 lines
Quoted 2 lines

This definitely needs a CONFIG switch (which can be "y" by default, but still we should provide a possibility to disable it)

yes, clearly

I just noticed that we already have a global config switch for such devices, so you could simply do:

obj-$(CONFIG_TEST_DEVICE) += ccw-pong.o

Thomas

#5 lore raw
Quoted 37 lines · Thomas Huth
Quoted 36 lines · Pierre Morel
Quoted 35 lines · Thomas Huth
Quoted 22 lines · Cornelia Huck

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

Minor nit for $SUBJECT: this isn't a kvm-unit-tests patch, that's just one consumer :)

Quoted 16 lines

The PONG device accept two commands: PONG_READ and PONG_WRITE which allow to read from and write to an internal buffer of 1024 bytes.

The QEMU device is named ccw-pong.

---
   hw/s390x/Makefile.objs  |   1 +
   hw/s390x/ccw-pong.c     | 186
++++++++++++++++++++++++++++++++++++++++++++++++
   include/hw/s390x/pong.h |  47 ++++++++++++
   3 files changed, 234 insertions(+)

  create mode 100644 hw/s390x/ccw-pong.c
  create mode 100644 include/hw/s390x/pong.h

Quoted 10 lines

hw/s390x/Makefile.objs obj-$(CONFIG_KVM) += tod-kvm.o · line 35

Quoted 9 lines
hw/s390x/Makefile.objs +1 -0
index ee91152..3a83438 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_KVM) += tod-kvm.o
   obj-$(CONFIG_KVM) += s390-skeys-kvm.o
   obj-$(CONFIG_KVM) += s390-stattrib-kvm.o s390-mchk.o
   obj-y += s390-ccw.o
+obj-y += ccw-pong.o

Not sure if unconditionally introducing a test device is a good idea.

This definitely needs a CONFIG switch (which can be "y" by default, but still we should provide a possibility to disable it)

Quoted 7 lines
Quoted 1 line

yes, clearly

I just noticed that we already have a global config switch for such devices, so you could simply do:

obj-$(CONFIG_TEST_DEVICE) += ccw-pong.o

Thomas

Thanks, will do! :)

regards,

Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#6 lore raw
In reply to Cornelia Huck
Quoted 5 lines · On Thu, 14 Nov 2019 11:38:23 +0100 Cornelia Huck <[email protected]> wrote:

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

Minor nit for $SUBJECT: this isn't a kvm-unit-tests patch, that's just one consumer :)

And subchannel is one word in s390-speak.

Quoted 1 line

[..]

Quoted 5 lines

Some questions regarding this device and its intended usage:

- What are you trying to test? Basic ccw processing, or something more specific? Is there any way you can use the kvm-unit-test infrastructure to test basic processing with an existing device?

I'm also curious about the big picture (what is in scope and what out of scope). Your design should be evaluated in the light of intended usage.

BTW have you had a look at this abandoned patch-set of mine:

https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg04220.html

We made some different design decisions, while aiming essentially for the same. Maybe it's due to different scope, maybe not. For instance one can't test IDA with PONG, I guess.

Regards,
Halil

Quoted 8 lines

- Who is instantiating this device? Only the kvm-unit-test?
- Can you instantiate multiple instances? Does that make sense? If yes, it should probably not request a new chpid every time :)
- What happens if someone instantiates this by hand? The only drawback is that it uses up a subchannel and a chpid, right?
- Do you plan to make this hotpluggable later?

#7 lore raw
Quoted 21 lines · On Thu, 14 Nov 2019 14:02:35 +0100 Halil Pasic <[email protected]> wrote:
Quoted 5 lines · On Thu, 14 Nov 2019 11:38:23 +0100 Cornelia Huck <[email protected]> wrote:

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

Minor nit for $SUBJECT: this isn't a kvm-unit-tests patch, that's just one consumer :)

And subchannel is one word in s390-speak.

Quoted 1 line

[..]

Quoted 5 lines

Some questions regarding this device and its intended usage:

- What are you trying to test? Basic ccw processing, or something more specific? Is there any way you can use the kvm-unit-test infrastructure to test basic processing with an existing device?

Quoted 7 lines

I'm also curious about the big picture (what is in scope and what out of scope). Your design should be evaluated in the light of intended usage.

BTW have you had a look at this abandoned patch-set of mine:

https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg04220.html

Do you recall why it was abandoned? Or did we just forget to follow up on it?

Quoted 4 lines

We made some different design decisions, while aiming essentially for the same. Maybe it's due to different scope, maybe not. For instance one can't test IDA with PONG, I guess.

Now that I saw this again, I also recall the discussion of comparing it with the "testdev" for pci/isa. Anybody knows if these are used by kvm-unit-tests?

Quoted 13 lines

Regards,
Halil

Quoted 8 lines

- Who is instantiating this device? Only the kvm-unit-test?
- Can you instantiate multiple instances? Does that make sense? If yes, it should probably not request a new chpid every time :)
- What happens if someone instantiates this by hand? The only drawback is that it uses up a subchannel and a chpid, right?
- Do you plan to make this hotpluggable later?

#8 lore raw
Quoted 28 lines · On Thu, 14 Nov 2019 14:19:15 +0100 Cornelia Huck <[email protected]> wrote:
Quoted 25 lines · On Thu, 14 Nov 2019 14:02:35 +0100 Halil Pasic <[email protected]> wrote:
Quoted 5 lines · On Thu, 14 Nov 2019 11:38:23 +0100 Cornelia Huck <[email protected]> wrote:

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

Minor nit for $SUBJECT: this isn't a kvm-unit-tests patch, that's just one consumer :)

And subchannel is one word in s390-speak.

Quoted 1 line

[..]

Quoted 5 lines

Some questions regarding this device and its intended usage:

- What are you trying to test? Basic ccw processing, or something more specific? Is there any way you can use the kvm-unit-test infrastructure to test basic processing with an existing device?

I'm also curious about the big picture (what is in scope and what out of scope). Your design should be evaluated in the light of intended usage.

Quoted 7 lines
Quoted 3 lines

BTW have you had a look at this abandoned patch-set of mine:

https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg04220.html

Do you recall why it was abandoned? Or did we just forget to follow up on it?

I think I do remember. Priorities. Some colleagues were supposed to take over the job of making proper tests for this device -- the part that is now intended to be played by kvm-uni-tests. But they never got to actually start working on it. And my tests for IDA are just a kernel module -- i.e. nothing sustainable. So without proper exploitation, and with no time to do a proper test suite myself, I decided to not invest any more for the time beeing.

Quoted 9 lines
Quoted 4 lines

We made some different design decisions, while aiming essentially for the same. Maybe it's due to different scope, maybe not. For instance one can't test IDA with PONG, I guess.

Now that I saw this again, I also recall the discussion of comparing it with the "testdev" for pci/isa. Anybody knows if these are used by kvm-unit-tests?

I don't.

Regards,
Halil

Quoted 15 lines
Quoted 13 lines

Regards,
Halil

Quoted 8 lines

- Who is instantiating this device? Only the kvm-unit-test?
- Can you instantiate multiple instances? Does that make sense? If yes, it should probably not request a new chpid every time :)
- What happens if someone instantiates this by hand? The only drawback is that it uses up a subchannel and a chpid, right?
- Do you plan to make this hotpluggable later?

#9 lore raw
In reply to Cornelia Huck
Quoted 9 lines · Cornelia Huck
Quoted 6 lines · On Thu, 14 Nov 2019 14:02:35 +0100 Halil Pasic <[email protected]> wrote:
Quoted 3 lines · On Thu, 14 Nov 2019 11:38:23 +0100 Cornelia Huck <[email protected]> wrote:

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

...snip...

Quoted 6 lines
Quoted 3 lines

We made some different design decisions, while aiming essentially for the same. Maybe it's due to different scope, maybe not. For instance one can't test IDA with PONG, I guess.

Now that I saw this again, I also recall the discussion of comparing it with the "testdev" for pci/isa. Anybody knows if these are used by kvm-unit-tests?

Only by X.

Regards,

Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#10 lore raw
Quoted 11 lines · On Thu, 14 Nov 2019 18:42:35 +0100 Pierre Morel <[email protected]> wrote:
Quoted 9 lines · Cornelia Huck
Quoted 6 lines · On Thu, 14 Nov 2019 14:02:35 +0100 Halil Pasic <[email protected]> wrote:
Quoted 3 lines · On Thu, 14 Nov 2019 11:38:23 +0100 Cornelia Huck <[email protected]> wrote:

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

...snip...

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

We made some different design decisions, while aiming essentially for the same. Maybe it's due to different scope, maybe not. For instance one can't test IDA with PONG, I guess.

Now that I saw this again, I also recall the discussion of comparing it with the "testdev" for pci/isa. Anybody knows if these are used by kvm-unit-tests?

Only by X.

If they use it, it might make sense for s390 to use a comparable approach.

Btw, I created https://wiki.qemu.org/Testing/CCWTestDevice back then; might make sense to collect ideas there?

Quoted 6 lines

Regards,

Pierre

#11 lore raw
Quoted 17 lines · Cornelia Huck
Quoted 14 lines · On Thu, 14 Nov 2019 18:42:35 +0100 Pierre Morel <[email protected]> wrote:
Quoted 9 lines · Cornelia Huck
Quoted 6 lines · On Thu, 14 Nov 2019 14:02:35 +0100 Halil Pasic <[email protected]> wrote:
Quoted 3 lines · On Thu, 14 Nov 2019 11:38:23 +0100 Cornelia Huck <[email protected]> wrote:

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

...snip...

Quoted 3 lines
Quoted 3 lines

We made some different design decisions, while aiming essentially for the same. Maybe it's due to different scope, maybe not. For instance one can't test IDA with PONG, I guess.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Now that I saw this again, I also recall the discussion of comparing it with the "testdev" for pci/isa. Anybody knows if these are used by kvm-unit-tests?

Only by X.

If they use it, it might make sense for s390 to use a comparable approach.

yes it does.

Quoted 3 lines

Btw, I created https://wiki.qemu.org/Testing/CCWTestDevice back then; might make sense to collect ideas there?

right, I forgot this too.

OK, will use it :)

Regards,

Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#12 lore raw
In reply to Halil Pasic
Quoted 9 lines · Halil Pasic
Quoted 5 lines · On Thu, 14 Nov 2019 11:38:23 +0100 Cornelia Huck <[email protected]> wrote:

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

Minor nit for $SUBJECT: this isn't a kvm-unit-tests patch, that's just one consumer :)

And subchannel is one word in s390-speak.

OK, surely better for grep

Quoted 8 lines

[..]

Quoted 5 lines

Some questions regarding this device and its intended usage:

- What are you trying to test? Basic ccw processing, or something more specific? Is there any way you can use the kvm-unit-test infrastructure to test basic processing with an existing device?

Quoted 7 lines

I'm also curious about the big picture (what is in scope and what out of scope). Your design should be evaluated in the light of intended usage.

BTW have you had a look at this abandoned patch-set of mine:

https://lists.gnu.org/archive/html/qemu-devel/2017-11/msg04220.html

No, but now yes.

Yes, it is something similar, I can remember as you did it.

Quoted 4 lines

We made some different design decisions, while aiming essentially for the same. Maybe it's due to different scope, maybe not. For instance one can't test IDA with PONG, I guess.

No not now.

Regards,

Pierre

Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen
#13 lore raw
In reply to Cornelia Huck
Quoted 5 lines · Cornelia Huck

On Wed, 13 Nov 2019 20:02:33 +0100
Pierre Morel <[email protected]> wrote:

Minor nit for $SUBJECT: this isn't a kvm-unit-tests patch, that's just one consumer :)

yes, right.

Quoted 16 lines
Quoted 16 lines

The PONG device accept two commands: PONG_READ and PONG_WRITE which allow to read from and write to an internal buffer of 1024 bytes.

The QEMU device is named ccw-pong.

---
  hw/s390x/Makefile.objs  |   1 +
  hw/s390x/ccw-pong.c     | 186 ++++++++++++++++++++++++++++++++++++++++++++++++
  include/hw/s390x/pong.h |  47 ++++++++++++
  3 files changed, 234 insertions(+)

create mode 100644 hw/s390x/ccw-pong.c
create mode 100644 include/hw/s390x/pong.h

Quoted 10 lines

hw/s390x/Makefile.objs obj-$(CONFIG_KVM) += tod-kvm.o · line 35

Quoted 9 lines
hw/s390x/Makefile.objs +1 -0
index ee91152..3a83438 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_KVM) += tod-kvm.o
  obj-$(CONFIG_KVM) += s390-skeys-kvm.o
  obj-$(CONFIG_KVM) += s390-stattrib-kvm.o s390-mchk.o
  obj-y += s390-ccw.o
+obj-y += ccw-pong.o

Not sure if unconditionally introducing a test device is a good idea.

sure not.

Quoted 91 lines
Quoted 79 lines
hw/s390x/Makefile.objs +0 -0
  obj-y += ap-device.o
  obj-y += ap-bridge.o
  obj-y += s390-sei.o
hw/s390x/ccw-pong.c new file +69 -0
new file mode 100644
index 0000000..e7439d5
@@ -0,0 +1,186 @@
+/*
+ * CCW PING-PONG
+ *
+ * Copyright 2019 IBM Corp.
+ * Author(s): Pierre Morel <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/module.h"
+#include "cpu.h"
+#include "exec/address-spaces.h"
+#include "hw/s390x/css.h"
+#include "hw/s390x/css-bridge.h"
+#include "hw/qdev-properties.h"
+#include "hw/s390x/pong.h"
+
+#define PONG_BUF_SIZE 0x1000
+static char buf[PONG_BUF_SIZE] = "Hello world\n";
+
+static inline int pong_rw(CCW1 *ccw, char *p, int len, bool dir)
+{
+    int ret;
+
+    ret = address_space_rw(&address_space_memory, ccw->cda,
+                           MEMTXATTRS_UNSPECIFIED,
+                           (unsigned char *)buf, len, dir);
+
+    return (ret == MEMTX_OK) ? -EIO : 0;
+}
+
+/* Handle READ ccw commands from guest */
+static int handle_payload_read(CcwPONGDevice *dev, CCW1 *ccw)
+{
+    CcwDevice *ccw_dev = CCW_DEVICE(dev);
+    int len;
+
+    if (!ccw->cda) {
+        return -EFAULT;
+    }
+
+    if (ccw->count > PONG_BUF_SIZE) {
+        len = PONG_BUF_SIZE;
+        ccw_dev->sch->curr_status.scsw.count = ccw->count - PONG_BUF_SIZE;
+    } else {
+        len = ccw->count;
+        ccw_dev->sch->curr_status.scsw.count = 0;
+    }
+
+    return pong_rw(ccw, buf, len, 1);
+}
+
+/*
+ * Handle WRITE ccw commands to write data to client
+ * The SCSW count is set to the number of bytes not transfered.
+ */
+static int handle_payload_write(CcwPONGDevice *dev, CCW1 *ccw)
+{
+    CcwDevice *ccw_dev = CCW_DEVICE(dev);
+    int len;
+
+    if (!ccw->cda) {
+        ccw_dev->sch->curr_status.scsw.count = ccw->count;
+        return -EFAULT;
+    }

hw/s390x/ccw-pong.c line 79

Quoted 10 lines
hw/s390x/ccw-pong.c new file +10 -0
+
+    if (ccw->count > PONG_BUF_SIZE) {
+        len = PONG_BUF_SIZE;
+        ccw_dev->sch->curr_status.scsw.count = ccw->count - PONG_BUF_SIZE;
+    } else {
+        len = ccw->count;
+        ccw_dev->sch->curr_status.scsw.count = 0;
+    }
+
+    return pong_rw(ccw, buf, len, 0);

Can you please use the dstream infrastructure for read/write handling?

Quoted 2 lines

You also seem to miss some basic checks e.g. for short reads/writes with and without SLI set.

OK,

Quoted 22 lines
Quoted 22 lines
hw/s390x/ccw-pong.c new file +21 -0
+}
+
+static int pong_ccw_cb(SubchDev *sch, CCW1 ccw)
+{
+    int rc = 0;
+    CcwPONGDevice *dev = sch->driver_data;
+
+    switch (ccw.cmd_code) {
+    case PONG_WRITE:
+        rc = handle_payload_write(dev, &ccw);
+        break;
+    case PONG_READ:
+        rc = handle_payload_read(dev, &ccw);
+        break;
+    default:
+        rc = -ENOSYS;
+        break;
+    }
+
+    if (rc == -EIO) {
+        /* I/O error, specific devices generate specific conditions */
Quoted 8 lines

hw/s390x/ccw-pong.c line 104

Quoted 4 lines
hw/s390x/ccw-pong.c new file +4 -0
+        SCHIB *schib = &sch->curr_status;
+
+        sch->curr_status.scsw.dstat = SCSW_DSTAT_UNIT_CHECK;
+        sch->sense_data[0] = 0x40;    /* intervention-req */

This is really odd. If it succeeds, you generate a unit check with intervention required? Confused. At the very least, this requires some description as to how this device is supposed to interact with the driver.

The unit check is only done in case of I/O error.

I thought it was right, since it should never happen.

Yes it needs some documentation.

Quoted 60 lines
Quoted 60 lines
hw/s390x/ccw-pong.c new file +59 -0
+        schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND;
+        schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL;
+        schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
+                   SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
+    }
+    return rc;
+}
+
+static void pong_ccw_realize(DeviceState *ds, Error **errp)
+{
+    uint16_t chpid;
+    CcwPONGDevice *dev = CCW_PONG(ds);
+    CcwDevice *cdev = CCW_DEVICE(ds);
+    CCWDeviceClass *cdk = CCW_DEVICE_GET_CLASS(cdev);
+    SubchDev *sch;
+    Error *err = NULL;
+
+    sch = css_create_sch(cdev->devno, errp);
+    if (!sch) {
+        return;
+    }
+
+    sch->driver_data = dev;
+    cdev->sch = sch;
+    chpid = css_find_free_chpid(sch->cssid);
+
+    if (chpid > MAX_CHPID) {
+        error_setg(&err, "No available chpid to use.");
+        goto out_err;
+    }
+
+    sch->id.reserved = 0xff;
+    sch->id.cu_type = CCW_PONG_CU_TYPE;
+    css_sch_build_virtual_schib(sch, (uint8_t)chpid,
+                                CCW_PONG_CHPID_TYPE);
+    sch->do_subchannel_work = do_subchannel_work_virtual;
+    sch->ccw_cb = pong_ccw_cb;
+
+    cdk->realize(cdev, &err);
+    if (err) {
+        goto out_err;
+    }
+
+    css_reset_sch(sch);
+    return;
+
+out_err:
+    error_propagate(errp, err);
+    css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
+    cdev->sch = NULL;
+    g_free(sch);
+}
+
+static Property pong_ccw_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void pong_ccw_class_init(ObjectClass *klass, void *data)
+{
Quoted 8 lines

hw/s390x/ccw-pong.c line 170

Quoted 7 lines
hw/s390x/ccw-pong.c new file +7 -0
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->props = pong_ccw_properties;
+    dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
+    dc->realize = pong_ccw_realize;
+    dc->hotpluggable = false;
+    set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories);

Huh? misc seems like a better idea for this :)

Sure.

Quoted 19 lines
Quoted 7 lines
hw/s390x/ccw-pong.c new file +6 -0
+}
+
+static const TypeInfo pong_ccw_info = {
+    .name = TYPE_CCW_PONG,
+    .parent = TYPE_CCW_DEVICE,
+    .instance_size = sizeof(CcwPONGDevice),

hw/s390x/ccw-pong.c line 186

Quoted 10 lines
hw/s390x/ccw-pong.c new file +10 -0
+    .class_init = pong_ccw_class_init,
+    .class_size = sizeof(CcwPONGClass),
+};
+
+static void pong_ccw_register(void)
+{
+    type_register_static(&pong_ccw_info);
+}
+
+type_init(pong_ccw_register)

Some questions regarding this device and its intended usage:

Quoted 2 lines

- What are you trying to test? Basic ccw processing, or something more specific?

The original purpose is to serve as a device for the kv-unit-test development.

Testing the QEMU CCW from inside Secure Execution (next step).

Quoted 2 lines

Is there any way you can use the kvm-unit-test
infrastructure to test basic processing with an existing device?

At first we will use it inside SE so that real devices will not be the purpose.

The goal of the css test in the kvm-unit-test development for SE is to test I/O through VIRTIO-CCW

Quoted 1 line

- Who is instantiating this device? Only the kvm-unit-test?

yes.

Quoted 1 line

- Can you instantiate multiple instances?

Not yet

Quoted 1 line

Does that make sense?

Probably not

Quoted 2 lines

If yes,
it should probably not request a new chpid every time :)

Yes, the development was quick.

Quoted 1 line

- What happens if someone instantiates this by hand?

this needs some work.

Quoted 2 lines

The only drawback
is that it uses up a subchannel and a chpid, right?

The development was very quick, I re-used something I developped 4 years ago.

It definitively needs more thinking.

Quoted 1 line

- Do you plan to make this hotpluggable later?

No, unless there is a good reason to.

Thanks a lot for the comments.

Regards,

Pierre

Quoted 2 lines
Signature · 2 lines
Pierre Morel
IBM Lab Boeblingen