All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC v2 00/12] basic channel IO passthrough infrastructure based on vfio
@ 2017-01-12  7:25 ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

The patch series introduce a basic channel I/O passthrough
infrastructure based on vfio.
- Focus on supporting dasd-eckd(cu_type/dev_type = 0x3990/0x3390) as
  the target device. 
- Support new qemu parameters in the style of:
   "-machine s390-ccw-virtio(,s390-map-css=on|off) ... 
    -device vfio-ccw,id=xx,hostid=xx(,guestid=xx),mdevid=xx".
  We want to support real (i.e. not virtual) channel devices even for
  guests that do not support MCSS-E (where guests may see devices from
  any channel subsystem image at once). As all virtio-ccw devices are in
  css 0xfe (and show up in the default css 0 for guests not activating
  MCSS-E), we need an option to map e.g. passed-through channel devices
  from their real css (0-3, or 0 for hosts not activating MCSS-E) into
  the default css, that is what the new machine option s390-map-css is
  added.

Build and install:
1. kernel configuration
  CONFIG_S390_CCW_IOMMU=m
  CONFIG_VFIO=m
  CONFIG_VFIO_MDEV=m
  CONFIG_VFIO_MDEV_DEVICE=m
  CONFIG_VFIO_CCW=m
2. modules required
  modprobe vfio.ko
  modprobe mdev.ko
  modprobe vfio_mdev.ko
  modprobe vfio_iommu_type1.ko
  modprobe vfio_ccw.ko
3. find a subchannel(0.0."%schid") of a DASD-ECKD device and bind it to
  vfio_ccw driver
  #find the dasd you can use with lsdasd on your host. e.g.:
  devno="7e52"
  schid="16ca"
  #unbind the ccw device from the subchannel
  echo 0.0."$devno" > /sys/bus/ccw/devices/0.0."$devno"/driver/unbind
  #unbind the subchannel from io_subchannel driver
  echo 0.0."$schid" > /sys/bus/css/devices/0.0."$schid"/driver/unbind
  #bind the subchannel with vfio_ccw driver
  echo 0.0."$schid" > /sys/bus/css/drivers/vfio_ccw/bind
4. create a mediated device
  #generate a uuid with uuidgen. e.g.:
  uuid="6dfd3ec5-e8b3-4e18-a6fe-57bc9eceb920"
  echo "$uuid" > \
  /sys/bus/css/devices/0.0."$schid"/mdev_supported_types/vfio_ccw-io/create
5. pass-through this device to a vm
  -M s390-ccw-virtio,s390-map-css=on \
  -device vfio-ccw,id=pass0, \
          hostid=0.0."$schid",guestid=0.0.1234, \
          mdevid="$uuid" \
  ... ...

Change log:

v1 -> v2:
1. Rebase the implementation to the mdev framework approach.
2. Use pread and pwrite on an I/O region to issue I/O requests and
   receive results.

Dong Jia Shi (4):
  update-linux-headers: add asm-s390/vfio_ccw.h
  s390x/css: realize css_create_sch
  vfio/ccw: get io region info
  vfio/ccw: update sense data if a unit check is pending

Xiao Feng Ren (8):
  vfio: linux-headers update for vfio-ccw
  s390x/css: add s390-map-css machine option
  s390x/css: realize css_sch_build_schib
  s390x/css: device support for s390-ccw passthrough
  vfio/ccw: vfio based subchannel passthrough driver
  vfio/ccw: get irqs info and set the eventfd fd
  s390x/css: introduce and realize ccw-request callback
  s390x/css: ccws translation infrastructure

 default-configs/s390x-softmmu.mak            |   1 +
 hw/s390x/Makefile.objs                       |   1 +
 hw/s390x/css-bridge.c                        |   3 +
 hw/s390x/css.c                               | 283 ++++++++++++++++-
 hw/s390x/s390-ccw.c                          | 132 ++++++++
 hw/s390x/s390-ccw.h                          |  39 +++
 hw/s390x/s390-virtio-ccw.c                   |  23 ++
 hw/s390x/virtio-ccw.c                        |   1 +
 hw/vfio/Makefile.objs                        |   1 +
 hw/vfio/ccw.c                                | 443 +++++++++++++++++++++++++++
 include/hw/s390x/css-bridge.h                |   1 +
 include/hw/s390x/css.h                       |  57 +++-
 include/hw/s390x/s390-virtio-ccw.h           |   1 +
 include/hw/vfio/vfio-common.h                |   1 +
 include/standard-headers/asm-s390/vfio_ccw.h |  28 ++
 linux-headers/linux/vfio.h                   |  17 +
 qemu-options.hx                              |   6 +-
 scripts/update-linux-headers.sh              |   1 +
 target-s390x/cpu.h                           |  10 +
 target-s390x/ioinst.c                        |   9 +
 20 files changed, 1029 insertions(+), 29 deletions(-)
 create mode 100644 hw/s390x/s390-ccw.c
 create mode 100644 hw/s390x/s390-ccw.h
 create mode 100644 hw/vfio/ccw.c
 create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h

-- 
2.8.4

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 00/12] basic channel IO passthrough infrastructure based on vfio
@ 2017-01-12  7:25 ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

The patch series introduce a basic channel I/O passthrough
infrastructure based on vfio.
- Focus on supporting dasd-eckd(cu_type/dev_type = 0x3990/0x3390) as
  the target device. 
- Support new qemu parameters in the style of:
   "-machine s390-ccw-virtio(,s390-map-css=on|off) ... 
    -device vfio-ccw,id=xx,hostid=xx(,guestid=xx),mdevid=xx".
  We want to support real (i.e. not virtual) channel devices even for
  guests that do not support MCSS-E (where guests may see devices from
  any channel subsystem image at once). As all virtio-ccw devices are in
  css 0xfe (and show up in the default css 0 for guests not activating
  MCSS-E), we need an option to map e.g. passed-through channel devices
  from their real css (0-3, or 0 for hosts not activating MCSS-E) into
  the default css, that is what the new machine option s390-map-css is
  added.

Build and install:
1. kernel configuration
  CONFIG_S390_CCW_IOMMU=m
  CONFIG_VFIO=m
  CONFIG_VFIO_MDEV=m
  CONFIG_VFIO_MDEV_DEVICE=m
  CONFIG_VFIO_CCW=m
2. modules required
  modprobe vfio.ko
  modprobe mdev.ko
  modprobe vfio_mdev.ko
  modprobe vfio_iommu_type1.ko
  modprobe vfio_ccw.ko
3. find a subchannel(0.0."%schid") of a DASD-ECKD device and bind it to
  vfio_ccw driver
  #find the dasd you can use with lsdasd on your host. e.g.:
  devno="7e52"
  schid="16ca"
  #unbind the ccw device from the subchannel
  echo 0.0."$devno" > /sys/bus/ccw/devices/0.0."$devno"/driver/unbind
  #unbind the subchannel from io_subchannel driver
  echo 0.0."$schid" > /sys/bus/css/devices/0.0."$schid"/driver/unbind
  #bind the subchannel with vfio_ccw driver
  echo 0.0."$schid" > /sys/bus/css/drivers/vfio_ccw/bind
4. create a mediated device
  #generate a uuid with uuidgen. e.g.:
  uuid="6dfd3ec5-e8b3-4e18-a6fe-57bc9eceb920"
  echo "$uuid" > \
  /sys/bus/css/devices/0.0."$schid"/mdev_supported_types/vfio_ccw-io/create
5. pass-through this device to a vm
  -M s390-ccw-virtio,s390-map-css=on \
  -device vfio-ccw,id=pass0, \
          hostid=0.0."$schid",guestid=0.0.1234, \
          mdevid="$uuid" \
  ... ...

Change log:

v1 -> v2:
1. Rebase the implementation to the mdev framework approach.
2. Use pread and pwrite on an I/O region to issue I/O requests and
   receive results.

Dong Jia Shi (4):
  update-linux-headers: add asm-s390/vfio_ccw.h
  s390x/css: realize css_create_sch
  vfio/ccw: get io region info
  vfio/ccw: update sense data if a unit check is pending

Xiao Feng Ren (8):
  vfio: linux-headers update for vfio-ccw
  s390x/css: add s390-map-css machine option
  s390x/css: realize css_sch_build_schib
  s390x/css: device support for s390-ccw passthrough
  vfio/ccw: vfio based subchannel passthrough driver
  vfio/ccw: get irqs info and set the eventfd fd
  s390x/css: introduce and realize ccw-request callback
  s390x/css: ccws translation infrastructure

 default-configs/s390x-softmmu.mak            |   1 +
 hw/s390x/Makefile.objs                       |   1 +
 hw/s390x/css-bridge.c                        |   3 +
 hw/s390x/css.c                               | 283 ++++++++++++++++-
 hw/s390x/s390-ccw.c                          | 132 ++++++++
 hw/s390x/s390-ccw.h                          |  39 +++
 hw/s390x/s390-virtio-ccw.c                   |  23 ++
 hw/s390x/virtio-ccw.c                        |   1 +
 hw/vfio/Makefile.objs                        |   1 +
 hw/vfio/ccw.c                                | 443 +++++++++++++++++++++++++++
 include/hw/s390x/css-bridge.h                |   1 +
 include/hw/s390x/css.h                       |  57 +++-
 include/hw/s390x/s390-virtio-ccw.h           |   1 +
 include/hw/vfio/vfio-common.h                |   1 +
 include/standard-headers/asm-s390/vfio_ccw.h |  28 ++
 linux-headers/linux/vfio.h                   |  17 +
 qemu-options.hx                              |   6 +-
 scripts/update-linux-headers.sh              |   1 +
 target-s390x/cpu.h                           |  10 +
 target-s390x/ioinst.c                        |   9 +
 20 files changed, 1029 insertions(+), 29 deletions(-)
 create mode 100644 hw/s390x/s390-ccw.c
 create mode 100644 hw/s390x/s390-ccw.h
 create mode 100644 hw/vfio/ccw.c
 create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h

-- 
2.8.4

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 01/12] update-linux-headers: add asm-s390/vfio_ccw.h
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

Add asm-s390/vfio_ccw.h as a new standard header.

Signed-off-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
---
 scripts/update-linux-headers.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index 08c4c4a..67320be 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -91,6 +91,7 @@ for arch in $ARCHLIST; do
     if [ $arch = s390 ]; then
         cp_portable "$tmpdir/include/asm/kvm_virtio.h" "$output/include/standard-headers/asm-s390/"
         cp_portable "$tmpdir/include/asm/virtio-ccw.h" "$output/include/standard-headers/asm-s390/"
+        cp_portable "$tmpdir/include/asm/vfio_ccw.h" "$output/include/standard-headers/asm-s390/"
     fi
     if [ $arch = x86 ]; then
         cp_portable "$tmpdir/include/asm/hyperv.h" "$output/include/standard-headers/asm-x86/"
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 01/12] update-linux-headers: add asm-s390/vfio_ccw.h
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

Add asm-s390/vfio_ccw.h as a new standard header.

Signed-off-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
---
 scripts/update-linux-headers.sh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh
index 08c4c4a..67320be 100755
--- a/scripts/update-linux-headers.sh
+++ b/scripts/update-linux-headers.sh
@@ -91,6 +91,7 @@ for arch in $ARCHLIST; do
     if [ $arch = s390 ]; then
         cp_portable "$tmpdir/include/asm/kvm_virtio.h" "$output/include/standard-headers/asm-s390/"
         cp_portable "$tmpdir/include/asm/virtio-ccw.h" "$output/include/standard-headers/asm-s390/"
+        cp_portable "$tmpdir/include/asm/vfio_ccw.h" "$output/include/standard-headers/asm-s390/"
     fi
     if [ $arch = x86 ]; then
         cp_portable "$tmpdir/include/asm/hyperv.h" "$output/include/standard-headers/asm-x86/"
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

This is a placeholder for a linux-headers update.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
 linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h

diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
new file mode 100644
index 0000000..cddc09b
--- /dev/null
+++ b/include/standard-headers/asm-s390/vfio_ccw.h
@@ -0,0 +1,28 @@
+/*
+ * Interfaces for vfio-ccw
+ *
+ * Copyright IBM Corp. 2017
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
+ */
+
+#ifndef _VFIO_CCW_H_
+#define _VFIO_CCW_H_
+
+#include "standard-headers/linux/types.h"
+
+struct ccw_io_region {
+#define ORB_AREA_SIZE 12
+	uint8_t  orb_area[ORB_AREA_SIZE];
+#define SCSW_AREA_SIZE 12
+	uint8_t  scsw_area[SCSW_AREA_SIZE];
+#define IRB_AREA_SIZE 96
+	uint8_t  irb_area[IRB_AREA_SIZE];
+	uint32_t ret_code;
+} QEMU_PACKED;
+
+#endif
diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
index 759b850..b09d247 100644
--- a/linux-headers/linux/vfio.h
+++ b/linux-headers/linux/vfio.h
@@ -198,6 +198,7 @@ struct vfio_device_info {
 #define VFIO_DEVICE_FLAGS_PCI	(1 << 1)	/* vfio-pci device */
 #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2)	/* vfio-platform device */
 #define VFIO_DEVICE_FLAGS_AMBA  (1 << 3)	/* vfio-amba device */
+#define VFIO_DEVICE_FLAGS_CCW   (1 << 4)	/* vfio-ccw device */
 	__u32	num_regions;	/* Max region index + 1 */
 	__u32	num_irqs;	/* Max IRQ index + 1 */
 };
@@ -436,6 +437,22 @@ enum {
 	VFIO_PCI_NUM_IRQS
 };
 
+/*
+ * The VFIO-CCW bus driver makes use of the following fixed region and
+ * IRQ index mapping.  Unimplemented regions return a size of zero.
+ * Unimplemented IRQ types return a count of zero.
+ */
+
+enum {
+        VFIO_CCW_CONFIG_REGION_INDEX,
+        VFIO_CCW_NUM_REGIONS
+};
+
+enum {
+        VFIO_CCW_IO_IRQ_INDEX,
+        VFIO_CCW_NUM_IRQS
+};
+
 /**
  * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IORW(VFIO_TYPE, VFIO_BASE + 12,
  *					      struct vfio_pci_hot_reset_info)
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

This is a placeholder for a linux-headers update.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
 linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h

diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
new file mode 100644
index 0000000..cddc09b
--- /dev/null
+++ b/include/standard-headers/asm-s390/vfio_ccw.h
@@ -0,0 +1,28 @@
+/*
+ * Interfaces for vfio-ccw
+ *
+ * Copyright IBM Corp. 2017
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License (version 2 only)
+ * as published by the Free Software Foundation.
+ *
+ * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
+ */
+
+#ifndef _VFIO_CCW_H_
+#define _VFIO_CCW_H_
+
+#include "standard-headers/linux/types.h"
+
+struct ccw_io_region {
+#define ORB_AREA_SIZE 12
+	uint8_t  orb_area[ORB_AREA_SIZE];
+#define SCSW_AREA_SIZE 12
+	uint8_t  scsw_area[SCSW_AREA_SIZE];
+#define IRB_AREA_SIZE 96
+	uint8_t  irb_area[IRB_AREA_SIZE];
+	uint32_t ret_code;
+} QEMU_PACKED;
+
+#endif
diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
index 759b850..b09d247 100644
--- a/linux-headers/linux/vfio.h
+++ b/linux-headers/linux/vfio.h
@@ -198,6 +198,7 @@ struct vfio_device_info {
 #define VFIO_DEVICE_FLAGS_PCI	(1 << 1)	/* vfio-pci device */
 #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2)	/* vfio-platform device */
 #define VFIO_DEVICE_FLAGS_AMBA  (1 << 3)	/* vfio-amba device */
+#define VFIO_DEVICE_FLAGS_CCW   (1 << 4)	/* vfio-ccw device */
 	__u32	num_regions;	/* Max region index + 1 */
 	__u32	num_irqs;	/* Max IRQ index + 1 */
 };
@@ -436,6 +437,22 @@ enum {
 	VFIO_PCI_NUM_IRQS
 };
 
+/*
+ * The VFIO-CCW bus driver makes use of the following fixed region and
+ * IRQ index mapping.  Unimplemented regions return a size of zero.
+ * Unimplemented IRQ types return a count of zero.
+ */
+
+enum {
+        VFIO_CCW_CONFIG_REGION_INDEX,
+        VFIO_CCW_NUM_REGIONS
+};
+
+enum {
+        VFIO_CCW_IO_IRQ_INDEX,
+        VFIO_CCW_NUM_IRQS
+};
+
 /**
  * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IORW(VFIO_TYPE, VFIO_BASE + 12,
  *					      struct vfio_pci_hot_reset_info)
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 03/12] s390x/css: add s390-map-css machine option
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

We want to support real (i.e. not virtual) channel devices
even for guests that do not support MCSS-E (where guests may
see devices from any channel subsystem image at once). As all
virtio-ccw devices are in css 0xfe (and show up in the default
css 0 for guests not activating MCSS-E), we need an option to
map e.g. passed-through subchannels from their real css (0-3,
or 0 for hosts not activating MCSS-E) into the default css.
This will be exploited in a later patch.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/s390x/s390-virtio-ccw.c         | 23 +++++++++++++++++++++++
 include/hw/s390x/s390-virtio-ccw.h |  1 +
 qemu-options.hx                    |  6 +++++-
 target-s390x/cpu.h                 | 10 ++++++++++
 4 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index e340eab..4e8ffda 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -272,6 +272,21 @@ bool cpu_model_allowed(void)
     return true;
 }
 
+static inline bool machine_get_map_css(Object *obj, Error **errp)
+{
+    S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
+
+    return ms->s390_map_css;
+}
+
+static inline void machine_set_map_css(Object *obj, bool value,
+                                       Error **errp)
+{
+    S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
+
+    ms->s390_map_css = value;
+}
+
 static inline void s390_machine_initfn(Object *obj)
 {
     object_property_add_bool(obj, "aes-key-wrap",
@@ -289,6 +304,14 @@ static inline void s390_machine_initfn(Object *obj)
             "enable/disable DEA key wrapping using the CPACF wrapping key",
             NULL);
     object_property_set_bool(obj, true, "dea-key-wrap", NULL);
+
+    object_property_add_bool(obj, "s390-map-css",
+                             machine_get_map_css,
+                             machine_set_map_css, NULL);
+    object_property_set_description(obj, "s390-map-css",
+            "enable/disable mapping passed-through subchannels into the "
+            "virtual css", NULL);
+    object_property_set_bool(obj, false, "s390-map-css", NULL);
 }
 
 static const TypeInfo ccw_machine_info = {
diff --git a/include/hw/s390x/s390-virtio-ccw.h b/include/hw/s390x/s390-virtio-ccw.h
index 6ecae00..bbc1d21 100644
--- a/include/hw/s390x/s390-virtio-ccw.h
+++ b/include/hw/s390x/s390-virtio-ccw.h
@@ -28,6 +28,7 @@ typedef struct S390CcwMachineState {
     /*< public >*/
     bool aes_key_wrap;
     bool dea_key_wrap;
+    bool s390_map_css;
 } S390CcwMachineState;
 
 typedef struct S390CcwMachineClass {
diff --git a/qemu-options.hx b/qemu-options.hx
index c534a2f..293783c 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -43,7 +43,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n"
     "                suppress-vmdesc=on|off disables self-describing migration (default=off)\n"
     "                nvdimm=on|off controls NVDIMM support (default=off)\n"
-    "                enforce-config-section=on|off enforce configuration section migration (default=off)\n",
+    "                enforce-config-section=on|off enforce configuration section migration (default=off)\n"
+    "                s390-map-css=on|off controls support for mapping into virtual css (default=off)\n",
     QEMU_ARCH_ALL)
 STEXI
 @item -machine [type=]@var{name}[,prop=@var{value}[,...]]
@@ -82,6 +83,9 @@ controls whether DEA wrapping keys will be created to allow
 execution of DEA cryptographic functions.  The default is on.
 @item nvdimm=on|off
 Enables or disables NVDIMM support. The default is off.
+@item s390-map-css=on|off
+Enables or disables mapping passed-through subchannels into the virtual css.
+The default is off.
 @end table
 ETEXI
 
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index fd36a25..85d705d 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -1249,6 +1249,16 @@ static inline void s390_crypto_reset(void)
     }
 }
 
+static inline bool s390_get_map_css(void)
+{
+    if (object_property_get_bool(OBJECT(qdev_get_machine()), "s390-map-css",
+                                 NULL)) {
+        return true;
+    }
+
+    return false;
+}
+
 /* machine check interruption code */
 
 /* subclasses */
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 03/12] s390x/css: add s390-map-css machine option
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

We want to support real (i.e. not virtual) channel devices
even for guests that do not support MCSS-E (where guests may
see devices from any channel subsystem image at once). As all
virtio-ccw devices are in css 0xfe (and show up in the default
css 0 for guests not activating MCSS-E), we need an option to
map e.g. passed-through subchannels from their real css (0-3,
or 0 for hosts not activating MCSS-E) into the default css.
This will be exploited in a later patch.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/s390x/s390-virtio-ccw.c         | 23 +++++++++++++++++++++++
 include/hw/s390x/s390-virtio-ccw.h |  1 +
 qemu-options.hx                    |  6 +++++-
 target-s390x/cpu.h                 | 10 ++++++++++
 4 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index e340eab..4e8ffda 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -272,6 +272,21 @@ bool cpu_model_allowed(void)
     return true;
 }
 
+static inline bool machine_get_map_css(Object *obj, Error **errp)
+{
+    S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
+
+    return ms->s390_map_css;
+}
+
+static inline void machine_set_map_css(Object *obj, bool value,
+                                       Error **errp)
+{
+    S390CcwMachineState *ms = S390_CCW_MACHINE(obj);
+
+    ms->s390_map_css = value;
+}
+
 static inline void s390_machine_initfn(Object *obj)
 {
     object_property_add_bool(obj, "aes-key-wrap",
@@ -289,6 +304,14 @@ static inline void s390_machine_initfn(Object *obj)
             "enable/disable DEA key wrapping using the CPACF wrapping key",
             NULL);
     object_property_set_bool(obj, true, "dea-key-wrap", NULL);
+
+    object_property_add_bool(obj, "s390-map-css",
+                             machine_get_map_css,
+                             machine_set_map_css, NULL);
+    object_property_set_description(obj, "s390-map-css",
+            "enable/disable mapping passed-through subchannels into the "
+            "virtual css", NULL);
+    object_property_set_bool(obj, false, "s390-map-css", NULL);
 }
 
 static const TypeInfo ccw_machine_info = {
diff --git a/include/hw/s390x/s390-virtio-ccw.h b/include/hw/s390x/s390-virtio-ccw.h
index 6ecae00..bbc1d21 100644
--- a/include/hw/s390x/s390-virtio-ccw.h
+++ b/include/hw/s390x/s390-virtio-ccw.h
@@ -28,6 +28,7 @@ typedef struct S390CcwMachineState {
     /*< public >*/
     bool aes_key_wrap;
     bool dea_key_wrap;
+    bool s390_map_css;
 } S390CcwMachineState;
 
 typedef struct S390CcwMachineClass {
diff --git a/qemu-options.hx b/qemu-options.hx
index c534a2f..293783c 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -43,7 +43,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n"
     "                suppress-vmdesc=on|off disables self-describing migration (default=off)\n"
     "                nvdimm=on|off controls NVDIMM support (default=off)\n"
-    "                enforce-config-section=on|off enforce configuration section migration (default=off)\n",
+    "                enforce-config-section=on|off enforce configuration section migration (default=off)\n"
+    "                s390-map-css=on|off controls support for mapping into virtual css (default=off)\n",
     QEMU_ARCH_ALL)
 STEXI
 @item -machine [type=]@var{name}[,prop=@var{value}[,...]]
@@ -82,6 +83,9 @@ controls whether DEA wrapping keys will be created to allow
 execution of DEA cryptographic functions.  The default is on.
 @item nvdimm=on|off
 Enables or disables NVDIMM support. The default is off.
+@item s390-map-css=on|off
+Enables or disables mapping passed-through subchannels into the virtual css.
+The default is off.
 @end table
 ETEXI
 
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index fd36a25..85d705d 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -1249,6 +1249,16 @@ static inline void s390_crypto_reset(void)
     }
 }
 
+static inline bool s390_get_map_css(void)
+{
+    if (object_property_get_bool(OBJECT(qdev_get_machine()), "s390-map-css",
+                                 NULL)) {
+        return true;
+    }
+
+    return false;
+}
+
 /* machine check interruption code */
 
 /* subclasses */
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 04/12] s390x/css: realize css_sch_build_schib
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

The S390 virtual css support already has a mechanism to build virtual
Sub-Channel Information Block and provide virtual subchannels to the
guest. However, to pass-through subchannels to a guest, we need to
introduce a new mechanism to build its schib according to the real
device information. Thus we realize a new css_sch_build_schib function
to extract the path_masks, chpids, chpid type from sysfs. To reuse
the existing code, we refactor css_add_virtual_chpid to css_add_chpid.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.vnet.ibm.com>
---
 hw/s390x/css.c         | 152 ++++++++++++++++++++++++++++++++++++++++++++++++-
 include/hw/s390x/css.h |  36 ++++++------
 2 files changed, 168 insertions(+), 20 deletions(-)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index 0f2580d..8703bc3 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -13,6 +13,7 @@
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "hw/qdev.h"
+#include "qemu/error-report.h"
 #include "qemu/bitops.h"
 #include "exec/address-spaces.h"
 #include "cpu.h"
@@ -1278,7 +1279,8 @@ bool css_schid_final(int m, uint8_t cssid, uint8_t ssid, uint16_t schid)
                                  (MAX_SCHID + 1) / sizeof(unsigned long));
 }
 
-static int css_add_virtual_chpid(uint8_t cssid, uint8_t chpid, uint8_t type)
+static int css_add_chpid(uint8_t cssid, uint8_t chpid, uint8_t type,
+                         bool is_virt)
 {
     CssImage *css;
 
@@ -1292,7 +1294,7 @@ static int css_add_virtual_chpid(uint8_t cssid, uint8_t chpid, uint8_t type)
     }
     css->chpids[chpid].in_use = 1;
     css->chpids[chpid].type = type;
-    css->chpids[chpid].is_virtual = 1;
+    css->chpids[chpid].is_virtual = is_virt;
 
     css_generate_chp_crws(cssid, chpid);
 
@@ -1316,7 +1318,7 @@ void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type)
     p->pam = 0x80;
     p->chpid[0] = chpid;
     if (!css->chpids[chpid].in_use) {
-        css_add_virtual_chpid(sch->cssid, chpid, type);
+        css_add_chpid(sch->cssid, chpid, type, true);
     }
 
     memset(s, 0, sizeof(SCSW));
@@ -1908,3 +1910,147 @@ SubchDev *css_create_virtual_sch(CssDevId bus_id, Error **errp)
     css_subch_assign(sch->cssid, sch->ssid, schid, sch->devno, sch);
     return sch;
 }
+
+static int css_sch_get_chpids(SubchDev *sch, CssDevId *dev_id)
+{
+    char *fid_path;
+    FILE *fd;
+    uint32_t chpid[8];
+    int i;
+    PMCW *p = &sch->curr_status.pmcw;
+
+    fid_path = g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x/chpids",
+                               dev_id->cssid, dev_id->ssid, dev_id->devid);
+    fd = fopen(fid_path, "r");
+    if (fd == NULL) {
+        error_report("%s: open %s failed", __func__, fid_path);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    if (fscanf(fd, "%x %x %x %x %x %x %x %x",
+        &chpid[0], &chpid[1], &chpid[2], &chpid[3],
+        &chpid[4], &chpid[5], &chpid[6], &chpid[7]) != 8) {
+        fclose(fd);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    for (i = 0; i < ARRAY_SIZE(p->chpid); i++) {
+        p->chpid[i] = chpid[i];
+    }
+
+    fclose(fd);
+    g_free(fid_path);
+
+    return 0;
+}
+
+static int css_sch_get_path_masks(SubchDev *sch, CssDevId *dev_id)
+{
+    char *fid_path;
+    FILE *fd;
+    uint32_t pim, pam, pom;
+    PMCW *p = &sch->curr_status.pmcw;
+
+    fid_path = g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x/pimpampom",
+                               dev_id->cssid, dev_id->ssid, dev_id->devid);
+    fd = fopen(fid_path, "r");
+    if (fd == NULL) {
+        error_report("%s: open %s failed", __func__, fid_path);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    if (fscanf(fd, "%x %x %x", &pim, &pam, &pom) != 3) {
+        fclose(fd);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    p->pim = pim;
+    p->pam = pam;
+    p->pom = pom;
+    fclose(fd);
+    g_free(fid_path);
+
+    return 0;
+}
+
+static int css_sch_get_chpid_type(uint8_t chpid, uint32_t *type, CssDevId *dev_id)
+{
+    char *fid_path;
+    FILE *fd;
+
+    fid_path = g_strdup_printf("/sys/devices/css%x/chp0.%02x/type",
+                               dev_id->cssid, chpid);
+    fd = fopen(fid_path, "r");
+    if (fd == NULL) {
+        error_report("%s: open %s failed", __func__, fid_path);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    if (fscanf(fd, "%x", type) != 1) {
+        fclose(fd);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    fclose(fd);
+    g_free(fid_path);
+
+    return 0;
+}
+
+/*
+ * We currently retrieve the real device information from sysfs to build the
+ * guest subchannel information block without considering the migration feature.
+ * If migrate, it won't be sure to use the real device information directly,
+ * this point will be handled in the future.
+ */
+int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id)
+{
+    CssImage *css = channel_subsys.css[sch->cssid];
+    PMCW *p = &sch->curr_status.pmcw;
+    SCSW *s = &sch->curr_status.scsw;
+    uint32_t type;
+    int i, ret;
+
+    /* We are dealing with I/O subchannels only. */
+    assert(css != NULL);
+    memset(p, 0, sizeof(PMCW));
+    p->flags |= PMCW_FLAGS_MASK_DNV;
+    p->devno = sch->devno;
+
+    /* Grab path mask from sysfs. */
+    ret = css_sch_get_path_masks(sch, dev_id);
+    if (ret) {
+        return ret;
+    }
+
+    /* Grab chpids from sysfs. */
+    ret = css_sch_get_chpids(sch, dev_id);
+    if (ret) {
+        return ret;
+    }
+
+   /* Build chpid type. */
+    for (i = 0; i < ARRAY_SIZE(p->chpid); i++) {
+        if (p->chpid[i] && !css->chpids[p->chpid[i]].in_use) {
+            ret = css_sch_get_chpid_type(p->chpid[i], &type, dev_id);
+            if (ret) {
+                return ret;
+            }
+            css_add_chpid(sch->cssid, p->chpid[i], type, false);
+        }
+    }
+
+    memset(s, 0, sizeof(SCSW));
+    sch->curr_status.mba = 0;
+    for (i = 0; i < ARRAY_SIZE(sch->curr_status.mda); i++) {
+        sch->curr_status.mda[i] = 0;
+    }
+
+    return 0;
+}
diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
index c96c862..648ea2f 100644
--- a/include/hw/s390x/css.h
+++ b/include/hw/s390x/css.h
@@ -92,6 +92,24 @@ struct SubchDev {
     void *driver_data;
 };
 
+/*
+ * Identify a device within the channel subsystem.
+ * Note that this can be used to identify either the subchannel or
+ * the attached I/O device, as there's always one I/O device per
+ * subchannel.
+ */
+typedef struct CssDevId {
+    uint8_t cssid;
+    uint8_t ssid;
+    uint16_t devid;
+    bool valid;
+} CssDevId;
+
+extern PropertyInfo css_devid_propinfo;
+
+#define DEFINE_PROP_CSS_DEV_ID(_n, _s, _f) \
+    DEFINE_PROP(_n, _s, _f, css_devid_propinfo, CssDevId)
+
 typedef struct IndAddr {
     hwaddr addr;
     uint64_t map;
@@ -113,6 +131,7 @@ bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno);
 void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
                       uint16_t devno, SubchDev *sch);
 void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type);
+int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id);
 uint16_t css_build_subchannel_id(SubchDev *sch);
 void css_reset(void);
 void css_reset_sch(SubchDev *sch);
@@ -154,23 +173,6 @@ int css_do_rsch(SubchDev *sch);
 int css_do_rchp(uint8_t cssid, uint8_t chpid);
 bool css_present(uint8_t cssid);
 #endif
-/*
- * Identify a device within the channel subsystem.
- * Note that this can be used to identify either the subchannel or
- * the attached I/O device, as there's always one I/O device per
- * subchannel.
- */
-typedef struct CssDevId {
-    uint8_t cssid;
-    uint8_t ssid;
-    uint16_t devid;
-    bool valid;
-} CssDevId;
-
-extern PropertyInfo css_devid_propinfo;
-
-#define DEFINE_PROP_CSS_DEV_ID(_n, _s, _f) \
-    DEFINE_PROP(_n, _s, _f, css_devid_propinfo, CssDevId)
 
 /**
  * Create a subchannel for the given bus id.
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 04/12] s390x/css: realize css_sch_build_schib
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

The S390 virtual css support already has a mechanism to build virtual
Sub-Channel Information Block and provide virtual subchannels to the
guest. However, to pass-through subchannels to a guest, we need to
introduce a new mechanism to build its schib according to the real
device information. Thus we realize a new css_sch_build_schib function
to extract the path_masks, chpids, chpid type from sysfs. To reuse
the existing code, we refactor css_add_virtual_chpid to css_add_chpid.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.vnet.ibm.com>
---
 hw/s390x/css.c         | 152 ++++++++++++++++++++++++++++++++++++++++++++++++-
 include/hw/s390x/css.h |  36 ++++++------
 2 files changed, 168 insertions(+), 20 deletions(-)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index 0f2580d..8703bc3 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -13,6 +13,7 @@
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "hw/qdev.h"
+#include "qemu/error-report.h"
 #include "qemu/bitops.h"
 #include "exec/address-spaces.h"
 #include "cpu.h"
@@ -1278,7 +1279,8 @@ bool css_schid_final(int m, uint8_t cssid, uint8_t ssid, uint16_t schid)
                                  (MAX_SCHID + 1) / sizeof(unsigned long));
 }
 
-static int css_add_virtual_chpid(uint8_t cssid, uint8_t chpid, uint8_t type)
+static int css_add_chpid(uint8_t cssid, uint8_t chpid, uint8_t type,
+                         bool is_virt)
 {
     CssImage *css;
 
@@ -1292,7 +1294,7 @@ static int css_add_virtual_chpid(uint8_t cssid, uint8_t chpid, uint8_t type)
     }
     css->chpids[chpid].in_use = 1;
     css->chpids[chpid].type = type;
-    css->chpids[chpid].is_virtual = 1;
+    css->chpids[chpid].is_virtual = is_virt;
 
     css_generate_chp_crws(cssid, chpid);
 
@@ -1316,7 +1318,7 @@ void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type)
     p->pam = 0x80;
     p->chpid[0] = chpid;
     if (!css->chpids[chpid].in_use) {
-        css_add_virtual_chpid(sch->cssid, chpid, type);
+        css_add_chpid(sch->cssid, chpid, type, true);
     }
 
     memset(s, 0, sizeof(SCSW));
@@ -1908,3 +1910,147 @@ SubchDev *css_create_virtual_sch(CssDevId bus_id, Error **errp)
     css_subch_assign(sch->cssid, sch->ssid, schid, sch->devno, sch);
     return sch;
 }
+
+static int css_sch_get_chpids(SubchDev *sch, CssDevId *dev_id)
+{
+    char *fid_path;
+    FILE *fd;
+    uint32_t chpid[8];
+    int i;
+    PMCW *p = &sch->curr_status.pmcw;
+
+    fid_path = g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x/chpids",
+                               dev_id->cssid, dev_id->ssid, dev_id->devid);
+    fd = fopen(fid_path, "r");
+    if (fd == NULL) {
+        error_report("%s: open %s failed", __func__, fid_path);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    if (fscanf(fd, "%x %x %x %x %x %x %x %x",
+        &chpid[0], &chpid[1], &chpid[2], &chpid[3],
+        &chpid[4], &chpid[5], &chpid[6], &chpid[7]) != 8) {
+        fclose(fd);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    for (i = 0; i < ARRAY_SIZE(p->chpid); i++) {
+        p->chpid[i] = chpid[i];
+    }
+
+    fclose(fd);
+    g_free(fid_path);
+
+    return 0;
+}
+
+static int css_sch_get_path_masks(SubchDev *sch, CssDevId *dev_id)
+{
+    char *fid_path;
+    FILE *fd;
+    uint32_t pim, pam, pom;
+    PMCW *p = &sch->curr_status.pmcw;
+
+    fid_path = g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x/pimpampom",
+                               dev_id->cssid, dev_id->ssid, dev_id->devid);
+    fd = fopen(fid_path, "r");
+    if (fd == NULL) {
+        error_report("%s: open %s failed", __func__, fid_path);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    if (fscanf(fd, "%x %x %x", &pim, &pam, &pom) != 3) {
+        fclose(fd);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    p->pim = pim;
+    p->pam = pam;
+    p->pom = pom;
+    fclose(fd);
+    g_free(fid_path);
+
+    return 0;
+}
+
+static int css_sch_get_chpid_type(uint8_t chpid, uint32_t *type, CssDevId *dev_id)
+{
+    char *fid_path;
+    FILE *fd;
+
+    fid_path = g_strdup_printf("/sys/devices/css%x/chp0.%02x/type",
+                               dev_id->cssid, chpid);
+    fd = fopen(fid_path, "r");
+    if (fd == NULL) {
+        error_report("%s: open %s failed", __func__, fid_path);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    if (fscanf(fd, "%x", type) != 1) {
+        fclose(fd);
+        g_free(fid_path);
+        return -EINVAL;
+    }
+
+    fclose(fd);
+    g_free(fid_path);
+
+    return 0;
+}
+
+/*
+ * We currently retrieve the real device information from sysfs to build the
+ * guest subchannel information block without considering the migration feature.
+ * If migrate, it won't be sure to use the real device information directly,
+ * this point will be handled in the future.
+ */
+int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id)
+{
+    CssImage *css = channel_subsys.css[sch->cssid];
+    PMCW *p = &sch->curr_status.pmcw;
+    SCSW *s = &sch->curr_status.scsw;
+    uint32_t type;
+    int i, ret;
+
+    /* We are dealing with I/O subchannels only. */
+    assert(css != NULL);
+    memset(p, 0, sizeof(PMCW));
+    p->flags |= PMCW_FLAGS_MASK_DNV;
+    p->devno = sch->devno;
+
+    /* Grab path mask from sysfs. */
+    ret = css_sch_get_path_masks(sch, dev_id);
+    if (ret) {
+        return ret;
+    }
+
+    /* Grab chpids from sysfs. */
+    ret = css_sch_get_chpids(sch, dev_id);
+    if (ret) {
+        return ret;
+    }
+
+   /* Build chpid type. */
+    for (i = 0; i < ARRAY_SIZE(p->chpid); i++) {
+        if (p->chpid[i] && !css->chpids[p->chpid[i]].in_use) {
+            ret = css_sch_get_chpid_type(p->chpid[i], &type, dev_id);
+            if (ret) {
+                return ret;
+            }
+            css_add_chpid(sch->cssid, p->chpid[i], type, false);
+        }
+    }
+
+    memset(s, 0, sizeof(SCSW));
+    sch->curr_status.mba = 0;
+    for (i = 0; i < ARRAY_SIZE(sch->curr_status.mda); i++) {
+        sch->curr_status.mda[i] = 0;
+    }
+
+    return 0;
+}
diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
index c96c862..648ea2f 100644
--- a/include/hw/s390x/css.h
+++ b/include/hw/s390x/css.h
@@ -92,6 +92,24 @@ struct SubchDev {
     void *driver_data;
 };
 
+/*
+ * Identify a device within the channel subsystem.
+ * Note that this can be used to identify either the subchannel or
+ * the attached I/O device, as there's always one I/O device per
+ * subchannel.
+ */
+typedef struct CssDevId {
+    uint8_t cssid;
+    uint8_t ssid;
+    uint16_t devid;
+    bool valid;
+} CssDevId;
+
+extern PropertyInfo css_devid_propinfo;
+
+#define DEFINE_PROP_CSS_DEV_ID(_n, _s, _f) \
+    DEFINE_PROP(_n, _s, _f, css_devid_propinfo, CssDevId)
+
 typedef struct IndAddr {
     hwaddr addr;
     uint64_t map;
@@ -113,6 +131,7 @@ bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno);
 void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
                       uint16_t devno, SubchDev *sch);
 void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type);
+int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id);
 uint16_t css_build_subchannel_id(SubchDev *sch);
 void css_reset(void);
 void css_reset_sch(SubchDev *sch);
@@ -154,23 +173,6 @@ int css_do_rsch(SubchDev *sch);
 int css_do_rchp(uint8_t cssid, uint8_t chpid);
 bool css_present(uint8_t cssid);
 #endif
-/*
- * Identify a device within the channel subsystem.
- * Note that this can be used to identify either the subchannel or
- * the attached I/O device, as there's always one I/O device per
- * subchannel.
- */
-typedef struct CssDevId {
-    uint8_t cssid;
-    uint8_t ssid;
-    uint16_t devid;
-    bool valid;
-} CssDevId;
-
-extern PropertyInfo css_devid_propinfo;
-
-#define DEFINE_PROP_CSS_DEV_ID(_n, _s, _f) \
-    DEFINE_PROP(_n, _s, _f, css_devid_propinfo, CssDevId)
 
 /**
  * Create a subchannel for the given bus id.
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 05/12] s390x/css: realize css_create_sch
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

The S390 virtual css support already has a mechanism to create a
virtual subchannel and provide it to the guest. However, to
pass-through subchannels to a guest, we need to introduce a new
mechanism to create the subchannel according to the real device
information. Thus we realize a new css_create_sch function to
allocate and initialize the subchannel according to the real
device information.

Signed-off-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.vnet.ibm.com>
---
 hw/s390x/css.c         | 39 +++++++++++++++++++++++++++++++++++++++
 include/hw/s390x/css.h | 15 +++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index 8703bc3..67fe468 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -1486,6 +1486,19 @@ bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno)
                       channel_subsys.css[cssid]->sch_set[ssid]->devnos_used);
 }
 
+bool css_schid_used(uint8_t cssid, uint8_t ssid, uint16_t schid)
+{
+    if (!channel_subsys.css[cssid]) {
+        return false;
+    }
+    if (!channel_subsys.css[cssid]->sch_set[ssid]) {
+        return false;
+    }
+
+    return !!test_bit(schid,
+                      channel_subsys.css[cssid]->sch_set[ssid]->schids_used);
+}
+
 void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
                       uint16_t devno, SubchDev *sch)
 {
@@ -1911,6 +1924,32 @@ SubchDev *css_create_virtual_sch(CssDevId bus_id, Error **errp)
     return sch;
 }
 
+SubchDev *css_create_sch(CssDevId bus_id, Error **errp)
+{
+    uint32_t devno;
+    SubchDev *sch;
+
+    if (css_schid_used(bus_id.cssid, bus_id.ssid, bus_id.devid)) {
+        error_setg(errp, "Subchannel %x.%x.%04x already exists",
+                   bus_id.cssid, bus_id.ssid, bus_id.devid);
+        return NULL;
+    }
+
+    devno = css_find_free_devno(bus_id.cssid, bus_id.ssid, bus_id.devid);
+    if (devno > MAX_DEVNO) {
+        error_setg(errp, "No free devno found");
+        return NULL;
+    }
+
+    sch = g_malloc0(sizeof(*sch));
+    sch->cssid = bus_id.cssid;
+    sch->ssid = bus_id.ssid;
+    sch->devno = devno;
+    sch->schid = bus_id.devid;
+    css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, sch);
+    return sch;
+}
+
 static int css_sch_get_chpids(SubchDev *sch, CssDevId *dev_id)
 {
     char *fid_path;
diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
index 648ea2f..c92f624 100644
--- a/include/hw/s390x/css.h
+++ b/include/hw/s390x/css.h
@@ -128,6 +128,7 @@ void subch_device_save(SubchDev *s, QEMUFile *f);
 int subch_device_load(SubchDev *s, QEMUFile *f);
 int css_create_css_image(uint8_t cssid, bool default_image);
 bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno);
+bool css_schid_used(uint8_t cssid, uint8_t ssid, uint16_t schid);
 void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
                       uint16_t devno, SubchDev *sch);
 void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type);
@@ -189,4 +190,18 @@ bool css_present(uint8_t cssid);
  * is responsible for unregistering and freeing it.
  */
 SubchDev *css_create_virtual_sch(CssDevId bus_id, Error **errp);
+
+/**
+ * Create a subchannel for the given bus id.
+ *
+ * If @p bus_id is valid, verify that it is not already in use, and find
+ * a free devno for it.
+ * Allocate a subchannel structure, initialise it with the bus id,
+ * subchannel id and device number, register it with the CSS and return
+ * it. Otherwise return NULL.
+ *
+ * The caller becomes owner of the returned subchannel structure and
+ * is responsible for unregistering and freeing it.
+ */
+SubchDev *css_create_sch(CssDevId bus_id, Error **errp);
 #endif
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 05/12] s390x/css: realize css_create_sch
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

The S390 virtual css support already has a mechanism to create a
virtual subchannel and provide it to the guest. However, to
pass-through subchannels to a guest, we need to introduce a new
mechanism to create the subchannel according to the real device
information. Thus we realize a new css_create_sch function to
allocate and initialize the subchannel according to the real
device information.

Signed-off-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.vnet.ibm.com>
---
 hw/s390x/css.c         | 39 +++++++++++++++++++++++++++++++++++++++
 include/hw/s390x/css.h | 15 +++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index 8703bc3..67fe468 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -1486,6 +1486,19 @@ bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno)
                       channel_subsys.css[cssid]->sch_set[ssid]->devnos_used);
 }
 
+bool css_schid_used(uint8_t cssid, uint8_t ssid, uint16_t schid)
+{
+    if (!channel_subsys.css[cssid]) {
+        return false;
+    }
+    if (!channel_subsys.css[cssid]->sch_set[ssid]) {
+        return false;
+    }
+
+    return !!test_bit(schid,
+                      channel_subsys.css[cssid]->sch_set[ssid]->schids_used);
+}
+
 void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
                       uint16_t devno, SubchDev *sch)
 {
@@ -1911,6 +1924,32 @@ SubchDev *css_create_virtual_sch(CssDevId bus_id, Error **errp)
     return sch;
 }
 
+SubchDev *css_create_sch(CssDevId bus_id, Error **errp)
+{
+    uint32_t devno;
+    SubchDev *sch;
+
+    if (css_schid_used(bus_id.cssid, bus_id.ssid, bus_id.devid)) {
+        error_setg(errp, "Subchannel %x.%x.%04x already exists",
+                   bus_id.cssid, bus_id.ssid, bus_id.devid);
+        return NULL;
+    }
+
+    devno = css_find_free_devno(bus_id.cssid, bus_id.ssid, bus_id.devid);
+    if (devno > MAX_DEVNO) {
+        error_setg(errp, "No free devno found");
+        return NULL;
+    }
+
+    sch = g_malloc0(sizeof(*sch));
+    sch->cssid = bus_id.cssid;
+    sch->ssid = bus_id.ssid;
+    sch->devno = devno;
+    sch->schid = bus_id.devid;
+    css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, sch);
+    return sch;
+}
+
 static int css_sch_get_chpids(SubchDev *sch, CssDevId *dev_id)
 {
     char *fid_path;
diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
index 648ea2f..c92f624 100644
--- a/include/hw/s390x/css.h
+++ b/include/hw/s390x/css.h
@@ -128,6 +128,7 @@ void subch_device_save(SubchDev *s, QEMUFile *f);
 int subch_device_load(SubchDev *s, QEMUFile *f);
 int css_create_css_image(uint8_t cssid, bool default_image);
 bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno);
+bool css_schid_used(uint8_t cssid, uint8_t ssid, uint16_t schid);
 void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
                       uint16_t devno, SubchDev *sch);
 void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type);
@@ -189,4 +190,18 @@ bool css_present(uint8_t cssid);
  * is responsible for unregistering and freeing it.
  */
 SubchDev *css_create_virtual_sch(CssDevId bus_id, Error **errp);
+
+/**
+ * Create a subchannel for the given bus id.
+ *
+ * If @p bus_id is valid, verify that it is not already in use, and find
+ * a free devno for it.
+ * Allocate a subchannel structure, initialise it with the bus id,
+ * subchannel id and device number, register it with the CSS and return
+ * it. Otherwise return NULL.
+ *
+ * The caller becomes owner of the returned subchannel structure and
+ * is responsible for unregistering and freeing it.
+ */
+SubchDev *css_create_sch(CssDevId bus_id, Error **errp);
 #endif
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 06/12] s390x/css: device support for s390-ccw passthrough
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

In order to support subchannels pass-through, we introduce a s390
subchannel device called "s390-ccw" to hold the real subchannel info.
The s390-ccw devices inherit from the abstract CcwDevice which connect
to the existing virtual-css-bus.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/s390x/Makefile.objs        |   1 +
 hw/s390x/css-bridge.c         |   3 ++
 hw/s390x/s390-ccw.c           | 120 ++++++++++++++++++++++++++++++++++++++++++
 hw/s390x/s390-ccw.h           |  37 +++++++++++++
 include/hw/s390x/css-bridge.h |   1 +
 5 files changed, 162 insertions(+)
 create mode 100644 hw/s390x/s390-ccw.c
 create mode 100644 hw/s390x/s390-ccw.h

diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs
index 41ac4ec..72a3d37 100644
--- a/hw/s390x/Makefile.objs
+++ b/hw/s390x/Makefile.objs
@@ -13,3 +13,4 @@ obj-y += ccw-device.o
 obj-y += s390-pci-bus.o s390-pci-inst.o
 obj-y += s390-skeys.o
 obj-$(CONFIG_KVM) += s390-skeys-kvm.o
+obj-y += s390-ccw.o
diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c
index 9a7f7ee..6523242 100644
--- a/hw/s390x/css-bridge.c
+++ b/hw/s390x/css-bridge.c
@@ -17,6 +17,7 @@
 #include "hw/s390x/css.h"
 #include "ccw-device.h"
 #include "hw/s390x/css-bridge.h"
+#include "target-s390x/cpu.h"
 
 /*
  * Invoke device-specific unplug handler, disable the subchannel
@@ -104,6 +105,8 @@ VirtualCssBus *virtual_css_bus_init(void)
     bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
     cbus = VIRTUAL_CSS_BUS(bus);
 
+    cbus->map_vir_css = s390_get_map_css();
+
     /* Enable hotplugging */
     qbus_set_hotplug_handler(bus, dev, &error_abort);
 
diff --git a/hw/s390x/s390-ccw.c b/hw/s390x/s390-ccw.c
new file mode 100644
index 0000000..6881fc6
--- /dev/null
+++ b/hw/s390x/s390-ccw.c
@@ -0,0 +1,120 @@
+/*
+ * s390 CCW Assignment Support
+ *
+ * Copyright 2017 IBM Corp
+ * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
+ *            Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
+ *            Pierre Morel <pmorel@linux.vnet.ibm.com>
+ *
+ * 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 "hw/sysbus.h"
+#include "libgen.h"
+#include "hw/s390x/css.h"
+#include "hw/s390x/css-bridge.h"
+#include "s390-ccw.h"
+
+static void s390_ccw_realize(S390CCWDevice *cdev, Error **errp)
+{
+    CcwDevice *ccw_dev = CCW_DEVICE(cdev);
+    DeviceState *parent = DEVICE(ccw_dev);
+    BusState *qbus;
+    VirtualCssBus *cbus;
+    SubchDev *sch;
+    CssDevId bus_id;
+    int ret;
+
+    if (!cdev->hostid.valid) {
+        error_setg(errp, "Invalid hostid");
+        return;
+    }
+
+    qbus = qdev_get_parent_bus(parent);
+    cbus = VIRTUAL_CSS_BUS(qbus);
+    if (ccw_dev->bus_id.valid) {
+        bus_id = ccw_dev->bus_id;
+
+        if (bus_id.cssid == VIRTUAL_CSSID) {
+            error_setg(errp, "Bad guest id: VIRTUAL_CSSID %x forbidden",
+                       bus_id.cssid);
+            return;
+        }
+
+        if (!cbus->map_vir_css) {
+            ret = css_create_css_image(bus_id.cssid, false);
+            if (ret == -EINVAL) {
+                error_setg(errp, "Invalid cssid: %x", bus_id.cssid);
+                return;
+            }
+        }
+    } else {
+        bus_id = cdev->hostid;
+    }
+
+    if (cbus->map_vir_css) {
+        bus_id.cssid = VIRTUAL_CSSID;
+    }
+
+    sch = css_create_sch(bus_id, errp);
+    if (!sch) {
+        return;
+    }
+
+    sch->driver_data = cdev;
+
+    ret = css_sch_build_schib(sch, &cdev->hostid);
+    if (ret) {
+        error_setg(errp, "%s: Failed to build initial schib: %d",
+                   __func__, ret);
+        css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
+        g_free(sch);
+        return;
+    }
+    css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid,
+                          parent->hotplugged, 1);
+
+    ccw_dev->sch = sch;
+    return;
+}
+
+static void s390_ccw_unrealize(S390CCWDevice *cdev, Error **errp)
+{
+    CcwDevice *ccw_dev = CCW_DEVICE(cdev);
+    SubchDev *sch = ccw_dev->sch;
+
+    if (sch) {
+        css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
+        g_free(sch);
+        ccw_dev->sch = NULL;
+    }
+}
+
+static void s390_ccw_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    S390CCWDeviceClass *cdc = S390_CCW_DEVICE_CLASS(klass);
+
+    dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
+    cdc->realize = s390_ccw_realize;
+    cdc->unrealize = s390_ccw_unrealize;
+}
+
+static const TypeInfo s390_ccw_info = {
+    .name          = TYPE_S390_CCW,
+    .parent        = TYPE_CCW_DEVICE,
+    .instance_size = sizeof(S390CCWDevice),
+    .abstract      = true,
+    .class_size    = sizeof(S390CCWDeviceClass),
+    .class_init    = s390_ccw_class_init,
+};
+
+static void register_s390_ccw_type(void)
+{
+    type_register_static(&s390_ccw_info);
+}
+
+type_init(register_s390_ccw_type)
diff --git a/hw/s390x/s390-ccw.h b/hw/s390x/s390-ccw.h
new file mode 100644
index 0000000..9ced8cb
--- /dev/null
+++ b/hw/s390x/s390-ccw.h
@@ -0,0 +1,37 @@
+/*
+ * s390 CCW Assignment Support
+ *
+ * Copyright 2017 IBM Corp.
+ * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
+ *            Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
+ *
+ * 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.
+ */
+
+#ifndef HW_S390_CCW_H
+#define HW_S390_CCW_H
+
+#include "hw/s390x/ccw-device.h"
+
+#define TYPE_S390_CCW "s390-ccw"
+#define S390_CCW_DEVICE(obj) \
+    OBJECT_CHECK(S390CCWDevice, (obj), TYPE_S390_CCW)
+#define S390_CCW_DEVICE_CLASS(klass) \
+    OBJECT_CLASS_CHECK(S390CCWDeviceClass, (klass), TYPE_S390_CCW)
+#define S390_CCW_DEVICE_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(S390CCWDeviceClass, (obj), TYPE_S390_CCW)
+
+typedef struct S390CCWDevice {
+    CcwDevice parent_obj;
+    CssDevId hostid;
+} S390CCWDevice;
+
+typedef struct S390CCWDeviceClass {
+    CCWDeviceClass parent_class;
+    void (*realize)(S390CCWDevice *dev, Error **errp);
+    void (*unrealize)(S390CCWDevice *dev, Error **errp);
+} S390CCWDeviceClass;
+
+#endif
diff --git a/include/hw/s390x/css-bridge.h b/include/hw/s390x/css-bridge.h
index 5a0203b..3fa842b 100644
--- a/include/hw/s390x/css-bridge.h
+++ b/include/hw/s390x/css-bridge.h
@@ -28,6 +28,7 @@ typedef struct VirtualCssBridge {
 /* virtual css bus type */
 typedef struct VirtualCssBus {
     BusState parent_obj;
+    bool map_vir_css;
 } VirtualCssBus;
 
 #define TYPE_VIRTUAL_CSS_BUS "virtual-css-bus"
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 06/12] s390x/css: device support for s390-ccw passthrough
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

In order to support subchannels pass-through, we introduce a s390
subchannel device called "s390-ccw" to hold the real subchannel info.
The s390-ccw devices inherit from the abstract CcwDevice which connect
to the existing virtual-css-bus.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/s390x/Makefile.objs        |   1 +
 hw/s390x/css-bridge.c         |   3 ++
 hw/s390x/s390-ccw.c           | 120 ++++++++++++++++++++++++++++++++++++++++++
 hw/s390x/s390-ccw.h           |  37 +++++++++++++
 include/hw/s390x/css-bridge.h |   1 +
 5 files changed, 162 insertions(+)
 create mode 100644 hw/s390x/s390-ccw.c
 create mode 100644 hw/s390x/s390-ccw.h

diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs
index 41ac4ec..72a3d37 100644
--- a/hw/s390x/Makefile.objs
+++ b/hw/s390x/Makefile.objs
@@ -13,3 +13,4 @@ obj-y += ccw-device.o
 obj-y += s390-pci-bus.o s390-pci-inst.o
 obj-y += s390-skeys.o
 obj-$(CONFIG_KVM) += s390-skeys-kvm.o
+obj-y += s390-ccw.o
diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c
index 9a7f7ee..6523242 100644
--- a/hw/s390x/css-bridge.c
+++ b/hw/s390x/css-bridge.c
@@ -17,6 +17,7 @@
 #include "hw/s390x/css.h"
 #include "ccw-device.h"
 #include "hw/s390x/css-bridge.h"
+#include "target-s390x/cpu.h"
 
 /*
  * Invoke device-specific unplug handler, disable the subchannel
@@ -104,6 +105,8 @@ VirtualCssBus *virtual_css_bus_init(void)
     bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
     cbus = VIRTUAL_CSS_BUS(bus);
 
+    cbus->map_vir_css = s390_get_map_css();
+
     /* Enable hotplugging */
     qbus_set_hotplug_handler(bus, dev, &error_abort);
 
diff --git a/hw/s390x/s390-ccw.c b/hw/s390x/s390-ccw.c
new file mode 100644
index 0000000..6881fc6
--- /dev/null
+++ b/hw/s390x/s390-ccw.c
@@ -0,0 +1,120 @@
+/*
+ * s390 CCW Assignment Support
+ *
+ * Copyright 2017 IBM Corp
+ * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
+ *            Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
+ *            Pierre Morel <pmorel@linux.vnet.ibm.com>
+ *
+ * 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 "hw/sysbus.h"
+#include "libgen.h"
+#include "hw/s390x/css.h"
+#include "hw/s390x/css-bridge.h"
+#include "s390-ccw.h"
+
+static void s390_ccw_realize(S390CCWDevice *cdev, Error **errp)
+{
+    CcwDevice *ccw_dev = CCW_DEVICE(cdev);
+    DeviceState *parent = DEVICE(ccw_dev);
+    BusState *qbus;
+    VirtualCssBus *cbus;
+    SubchDev *sch;
+    CssDevId bus_id;
+    int ret;
+
+    if (!cdev->hostid.valid) {
+        error_setg(errp, "Invalid hostid");
+        return;
+    }
+
+    qbus = qdev_get_parent_bus(parent);
+    cbus = VIRTUAL_CSS_BUS(qbus);
+    if (ccw_dev->bus_id.valid) {
+        bus_id = ccw_dev->bus_id;
+
+        if (bus_id.cssid == VIRTUAL_CSSID) {
+            error_setg(errp, "Bad guest id: VIRTUAL_CSSID %x forbidden",
+                       bus_id.cssid);
+            return;
+        }
+
+        if (!cbus->map_vir_css) {
+            ret = css_create_css_image(bus_id.cssid, false);
+            if (ret == -EINVAL) {
+                error_setg(errp, "Invalid cssid: %x", bus_id.cssid);
+                return;
+            }
+        }
+    } else {
+        bus_id = cdev->hostid;
+    }
+
+    if (cbus->map_vir_css) {
+        bus_id.cssid = VIRTUAL_CSSID;
+    }
+
+    sch = css_create_sch(bus_id, errp);
+    if (!sch) {
+        return;
+    }
+
+    sch->driver_data = cdev;
+
+    ret = css_sch_build_schib(sch, &cdev->hostid);
+    if (ret) {
+        error_setg(errp, "%s: Failed to build initial schib: %d",
+                   __func__, ret);
+        css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
+        g_free(sch);
+        return;
+    }
+    css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid,
+                          parent->hotplugged, 1);
+
+    ccw_dev->sch = sch;
+    return;
+}
+
+static void s390_ccw_unrealize(S390CCWDevice *cdev, Error **errp)
+{
+    CcwDevice *ccw_dev = CCW_DEVICE(cdev);
+    SubchDev *sch = ccw_dev->sch;
+
+    if (sch) {
+        css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
+        g_free(sch);
+        ccw_dev->sch = NULL;
+    }
+}
+
+static void s390_ccw_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    S390CCWDeviceClass *cdc = S390_CCW_DEVICE_CLASS(klass);
+
+    dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
+    cdc->realize = s390_ccw_realize;
+    cdc->unrealize = s390_ccw_unrealize;
+}
+
+static const TypeInfo s390_ccw_info = {
+    .name          = TYPE_S390_CCW,
+    .parent        = TYPE_CCW_DEVICE,
+    .instance_size = sizeof(S390CCWDevice),
+    .abstract      = true,
+    .class_size    = sizeof(S390CCWDeviceClass),
+    .class_init    = s390_ccw_class_init,
+};
+
+static void register_s390_ccw_type(void)
+{
+    type_register_static(&s390_ccw_info);
+}
+
+type_init(register_s390_ccw_type)
diff --git a/hw/s390x/s390-ccw.h b/hw/s390x/s390-ccw.h
new file mode 100644
index 0000000..9ced8cb
--- /dev/null
+++ b/hw/s390x/s390-ccw.h
@@ -0,0 +1,37 @@
+/*
+ * s390 CCW Assignment Support
+ *
+ * Copyright 2017 IBM Corp.
+ * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
+ *            Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
+ *
+ * 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.
+ */
+
+#ifndef HW_S390_CCW_H
+#define HW_S390_CCW_H
+
+#include "hw/s390x/ccw-device.h"
+
+#define TYPE_S390_CCW "s390-ccw"
+#define S390_CCW_DEVICE(obj) \
+    OBJECT_CHECK(S390CCWDevice, (obj), TYPE_S390_CCW)
+#define S390_CCW_DEVICE_CLASS(klass) \
+    OBJECT_CLASS_CHECK(S390CCWDeviceClass, (klass), TYPE_S390_CCW)
+#define S390_CCW_DEVICE_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(S390CCWDeviceClass, (obj), TYPE_S390_CCW)
+
+typedef struct S390CCWDevice {
+    CcwDevice parent_obj;
+    CssDevId hostid;
+} S390CCWDevice;
+
+typedef struct S390CCWDeviceClass {
+    CCWDeviceClass parent_class;
+    void (*realize)(S390CCWDevice *dev, Error **errp);
+    void (*unrealize)(S390CCWDevice *dev, Error **errp);
+} S390CCWDeviceClass;
+
+#endif
diff --git a/include/hw/s390x/css-bridge.h b/include/hw/s390x/css-bridge.h
index 5a0203b..3fa842b 100644
--- a/include/hw/s390x/css-bridge.h
+++ b/include/hw/s390x/css-bridge.h
@@ -28,6 +28,7 @@ typedef struct VirtualCssBridge {
 /* virtual css bus type */
 typedef struct VirtualCssBus {
     BusState parent_obj;
+    bool map_vir_css;
 } VirtualCssBus;
 
 #define TYPE_VIRTUAL_CSS_BUS "virtual-css-bus"
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 07/12] vfio/ccw: vfio based subchannel passthrough driver
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

We use the IOMMU_TYPE1 of VFIO to realize the subchannels
passthrough, implement a vfio based subchannels passthrough
driver called "vfio-ccw".

Support qemu parameters in the style of:
"-device vfio-ccw,id=xx,hostid=xx(,guestid=xx),mdevid=xx"

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 default-configs/s390x-softmmu.mak |   1 +
 hw/s390x/s390-ccw.h               |   1 +
 hw/vfio/Makefile.objs             |   1 +
 hw/vfio/ccw.c                     | 209 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio-common.h     |   1 +
 5 files changed, 213 insertions(+)
 create mode 100644 hw/vfio/ccw.c

diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-softmmu.mak
index 36e15de..5576b0a 100644
--- a/default-configs/s390x-softmmu.mak
+++ b/default-configs/s390x-softmmu.mak
@@ -4,4 +4,5 @@ CONFIG_VIRTIO=y
 CONFIG_SCLPCONSOLE=y
 CONFIG_S390_FLIC=y
 CONFIG_S390_FLIC_KVM=$(CONFIG_KVM)
+CONFIG_VFIO_CCW=$(CONFIG_LINUX)
 CONFIG_WDT_DIAG288=y
diff --git a/hw/s390x/s390-ccw.h b/hw/s390x/s390-ccw.h
index 9ced8cb..1fa4a97 100644
--- a/hw/s390x/s390-ccw.h
+++ b/hw/s390x/s390-ccw.h
@@ -26,6 +26,7 @@
 typedef struct S390CCWDevice {
     CcwDevice parent_obj;
     CssDevId hostid;
+    char *mdevid;
 } S390CCWDevice;
 
 typedef struct S390CCWDeviceClass {
diff --git a/hw/vfio/Makefile.objs b/hw/vfio/Makefile.objs
index c25e32b..4c3a462 100644
--- a/hw/vfio/Makefile.objs
+++ b/hw/vfio/Makefile.objs
@@ -1,6 +1,7 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
 obj-$(CONFIG_PCI) += pci.o pci-quirks.o
+obj-$(CONFIG_VFIO_CCW) += ccw.o
 obj-$(CONFIG_SOFTMMU) += platform.o
 obj-$(CONFIG_SOFTMMU) += calxeda-xgmac.o
 obj-$(CONFIG_SOFTMMU) += amd-xgbe.o
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
new file mode 100644
index 0000000..881010b
--- /dev/null
+++ b/hw/vfio/ccw.c
@@ -0,0 +1,209 @@
+/*
+ * vfio based subchannel assignment support
+ *
+ * Copyright 2017 IBM Corp.
+ * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
+ *            Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
+ *            Pierre Morel <pmorel@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or(at
+ * your option) any version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include <linux/vfio.h>
+#include <sys/ioctl.h>
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/sysbus.h"
+#include "hw/vfio/vfio.h"
+#include "hw/vfio/vfio-common.h"
+#include "hw/s390x/s390-ccw.h"
+#include "hw/s390x/ccw-device.h"
+
+#define TYPE_VFIO_CCW "vfio-ccw"
+typedef struct VFIOCCWDevice {
+    S390CCWDevice cdev;
+    VFIODevice vdev;
+} VFIOCCWDevice;
+
+static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
+{
+    vdev->needs_reset = false;
+}
+
+/*
+ * We don't need vfio_hot_reset_multi and vfio_eoi operationis for
+ * vfio_ccw device now.
+ */
+struct VFIODeviceOps vfio_ccw_ops = {
+    .vfio_compute_needs_reset = vfio_ccw_compute_needs_reset,
+};
+
+static void vfio_ccw_reset(DeviceState *dev)
+{
+    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
+    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
+    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
+
+    ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
+}
+
+static void vfio_put_device(VFIOCCWDevice *vcdev)
+{
+    g_free(vcdev->vdev.name);
+    vfio_put_base_device(&vcdev->vdev);
+}
+
+static VFIOGroup *vfio_ccw_get_group(S390CCWDevice *cdev, char **path,
+                                     Error **errp)
+{
+    struct stat st;
+    int groupid;
+    GError *gerror = NULL;
+
+    /* Check that host subchannel exists. */
+    path[0] = g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x",
+                              cdev->hostid.cssid,
+                              cdev->hostid.ssid,
+                              cdev->hostid.devid);
+    if (stat(path[0], &st) < 0) {
+        error_setg(errp, "vfio: no such host subchannel %s", path[0]);
+        return NULL;
+    }
+
+    /* Check that mediated device exists. */
+    path[1] = g_strdup_printf("%s/%s", path[0], cdev->mdevid);
+    if (stat(path[0], &st) < 0) {
+        error_setg(errp, "vfio: no such mediated device %s", path[1]);
+        return NULL;
+    }
+
+    /* Get the iommu_group patch as the interim variable. */
+    path[2] = g_strconcat(path[1], "/iommu_group", NULL);
+
+    /* Get the link file path of the device iommu_group. */
+    path[3] = g_file_read_link(path[2], &gerror);
+    if (!path[3]) {
+        error_setg(errp, "vfio: error no iommu_group for subchannel");
+        return NULL;
+    }
+
+    /* Get the device groupid. */
+    if (sscanf(basename(path[3]), "%d", &groupid) != 1) {
+        error_setg(errp, "vfio: error reading %s:%m", path[3]);
+        return NULL;
+    }
+
+    return vfio_get_group(groupid, &address_space_memory, errp);
+}
+
+static void vfio_ccw_put_group(VFIOGroup *group, char **path)
+{
+    g_free(path);
+    vfio_put_group(group);
+}
+
+static void vfio_ccw_realize(DeviceState *dev, Error **errp)
+{
+    VFIODevice *vbasedev;
+    VFIOGroup *group;
+    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
+    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
+    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
+    S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
+    char *path[4] = {NULL, NULL, NULL, NULL};
+
+    /* Call the class init function for subchannel. */
+    if (cdc->realize) {
+        cdc->realize(cdev, errp);
+        if (*errp) {
+            return;
+        }
+    }
+
+    group = vfio_ccw_get_group(cdev, path, errp);
+    if (!group) {
+        goto out_group_err;
+    }
+
+    vcdev->vdev.ops = &vfio_ccw_ops;
+    vcdev->vdev.type = VFIO_DEVICE_TYPE_CCW;
+    vcdev->vdev.name = g_strdup_printf("%x.%x.%04x", cdev->hostid.cssid,
+                                       cdev->hostid.ssid, cdev->hostid.devid);
+    QLIST_FOREACH(vbasedev, &group->device_list, next) {
+        if (strcmp(vbasedev->name, vcdev->vdev.name) == 0) {
+            error_setg(errp, "vfio: subchannel %s has already been attached",
+                       basename(path[0]));
+            goto out_device_err;
+        }
+    }
+
+    if (vfio_get_device(group, cdev->mdevid, &vcdev->vdev, errp)) {
+        goto out_device_err;
+    }
+
+    return;
+
+out_device_err:
+    vfio_ccw_put_group(group, path);
+out_group_err:
+    if (cdc->unrealize) {
+        cdc->unrealize(cdev, errp);
+    }
+}
+
+static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
+{
+    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
+    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
+    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
+    S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
+    VFIOGroup *group = vcdev->vdev.group;
+
+    if (cdc->unrealize) {
+        cdc->unrealize(cdev, errp);
+    }
+
+    vfio_put_device(vcdev);
+    vfio_put_group(group);
+}
+
+static Property vfio_ccw_properties[] = {
+    DEFINE_PROP_CSS_DEV_ID("hostid", VFIOCCWDevice, cdev.hostid),
+    DEFINE_PROP_CSS_DEV_ID("guestid", VFIOCCWDevice, cdev.parent_obj.bus_id),
+    DEFINE_PROP_STRING("mdevid", VFIOCCWDevice, cdev.mdevid),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static const VMStateDescription vfio_ccw_vmstate = {
+    .name = TYPE_VFIO_CCW,
+    .unmigratable = 1,
+};
+
+static void vfio_ccw_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->props = vfio_ccw_properties;
+    dc->vmsd = &vfio_ccw_vmstate;
+    dc->desc = "VFIO-based subchannel assignment";
+    dc->realize = vfio_ccw_realize;
+    dc->unrealize = vfio_ccw_unrealize;
+    dc->reset = vfio_ccw_reset;
+}
+
+static const TypeInfo vfio_ccw_info = {
+    .name = TYPE_VFIO_CCW,
+    .parent = TYPE_S390_CCW,
+    .instance_size = sizeof(VFIOCCWDevice),
+    .class_init = vfio_ccw_class_init,
+};
+
+static void register_vfio_ccw_type(void)
+{
+    type_register_static(&vfio_ccw_info);
+}
+
+type_init(register_vfio_ccw_type)
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index c582de1..9521013 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -45,6 +45,7 @@
 enum {
     VFIO_DEVICE_TYPE_PCI = 0,
     VFIO_DEVICE_TYPE_PLATFORM = 1,
+    VFIO_DEVICE_TYPE_CCW = 2,
 };
 
 typedef struct VFIOMmap {
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 07/12] vfio/ccw: vfio based subchannel passthrough driver
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

We use the IOMMU_TYPE1 of VFIO to realize the subchannels
passthrough, implement a vfio based subchannels passthrough
driver called "vfio-ccw".

Support qemu parameters in the style of:
"-device vfio-ccw,id=xx,hostid=xx(,guestid=xx),mdevid=xx"

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 default-configs/s390x-softmmu.mak |   1 +
 hw/s390x/s390-ccw.h               |   1 +
 hw/vfio/Makefile.objs             |   1 +
 hw/vfio/ccw.c                     | 209 ++++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio-common.h     |   1 +
 5 files changed, 213 insertions(+)
 create mode 100644 hw/vfio/ccw.c

diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-softmmu.mak
index 36e15de..5576b0a 100644
--- a/default-configs/s390x-softmmu.mak
+++ b/default-configs/s390x-softmmu.mak
@@ -4,4 +4,5 @@ CONFIG_VIRTIO=y
 CONFIG_SCLPCONSOLE=y
 CONFIG_S390_FLIC=y
 CONFIG_S390_FLIC_KVM=$(CONFIG_KVM)
+CONFIG_VFIO_CCW=$(CONFIG_LINUX)
 CONFIG_WDT_DIAG288=y
diff --git a/hw/s390x/s390-ccw.h b/hw/s390x/s390-ccw.h
index 9ced8cb..1fa4a97 100644
--- a/hw/s390x/s390-ccw.h
+++ b/hw/s390x/s390-ccw.h
@@ -26,6 +26,7 @@
 typedef struct S390CCWDevice {
     CcwDevice parent_obj;
     CssDevId hostid;
+    char *mdevid;
 } S390CCWDevice;
 
 typedef struct S390CCWDeviceClass {
diff --git a/hw/vfio/Makefile.objs b/hw/vfio/Makefile.objs
index c25e32b..4c3a462 100644
--- a/hw/vfio/Makefile.objs
+++ b/hw/vfio/Makefile.objs
@@ -1,6 +1,7 @@
 ifeq ($(CONFIG_LINUX), y)
 obj-$(CONFIG_SOFTMMU) += common.o
 obj-$(CONFIG_PCI) += pci.o pci-quirks.o
+obj-$(CONFIG_VFIO_CCW) += ccw.o
 obj-$(CONFIG_SOFTMMU) += platform.o
 obj-$(CONFIG_SOFTMMU) += calxeda-xgmac.o
 obj-$(CONFIG_SOFTMMU) += amd-xgbe.o
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
new file mode 100644
index 0000000..881010b
--- /dev/null
+++ b/hw/vfio/ccw.c
@@ -0,0 +1,209 @@
+/*
+ * vfio based subchannel assignment support
+ *
+ * Copyright 2017 IBM Corp.
+ * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
+ *            Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
+ *            Pierre Morel <pmorel@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or(at
+ * your option) any version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include <linux/vfio.h>
+#include <sys/ioctl.h>
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "hw/sysbus.h"
+#include "hw/vfio/vfio.h"
+#include "hw/vfio/vfio-common.h"
+#include "hw/s390x/s390-ccw.h"
+#include "hw/s390x/ccw-device.h"
+
+#define TYPE_VFIO_CCW "vfio-ccw"
+typedef struct VFIOCCWDevice {
+    S390CCWDevice cdev;
+    VFIODevice vdev;
+} VFIOCCWDevice;
+
+static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
+{
+    vdev->needs_reset = false;
+}
+
+/*
+ * We don't need vfio_hot_reset_multi and vfio_eoi operationis for
+ * vfio_ccw device now.
+ */
+struct VFIODeviceOps vfio_ccw_ops = {
+    .vfio_compute_needs_reset = vfio_ccw_compute_needs_reset,
+};
+
+static void vfio_ccw_reset(DeviceState *dev)
+{
+    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
+    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
+    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
+
+    ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
+}
+
+static void vfio_put_device(VFIOCCWDevice *vcdev)
+{
+    g_free(vcdev->vdev.name);
+    vfio_put_base_device(&vcdev->vdev);
+}
+
+static VFIOGroup *vfio_ccw_get_group(S390CCWDevice *cdev, char **path,
+                                     Error **errp)
+{
+    struct stat st;
+    int groupid;
+    GError *gerror = NULL;
+
+    /* Check that host subchannel exists. */
+    path[0] = g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x",
+                              cdev->hostid.cssid,
+                              cdev->hostid.ssid,
+                              cdev->hostid.devid);
+    if (stat(path[0], &st) < 0) {
+        error_setg(errp, "vfio: no such host subchannel %s", path[0]);
+        return NULL;
+    }
+
+    /* Check that mediated device exists. */
+    path[1] = g_strdup_printf("%s/%s", path[0], cdev->mdevid);
+    if (stat(path[0], &st) < 0) {
+        error_setg(errp, "vfio: no such mediated device %s", path[1]);
+        return NULL;
+    }
+
+    /* Get the iommu_group patch as the interim variable. */
+    path[2] = g_strconcat(path[1], "/iommu_group", NULL);
+
+    /* Get the link file path of the device iommu_group. */
+    path[3] = g_file_read_link(path[2], &gerror);
+    if (!path[3]) {
+        error_setg(errp, "vfio: error no iommu_group for subchannel");
+        return NULL;
+    }
+
+    /* Get the device groupid. */
+    if (sscanf(basename(path[3]), "%d", &groupid) != 1) {
+        error_setg(errp, "vfio: error reading %s:%m", path[3]);
+        return NULL;
+    }
+
+    return vfio_get_group(groupid, &address_space_memory, errp);
+}
+
+static void vfio_ccw_put_group(VFIOGroup *group, char **path)
+{
+    g_free(path);
+    vfio_put_group(group);
+}
+
+static void vfio_ccw_realize(DeviceState *dev, Error **errp)
+{
+    VFIODevice *vbasedev;
+    VFIOGroup *group;
+    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
+    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
+    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
+    S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
+    char *path[4] = {NULL, NULL, NULL, NULL};
+
+    /* Call the class init function for subchannel. */
+    if (cdc->realize) {
+        cdc->realize(cdev, errp);
+        if (*errp) {
+            return;
+        }
+    }
+
+    group = vfio_ccw_get_group(cdev, path, errp);
+    if (!group) {
+        goto out_group_err;
+    }
+
+    vcdev->vdev.ops = &vfio_ccw_ops;
+    vcdev->vdev.type = VFIO_DEVICE_TYPE_CCW;
+    vcdev->vdev.name = g_strdup_printf("%x.%x.%04x", cdev->hostid.cssid,
+                                       cdev->hostid.ssid, cdev->hostid.devid);
+    QLIST_FOREACH(vbasedev, &group->device_list, next) {
+        if (strcmp(vbasedev->name, vcdev->vdev.name) == 0) {
+            error_setg(errp, "vfio: subchannel %s has already been attached",
+                       basename(path[0]));
+            goto out_device_err;
+        }
+    }
+
+    if (vfio_get_device(group, cdev->mdevid, &vcdev->vdev, errp)) {
+        goto out_device_err;
+    }
+
+    return;
+
+out_device_err:
+    vfio_ccw_put_group(group, path);
+out_group_err:
+    if (cdc->unrealize) {
+        cdc->unrealize(cdev, errp);
+    }
+}
+
+static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
+{
+    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
+    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
+    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
+    S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
+    VFIOGroup *group = vcdev->vdev.group;
+
+    if (cdc->unrealize) {
+        cdc->unrealize(cdev, errp);
+    }
+
+    vfio_put_device(vcdev);
+    vfio_put_group(group);
+}
+
+static Property vfio_ccw_properties[] = {
+    DEFINE_PROP_CSS_DEV_ID("hostid", VFIOCCWDevice, cdev.hostid),
+    DEFINE_PROP_CSS_DEV_ID("guestid", VFIOCCWDevice, cdev.parent_obj.bus_id),
+    DEFINE_PROP_STRING("mdevid", VFIOCCWDevice, cdev.mdevid),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static const VMStateDescription vfio_ccw_vmstate = {
+    .name = TYPE_VFIO_CCW,
+    .unmigratable = 1,
+};
+
+static void vfio_ccw_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->props = vfio_ccw_properties;
+    dc->vmsd = &vfio_ccw_vmstate;
+    dc->desc = "VFIO-based subchannel assignment";
+    dc->realize = vfio_ccw_realize;
+    dc->unrealize = vfio_ccw_unrealize;
+    dc->reset = vfio_ccw_reset;
+}
+
+static const TypeInfo vfio_ccw_info = {
+    .name = TYPE_VFIO_CCW,
+    .parent = TYPE_S390_CCW,
+    .instance_size = sizeof(VFIOCCWDevice),
+    .class_init = vfio_ccw_class_init,
+};
+
+static void register_vfio_ccw_type(void)
+{
+    type_register_static(&vfio_ccw_info);
+}
+
+type_init(register_vfio_ccw_type)
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index c582de1..9521013 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -45,6 +45,7 @@
 enum {
     VFIO_DEVICE_TYPE_PCI = 0,
     VFIO_DEVICE_TYPE_PLATFORM = 1,
+    VFIO_DEVICE_TYPE_CCW = 2,
 };
 
 typedef struct VFIOMmap {
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 08/12] vfio/ccw: get io region info
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

vfio-ccw provides an MMIO region for I/O operations. We fetch its
information via ioctls here, then we can use it performing I/O
instructions and retrieving I/O results later on.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/vfio/ccw.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index 881010b..93394c2 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -21,11 +21,15 @@
 #include "hw/vfio/vfio-common.h"
 #include "hw/s390x/s390-ccw.h"
 #include "hw/s390x/ccw-device.h"
+#include "standard-headers/asm-s390/vfio_ccw.h"
 
 #define TYPE_VFIO_CCW "vfio-ccw"
 typedef struct VFIOCCWDevice {
     S390CCWDevice cdev;
     VFIODevice vdev;
+    uint64_t io_region_size;
+    uint64_t io_region_offset;
+    struct ccw_io_region *io_region;
 } VFIOCCWDevice;
 
 static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
@@ -50,6 +54,46 @@ static void vfio_ccw_reset(DeviceState *dev)
     ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
 }
 
+static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
+{
+    VFIODevice *vdev = &vcdev->vdev;
+    struct vfio_region_info *info;
+    int ret;
+
+    /* Sanity check device */
+    if (!(vdev->flags & VFIO_DEVICE_FLAGS_CCW)) {
+        error_setg(errp, "vfio: Um, this isn't a vfio-ccw device");
+        return;
+    }
+
+    if (vdev->num_regions != VFIO_CCW_NUM_REGIONS) {
+        error_setg(errp, "vfio: Unexpected number of the I/O region %u",
+                   vdev->num_regions);
+        return;
+    }
+
+    ret = vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info);
+    if (ret) {
+        error_setg(errp, "vfio: Error getting config info: %d", ret);
+        return;
+    }
+
+    vcdev->io_region_size = info->size;
+    if (sizeof(*vcdev->io_region) != vcdev->io_region_size) {
+        error_setg(errp, "vfio: Unexpected size of the I/O region");
+        return;
+    }
+    vcdev->io_region_offset = info->offset;
+    vcdev->io_region = g_malloc0(info->size);
+
+    g_free(info);
+}
+
+static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
+{
+    g_free(vcdev->io_region);
+}
+
 static void vfio_put_device(VFIOCCWDevice *vcdev)
 {
     g_free(vcdev->vdev.name);
@@ -144,8 +188,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
         goto out_device_err;
     }
 
+    vfio_ccw_get_region(vcdev, errp);
+    if (*errp) {
+        goto out_region_err;
+    }
+
     return;
 
+out_region_err:
+    vfio_put_device(vcdev);
 out_device_err:
     vfio_ccw_put_group(group, path);
 out_group_err:
@@ -166,6 +217,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
         cdc->unrealize(cdev, errp);
     }
 
+    vfio_ccw_put_region(vcdev);
     vfio_put_device(vcdev);
     vfio_put_group(group);
 }
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 08/12] vfio/ccw: get io region info
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

vfio-ccw provides an MMIO region for I/O operations. We fetch its
information via ioctls here, then we can use it performing I/O
instructions and retrieving I/O results later on.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/vfio/ccw.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index 881010b..93394c2 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -21,11 +21,15 @@
 #include "hw/vfio/vfio-common.h"
 #include "hw/s390x/s390-ccw.h"
 #include "hw/s390x/ccw-device.h"
+#include "standard-headers/asm-s390/vfio_ccw.h"
 
 #define TYPE_VFIO_CCW "vfio-ccw"
 typedef struct VFIOCCWDevice {
     S390CCWDevice cdev;
     VFIODevice vdev;
+    uint64_t io_region_size;
+    uint64_t io_region_offset;
+    struct ccw_io_region *io_region;
 } VFIOCCWDevice;
 
 static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
@@ -50,6 +54,46 @@ static void vfio_ccw_reset(DeviceState *dev)
     ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
 }
 
+static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
+{
+    VFIODevice *vdev = &vcdev->vdev;
+    struct vfio_region_info *info;
+    int ret;
+
+    /* Sanity check device */
+    if (!(vdev->flags & VFIO_DEVICE_FLAGS_CCW)) {
+        error_setg(errp, "vfio: Um, this isn't a vfio-ccw device");
+        return;
+    }
+
+    if (vdev->num_regions != VFIO_CCW_NUM_REGIONS) {
+        error_setg(errp, "vfio: Unexpected number of the I/O region %u",
+                   vdev->num_regions);
+        return;
+    }
+
+    ret = vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info);
+    if (ret) {
+        error_setg(errp, "vfio: Error getting config info: %d", ret);
+        return;
+    }
+
+    vcdev->io_region_size = info->size;
+    if (sizeof(*vcdev->io_region) != vcdev->io_region_size) {
+        error_setg(errp, "vfio: Unexpected size of the I/O region");
+        return;
+    }
+    vcdev->io_region_offset = info->offset;
+    vcdev->io_region = g_malloc0(info->size);
+
+    g_free(info);
+}
+
+static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
+{
+    g_free(vcdev->io_region);
+}
+
 static void vfio_put_device(VFIOCCWDevice *vcdev)
 {
     g_free(vcdev->vdev.name);
@@ -144,8 +188,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
         goto out_device_err;
     }
 
+    vfio_ccw_get_region(vcdev, errp);
+    if (*errp) {
+        goto out_region_err;
+    }
+
     return;
 
+out_region_err:
+    vfio_put_device(vcdev);
 out_device_err:
     vfio_ccw_put_group(group, path);
 out_group_err:
@@ -166,6 +217,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
         cdc->unrealize(cdev, errp);
     }
 
+    vfio_ccw_put_region(vcdev);
     vfio_put_device(vcdev);
     vfio_put_group(group);
 }
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 09/12] vfio/ccw: get irqs info and set the eventfd fd
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

vfio-ccw resorts to the eventfd mechanism to communicate with userspace.
We fetch the irqs info via the ioctl VFIO_DEVICE_GET_IRQ_INFO,
register a event notifier to get the eventfd fd which is sent
to kernel via the ioctl VFIO_DEVICE_SET_IRQS, then we can implement
read operation once kernel sends the signal.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/vfio/ccw.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)

diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index 93394c2..c6bfce7 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -21,6 +21,7 @@
 #include "hw/vfio/vfio-common.h"
 #include "hw/s390x/s390-ccw.h"
 #include "hw/s390x/ccw-device.h"
+#include "qemu/error-report.h"
 #include "standard-headers/asm-s390/vfio_ccw.h"
 
 #define TYPE_VFIO_CCW "vfio-ccw"
@@ -30,6 +31,7 @@ typedef struct VFIOCCWDevice {
     uint64_t io_region_size;
     uint64_t io_region_offset;
     struct ccw_io_region *io_region;
+    EventNotifier io_notifier;
 } VFIOCCWDevice;
 
 static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
@@ -54,6 +56,98 @@ static void vfio_ccw_reset(DeviceState *dev)
     ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
 }
 
+static void vfio_ccw_io_notifier_handler(void *opaque)
+{
+    VFIOCCWDevice *vcdev = opaque;
+
+    if (!event_notifier_test_and_clear(&vcdev->io_notifier)) {
+        return;
+    }
+}
+
+static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
+{
+    VFIODevice *vdev = &vcdev->vdev;
+    struct vfio_irq_info *irq_info;
+    struct vfio_irq_set *irq_set;
+    size_t argsz;
+    int32_t *pfd;
+
+    if (vdev->num_irqs != VFIO_CCW_NUM_IRQS) {
+        error_setg(errp, "vfio: unexpected number of io irqs %u",
+                   vdev->num_irqs);
+        return;
+    }
+
+    argsz = sizeof(*irq_set);
+    irq_info = g_malloc0(argsz);
+    irq_info->index = VFIO_CCW_IO_IRQ_INDEX;
+    irq_info->argsz = argsz;
+    if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
+              irq_info) < 0 || irq_info->count < 1) {
+        error_setg(errp, "vfio: Error getting irq info");
+        goto get_error;
+    }
+
+    if (event_notifier_init(&vcdev->io_notifier, 0)) {
+        error_setg(errp, "vfio: Unable to init event notifier for IO");
+        goto get_error;
+    }
+
+    argsz = sizeof(*irq_set) + sizeof(*pfd);
+    irq_set = g_malloc0(argsz);
+    irq_set->argsz = argsz;
+    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
+                     VFIO_IRQ_SET_ACTION_TRIGGER;
+    irq_set->index = VFIO_CCW_IO_IRQ_INDEX;
+    irq_set->start = 0;
+    irq_set->count = 1;
+    pfd = (int32_t *) &irq_set->data;
+
+    *pfd = event_notifier_get_fd(&vcdev->io_notifier);
+    qemu_set_fd_handler(*pfd, vfio_ccw_io_notifier_handler, NULL, vcdev);
+    if (ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
+        error_setg(errp, "vfio: Failed to set up io notification");
+        qemu_set_fd_handler(*pfd, NULL, NULL, vcdev);
+        event_notifier_cleanup(&vcdev->io_notifier);
+        goto set_error;
+    }
+
+set_error:
+    g_free(irq_set);
+
+get_error:
+    g_free(irq_info);
+}
+
+static void vfio_ccw_unregister_io_notifier(VFIOCCWDevice *vcdev)
+{
+    struct vfio_irq_set *irq_set;
+    size_t argsz;
+    int32_t *pfd;
+
+    argsz = sizeof(*irq_set) + sizeof(*pfd);
+    irq_set = g_malloc0(argsz);
+    irq_set->argsz = argsz;
+    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
+                     VFIO_IRQ_SET_ACTION_TRIGGER;
+    irq_set->index = VFIO_CCW_IO_IRQ_INDEX;
+    irq_set->start = 0;
+    irq_set->count = 1;
+    pfd = (int32_t *) &irq_set->data;
+    *pfd = -1;
+
+    if (ioctl(vcdev->vdev.fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
+        error_report("vfio: Failed to de-assign device io fd");
+    }
+
+    qemu_set_fd_handler(event_notifier_get_fd(&vcdev->io_notifier),
+                        NULL, NULL, vcdev);
+    event_notifier_cleanup(&vcdev->io_notifier);
+
+    g_free(irq_set);
+}
+
 static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
 {
     VFIODevice *vdev = &vcdev->vdev;
@@ -193,8 +287,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
         goto out_region_err;
     }
 
+    vfio_ccw_register_io_notifier(vcdev, errp);
+    if (*errp) {
+        goto out_notifier_err;
+    }
+
     return;
 
+out_notifier_err:
+    vfio_ccw_put_region(vcdev);
 out_region_err:
     vfio_put_device(vcdev);
 out_device_err:
@@ -217,6 +318,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
         cdc->unrealize(cdev, errp);
     }
 
+    vfio_ccw_unregister_io_notifier(vcdev);
     vfio_ccw_put_region(vcdev);
     vfio_put_device(vcdev);
     vfio_put_group(group);
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 09/12] vfio/ccw: get irqs info and set the eventfd fd
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

vfio-ccw resorts to the eventfd mechanism to communicate with userspace.
We fetch the irqs info via the ioctl VFIO_DEVICE_GET_IRQ_INFO,
register a event notifier to get the eventfd fd which is sent
to kernel via the ioctl VFIO_DEVICE_SET_IRQS, then we can implement
read operation once kernel sends the signal.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/vfio/ccw.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)

diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index 93394c2..c6bfce7 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -21,6 +21,7 @@
 #include "hw/vfio/vfio-common.h"
 #include "hw/s390x/s390-ccw.h"
 #include "hw/s390x/ccw-device.h"
+#include "qemu/error-report.h"
 #include "standard-headers/asm-s390/vfio_ccw.h"
 
 #define TYPE_VFIO_CCW "vfio-ccw"
@@ -30,6 +31,7 @@ typedef struct VFIOCCWDevice {
     uint64_t io_region_size;
     uint64_t io_region_offset;
     struct ccw_io_region *io_region;
+    EventNotifier io_notifier;
 } VFIOCCWDevice;
 
 static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
@@ -54,6 +56,98 @@ static void vfio_ccw_reset(DeviceState *dev)
     ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
 }
 
+static void vfio_ccw_io_notifier_handler(void *opaque)
+{
+    VFIOCCWDevice *vcdev = opaque;
+
+    if (!event_notifier_test_and_clear(&vcdev->io_notifier)) {
+        return;
+    }
+}
+
+static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
+{
+    VFIODevice *vdev = &vcdev->vdev;
+    struct vfio_irq_info *irq_info;
+    struct vfio_irq_set *irq_set;
+    size_t argsz;
+    int32_t *pfd;
+
+    if (vdev->num_irqs != VFIO_CCW_NUM_IRQS) {
+        error_setg(errp, "vfio: unexpected number of io irqs %u",
+                   vdev->num_irqs);
+        return;
+    }
+
+    argsz = sizeof(*irq_set);
+    irq_info = g_malloc0(argsz);
+    irq_info->index = VFIO_CCW_IO_IRQ_INDEX;
+    irq_info->argsz = argsz;
+    if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
+              irq_info) < 0 || irq_info->count < 1) {
+        error_setg(errp, "vfio: Error getting irq info");
+        goto get_error;
+    }
+
+    if (event_notifier_init(&vcdev->io_notifier, 0)) {
+        error_setg(errp, "vfio: Unable to init event notifier for IO");
+        goto get_error;
+    }
+
+    argsz = sizeof(*irq_set) + sizeof(*pfd);
+    irq_set = g_malloc0(argsz);
+    irq_set->argsz = argsz;
+    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
+                     VFIO_IRQ_SET_ACTION_TRIGGER;
+    irq_set->index = VFIO_CCW_IO_IRQ_INDEX;
+    irq_set->start = 0;
+    irq_set->count = 1;
+    pfd = (int32_t *) &irq_set->data;
+
+    *pfd = event_notifier_get_fd(&vcdev->io_notifier);
+    qemu_set_fd_handler(*pfd, vfio_ccw_io_notifier_handler, NULL, vcdev);
+    if (ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
+        error_setg(errp, "vfio: Failed to set up io notification");
+        qemu_set_fd_handler(*pfd, NULL, NULL, vcdev);
+        event_notifier_cleanup(&vcdev->io_notifier);
+        goto set_error;
+    }
+
+set_error:
+    g_free(irq_set);
+
+get_error:
+    g_free(irq_info);
+}
+
+static void vfio_ccw_unregister_io_notifier(VFIOCCWDevice *vcdev)
+{
+    struct vfio_irq_set *irq_set;
+    size_t argsz;
+    int32_t *pfd;
+
+    argsz = sizeof(*irq_set) + sizeof(*pfd);
+    irq_set = g_malloc0(argsz);
+    irq_set->argsz = argsz;
+    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
+                     VFIO_IRQ_SET_ACTION_TRIGGER;
+    irq_set->index = VFIO_CCW_IO_IRQ_INDEX;
+    irq_set->start = 0;
+    irq_set->count = 1;
+    pfd = (int32_t *) &irq_set->data;
+    *pfd = -1;
+
+    if (ioctl(vcdev->vdev.fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
+        error_report("vfio: Failed to de-assign device io fd");
+    }
+
+    qemu_set_fd_handler(event_notifier_get_fd(&vcdev->io_notifier),
+                        NULL, NULL, vcdev);
+    event_notifier_cleanup(&vcdev->io_notifier);
+
+    g_free(irq_set);
+}
+
 static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
 {
     VFIODevice *vdev = &vcdev->vdev;
@@ -193,8 +287,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
         goto out_region_err;
     }
 
+    vfio_ccw_register_io_notifier(vcdev, errp);
+    if (*errp) {
+        goto out_notifier_err;
+    }
+
     return;
 
+out_notifier_err:
+    vfio_ccw_put_region(vcdev);
 out_region_err:
     vfio_put_device(vcdev);
 out_device_err:
@@ -217,6 +318,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
         cdc->unrealize(cdev, errp);
     }
 
+    vfio_ccw_unregister_io_notifier(vcdev);
     vfio_ccw_put_region(vcdev);
     vfio_put_device(vcdev);
     vfio_put_group(group);
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 10/12] s390x/css: introduce and realize ccw-request callback
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

Introduce a new callback on subchannel to handle ccw-request.
Realize the callback in vfio-ccw device. Besides, resort to
the event notifier handler to handling the ccw-request results.
1. Pread the I/O results via MMIO region.
2. Update the scsw info to guest.
3. Inject an I/O interrupt to notify guest the I/O result.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/s390x/css.c         |  4 +--
 hw/s390x/s390-ccw.h    |  1 +
 hw/vfio/ccw.c          | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/s390x/css.h |  2 ++
 4 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index 67fe468..c3a323e 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -238,7 +238,7 @@ uint16_t css_build_subchannel_id(SubchDev *sch)
     return css_do_build_subchannel_id(sch->cssid, sch->ssid);
 }
 
-static void css_inject_io_interrupt(SubchDev *sch)
+void css_inject_io_interrupt(SubchDev *sch)
 {
     uint8_t isc = (sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ISC) >> 11;
 
@@ -644,7 +644,7 @@ static void copy_pmcw_to_guest(PMCW *dest, const PMCW *src)
     dest->chars = cpu_to_be32(src->chars);
 }
 
-static void copy_scsw_to_guest(SCSW *dest, const SCSW *src)
+void copy_scsw_to_guest(SCSW *dest, const SCSW *src)
 {
     dest->flags = cpu_to_be16(src->flags);
     dest->ctrl = cpu_to_be16(src->ctrl);
diff --git a/hw/s390x/s390-ccw.h b/hw/s390x/s390-ccw.h
index 1fa4a97..2d3a2b5 100644
--- a/hw/s390x/s390-ccw.h
+++ b/hw/s390x/s390-ccw.h
@@ -27,6 +27,7 @@ typedef struct S390CCWDevice {
     CcwDevice parent_obj;
     CssDevId hostid;
     char *mdevid;
+    int (*handle_request) (ORB *, SCSW *, void *);
 } S390CCWDevice;
 
 typedef struct S390CCWDeviceClass {
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index c6bfce7..34c719a 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -47,6 +47,36 @@ struct VFIODeviceOps vfio_ccw_ops = {
     .vfio_compute_needs_reset = vfio_ccw_compute_needs_reset,
 };
 
+static int vfio_ccw_handle_request(ORB *orb, SCSW *scsw, void *data)
+{
+    S390CCWDevice *cdev = data;
+    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
+    struct ccw_io_region *region = vcdev->io_region;
+    int ret;
+
+    QEMU_BUILD_BUG_ON(sizeof(region->orb_area) != sizeof(ORB));
+    QEMU_BUILD_BUG_ON(sizeof(region->scsw_area) != sizeof(SCSW));
+    QEMU_BUILD_BUG_ON(sizeof(region->irb_area) != sizeof(IRB));
+
+    memset(region, 0, sizeof(*region));
+
+    memcpy(region->orb_area, orb, sizeof(ORB));
+    memcpy(region->scsw_area, scsw, sizeof(SCSW));
+
+again:
+    ret = pwrite(vcdev->vdev.fd, region,
+                 vcdev->io_region_size, vcdev->io_region_offset);
+    if (ret != vcdev->io_region_size) {
+        if (errno == EAGAIN) {
+            goto again;
+        }
+        error_report("vfio-ccw: wirte I/O region failed with errno=%d",errno);
+        return -errno;
+    }
+
+    return region->ret_code;
+}
+
 static void vfio_ccw_reset(DeviceState *dev)
 {
     CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
@@ -59,10 +89,52 @@ static void vfio_ccw_reset(DeviceState *dev)
 static void vfio_ccw_io_notifier_handler(void *opaque)
 {
     VFIOCCWDevice *vcdev = opaque;
+    struct ccw_io_region *region = vcdev->io_region;
+    S390CCWDevice *cdev = S390_CCW_DEVICE(vcdev);
+    CcwDevice *ccw_dev = CCW_DEVICE(cdev);
+    SubchDev *sch = ccw_dev->sch;
+    SCSW *s = &sch->curr_status.scsw;
+    IRB irb;
 
     if (!event_notifier_test_and_clear(&vcdev->io_notifier)) {
         return;
     }
+
+    if (pread(vcdev->vdev.fd, region,
+              vcdev->io_region_size, vcdev->io_region_offset) == -1) {
+        switch (errno) {
+        case ENODEV:
+            /* Generate a deferred cc 3 condition. */
+            s->flags |= SCSW_FLAGS_MASK_CC;
+            s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
+            s->ctrl |= (SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND);
+            goto read_err;
+        case EFAULT:
+            /* memory problem, generate channel data check */
+            s->ctrl &= ~SCSW_ACTL_START_PEND;
+            s->cstat = SCSW_CSTAT_DATA_CHECK;
+            s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
+            s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
+                    SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
+            goto read_err;
+        default:
+            /* error, generate channel program check */
+            s->ctrl &= ~SCSW_ACTL_START_PEND;
+            s->cstat = SCSW_CSTAT_PROG_CHECK;
+            s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
+            s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
+                    SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
+            goto read_err;
+        }
+    }
+
+    memcpy(&irb, region->irb_area, sizeof(IRB));
+
+    /* Update control block via irb. */
+    copy_scsw_to_guest(s, &irb.scsw);
+
+read_err:
+    css_inject_io_interrupt(sch);
 }
 
 static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
@@ -253,6 +325,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
     S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
     char *path[4] = {NULL, NULL, NULL, NULL};
 
+    cdev->handle_request = vfio_ccw_handle_request;
     /* Call the class init function for subchannel. */
     if (cdc->realize) {
         cdc->realize(cdev, errp);
diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
index c92f624..2884439 100644
--- a/include/hw/s390x/css.h
+++ b/include/hw/s390x/css.h
@@ -134,6 +134,8 @@ void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
 void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type);
 int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id);
 uint16_t css_build_subchannel_id(SubchDev *sch);
+void copy_scsw_to_guest(SCSW *dest, const SCSW *src);
+void css_inject_io_interrupt(SubchDev *sch);
 void css_reset(void);
 void css_reset_sch(SubchDev *sch);
 void css_queue_crw(uint8_t rsc, uint8_t erc, int chain, uint16_t rsid);
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 10/12] s390x/css: introduce and realize ccw-request callback
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

Introduce a new callback on subchannel to handle ccw-request.
Realize the callback in vfio-ccw device. Besides, resort to
the event notifier handler to handling the ccw-request results.
1. Pread the I/O results via MMIO region.
2. Update the scsw info to guest.
3. Inject an I/O interrupt to notify guest the I/O result.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/s390x/css.c         |  4 +--
 hw/s390x/s390-ccw.h    |  1 +
 hw/vfio/ccw.c          | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/s390x/css.h |  2 ++
 4 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index 67fe468..c3a323e 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -238,7 +238,7 @@ uint16_t css_build_subchannel_id(SubchDev *sch)
     return css_do_build_subchannel_id(sch->cssid, sch->ssid);
 }
 
-static void css_inject_io_interrupt(SubchDev *sch)
+void css_inject_io_interrupt(SubchDev *sch)
 {
     uint8_t isc = (sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ISC) >> 11;
 
@@ -644,7 +644,7 @@ static void copy_pmcw_to_guest(PMCW *dest, const PMCW *src)
     dest->chars = cpu_to_be32(src->chars);
 }
 
-static void copy_scsw_to_guest(SCSW *dest, const SCSW *src)
+void copy_scsw_to_guest(SCSW *dest, const SCSW *src)
 {
     dest->flags = cpu_to_be16(src->flags);
     dest->ctrl = cpu_to_be16(src->ctrl);
diff --git a/hw/s390x/s390-ccw.h b/hw/s390x/s390-ccw.h
index 1fa4a97..2d3a2b5 100644
--- a/hw/s390x/s390-ccw.h
+++ b/hw/s390x/s390-ccw.h
@@ -27,6 +27,7 @@ typedef struct S390CCWDevice {
     CcwDevice parent_obj;
     CssDevId hostid;
     char *mdevid;
+    int (*handle_request) (ORB *, SCSW *, void *);
 } S390CCWDevice;
 
 typedef struct S390CCWDeviceClass {
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index c6bfce7..34c719a 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -47,6 +47,36 @@ struct VFIODeviceOps vfio_ccw_ops = {
     .vfio_compute_needs_reset = vfio_ccw_compute_needs_reset,
 };
 
+static int vfio_ccw_handle_request(ORB *orb, SCSW *scsw, void *data)
+{
+    S390CCWDevice *cdev = data;
+    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
+    struct ccw_io_region *region = vcdev->io_region;
+    int ret;
+
+    QEMU_BUILD_BUG_ON(sizeof(region->orb_area) != sizeof(ORB));
+    QEMU_BUILD_BUG_ON(sizeof(region->scsw_area) != sizeof(SCSW));
+    QEMU_BUILD_BUG_ON(sizeof(region->irb_area) != sizeof(IRB));
+
+    memset(region, 0, sizeof(*region));
+
+    memcpy(region->orb_area, orb, sizeof(ORB));
+    memcpy(region->scsw_area, scsw, sizeof(SCSW));
+
+again:
+    ret = pwrite(vcdev->vdev.fd, region,
+                 vcdev->io_region_size, vcdev->io_region_offset);
+    if (ret != vcdev->io_region_size) {
+        if (errno == EAGAIN) {
+            goto again;
+        }
+        error_report("vfio-ccw: wirte I/O region failed with errno=%d",errno);
+        return -errno;
+    }
+
+    return region->ret_code;
+}
+
 static void vfio_ccw_reset(DeviceState *dev)
 {
     CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
@@ -59,10 +89,52 @@ static void vfio_ccw_reset(DeviceState *dev)
 static void vfio_ccw_io_notifier_handler(void *opaque)
 {
     VFIOCCWDevice *vcdev = opaque;
+    struct ccw_io_region *region = vcdev->io_region;
+    S390CCWDevice *cdev = S390_CCW_DEVICE(vcdev);
+    CcwDevice *ccw_dev = CCW_DEVICE(cdev);
+    SubchDev *sch = ccw_dev->sch;
+    SCSW *s = &sch->curr_status.scsw;
+    IRB irb;
 
     if (!event_notifier_test_and_clear(&vcdev->io_notifier)) {
         return;
     }
+
+    if (pread(vcdev->vdev.fd, region,
+              vcdev->io_region_size, vcdev->io_region_offset) == -1) {
+        switch (errno) {
+        case ENODEV:
+            /* Generate a deferred cc 3 condition. */
+            s->flags |= SCSW_FLAGS_MASK_CC;
+            s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
+            s->ctrl |= (SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND);
+            goto read_err;
+        case EFAULT:
+            /* memory problem, generate channel data check */
+            s->ctrl &= ~SCSW_ACTL_START_PEND;
+            s->cstat = SCSW_CSTAT_DATA_CHECK;
+            s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
+            s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
+                    SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
+            goto read_err;
+        default:
+            /* error, generate channel program check */
+            s->ctrl &= ~SCSW_ACTL_START_PEND;
+            s->cstat = SCSW_CSTAT_PROG_CHECK;
+            s->ctrl &= ~SCSW_CTRL_MASK_STCTL;
+            s->ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY |
+                    SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND;
+            goto read_err;
+        }
+    }
+
+    memcpy(&irb, region->irb_area, sizeof(IRB));
+
+    /* Update control block via irb. */
+    copy_scsw_to_guest(s, &irb.scsw);
+
+read_err:
+    css_inject_io_interrupt(sch);
 }
 
 static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
@@ -253,6 +325,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
     S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
     char *path[4] = {NULL, NULL, NULL, NULL};
 
+    cdev->handle_request = vfio_ccw_handle_request;
     /* Call the class init function for subchannel. */
     if (cdc->realize) {
         cdc->realize(cdev, errp);
diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
index c92f624..2884439 100644
--- a/include/hw/s390x/css.h
+++ b/include/hw/s390x/css.h
@@ -134,6 +134,8 @@ void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid,
 void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type);
 int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id);
 uint16_t css_build_subchannel_id(SubchDev *sch);
+void copy_scsw_to_guest(SCSW *dest, const SCSW *src);
+void css_inject_io_interrupt(SubchDev *sch);
 void css_reset(void);
 void css_reset_sch(SubchDev *sch);
 void css_queue_crw(uint8_t rsc, uint8_t erc, int chain, uint16_t rsid);
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 11/12] s390x/css: ccws translation infrastructure
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

Implement a basic infrastructure of handling channel I/O instruction
interception for passed through subchannels:
1. Branch the code path of instruction interception handling by
   SubChannel type.
2. For a passed-through subchannel, issue the ORB to kernel to do ccw
   translation and perform an I/O operation.
3. Assign different condition code based on the I/O result, or
   trigger a program check.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/s390x/css.c         | 88 ++++++++++++++++++++++++++++++++++++++++++++++----
 hw/s390x/s390-ccw.c    | 12 +++++++
 hw/s390x/virtio-ccw.c  |  1 +
 include/hw/s390x/css.h |  4 +++
 target-s390x/ioinst.c  |  9 ++++++
 5 files changed, 108 insertions(+), 6 deletions(-)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index c3a323e..0e3b0ae 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -500,7 +500,7 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr ccw_addr,
     return ret;
 }
 
-static void sch_handle_start_func(SubchDev *sch, ORB *orb)
+static void sch_handle_start_func_virtual(SubchDev *sch, ORB *orb)
 {
 
     PMCW *p = &sch->curr_status.pmcw;
@@ -599,13 +599,57 @@ static void sch_handle_start_func(SubchDev *sch, ORB *orb)
 
 }
 
+static int sch_handle_start_func_passthrough(SubchDev *sch, ORB *orb)
+{
+
+    PMCW *p = &sch->curr_status.pmcw;
+    SCSW *s = &sch->curr_status.scsw;
+    int ret;
+
+    if (!(s->ctrl & SCSW_ACTL_SUSP)) {
+        assert(orb != NULL);
+        p->intparm = orb->intparm;
+    }
+
+    /*
+     * Only support prefetch enable mode.
+     * Only support 64bit addressing idal.
+     */
+    if (!(orb->ctrl0 & ORB_CTRL0_MASK_PFCH) ||
+        !(orb->ctrl0 & ORB_CTRL0_MASK_C64)) {
+        return -EINVAL;
+    }
+
+    ret = s390_ccw_cmd_request(orb, s, sch->driver_data);
+    switch (ret) {
+    /* Currently we don't update control block and just return the cc code. */
+    case 0:
+        break;
+    case -EBUSY:
+        break;
+    case -ENODEV:
+        break;
+    case -EACCES:
+        /* Let's reflect an inaccessible host device by cc 3. */
+        ret = -ENODEV;
+        break;
+    default:
+       /* All other return codes will trigger a program check,
+        * or set cc to 1.
+        */
+       break;
+    };
+
+    return ret;
+}
+
 /*
  * On real machines, this would run asynchronously to the main vcpus.
  * We might want to make some parts of the ssch handling (interpreting
  * read/writes) asynchronous later on if we start supporting more than
  * our current very simple devices.
  */
-static void do_subchannel_work(SubchDev *sch, ORB *orb)
+int do_subchannel_work_virtual(SubchDev *sch, ORB *orb)
 {
 
     SCSW *s = &sch->curr_status.scsw;
@@ -616,12 +660,45 @@ static void do_subchannel_work(SubchDev *sch, ORB *orb)
         sch_handle_halt_func(sch);
     } else if (s->ctrl & SCSW_FCTL_START_FUNC) {
         /* Triggered by both ssch and rsch. */
-        sch_handle_start_func(sch, orb);
+        sch_handle_start_func_virtual(sch, orb);
     } else {
         /* Cannot happen. */
-        return;
+        return 0;
     }
     css_inject_io_interrupt(sch);
+    return 0;
+}
+
+int do_subchannel_work_passthrough(SubchDev *sch, ORB *orb)
+{
+    int ret;
+    SCSW *s = &sch->curr_status.scsw;
+
+    if (s->ctrl & SCSW_FCTL_CLEAR_FUNC) {
+        /* TODO: Clear handling */
+        sch_handle_clear_func(sch);
+        ret = 0;
+    } else if (s->ctrl & SCSW_FCTL_HALT_FUNC) {
+        /* TODO: Halt handling */
+        sch_handle_halt_func(sch);
+        ret = 0;
+    } else if (s->ctrl & SCSW_FCTL_START_FUNC) {
+        ret = sch_handle_start_func_passthrough(sch, orb);
+    } else {
+        /* Cannot happen. */
+        return -ENODEV;
+    }
+
+    return ret;
+}
+
+static int do_subchannel_work(SubchDev *sch, ORB *orb)
+{
+    if (sch->do_subchannel_work) {
+        return sch->do_subchannel_work(sch, orb);
+    } else {
+        return -EINVAL;
+    }
 }
 
 static void copy_pmcw_to_guest(PMCW *dest, const PMCW *src)
@@ -940,8 +1017,7 @@ int css_do_ssch(SubchDev *sch, ORB *orb)
     s->ctrl |= (SCSW_FCTL_START_FUNC | SCSW_ACTL_START_PEND);
     s->flags &= ~SCSW_FLAGS_MASK_PNO;
 
-    do_subchannel_work(sch, orb);
-    ret = 0;
+    ret = do_subchannel_work(sch, orb);
 
 out:
     return ret;
diff --git a/hw/s390x/s390-ccw.c b/hw/s390x/s390-ccw.c
index 6881fc6..58fb916 100644
--- a/hw/s390x/s390-ccw.c
+++ b/hw/s390x/s390-ccw.c
@@ -18,6 +18,17 @@
 #include "hw/s390x/css-bridge.h"
 #include "s390-ccw.h"
 
+int s390_ccw_cmd_request(ORB *orb, SCSW *scsw, void *data)
+{
+    S390CCWDevice *cdev = data;
+
+    if (cdev->handle_request) {
+        return cdev->handle_request(orb, scsw, data);
+    } else {
+        return -ENOSYS;
+    }
+}
+
 static void s390_ccw_realize(S390CCWDevice *cdev, Error **errp)
 {
     CcwDevice *ccw_dev = CCW_DEVICE(cdev);
@@ -65,6 +76,7 @@ static void s390_ccw_realize(S390CCWDevice *cdev, Error **errp)
     }
 
     sch->driver_data = cdev;
+    sch->do_subchannel_work = do_subchannel_work_passthrough;
 
     ret = css_sch_build_schib(sch, &cdev->hostid);
     if (ret) {
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index f5c1d98..c4946f4 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -675,6 +675,7 @@ static void virtio_ccw_device_realize(VirtioCcwDevice *dev, Error **errp)
     sch->disable_cb = virtio_sch_disable_cb;
     sch->id.reserved = 0xff;
     sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
+    sch->do_subchannel_work = do_subchannel_work_virtual;
     ccw_dev->sch = sch;
     dev->indicators = NULL;
     dev->revision = -1;
diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
index 2884439..6e0cd86 100644
--- a/include/hw/s390x/css.h
+++ b/include/hw/s390x/css.h
@@ -88,6 +88,7 @@ struct SubchDev {
     /* transport-provided data: */
     int (*ccw_cb) (SubchDev *, CCW1);
     void (*disable_cb)(SubchDev *);
+    int (*do_subchannel_work) (SubchDev *, ORB *);
     SenseId id;
     void *driver_data;
 };
@@ -145,6 +146,9 @@ void css_generate_chp_crws(uint8_t cssid, uint8_t chpid);
 void css_generate_css_crws(uint8_t cssid);
 void css_clear_sei_pending(void);
 void css_adapter_interrupt(uint8_t isc);
+int s390_ccw_cmd_request(ORB *orb, SCSW *scsw, void *data);
+int do_subchannel_work_virtual(SubchDev *sub, ORB *orb);
+int do_subchannel_work_passthrough(SubchDev *sub, ORB *orb);
 
 #define CSS_IO_ADAPTER_VIRTIO 1
 int css_register_io_adapter(uint8_t type, uint8_t isc, bool swap,
diff --git a/target-s390x/ioinst.c b/target-s390x/ioinst.c
index 590bfa4..62a7771 100644
--- a/target-s390x/ioinst.c
+++ b/target-s390x/ioinst.c
@@ -244,6 +244,15 @@ void ioinst_handle_ssch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)
     case -EBUSY:
         cc = 2;
         break;
+    case -EFAULT:
+        /*
+         * TODO:
+         * I'm wondering whether there is something better
+         * to do for us here (like setting some device or
+         * subchannel status).
+         */
+        program_interrupt(env, PGM_ADDRESSING, 4);
+        return;
     case 0:
         cc = 0;
         break;
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 11/12] s390x/css: ccws translation infrastructure
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>

Implement a basic infrastructure of handling channel I/O instruction
interception for passed through subchannels:
1. Branch the code path of instruction interception handling by
   SubChannel type.
2. For a passed-through subchannel, issue the ORB to kernel to do ccw
   translation and perform an I/O operation.
3. Assign different condition code based on the I/O result, or
   trigger a program check.

Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
---
 hw/s390x/css.c         | 88 ++++++++++++++++++++++++++++++++++++++++++++++----
 hw/s390x/s390-ccw.c    | 12 +++++++
 hw/s390x/virtio-ccw.c  |  1 +
 include/hw/s390x/css.h |  4 +++
 target-s390x/ioinst.c  |  9 ++++++
 5 files changed, 108 insertions(+), 6 deletions(-)

diff --git a/hw/s390x/css.c b/hw/s390x/css.c
index c3a323e..0e3b0ae 100644
--- a/hw/s390x/css.c
+++ b/hw/s390x/css.c
@@ -500,7 +500,7 @@ static int css_interpret_ccw(SubchDev *sch, hwaddr ccw_addr,
     return ret;
 }
 
-static void sch_handle_start_func(SubchDev *sch, ORB *orb)
+static void sch_handle_start_func_virtual(SubchDev *sch, ORB *orb)
 {
 
     PMCW *p = &sch->curr_status.pmcw;
@@ -599,13 +599,57 @@ static void sch_handle_start_func(SubchDev *sch, ORB *orb)
 
 }
 
+static int sch_handle_start_func_passthrough(SubchDev *sch, ORB *orb)
+{
+
+    PMCW *p = &sch->curr_status.pmcw;
+    SCSW *s = &sch->curr_status.scsw;
+    int ret;
+
+    if (!(s->ctrl & SCSW_ACTL_SUSP)) {
+        assert(orb != NULL);
+        p->intparm = orb->intparm;
+    }
+
+    /*
+     * Only support prefetch enable mode.
+     * Only support 64bit addressing idal.
+     */
+    if (!(orb->ctrl0 & ORB_CTRL0_MASK_PFCH) ||
+        !(orb->ctrl0 & ORB_CTRL0_MASK_C64)) {
+        return -EINVAL;
+    }
+
+    ret = s390_ccw_cmd_request(orb, s, sch->driver_data);
+    switch (ret) {
+    /* Currently we don't update control block and just return the cc code. */
+    case 0:
+        break;
+    case -EBUSY:
+        break;
+    case -ENODEV:
+        break;
+    case -EACCES:
+        /* Let's reflect an inaccessible host device by cc 3. */
+        ret = -ENODEV;
+        break;
+    default:
+       /* All other return codes will trigger a program check,
+        * or set cc to 1.
+        */
+       break;
+    };
+
+    return ret;
+}
+
 /*
  * On real machines, this would run asynchronously to the main vcpus.
  * We might want to make some parts of the ssch handling (interpreting
  * read/writes) asynchronous later on if we start supporting more than
  * our current very simple devices.
  */
-static void do_subchannel_work(SubchDev *sch, ORB *orb)
+int do_subchannel_work_virtual(SubchDev *sch, ORB *orb)
 {
 
     SCSW *s = &sch->curr_status.scsw;
@@ -616,12 +660,45 @@ static void do_subchannel_work(SubchDev *sch, ORB *orb)
         sch_handle_halt_func(sch);
     } else if (s->ctrl & SCSW_FCTL_START_FUNC) {
         /* Triggered by both ssch and rsch. */
-        sch_handle_start_func(sch, orb);
+        sch_handle_start_func_virtual(sch, orb);
     } else {
         /* Cannot happen. */
-        return;
+        return 0;
     }
     css_inject_io_interrupt(sch);
+    return 0;
+}
+
+int do_subchannel_work_passthrough(SubchDev *sch, ORB *orb)
+{
+    int ret;
+    SCSW *s = &sch->curr_status.scsw;
+
+    if (s->ctrl & SCSW_FCTL_CLEAR_FUNC) {
+        /* TODO: Clear handling */
+        sch_handle_clear_func(sch);
+        ret = 0;
+    } else if (s->ctrl & SCSW_FCTL_HALT_FUNC) {
+        /* TODO: Halt handling */
+        sch_handle_halt_func(sch);
+        ret = 0;
+    } else if (s->ctrl & SCSW_FCTL_START_FUNC) {
+        ret = sch_handle_start_func_passthrough(sch, orb);
+    } else {
+        /* Cannot happen. */
+        return -ENODEV;
+    }
+
+    return ret;
+}
+
+static int do_subchannel_work(SubchDev *sch, ORB *orb)
+{
+    if (sch->do_subchannel_work) {
+        return sch->do_subchannel_work(sch, orb);
+    } else {
+        return -EINVAL;
+    }
 }
 
 static void copy_pmcw_to_guest(PMCW *dest, const PMCW *src)
@@ -940,8 +1017,7 @@ int css_do_ssch(SubchDev *sch, ORB *orb)
     s->ctrl |= (SCSW_FCTL_START_FUNC | SCSW_ACTL_START_PEND);
     s->flags &= ~SCSW_FLAGS_MASK_PNO;
 
-    do_subchannel_work(sch, orb);
-    ret = 0;
+    ret = do_subchannel_work(sch, orb);
 
 out:
     return ret;
diff --git a/hw/s390x/s390-ccw.c b/hw/s390x/s390-ccw.c
index 6881fc6..58fb916 100644
--- a/hw/s390x/s390-ccw.c
+++ b/hw/s390x/s390-ccw.c
@@ -18,6 +18,17 @@
 #include "hw/s390x/css-bridge.h"
 #include "s390-ccw.h"
 
+int s390_ccw_cmd_request(ORB *orb, SCSW *scsw, void *data)
+{
+    S390CCWDevice *cdev = data;
+
+    if (cdev->handle_request) {
+        return cdev->handle_request(orb, scsw, data);
+    } else {
+        return -ENOSYS;
+    }
+}
+
 static void s390_ccw_realize(S390CCWDevice *cdev, Error **errp)
 {
     CcwDevice *ccw_dev = CCW_DEVICE(cdev);
@@ -65,6 +76,7 @@ static void s390_ccw_realize(S390CCWDevice *cdev, Error **errp)
     }
 
     sch->driver_data = cdev;
+    sch->do_subchannel_work = do_subchannel_work_passthrough;
 
     ret = css_sch_build_schib(sch, &cdev->hostid);
     if (ret) {
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index f5c1d98..c4946f4 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -675,6 +675,7 @@ static void virtio_ccw_device_realize(VirtioCcwDevice *dev, Error **errp)
     sch->disable_cb = virtio_sch_disable_cb;
     sch->id.reserved = 0xff;
     sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
+    sch->do_subchannel_work = do_subchannel_work_virtual;
     ccw_dev->sch = sch;
     dev->indicators = NULL;
     dev->revision = -1;
diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h
index 2884439..6e0cd86 100644
--- a/include/hw/s390x/css.h
+++ b/include/hw/s390x/css.h
@@ -88,6 +88,7 @@ struct SubchDev {
     /* transport-provided data: */
     int (*ccw_cb) (SubchDev *, CCW1);
     void (*disable_cb)(SubchDev *);
+    int (*do_subchannel_work) (SubchDev *, ORB *);
     SenseId id;
     void *driver_data;
 };
@@ -145,6 +146,9 @@ void css_generate_chp_crws(uint8_t cssid, uint8_t chpid);
 void css_generate_css_crws(uint8_t cssid);
 void css_clear_sei_pending(void);
 void css_adapter_interrupt(uint8_t isc);
+int s390_ccw_cmd_request(ORB *orb, SCSW *scsw, void *data);
+int do_subchannel_work_virtual(SubchDev *sub, ORB *orb);
+int do_subchannel_work_passthrough(SubchDev *sub, ORB *orb);
 
 #define CSS_IO_ADAPTER_VIRTIO 1
 int css_register_io_adapter(uint8_t type, uint8_t isc, bool swap,
diff --git a/target-s390x/ioinst.c b/target-s390x/ioinst.c
index 590bfa4..62a7771 100644
--- a/target-s390x/ioinst.c
+++ b/target-s390x/ioinst.c
@@ -244,6 +244,15 @@ void ioinst_handle_ssch(S390CPU *cpu, uint64_t reg1, uint32_t ipb)
     case -EBUSY:
         cc = 2;
         break;
+    case -EFAULT:
+        /*
+         * TODO:
+         * I'm wondering whether there is something better
+         * to do for us here (like setting some device or
+         * subchannel status).
+         */
+        program_interrupt(env, PGM_ADDRESSING, 4);
+        return;
     case 0:
         cc = 0;
         break;
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH RFC v2 12/12] vfio/ccw: update sense data if a unit check is pending
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-12  7:25   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

Concurrent-sense data is currently not delivered. This patch stores
the concurrent-sense data to the subchannel if a unit check is pending
and the concurrent-sense bit is enabled. Then a TSCH can retreive the
right IRB data back to the guest.

Signed-off-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
---
 hw/vfio/ccw.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index 34c719a..cc745b0 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -94,6 +94,7 @@ static void vfio_ccw_io_notifier_handler(void *opaque)
     CcwDevice *ccw_dev = CCW_DEVICE(cdev);
     SubchDev *sch = ccw_dev->sch;
     SCSW *s = &sch->curr_status.scsw;
+    PMCW *p = &sch->curr_status.pmcw;
     IRB irb;
 
     if (!event_notifier_test_and_clear(&vcdev->io_notifier)) {
@@ -133,6 +134,12 @@ static void vfio_ccw_io_notifier_handler(void *opaque)
     /* Update control block via irb. */
     copy_scsw_to_guest(s, &irb.scsw);
 
+    /* If a uint check is pending, copy sense data. */
+    if ((s->dstat & SCSW_DSTAT_UNIT_CHECK) &&
+        (p->chars & PMCW_CHARS_MASK_CSENSE)) {
+        memcpy(sch->sense_data, irb.ecw, sizeof(irb.ecw));
+    }
+
 read_err:
     css_inject_io_interrupt(sch);
 }
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [Qemu-devel] [PATCH RFC v2 12/12] vfio/ccw: update sense data if a unit check is pending
@ 2017-01-12  7:25   ` Dong Jia Shi
  0 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-12  7:25 UTC (permalink / raw)
  To: kvm, linux-s390, qemu-devel
  Cc: bjsdjshi, renxiaof, cornelia.huck, borntraeger, agraf,
	alex.williamson, pmorel, pasic, wkywang

Concurrent-sense data is currently not delivered. This patch stores
the concurrent-sense data to the subchannel if a unit check is pending
and the concurrent-sense bit is enabled. Then a TSCH can retreive the
right IRB data back to the guest.

Signed-off-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
---
 hw/vfio/ccw.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index 34c719a..cc745b0 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -94,6 +94,7 @@ static void vfio_ccw_io_notifier_handler(void *opaque)
     CcwDevice *ccw_dev = CCW_DEVICE(cdev);
     SubchDev *sch = ccw_dev->sch;
     SCSW *s = &sch->curr_status.scsw;
+    PMCW *p = &sch->curr_status.pmcw;
     IRB irb;
 
     if (!event_notifier_test_and_clear(&vcdev->io_notifier)) {
@@ -133,6 +134,12 @@ static void vfio_ccw_io_notifier_handler(void *opaque)
     /* Update control block via irb. */
     copy_scsw_to_guest(s, &irb.scsw);
 
+    /* If a uint check is pending, copy sense data. */
+    if ((s->dstat & SCSW_DSTAT_UNIT_CHECK) &&
+        (p->chars & PMCW_CHARS_MASK_CSENSE)) {
+        memcpy(sch->sense_data, irb.ecw, sizeof(irb.ecw));
+    }
+
 read_err:
     css_inject_io_interrupt(sch);
 }
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 00/12] basic channel IO passthrough infrastructure based on vfio
  2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
  (?)
@ 2017-01-12  8:00   ` no-reply
  -1 siblings, 0 replies; 55+ messages in thread
From: no-reply @ 2017-01-12  8:00 UTC (permalink / raw)
  Cc: famz, kvm, linux-s390, qemu-devel, pasic, pmorel, borntraeger,
	alex.williamson, renxiaof, wkywang, cornelia.huck, bjsdjshi,
	agraf

Hi,

Your series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20170112072513.98411-1-bjsdjshi@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH RFC v2 00/12] basic channel IO passthrough infrastructure based on vfio

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]         patchew/20170112072513.98411-1-bjsdjshi@linux.vnet.ibm.com -> patchew/20170112072513.98411-1-bjsdjshi@linux.vnet.ibm.com
Switched to a new branch 'test'
694b0ee vfio/ccw: update sense data if a unit check is pending
4afcfb2 s390x/css: ccws translation infrastructure
cba9095 s390x/css: introduce and realize ccw-request callback
4f8d64a vfio/ccw: get irqs info and set the eventfd fd
96bc1b5 vfio/ccw: get io region info
90691ec vfio/ccw: vfio based subchannel passthrough driver
b40a567 s390x/css: device support for s390-ccw passthrough
0d68f21 s390x/css: realize css_create_sch
01179e5 s390x/css: realize css_sch_build_schib
1564f88 s390x/css: add s390-map-css machine option
79b5e81 vfio: linux-headers update for vfio-ccw
52b52ad update-linux-headers: add asm-s390/vfio_ccw.h

=== OUTPUT BEGIN ===
Checking PATCH 1/12: update-linux-headers: add asm-s390/vfio_ccw.h...
ERROR: line over 90 characters
#19: FILE: scripts/update-linux-headers.sh:94:
+        cp_portable "$tmpdir/include/asm/vfio_ccw.h" "$output/include/standard-headers/asm-s390/"

total: 1 errors, 0 warnings, 7 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 2/12: vfio: linux-headers update for vfio-ccw...
Checking PATCH 3/12: s390x/css: add s390-map-css machine option...
Checking PATCH 4/12: s390x/css: realize css_sch_build_schib...
WARNING: line over 80 characters
#129: FILE: hw/s390x/css.c:1980:
+static int css_sch_get_chpid_type(uint8_t chpid, uint32_t *type, CssDevId *dev_id)

total: 0 errors, 1 warnings, 233 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 5/12: s390x/css: realize css_create_sch...
Checking PATCH 6/12: s390x/css: device support for s390-ccw passthrough...
Checking PATCH 7/12: vfio/ccw: vfio based subchannel passthrough driver...
Checking PATCH 8/12: vfio/ccw: get io region info...
Checking PATCH 9/12: vfio/ccw: get irqs info and set the eventfd fd...
Checking PATCH 10/12: s390x/css: introduce and realize ccw-request callback...
ERROR: space required after that ',' (ctx:VxV)
#81: FILE: hw/vfio/ccw.c:73:
+        error_report("vfio-ccw: wirte I/O region failed with errno=%d",errno);
                                                                       ^

total: 1 errors, 0 warnings, 126 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 11/12: s390x/css: ccws translation infrastructure...
Checking PATCH 12/12: vfio/ccw: update sense data if a unit check is pending...
=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 00/12] basic channel IO passthrough infrastructure based on vfio
@ 2017-01-12  8:00   ` no-reply
  0 siblings, 0 replies; 55+ messages in thread
From: no-reply @ 2017-01-12  8:00 UTC (permalink / raw)
  To: bjsdjshi
  Cc: famz, kvm, linux-s390, qemu-devel, pasic, pmorel, borntraeger,
	alex.williamson, renxiaof, wkywang, cornelia.huck, bjsdjshi,
	agraf

Hi,

Your series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20170112072513.98411-1-bjsdjshi@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH RFC v2 00/12] basic channel IO passthrough infrastructure based on vfio

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]         patchew/20170112072513.98411-1-bjsdjshi@linux.vnet.ibm.com -> patchew/20170112072513.98411-1-bjsdjshi@linux.vnet.ibm.com
Switched to a new branch 'test'
694b0ee vfio/ccw: update sense data if a unit check is pending
4afcfb2 s390x/css: ccws translation infrastructure
cba9095 s390x/css: introduce and realize ccw-request callback
4f8d64a vfio/ccw: get irqs info and set the eventfd fd
96bc1b5 vfio/ccw: get io region info
90691ec vfio/ccw: vfio based subchannel passthrough driver
b40a567 s390x/css: device support for s390-ccw passthrough
0d68f21 s390x/css: realize css_create_sch
01179e5 s390x/css: realize css_sch_build_schib
1564f88 s390x/css: add s390-map-css machine option
79b5e81 vfio: linux-headers update for vfio-ccw
52b52ad update-linux-headers: add asm-s390/vfio_ccw.h

=== OUTPUT BEGIN ===
Checking PATCH 1/12: update-linux-headers: add asm-s390/vfio_ccw.h...
ERROR: line over 90 characters
#19: FILE: scripts/update-linux-headers.sh:94:
+        cp_portable "$tmpdir/include/asm/vfio_ccw.h" "$output/include/standard-headers/asm-s390/"

total: 1 errors, 0 warnings, 7 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 2/12: vfio: linux-headers update for vfio-ccw...
Checking PATCH 3/12: s390x/css: add s390-map-css machine option...
Checking PATCH 4/12: s390x/css: realize css_sch_build_schib...
WARNING: line over 80 characters
#129: FILE: hw/s390x/css.c:1980:
+static int css_sch_get_chpid_type(uint8_t chpid, uint32_t *type, CssDevId *dev_id)

total: 0 errors, 1 warnings, 233 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 5/12: s390x/css: realize css_create_sch...
Checking PATCH 6/12: s390x/css: device support for s390-ccw passthrough...
Checking PATCH 7/12: vfio/ccw: vfio based subchannel passthrough driver...
Checking PATCH 8/12: vfio/ccw: get io region info...
Checking PATCH 9/12: vfio/ccw: get irqs info and set the eventfd fd...
Checking PATCH 10/12: s390x/css: introduce and realize ccw-request callback...
ERROR: space required after that ',' (ctx:VxV)
#81: FILE: hw/vfio/ccw.c:73:
+        error_report("vfio-ccw: wirte I/O region failed with errno=%d",errno);
                                                                       ^

total: 1 errors, 0 warnings, 126 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 11/12: s390x/css: ccws translation infrastructure...
Checking PATCH 12/12: vfio/ccw: update sense data if a unit check is pending...
=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 00/12] basic channel IO passthrough infrastructure based on vfio
@ 2017-01-12  8:00   ` no-reply
  0 siblings, 0 replies; 55+ messages in thread
From: no-reply @ 2017-01-12  8:00 UTC (permalink / raw)
  To: bjsdjshi
  Cc: famz, kvm, linux-s390, qemu-devel, pasic, pmorel, borntraeger,
	alex.williamson, renxiaof, wkywang, cornelia.huck, agraf

Hi,

Your series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20170112072513.98411-1-bjsdjshi@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH RFC v2 00/12] basic channel IO passthrough infrastructure based on vfio

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
    echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag]         patchew/20170112072513.98411-1-bjsdjshi@linux.vnet.ibm.com -> patchew/20170112072513.98411-1-bjsdjshi@linux.vnet.ibm.com
Switched to a new branch 'test'
694b0ee vfio/ccw: update sense data if a unit check is pending
4afcfb2 s390x/css: ccws translation infrastructure
cba9095 s390x/css: introduce and realize ccw-request callback
4f8d64a vfio/ccw: get irqs info and set the eventfd fd
96bc1b5 vfio/ccw: get io region info
90691ec vfio/ccw: vfio based subchannel passthrough driver
b40a567 s390x/css: device support for s390-ccw passthrough
0d68f21 s390x/css: realize css_create_sch
01179e5 s390x/css: realize css_sch_build_schib
1564f88 s390x/css: add s390-map-css machine option
79b5e81 vfio: linux-headers update for vfio-ccw
52b52ad update-linux-headers: add asm-s390/vfio_ccw.h

=== OUTPUT BEGIN ===
Checking PATCH 1/12: update-linux-headers: add asm-s390/vfio_ccw.h...
ERROR: line over 90 characters
#19: FILE: scripts/update-linux-headers.sh:94:
+        cp_portable "$tmpdir/include/asm/vfio_ccw.h" "$output/include/standard-headers/asm-s390/"

total: 1 errors, 0 warnings, 7 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 2/12: vfio: linux-headers update for vfio-ccw...
Checking PATCH 3/12: s390x/css: add s390-map-css machine option...
Checking PATCH 4/12: s390x/css: realize css_sch_build_schib...
WARNING: line over 80 characters
#129: FILE: hw/s390x/css.c:1980:
+static int css_sch_get_chpid_type(uint8_t chpid, uint32_t *type, CssDevId *dev_id)

total: 0 errors, 1 warnings, 233 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
Checking PATCH 5/12: s390x/css: realize css_create_sch...
Checking PATCH 6/12: s390x/css: device support for s390-ccw passthrough...
Checking PATCH 7/12: vfio/ccw: vfio based subchannel passthrough driver...
Checking PATCH 8/12: vfio/ccw: get io region info...
Checking PATCH 9/12: vfio/ccw: get irqs info and set the eventfd fd...
Checking PATCH 10/12: s390x/css: introduce and realize ccw-request callback...
ERROR: space required after that ',' (ctx:VxV)
#81: FILE: hw/vfio/ccw.c:73:
+        error_report("vfio-ccw: wirte I/O region failed with errno=%d",errno);
                                                                       ^

total: 1 errors, 0 warnings, 126 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

Checking PATCH 11/12: s390x/css: ccws translation infrastructure...
Checking PATCH 12/12: vfio/ccw: update sense data if a unit check is pending...
=== OUTPUT END ===

Test command exited with code: 1


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@freelists.org

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
  2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-17 21:51     ` Alex Williamson
  -1 siblings, 0 replies; 55+ messages in thread
From: Alex Williamson @ 2017-01-17 21:51 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: kvm, linux-s390, qemu-devel, renxiaof, cornelia.huck,
	borntraeger, agraf, pmorel, pasic, wkywang

On Thu, 12 Jan 2017 08:25:03 +0100
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> 
> This is a placeholder for a linux-headers update.
> 
> Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> ---
>  include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
>  linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
>  2 files changed, 45 insertions(+)
>  create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h
> 
> diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
> new file mode 100644
> index 0000000..cddc09b
> --- /dev/null
> +++ b/include/standard-headers/asm-s390/vfio_ccw.h
> @@ -0,0 +1,28 @@
> +/*
> + * Interfaces for vfio-ccw
> + *
> + * Copyright IBM Corp. 2017
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License (version 2 only)
> + * as published by the Free Software Foundation.
> + *
> + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> + */
> +
> +#ifndef _VFIO_CCW_H_
> +#define _VFIO_CCW_H_
> +
> +#include "standard-headers/linux/types.h"
> +
> +struct ccw_io_region {
> +#define ORB_AREA_SIZE 12
> +	uint8_t  orb_area[ORB_AREA_SIZE];
> +#define SCSW_AREA_SIZE 12
> +	uint8_t  scsw_area[SCSW_AREA_SIZE];
> +#define IRB_AREA_SIZE 96
> +	uint8_t  irb_area[IRB_AREA_SIZE];
> +	uint32_t ret_code;
> +} QEMU_PACKED;
> +
> +#endif

This is really part of the uapi for the vfio-ccw mdev device, isn't it?
Should it really be buried in asm-s390 in the kernel?

> diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
> index 759b850..b09d247 100644
> --- a/linux-headers/linux/vfio.h
> +++ b/linux-headers/linux/vfio.h
> @@ -198,6 +198,7 @@ struct vfio_device_info {
>  #define VFIO_DEVICE_FLAGS_PCI	(1 << 1)	/* vfio-pci device */
>  #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2)	/* vfio-platform device */
>  #define VFIO_DEVICE_FLAGS_AMBA  (1 << 3)	/* vfio-amba device */
> +#define VFIO_DEVICE_FLAGS_CCW   (1 << 4)	/* vfio-ccw device */
>  	__u32	num_regions;	/* Max region index + 1 */
>  	__u32	num_irqs;	/* Max IRQ index + 1 */
>  };
> @@ -436,6 +437,22 @@ enum {
>  	VFIO_PCI_NUM_IRQS
>  };
>  
> +/*
> + * The VFIO-CCW bus driver makes use of the following fixed region and
> + * IRQ index mapping.  Unimplemented regions return a size of zero.
> + * Unimplemented IRQ types return a count of zero.
> + */
> +
> +enum {
> +        VFIO_CCW_CONFIG_REGION_INDEX,
> +        VFIO_CCW_NUM_REGIONS
> +};
> +
> +enum {
> +        VFIO_CCW_IO_IRQ_INDEX,
> +        VFIO_CCW_NUM_IRQS
> +};
> +
>  /**
>   * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IORW(VFIO_TYPE, VFIO_BASE + 12,
>   *					      struct vfio_pci_hot_reset_info)

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
@ 2017-01-17 21:51     ` Alex Williamson
  0 siblings, 0 replies; 55+ messages in thread
From: Alex Williamson @ 2017-01-17 21:51 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: kvm, linux-s390, qemu-devel, renxiaof, cornelia.huck,
	borntraeger, agraf, pmorel, pasic, wkywang

On Thu, 12 Jan 2017 08:25:03 +0100
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> 
> This is a placeholder for a linux-headers update.
> 
> Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> ---
>  include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
>  linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
>  2 files changed, 45 insertions(+)
>  create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h
> 
> diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
> new file mode 100644
> index 0000000..cddc09b
> --- /dev/null
> +++ b/include/standard-headers/asm-s390/vfio_ccw.h
> @@ -0,0 +1,28 @@
> +/*
> + * Interfaces for vfio-ccw
> + *
> + * Copyright IBM Corp. 2017
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License (version 2 only)
> + * as published by the Free Software Foundation.
> + *
> + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> + */
> +
> +#ifndef _VFIO_CCW_H_
> +#define _VFIO_CCW_H_
> +
> +#include "standard-headers/linux/types.h"
> +
> +struct ccw_io_region {
> +#define ORB_AREA_SIZE 12
> +	uint8_t  orb_area[ORB_AREA_SIZE];
> +#define SCSW_AREA_SIZE 12
> +	uint8_t  scsw_area[SCSW_AREA_SIZE];
> +#define IRB_AREA_SIZE 96
> +	uint8_t  irb_area[IRB_AREA_SIZE];
> +	uint32_t ret_code;
> +} QEMU_PACKED;
> +
> +#endif

This is really part of the uapi for the vfio-ccw mdev device, isn't it?
Should it really be buried in asm-s390 in the kernel?

> diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
> index 759b850..b09d247 100644
> --- a/linux-headers/linux/vfio.h
> +++ b/linux-headers/linux/vfio.h
> @@ -198,6 +198,7 @@ struct vfio_device_info {
>  #define VFIO_DEVICE_FLAGS_PCI	(1 << 1)	/* vfio-pci device */
>  #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2)	/* vfio-platform device */
>  #define VFIO_DEVICE_FLAGS_AMBA  (1 << 3)	/* vfio-amba device */
> +#define VFIO_DEVICE_FLAGS_CCW   (1 << 4)	/* vfio-ccw device */
>  	__u32	num_regions;	/* Max region index + 1 */
>  	__u32	num_irqs;	/* Max IRQ index + 1 */
>  };
> @@ -436,6 +437,22 @@ enum {
>  	VFIO_PCI_NUM_IRQS
>  };
>  
> +/*
> + * The VFIO-CCW bus driver makes use of the following fixed region and
> + * IRQ index mapping.  Unimplemented regions return a size of zero.
> + * Unimplemented IRQ types return a count of zero.
> + */
> +
> +enum {
> +        VFIO_CCW_CONFIG_REGION_INDEX,
> +        VFIO_CCW_NUM_REGIONS
> +};
> +
> +enum {
> +        VFIO_CCW_IO_IRQ_INDEX,
> +        VFIO_CCW_NUM_IRQS
> +};
> +
>  /**
>   * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IORW(VFIO_TYPE, VFIO_BASE + 12,
>   *					      struct vfio_pci_hot_reset_info)

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 07/12] vfio/ccw: vfio based subchannel passthrough driver
  2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-17 22:49     ` Alex Williamson
  -1 siblings, 0 replies; 55+ messages in thread
From: Alex Williamson @ 2017-01-17 22:49 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: linux-s390, pasic, kvm, pmorel, qemu-devel, borntraeger,
	renxiaof, wkywang, cornelia.huck, agraf

On Thu, 12 Jan 2017 08:25:08 +0100
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> 
> We use the IOMMU_TYPE1 of VFIO to realize the subchannels
> passthrough, implement a vfio based subchannels passthrough
> driver called "vfio-ccw".
> 
> Support qemu parameters in the style of:
> "-device vfio-ccw,id=xx,hostid=xx(,guestid=xx),mdevid=xx"

Why not adopt the same syntax as vfio-pci with mdev devices,
sysfsdev=%s where %s is a path to the mdev device in sysfs, which can
be /sys/bus/mdev/devices/$UUID or as you create from the hostid
below /sys/bus/css/devices/%x.%x.%04x/$UUID.  It seems if we know where
to find the mdev device then we can determine the parent information on
our own through sysfs.

> Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> ---
>  default-configs/s390x-softmmu.mak |   1 +
>  hw/s390x/s390-ccw.h               |   1 +
>  hw/vfio/Makefile.objs             |   1 +
>  hw/vfio/ccw.c                     | 209 ++++++++++++++++++++++++++++++++++++++
>  include/hw/vfio/vfio-common.h     |   1 +
>  5 files changed, 213 insertions(+)
>  create mode 100644 hw/vfio/ccw.c
> 
> diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-softmmu.mak
> index 36e15de..5576b0a 100644
> --- a/default-configs/s390x-softmmu.mak
> +++ b/default-configs/s390x-softmmu.mak
> @@ -4,4 +4,5 @@ CONFIG_VIRTIO=y
>  CONFIG_SCLPCONSOLE=y
>  CONFIG_S390_FLIC=y
>  CONFIG_S390_FLIC_KVM=$(CONFIG_KVM)
> +CONFIG_VFIO_CCW=$(CONFIG_LINUX)
>  CONFIG_WDT_DIAG288=y
> diff --git a/hw/s390x/s390-ccw.h b/hw/s390x/s390-ccw.h
> index 9ced8cb..1fa4a97 100644
> --- a/hw/s390x/s390-ccw.h
> +++ b/hw/s390x/s390-ccw.h
> @@ -26,6 +26,7 @@
>  typedef struct S390CCWDevice {
>      CcwDevice parent_obj;
>      CssDevId hostid;
> +    char *mdevid;
>  } S390CCWDevice;
>  
>  typedef struct S390CCWDeviceClass {
> diff --git a/hw/vfio/Makefile.objs b/hw/vfio/Makefile.objs
> index c25e32b..4c3a462 100644
> --- a/hw/vfio/Makefile.objs
> +++ b/hw/vfio/Makefile.objs
> @@ -1,6 +1,7 @@
>  ifeq ($(CONFIG_LINUX), y)
>  obj-$(CONFIG_SOFTMMU) += common.o
>  obj-$(CONFIG_PCI) += pci.o pci-quirks.o
> +obj-$(CONFIG_VFIO_CCW) += ccw.o
>  obj-$(CONFIG_SOFTMMU) += platform.o
>  obj-$(CONFIG_SOFTMMU) += calxeda-xgmac.o
>  obj-$(CONFIG_SOFTMMU) += amd-xgbe.o
> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> new file mode 100644
> index 0000000..881010b
> --- /dev/null
> +++ b/hw/vfio/ccw.c
> @@ -0,0 +1,209 @@
> +/*
> + * vfio based subchannel assignment support
> + *
> + * Copyright 2017 IBM Corp.
> + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> + *            Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> + *            Pierre Morel <pmorel@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or(at
> + * your option) any version. See the COPYING file in the top-level
> + * directory.
> + */
> +
> +#include <linux/vfio.h>
> +#include <sys/ioctl.h>
> +
> +#include "qemu/osdep.h"
> +#include "qapi/error.h"
> +#include "hw/sysbus.h"
> +#include "hw/vfio/vfio.h"
> +#include "hw/vfio/vfio-common.h"
> +#include "hw/s390x/s390-ccw.h"
> +#include "hw/s390x/ccw-device.h"
> +
> +#define TYPE_VFIO_CCW "vfio-ccw"
> +typedef struct VFIOCCWDevice {
> +    S390CCWDevice cdev;
> +    VFIODevice vdev;
> +} VFIOCCWDevice;
> +
> +static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> +{
> +    vdev->needs_reset = false;
> +}
> +
> +/*
> + * We don't need vfio_hot_reset_multi and vfio_eoi operationis for
> + * vfio_ccw device now.
> + */
> +struct VFIODeviceOps vfio_ccw_ops = {
> +    .vfio_compute_needs_reset = vfio_ccw_compute_needs_reset,
> +};
> +
> +static void vfio_ccw_reset(DeviceState *dev)
> +{
> +    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
> +    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
> +    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
> +
> +    ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
> +}
> +
> +static void vfio_put_device(VFIOCCWDevice *vcdev)
> +{
> +    g_free(vcdev->vdev.name);
> +    vfio_put_base_device(&vcdev->vdev);
> +}
> +
> +static VFIOGroup *vfio_ccw_get_group(S390CCWDevice *cdev, char **path,
> +                                     Error **errp)
> +{
> +    struct stat st;
> +    int groupid;
> +    GError *gerror = NULL;
> +
> +    /* Check that host subchannel exists. */
> +    path[0] = g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x",
> +                              cdev->hostid.cssid,
> +                              cdev->hostid.ssid,
> +                              cdev->hostid.devid);
> +    if (stat(path[0], &st) < 0) {
> +        error_setg(errp, "vfio: no such host subchannel %s", path[0]);
> +        return NULL;
> +    }
> +
> +    /* Check that mediated device exists. */
> +    path[1] = g_strdup_printf("%s/%s", path[0], cdev->mdevid);
> +    if (stat(path[0], &st) < 0) {
> +        error_setg(errp, "vfio: no such mediated device %s", path[1]);
> +        return NULL;
> +    }
> +
> +    /* Get the iommu_group patch as the interim variable. */
> +    path[2] = g_strconcat(path[1], "/iommu_group", NULL);
> +
> +    /* Get the link file path of the device iommu_group. */
> +    path[3] = g_file_read_link(path[2], &gerror);
> +    if (!path[3]) {
> +        error_setg(errp, "vfio: error no iommu_group for subchannel");
> +        return NULL;
> +    }
> +
> +    /* Get the device groupid. */
> +    if (sscanf(basename(path[3]), "%d", &groupid) != 1) {
> +        error_setg(errp, "vfio: error reading %s:%m", path[3]);
> +        return NULL;
> +    }
> +
> +    return vfio_get_group(groupid, &address_space_memory, errp);
> +}
> +
> +static void vfio_ccw_put_group(VFIOGroup *group, char **path)
> +{
> +    g_free(path);
> +    vfio_put_group(group);
> +}
> +
> +static void vfio_ccw_realize(DeviceState *dev, Error **errp)
> +{
> +    VFIODevice *vbasedev;
> +    VFIOGroup *group;
> +    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
> +    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
> +    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
> +    S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
> +    char *path[4] = {NULL, NULL, NULL, NULL};
> +
> +    /* Call the class init function for subchannel. */
> +    if (cdc->realize) {
> +        cdc->realize(cdev, errp);
> +        if (*errp) {
> +            return;
> +        }
> +    }
> +
> +    group = vfio_ccw_get_group(cdev, path, errp);
> +    if (!group) {
> +        goto out_group_err;
> +    }
> +
> +    vcdev->vdev.ops = &vfio_ccw_ops;
> +    vcdev->vdev.type = VFIO_DEVICE_TYPE_CCW;
> +    vcdev->vdev.name = g_strdup_printf("%x.%x.%04x", cdev->hostid.cssid,
> +                                       cdev->hostid.ssid, cdev->hostid.devid);
> +    QLIST_FOREACH(vbasedev, &group->device_list, next) {
> +        if (strcmp(vbasedev->name, vcdev->vdev.name) == 0) {
> +            error_setg(errp, "vfio: subchannel %s has already been attached",
> +                       basename(path[0]));
> +            goto out_device_err;
> +        }
> +    }
> +
> +    if (vfio_get_device(group, cdev->mdevid, &vcdev->vdev, errp)) {
> +        goto out_device_err;
> +    }
> +
> +    return;
> +
> +out_device_err:
> +    vfio_ccw_put_group(group, path);
> +out_group_err:
> +    if (cdc->unrealize) {
> +        cdc->unrealize(cdev, errp);
> +    }
> +}
> +
> +static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
> +{
> +    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
> +    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
> +    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
> +    S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
> +    VFIOGroup *group = vcdev->vdev.group;
> +
> +    if (cdc->unrealize) {
> +        cdc->unrealize(cdev, errp);
> +    }
> +
> +    vfio_put_device(vcdev);
> +    vfio_put_group(group);
> +}
> +
> +static Property vfio_ccw_properties[] = {
> +    DEFINE_PROP_CSS_DEV_ID("hostid", VFIOCCWDevice, cdev.hostid),
> +    DEFINE_PROP_CSS_DEV_ID("guestid", VFIOCCWDevice, cdev.parent_obj.bus_id),
> +    DEFINE_PROP_STRING("mdevid", VFIOCCWDevice, cdev.mdevid),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static const VMStateDescription vfio_ccw_vmstate = {
> +    .name = TYPE_VFIO_CCW,
> +    .unmigratable = 1,
> +};
> +
> +static void vfio_ccw_class_init(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +
> +    dc->props = vfio_ccw_properties;
> +    dc->vmsd = &vfio_ccw_vmstate;
> +    dc->desc = "VFIO-based subchannel assignment";
> +    dc->realize = vfio_ccw_realize;
> +    dc->unrealize = vfio_ccw_unrealize;
> +    dc->reset = vfio_ccw_reset;
> +}
> +
> +static const TypeInfo vfio_ccw_info = {
> +    .name = TYPE_VFIO_CCW,
> +    .parent = TYPE_S390_CCW,
> +    .instance_size = sizeof(VFIOCCWDevice),
> +    .class_init = vfio_ccw_class_init,
> +};
> +
> +static void register_vfio_ccw_type(void)
> +{
> +    type_register_static(&vfio_ccw_info);
> +}
> +
> +type_init(register_vfio_ccw_type)
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index c582de1..9521013 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -45,6 +45,7 @@
>  enum {
>      VFIO_DEVICE_TYPE_PCI = 0,
>      VFIO_DEVICE_TYPE_PLATFORM = 1,
> +    VFIO_DEVICE_TYPE_CCW = 2,
>  };
>  
>  typedef struct VFIOMmap {

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 07/12] vfio/ccw: vfio based subchannel passthrough driver
@ 2017-01-17 22:49     ` Alex Williamson
  0 siblings, 0 replies; 55+ messages in thread
From: Alex Williamson @ 2017-01-17 22:49 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: kvm, linux-s390, qemu-devel, renxiaof, cornelia.huck,
	borntraeger, agraf, pmorel, pasic, wkywang

On Thu, 12 Jan 2017 08:25:08 +0100
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> 
> We use the IOMMU_TYPE1 of VFIO to realize the subchannels
> passthrough, implement a vfio based subchannels passthrough
> driver called "vfio-ccw".
> 
> Support qemu parameters in the style of:
> "-device vfio-ccw,id=xx,hostid=xx(,guestid=xx),mdevid=xx"

Why not adopt the same syntax as vfio-pci with mdev devices,
sysfsdev=%s where %s is a path to the mdev device in sysfs, which can
be /sys/bus/mdev/devices/$UUID or as you create from the hostid
below /sys/bus/css/devices/%x.%x.%04x/$UUID.  It seems if we know where
to find the mdev device then we can determine the parent information on
our own through sysfs.

> Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> ---
>  default-configs/s390x-softmmu.mak |   1 +
>  hw/s390x/s390-ccw.h               |   1 +
>  hw/vfio/Makefile.objs             |   1 +
>  hw/vfio/ccw.c                     | 209 ++++++++++++++++++++++++++++++++++++++
>  include/hw/vfio/vfio-common.h     |   1 +
>  5 files changed, 213 insertions(+)
>  create mode 100644 hw/vfio/ccw.c
> 
> diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-softmmu.mak
> index 36e15de..5576b0a 100644
> --- a/default-configs/s390x-softmmu.mak
> +++ b/default-configs/s390x-softmmu.mak
> @@ -4,4 +4,5 @@ CONFIG_VIRTIO=y
>  CONFIG_SCLPCONSOLE=y
>  CONFIG_S390_FLIC=y
>  CONFIG_S390_FLIC_KVM=$(CONFIG_KVM)
> +CONFIG_VFIO_CCW=$(CONFIG_LINUX)
>  CONFIG_WDT_DIAG288=y
> diff --git a/hw/s390x/s390-ccw.h b/hw/s390x/s390-ccw.h
> index 9ced8cb..1fa4a97 100644
> --- a/hw/s390x/s390-ccw.h
> +++ b/hw/s390x/s390-ccw.h
> @@ -26,6 +26,7 @@
>  typedef struct S390CCWDevice {
>      CcwDevice parent_obj;
>      CssDevId hostid;
> +    char *mdevid;
>  } S390CCWDevice;
>  
>  typedef struct S390CCWDeviceClass {
> diff --git a/hw/vfio/Makefile.objs b/hw/vfio/Makefile.objs
> index c25e32b..4c3a462 100644
> --- a/hw/vfio/Makefile.objs
> +++ b/hw/vfio/Makefile.objs
> @@ -1,6 +1,7 @@
>  ifeq ($(CONFIG_LINUX), y)
>  obj-$(CONFIG_SOFTMMU) += common.o
>  obj-$(CONFIG_PCI) += pci.o pci-quirks.o
> +obj-$(CONFIG_VFIO_CCW) += ccw.o
>  obj-$(CONFIG_SOFTMMU) += platform.o
>  obj-$(CONFIG_SOFTMMU) += calxeda-xgmac.o
>  obj-$(CONFIG_SOFTMMU) += amd-xgbe.o
> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> new file mode 100644
> index 0000000..881010b
> --- /dev/null
> +++ b/hw/vfio/ccw.c
> @@ -0,0 +1,209 @@
> +/*
> + * vfio based subchannel assignment support
> + *
> + * Copyright 2017 IBM Corp.
> + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> + *            Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> + *            Pierre Morel <pmorel@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or(at
> + * your option) any version. See the COPYING file in the top-level
> + * directory.
> + */
> +
> +#include <linux/vfio.h>
> +#include <sys/ioctl.h>
> +
> +#include "qemu/osdep.h"
> +#include "qapi/error.h"
> +#include "hw/sysbus.h"
> +#include "hw/vfio/vfio.h"
> +#include "hw/vfio/vfio-common.h"
> +#include "hw/s390x/s390-ccw.h"
> +#include "hw/s390x/ccw-device.h"
> +
> +#define TYPE_VFIO_CCW "vfio-ccw"
> +typedef struct VFIOCCWDevice {
> +    S390CCWDevice cdev;
> +    VFIODevice vdev;
> +} VFIOCCWDevice;
> +
> +static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> +{
> +    vdev->needs_reset = false;
> +}
> +
> +/*
> + * We don't need vfio_hot_reset_multi and vfio_eoi operationis for
> + * vfio_ccw device now.
> + */
> +struct VFIODeviceOps vfio_ccw_ops = {
> +    .vfio_compute_needs_reset = vfio_ccw_compute_needs_reset,
> +};
> +
> +static void vfio_ccw_reset(DeviceState *dev)
> +{
> +    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
> +    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
> +    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
> +
> +    ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
> +}
> +
> +static void vfio_put_device(VFIOCCWDevice *vcdev)
> +{
> +    g_free(vcdev->vdev.name);
> +    vfio_put_base_device(&vcdev->vdev);
> +}
> +
> +static VFIOGroup *vfio_ccw_get_group(S390CCWDevice *cdev, char **path,
> +                                     Error **errp)
> +{
> +    struct stat st;
> +    int groupid;
> +    GError *gerror = NULL;
> +
> +    /* Check that host subchannel exists. */
> +    path[0] = g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x",
> +                              cdev->hostid.cssid,
> +                              cdev->hostid.ssid,
> +                              cdev->hostid.devid);
> +    if (stat(path[0], &st) < 0) {
> +        error_setg(errp, "vfio: no such host subchannel %s", path[0]);
> +        return NULL;
> +    }
> +
> +    /* Check that mediated device exists. */
> +    path[1] = g_strdup_printf("%s/%s", path[0], cdev->mdevid);
> +    if (stat(path[0], &st) < 0) {
> +        error_setg(errp, "vfio: no such mediated device %s", path[1]);
> +        return NULL;
> +    }
> +
> +    /* Get the iommu_group patch as the interim variable. */
> +    path[2] = g_strconcat(path[1], "/iommu_group", NULL);
> +
> +    /* Get the link file path of the device iommu_group. */
> +    path[3] = g_file_read_link(path[2], &gerror);
> +    if (!path[3]) {
> +        error_setg(errp, "vfio: error no iommu_group for subchannel");
> +        return NULL;
> +    }
> +
> +    /* Get the device groupid. */
> +    if (sscanf(basename(path[3]), "%d", &groupid) != 1) {
> +        error_setg(errp, "vfio: error reading %s:%m", path[3]);
> +        return NULL;
> +    }
> +
> +    return vfio_get_group(groupid, &address_space_memory, errp);
> +}
> +
> +static void vfio_ccw_put_group(VFIOGroup *group, char **path)
> +{
> +    g_free(path);
> +    vfio_put_group(group);
> +}
> +
> +static void vfio_ccw_realize(DeviceState *dev, Error **errp)
> +{
> +    VFIODevice *vbasedev;
> +    VFIOGroup *group;
> +    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
> +    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
> +    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
> +    S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
> +    char *path[4] = {NULL, NULL, NULL, NULL};
> +
> +    /* Call the class init function for subchannel. */
> +    if (cdc->realize) {
> +        cdc->realize(cdev, errp);
> +        if (*errp) {
> +            return;
> +        }
> +    }
> +
> +    group = vfio_ccw_get_group(cdev, path, errp);
> +    if (!group) {
> +        goto out_group_err;
> +    }
> +
> +    vcdev->vdev.ops = &vfio_ccw_ops;
> +    vcdev->vdev.type = VFIO_DEVICE_TYPE_CCW;
> +    vcdev->vdev.name = g_strdup_printf("%x.%x.%04x", cdev->hostid.cssid,
> +                                       cdev->hostid.ssid, cdev->hostid.devid);
> +    QLIST_FOREACH(vbasedev, &group->device_list, next) {
> +        if (strcmp(vbasedev->name, vcdev->vdev.name) == 0) {
> +            error_setg(errp, "vfio: subchannel %s has already been attached",
> +                       basename(path[0]));
> +            goto out_device_err;
> +        }
> +    }
> +
> +    if (vfio_get_device(group, cdev->mdevid, &vcdev->vdev, errp)) {
> +        goto out_device_err;
> +    }
> +
> +    return;
> +
> +out_device_err:
> +    vfio_ccw_put_group(group, path);
> +out_group_err:
> +    if (cdc->unrealize) {
> +        cdc->unrealize(cdev, errp);
> +    }
> +}
> +
> +static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
> +{
> +    CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
> +    S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
> +    VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
> +    S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
> +    VFIOGroup *group = vcdev->vdev.group;
> +
> +    if (cdc->unrealize) {
> +        cdc->unrealize(cdev, errp);
> +    }
> +
> +    vfio_put_device(vcdev);
> +    vfio_put_group(group);
> +}
> +
> +static Property vfio_ccw_properties[] = {
> +    DEFINE_PROP_CSS_DEV_ID("hostid", VFIOCCWDevice, cdev.hostid),
> +    DEFINE_PROP_CSS_DEV_ID("guestid", VFIOCCWDevice, cdev.parent_obj.bus_id),
> +    DEFINE_PROP_STRING("mdevid", VFIOCCWDevice, cdev.mdevid),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static const VMStateDescription vfio_ccw_vmstate = {
> +    .name = TYPE_VFIO_CCW,
> +    .unmigratable = 1,
> +};
> +
> +static void vfio_ccw_class_init(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +
> +    dc->props = vfio_ccw_properties;
> +    dc->vmsd = &vfio_ccw_vmstate;
> +    dc->desc = "VFIO-based subchannel assignment";
> +    dc->realize = vfio_ccw_realize;
> +    dc->unrealize = vfio_ccw_unrealize;
> +    dc->reset = vfio_ccw_reset;
> +}
> +
> +static const TypeInfo vfio_ccw_info = {
> +    .name = TYPE_VFIO_CCW,
> +    .parent = TYPE_S390_CCW,
> +    .instance_size = sizeof(VFIOCCWDevice),
> +    .class_init = vfio_ccw_class_init,
> +};
> +
> +static void register_vfio_ccw_type(void)
> +{
> +    type_register_static(&vfio_ccw_info);
> +}
> +
> +type_init(register_vfio_ccw_type)
> diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> index c582de1..9521013 100644
> --- a/include/hw/vfio/vfio-common.h
> +++ b/include/hw/vfio/vfio-common.h
> @@ -45,6 +45,7 @@
>  enum {
>      VFIO_DEVICE_TYPE_PCI = 0,
>      VFIO_DEVICE_TYPE_PLATFORM = 1,
> +    VFIO_DEVICE_TYPE_CCW = 2,
>  };
>  
>  typedef struct VFIOMmap {

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 08/12] vfio/ccw: get io region info
  2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-17 22:49     ` Alex Williamson
  -1 siblings, 0 replies; 55+ messages in thread
From: Alex Williamson @ 2017-01-17 22:49 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: linux-s390, pasic, kvm, pmorel, qemu-devel, borntraeger,
	renxiaof, wkywang, cornelia.huck, agraf

On Thu, 12 Jan 2017 08:25:09 +0100
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> vfio-ccw provides an MMIO region for I/O operations. We fetch its
> information via ioctls here, then we can use it performing I/O
> instructions and retrieving I/O results later on.
> 
> Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> ---
>  hw/vfio/ccw.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> index 881010b..93394c2 100644
> --- a/hw/vfio/ccw.c
> +++ b/hw/vfio/ccw.c
> @@ -21,11 +21,15 @@
>  #include "hw/vfio/vfio-common.h"
>  #include "hw/s390x/s390-ccw.h"
>  #include "hw/s390x/ccw-device.h"
> +#include "standard-headers/asm-s390/vfio_ccw.h"
>  
>  #define TYPE_VFIO_CCW "vfio-ccw"
>  typedef struct VFIOCCWDevice {
>      S390CCWDevice cdev;
>      VFIODevice vdev;
> +    uint64_t io_region_size;
> +    uint64_t io_region_offset;
> +    struct ccw_io_region *io_region;
>  } VFIOCCWDevice;
>  
>  static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> @@ -50,6 +54,46 @@ static void vfio_ccw_reset(DeviceState *dev)
>      ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
>  }
>  
> +static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
> +{
> +    VFIODevice *vdev = &vcdev->vdev;
> +    struct vfio_region_info *info;
> +    int ret;
> +
> +    /* Sanity check device */
> +    if (!(vdev->flags & VFIO_DEVICE_FLAGS_CCW)) {
> +        error_setg(errp, "vfio: Um, this isn't a vfio-ccw device");
> +        return;
> +    }
> +
> +    if (vdev->num_regions != VFIO_CCW_NUM_REGIONS) {
> +        error_setg(errp, "vfio: Unexpected number of the I/O region %u",
> +                   vdev->num_regions);
> +        return;
> +    }

I think you want < here, not !=, otherwise you we can never add another
region to describe something new on a vfio-ccw device without breaking
this code.  You've defined in the uapi that region index zero is always
VFIO_CCW_CONFIG_REGION_INDEX and this code only depends on that, no
matter what additional regions might be added.  That's done below.

> +
> +    ret = vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info);
> +    if (ret) {
> +        error_setg(errp, "vfio: Error getting config info: %d", ret);
> +        return;
> +    }
> +
> +    vcdev->io_region_size = info->size;
> +    if (sizeof(*vcdev->io_region) != vcdev->io_region_size) {
> +        error_setg(errp, "vfio: Unexpected size of the I/O region");
> +        return;
> +    }
> +    vcdev->io_region_offset = info->offset;
> +    vcdev->io_region = g_malloc0(info->size);
> +
> +    g_free(info);
> +}
> +
> +static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
> +{
> +    g_free(vcdev->io_region);
> +}
> +
>  static void vfio_put_device(VFIOCCWDevice *vcdev)
>  {
>      g_free(vcdev->vdev.name);
> @@ -144,8 +188,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
>          goto out_device_err;
>      }
>  
> +    vfio_ccw_get_region(vcdev, errp);
> +    if (*errp) {
> +        goto out_region_err;
> +    }
> +
>      return;
>  
> +out_region_err:
> +    vfio_put_device(vcdev);
>  out_device_err:
>      vfio_ccw_put_group(group, path);
>  out_group_err:
> @@ -166,6 +217,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
>          cdc->unrealize(cdev, errp);
>      }
>  
> +    vfio_ccw_put_region(vcdev);
>      vfio_put_device(vcdev);
>      vfio_put_group(group);
>  }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 08/12] vfio/ccw: get io region info
@ 2017-01-17 22:49     ` Alex Williamson
  0 siblings, 0 replies; 55+ messages in thread
From: Alex Williamson @ 2017-01-17 22:49 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: kvm, linux-s390, qemu-devel, renxiaof, cornelia.huck,
	borntraeger, agraf, pmorel, pasic, wkywang

On Thu, 12 Jan 2017 08:25:09 +0100
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> vfio-ccw provides an MMIO region for I/O operations. We fetch its
> information via ioctls here, then we can use it performing I/O
> instructions and retrieving I/O results later on.
> 
> Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> ---
>  hw/vfio/ccw.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> index 881010b..93394c2 100644
> --- a/hw/vfio/ccw.c
> +++ b/hw/vfio/ccw.c
> @@ -21,11 +21,15 @@
>  #include "hw/vfio/vfio-common.h"
>  #include "hw/s390x/s390-ccw.h"
>  #include "hw/s390x/ccw-device.h"
> +#include "standard-headers/asm-s390/vfio_ccw.h"
>  
>  #define TYPE_VFIO_CCW "vfio-ccw"
>  typedef struct VFIOCCWDevice {
>      S390CCWDevice cdev;
>      VFIODevice vdev;
> +    uint64_t io_region_size;
> +    uint64_t io_region_offset;
> +    struct ccw_io_region *io_region;
>  } VFIOCCWDevice;
>  
>  static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> @@ -50,6 +54,46 @@ static void vfio_ccw_reset(DeviceState *dev)
>      ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
>  }
>  
> +static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
> +{
> +    VFIODevice *vdev = &vcdev->vdev;
> +    struct vfio_region_info *info;
> +    int ret;
> +
> +    /* Sanity check device */
> +    if (!(vdev->flags & VFIO_DEVICE_FLAGS_CCW)) {
> +        error_setg(errp, "vfio: Um, this isn't a vfio-ccw device");
> +        return;
> +    }
> +
> +    if (vdev->num_regions != VFIO_CCW_NUM_REGIONS) {
> +        error_setg(errp, "vfio: Unexpected number of the I/O region %u",
> +                   vdev->num_regions);
> +        return;
> +    }

I think you want < here, not !=, otherwise you we can never add another
region to describe something new on a vfio-ccw device without breaking
this code.  You've defined in the uapi that region index zero is always
VFIO_CCW_CONFIG_REGION_INDEX and this code only depends on that, no
matter what additional regions might be added.  That's done below.

> +
> +    ret = vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info);
> +    if (ret) {
> +        error_setg(errp, "vfio: Error getting config info: %d", ret);
> +        return;
> +    }
> +
> +    vcdev->io_region_size = info->size;
> +    if (sizeof(*vcdev->io_region) != vcdev->io_region_size) {
> +        error_setg(errp, "vfio: Unexpected size of the I/O region");
> +        return;
> +    }
> +    vcdev->io_region_offset = info->offset;
> +    vcdev->io_region = g_malloc0(info->size);
> +
> +    g_free(info);
> +}
> +
> +static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
> +{
> +    g_free(vcdev->io_region);
> +}
> +
>  static void vfio_put_device(VFIOCCWDevice *vcdev)
>  {
>      g_free(vcdev->vdev.name);
> @@ -144,8 +188,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
>          goto out_device_err;
>      }
>  
> +    vfio_ccw_get_region(vcdev, errp);
> +    if (*errp) {
> +        goto out_region_err;
> +    }
> +
>      return;
>  
> +out_region_err:
> +    vfio_put_device(vcdev);
>  out_device_err:
>      vfio_ccw_put_group(group, path);
>  out_group_err:
> @@ -166,6 +217,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
>          cdc->unrealize(cdev, errp);
>      }
>  
> +    vfio_ccw_put_region(vcdev);
>      vfio_put_device(vcdev);
>      vfio_put_group(group);
>  }

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 09/12] vfio/ccw: get irqs info and set the eventfd fd
  2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-17 22:53     ` Alex Williamson
  -1 siblings, 0 replies; 55+ messages in thread
From: Alex Williamson @ 2017-01-17 22:53 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: linux-s390, pasic, kvm, pmorel, qemu-devel, borntraeger,
	renxiaof, wkywang, cornelia.huck, agraf

On Thu, 12 Jan 2017 08:25:10 +0100
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> 
> vfio-ccw resorts to the eventfd mechanism to communicate with userspace.
> We fetch the irqs info via the ioctl VFIO_DEVICE_GET_IRQ_INFO,
> register a event notifier to get the eventfd fd which is sent
> to kernel via the ioctl VFIO_DEVICE_SET_IRQS, then we can implement
> read operation once kernel sends the signal.
> 
> Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> ---
>  hw/vfio/ccw.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 102 insertions(+)
> 
> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> index 93394c2..c6bfce7 100644
> --- a/hw/vfio/ccw.c
> +++ b/hw/vfio/ccw.c
> @@ -21,6 +21,7 @@
>  #include "hw/vfio/vfio-common.h"
>  #include "hw/s390x/s390-ccw.h"
>  #include "hw/s390x/ccw-device.h"
> +#include "qemu/error-report.h"
>  #include "standard-headers/asm-s390/vfio_ccw.h"
>  
>  #define TYPE_VFIO_CCW "vfio-ccw"
> @@ -30,6 +31,7 @@ typedef struct VFIOCCWDevice {
>      uint64_t io_region_size;
>      uint64_t io_region_offset;
>      struct ccw_io_region *io_region;
> +    EventNotifier io_notifier;
>  } VFIOCCWDevice;
>  
>  static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> @@ -54,6 +56,98 @@ static void vfio_ccw_reset(DeviceState *dev)
>      ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
>  }
>  
> +static void vfio_ccw_io_notifier_handler(void *opaque)
> +{
> +    VFIOCCWDevice *vcdev = opaque;
> +
> +    if (!event_notifier_test_and_clear(&vcdev->io_notifier)) {
> +        return;
> +    }
> +}
> +
> +static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
> +{
> +    VFIODevice *vdev = &vcdev->vdev;
> +    struct vfio_irq_info *irq_info;
> +    struct vfio_irq_set *irq_set;
> +    size_t argsz;
> +    int32_t *pfd;
> +
> +    if (vdev->num_irqs != VFIO_CCW_NUM_IRQS) {
> +        error_setg(errp, "vfio: unexpected number of io irqs %u",
> +                   vdev->num_irqs);
> +        return;
> +    }

Same issue here as with region info, we may find reasons to add new
interrupts in the kernel, it's happened for PCI support with things
like device error recovery and requests to release the device.  Don't
lock us into never expanding these, just make sure that the index that
this implementation depends on is here.

> +
> +    argsz = sizeof(*irq_set);
> +    irq_info = g_malloc0(argsz);
> +    irq_info->index = VFIO_CCW_IO_IRQ_INDEX;
> +    irq_info->argsz = argsz;
> +    if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
> +              irq_info) < 0 || irq_info->count < 1) {
> +        error_setg(errp, "vfio: Error getting irq info");
> +        goto get_error;
> +    }
> +
> +    if (event_notifier_init(&vcdev->io_notifier, 0)) {
> +        error_setg(errp, "vfio: Unable to init event notifier for IO");
> +        goto get_error;
> +    }
> +
> +    argsz = sizeof(*irq_set) + sizeof(*pfd);
> +    irq_set = g_malloc0(argsz);
> +    irq_set->argsz = argsz;
> +    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
> +                     VFIO_IRQ_SET_ACTION_TRIGGER;
> +    irq_set->index = VFIO_CCW_IO_IRQ_INDEX;
> +    irq_set->start = 0;
> +    irq_set->count = 1;
> +    pfd = (int32_t *) &irq_set->data;
> +
> +    *pfd = event_notifier_get_fd(&vcdev->io_notifier);
> +    qemu_set_fd_handler(*pfd, vfio_ccw_io_notifier_handler, NULL, vcdev);
> +    if (ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
> +        error_setg(errp, "vfio: Failed to set up io notification");
> +        qemu_set_fd_handler(*pfd, NULL, NULL, vcdev);
> +        event_notifier_cleanup(&vcdev->io_notifier);
> +        goto set_error;
> +    }
> +
> +set_error:
> +    g_free(irq_set);
> +
> +get_error:
> +    g_free(irq_info);
> +}
> +
> +static void vfio_ccw_unregister_io_notifier(VFIOCCWDevice *vcdev)
> +{
> +    struct vfio_irq_set *irq_set;
> +    size_t argsz;
> +    int32_t *pfd;
> +
> +    argsz = sizeof(*irq_set) + sizeof(*pfd);
> +    irq_set = g_malloc0(argsz);
> +    irq_set->argsz = argsz;
> +    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
> +                     VFIO_IRQ_SET_ACTION_TRIGGER;
> +    irq_set->index = VFIO_CCW_IO_IRQ_INDEX;
> +    irq_set->start = 0;
> +    irq_set->count = 1;
> +    pfd = (int32_t *) &irq_set->data;
> +    *pfd = -1;
> +
> +    if (ioctl(vcdev->vdev.fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
> +        error_report("vfio: Failed to de-assign device io fd");
> +    }
> +
> +    qemu_set_fd_handler(event_notifier_get_fd(&vcdev->io_notifier),
> +                        NULL, NULL, vcdev);
> +    event_notifier_cleanup(&vcdev->io_notifier);
> +
> +    g_free(irq_set);
> +}
> +
>  static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
>  {
>      VFIODevice *vdev = &vcdev->vdev;
> @@ -193,8 +287,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
>          goto out_region_err;
>      }
>  
> +    vfio_ccw_register_io_notifier(vcdev, errp);
> +    if (*errp) {
> +        goto out_notifier_err;
> +    }
> +
>      return;
>  
> +out_notifier_err:
> +    vfio_ccw_put_region(vcdev);
>  out_region_err:
>      vfio_put_device(vcdev);
>  out_device_err:
> @@ -217,6 +318,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
>          cdc->unrealize(cdev, errp);
>      }
>  
> +    vfio_ccw_unregister_io_notifier(vcdev);
>      vfio_ccw_put_region(vcdev);
>      vfio_put_device(vcdev);
>      vfio_put_group(group);

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 09/12] vfio/ccw: get irqs info and set the eventfd fd
@ 2017-01-17 22:53     ` Alex Williamson
  0 siblings, 0 replies; 55+ messages in thread
From: Alex Williamson @ 2017-01-17 22:53 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: kvm, linux-s390, qemu-devel, renxiaof, cornelia.huck,
	borntraeger, agraf, pmorel, pasic, wkywang

On Thu, 12 Jan 2017 08:25:10 +0100
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> 
> vfio-ccw resorts to the eventfd mechanism to communicate with userspace.
> We fetch the irqs info via the ioctl VFIO_DEVICE_GET_IRQ_INFO,
> register a event notifier to get the eventfd fd which is sent
> to kernel via the ioctl VFIO_DEVICE_SET_IRQS, then we can implement
> read operation once kernel sends the signal.
> 
> Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> ---
>  hw/vfio/ccw.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 102 insertions(+)
> 
> diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> index 93394c2..c6bfce7 100644
> --- a/hw/vfio/ccw.c
> +++ b/hw/vfio/ccw.c
> @@ -21,6 +21,7 @@
>  #include "hw/vfio/vfio-common.h"
>  #include "hw/s390x/s390-ccw.h"
>  #include "hw/s390x/ccw-device.h"
> +#include "qemu/error-report.h"
>  #include "standard-headers/asm-s390/vfio_ccw.h"
>  
>  #define TYPE_VFIO_CCW "vfio-ccw"
> @@ -30,6 +31,7 @@ typedef struct VFIOCCWDevice {
>      uint64_t io_region_size;
>      uint64_t io_region_offset;
>      struct ccw_io_region *io_region;
> +    EventNotifier io_notifier;
>  } VFIOCCWDevice;
>  
>  static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> @@ -54,6 +56,98 @@ static void vfio_ccw_reset(DeviceState *dev)
>      ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
>  }
>  
> +static void vfio_ccw_io_notifier_handler(void *opaque)
> +{
> +    VFIOCCWDevice *vcdev = opaque;
> +
> +    if (!event_notifier_test_and_clear(&vcdev->io_notifier)) {
> +        return;
> +    }
> +}
> +
> +static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
> +{
> +    VFIODevice *vdev = &vcdev->vdev;
> +    struct vfio_irq_info *irq_info;
> +    struct vfio_irq_set *irq_set;
> +    size_t argsz;
> +    int32_t *pfd;
> +
> +    if (vdev->num_irqs != VFIO_CCW_NUM_IRQS) {
> +        error_setg(errp, "vfio: unexpected number of io irqs %u",
> +                   vdev->num_irqs);
> +        return;
> +    }

Same issue here as with region info, we may find reasons to add new
interrupts in the kernel, it's happened for PCI support with things
like device error recovery and requests to release the device.  Don't
lock us into never expanding these, just make sure that the index that
this implementation depends on is here.

> +
> +    argsz = sizeof(*irq_set);
> +    irq_info = g_malloc0(argsz);
> +    irq_info->index = VFIO_CCW_IO_IRQ_INDEX;
> +    irq_info->argsz = argsz;
> +    if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
> +              irq_info) < 0 || irq_info->count < 1) {
> +        error_setg(errp, "vfio: Error getting irq info");
> +        goto get_error;
> +    }
> +
> +    if (event_notifier_init(&vcdev->io_notifier, 0)) {
> +        error_setg(errp, "vfio: Unable to init event notifier for IO");
> +        goto get_error;
> +    }
> +
> +    argsz = sizeof(*irq_set) + sizeof(*pfd);
> +    irq_set = g_malloc0(argsz);
> +    irq_set->argsz = argsz;
> +    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
> +                     VFIO_IRQ_SET_ACTION_TRIGGER;
> +    irq_set->index = VFIO_CCW_IO_IRQ_INDEX;
> +    irq_set->start = 0;
> +    irq_set->count = 1;
> +    pfd = (int32_t *) &irq_set->data;
> +
> +    *pfd = event_notifier_get_fd(&vcdev->io_notifier);
> +    qemu_set_fd_handler(*pfd, vfio_ccw_io_notifier_handler, NULL, vcdev);
> +    if (ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
> +        error_setg(errp, "vfio: Failed to set up io notification");
> +        qemu_set_fd_handler(*pfd, NULL, NULL, vcdev);
> +        event_notifier_cleanup(&vcdev->io_notifier);
> +        goto set_error;
> +    }
> +
> +set_error:
> +    g_free(irq_set);
> +
> +get_error:
> +    g_free(irq_info);
> +}
> +
> +static void vfio_ccw_unregister_io_notifier(VFIOCCWDevice *vcdev)
> +{
> +    struct vfio_irq_set *irq_set;
> +    size_t argsz;
> +    int32_t *pfd;
> +
> +    argsz = sizeof(*irq_set) + sizeof(*pfd);
> +    irq_set = g_malloc0(argsz);
> +    irq_set->argsz = argsz;
> +    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
> +                     VFIO_IRQ_SET_ACTION_TRIGGER;
> +    irq_set->index = VFIO_CCW_IO_IRQ_INDEX;
> +    irq_set->start = 0;
> +    irq_set->count = 1;
> +    pfd = (int32_t *) &irq_set->data;
> +    *pfd = -1;
> +
> +    if (ioctl(vcdev->vdev.fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
> +        error_report("vfio: Failed to de-assign device io fd");
> +    }
> +
> +    qemu_set_fd_handler(event_notifier_get_fd(&vcdev->io_notifier),
> +                        NULL, NULL, vcdev);
> +    event_notifier_cleanup(&vcdev->io_notifier);
> +
> +    g_free(irq_set);
> +}
> +
>  static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
>  {
>      VFIODevice *vdev = &vcdev->vdev;
> @@ -193,8 +287,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
>          goto out_region_err;
>      }
>  
> +    vfio_ccw_register_io_notifier(vcdev, errp);
> +    if (*errp) {
> +        goto out_notifier_err;
> +    }
> +
>      return;
>  
> +out_notifier_err:
> +    vfio_ccw_put_region(vcdev);
>  out_region_err:
>      vfio_put_device(vcdev);
>  out_device_err:
> @@ -217,6 +318,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
>          cdc->unrealize(cdev, errp);
>      }
>  
> +    vfio_ccw_unregister_io_notifier(vcdev);
>      vfio_ccw_put_region(vcdev);
>      vfio_put_device(vcdev);
>      vfio_put_group(group);

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
  2017-01-17 21:51     ` [Qemu-devel] " Alex Williamson
  (?)
@ 2017-01-18  2:51     ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-18  2:51 UTC (permalink / raw)
  To: Alex Williamson
  Cc: linux-s390, pasic, kvm, pmorel, qemu-devel, borntraeger,
	renxiaof, wkywang, cornelia.huck, Dong Jia Shi, agraf

* Alex Williamson <alex.williamson@redhat.com> [2017-01-17 14:51:42 -0700]:

> On Thu, 12 Jan 2017 08:25:03 +0100
> Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> 
> > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > 
> > This is a placeholder for a linux-headers update.
> > 
> > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > ---
> >  include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
> >  linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
> >  2 files changed, 45 insertions(+)
> >  create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h
> > 
> > diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
> > new file mode 100644
> > index 0000000..cddc09b
> > --- /dev/null
> > +++ b/include/standard-headers/asm-s390/vfio_ccw.h
> > @@ -0,0 +1,28 @@
> > +/*
> > + * Interfaces for vfio-ccw
> > + *
> > + * Copyright IBM Corp. 2017
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License (version 2 only)
> > + * as published by the Free Software Foundation.
> > + *
> > + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> > + */
> > +
> > +#ifndef _VFIO_CCW_H_
> > +#define _VFIO_CCW_H_
> > +
> > +#include "standard-headers/linux/types.h"
> > +
> > +struct ccw_io_region {
> > +#define ORB_AREA_SIZE 12
> > +	uint8_t  orb_area[ORB_AREA_SIZE];
> > +#define SCSW_AREA_SIZE 12
> > +	uint8_t  scsw_area[SCSW_AREA_SIZE];
> > +#define IRB_AREA_SIZE 96
> > +	uint8_t  irb_area[IRB_AREA_SIZE];
> > +	uint32_t ret_code;
> > +} QEMU_PACKED;
> > +
> > +#endif
> 
> This is really part of the uapi for the vfio-ccw mdev device, isn't it?
Yes, it is.

> Should it really be buried in asm-s390 in the kernel?
> 
We had an internal discussion on this question before, since we think
this interface is strongly s390 dependent, we put it here. What do you
suggest? Thanks,

[...]

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
  2017-01-17 21:51     ` [Qemu-devel] " Alex Williamson
  (?)
  (?)
@ 2017-01-18  2:51     ` Dong Jia Shi
  2017-01-18 12:41         ` [Qemu-devel] " Cornelia Huck
  -1 siblings, 1 reply; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-18  2:51 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Dong Jia Shi, kvm, linux-s390, qemu-devel, renxiaof,
	cornelia.huck, borntraeger, agraf, pmorel, pasic, wkywang

* Alex Williamson <alex.williamson@redhat.com> [2017-01-17 14:51:42 -0700]:

> On Thu, 12 Jan 2017 08:25:03 +0100
> Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> 
> > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > 
> > This is a placeholder for a linux-headers update.
> > 
> > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > ---
> >  include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
> >  linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
> >  2 files changed, 45 insertions(+)
> >  create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h
> > 
> > diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
> > new file mode 100644
> > index 0000000..cddc09b
> > --- /dev/null
> > +++ b/include/standard-headers/asm-s390/vfio_ccw.h
> > @@ -0,0 +1,28 @@
> > +/*
> > + * Interfaces for vfio-ccw
> > + *
> > + * Copyright IBM Corp. 2017
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License (version 2 only)
> > + * as published by the Free Software Foundation.
> > + *
> > + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> > + */
> > +
> > +#ifndef _VFIO_CCW_H_
> > +#define _VFIO_CCW_H_
> > +
> > +#include "standard-headers/linux/types.h"
> > +
> > +struct ccw_io_region {
> > +#define ORB_AREA_SIZE 12
> > +	uint8_t  orb_area[ORB_AREA_SIZE];
> > +#define SCSW_AREA_SIZE 12
> > +	uint8_t  scsw_area[SCSW_AREA_SIZE];
> > +#define IRB_AREA_SIZE 96
> > +	uint8_t  irb_area[IRB_AREA_SIZE];
> > +	uint32_t ret_code;
> > +} QEMU_PACKED;
> > +
> > +#endif
> 
> This is really part of the uapi for the vfio-ccw mdev device, isn't it?
Yes, it is.

> Should it really be buried in asm-s390 in the kernel?
> 
We had an internal discussion on this question before, since we think
this interface is strongly s390 dependent, we put it here. What do you
suggest? Thanks,

[...]

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 07/12] vfio/ccw: vfio based subchannel passthrough driver
  2017-01-17 22:49     ` [Qemu-devel] " Alex Williamson
  (?)
@ 2017-01-18  3:22     ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-18  3:22 UTC (permalink / raw)
  To: Alex Williamson
  Cc: linux-s390, pasic, kvm, pmorel, qemu-devel, borntraeger,
	renxiaof, wkywang, cornelia.huck, Dong Jia Shi, agraf

* Alex Williamson <alex.williamson@redhat.com> [2017-01-17 15:49:28 -0700]:

> On Thu, 12 Jan 2017 08:25:08 +0100
> Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> 
> > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > 
> > We use the IOMMU_TYPE1 of VFIO to realize the subchannels
> > passthrough, implement a vfio based subchannels passthrough
> > driver called "vfio-ccw".
> > 
> > Support qemu parameters in the style of:
> > "-device vfio-ccw,id=xx,hostid=xx(,guestid=xx),mdevid=xx"
> 
> Why not adopt the same syntax as vfio-pci with mdev devices,
> sysfsdev=%s where %s is a path to the mdev device in sysfs, which can
> be /sys/bus/mdev/devices/$UUID or as you create from the hostid
> below /sys/bus/css/devices/%x.%x.%04x/$UUID.
Ok. This is a good point.

I will change the cmdline interface to:
-device vfio-ccw,id=xx,sysfsdev=xx(,devno=xx)

Since "hostid" is removed, I will also rename "guestid" to "devno" to
make it looking consistent with the virtio-ccw devices.

> It seems if we know where
> to find the mdev device then we can determine the parent information on
> our own through sysfs.
> 
This is true.

> > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
[...]

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 07/12] vfio/ccw: vfio based subchannel passthrough driver
  2017-01-17 22:49     ` [Qemu-devel] " Alex Williamson
  (?)
  (?)
@ 2017-01-18  3:22     ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-18  3:22 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Dong Jia Shi, kvm, linux-s390, qemu-devel, renxiaof,
	cornelia.huck, borntraeger, agraf, pmorel, pasic, wkywang

* Alex Williamson <alex.williamson@redhat.com> [2017-01-17 15:49:28 -0700]:

> On Thu, 12 Jan 2017 08:25:08 +0100
> Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> 
> > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > 
> > We use the IOMMU_TYPE1 of VFIO to realize the subchannels
> > passthrough, implement a vfio based subchannels passthrough
> > driver called "vfio-ccw".
> > 
> > Support qemu parameters in the style of:
> > "-device vfio-ccw,id=xx,hostid=xx(,guestid=xx),mdevid=xx"
> 
> Why not adopt the same syntax as vfio-pci with mdev devices,
> sysfsdev=%s where %s is a path to the mdev device in sysfs, which can
> be /sys/bus/mdev/devices/$UUID or as you create from the hostid
> below /sys/bus/css/devices/%x.%x.%04x/$UUID.
Ok. This is a good point.

I will change the cmdline interface to:
-device vfio-ccw,id=xx,sysfsdev=xx(,devno=xx)

Since "hostid" is removed, I will also rename "guestid" to "devno" to
make it looking consistent with the virtio-ccw devices.

> It seems if we know where
> to find the mdev device then we can determine the parent information on
> our own through sysfs.
> 
This is true.

> > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
[...]

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 08/12] vfio/ccw: get io region info
  2017-01-17 22:49     ` [Qemu-devel] " Alex Williamson
  (?)
@ 2017-01-18  5:22     ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-18  5:22 UTC (permalink / raw)
  To: Alex Williamson
  Cc: linux-s390, pasic, kvm, pmorel, qemu-devel, borntraeger,
	renxiaof, wkywang, cornelia.huck, Dong Jia Shi, agraf

* Alex Williamson <alex.williamson@redhat.com> [2017-01-17 15:49:34 -0700]:

> On Thu, 12 Jan 2017 08:25:09 +0100
> Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> 
> > vfio-ccw provides an MMIO region for I/O operations. We fetch its
> > information via ioctls here, then we can use it performing I/O
> > instructions and retrieving I/O results later on.
> > 
> > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > ---
> >  hw/vfio/ccw.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 52 insertions(+)
> > 
> > diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> > index 881010b..93394c2 100644
> > --- a/hw/vfio/ccw.c
> > +++ b/hw/vfio/ccw.c
> > @@ -21,11 +21,15 @@
> >  #include "hw/vfio/vfio-common.h"
> >  #include "hw/s390x/s390-ccw.h"
> >  #include "hw/s390x/ccw-device.h"
> > +#include "standard-headers/asm-s390/vfio_ccw.h"
> >  
> >  #define TYPE_VFIO_CCW "vfio-ccw"
> >  typedef struct VFIOCCWDevice {
> >      S390CCWDevice cdev;
> >      VFIODevice vdev;
> > +    uint64_t io_region_size;
> > +    uint64_t io_region_offset;
> > +    struct ccw_io_region *io_region;
> >  } VFIOCCWDevice;
> >  
> >  static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> > @@ -50,6 +54,46 @@ static void vfio_ccw_reset(DeviceState *dev)
> >      ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
> >  }
> >  
> > +static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
> > +{
> > +    VFIODevice *vdev = &vcdev->vdev;
> > +    struct vfio_region_info *info;
> > +    int ret;
> > +
> > +    /* Sanity check device */
> > +    if (!(vdev->flags & VFIO_DEVICE_FLAGS_CCW)) {
> > +        error_setg(errp, "vfio: Um, this isn't a vfio-ccw device");
> > +        return;
> > +    }
> > +
> > +    if (vdev->num_regions != VFIO_CCW_NUM_REGIONS) {
> > +        error_setg(errp, "vfio: Unexpected number of the I/O region %u",
> > +                   vdev->num_regions);
> > +        return;
> > +    }
> 
> I think you want < here, not !=, otherwise you we can never add another
> region to describe something new on a vfio-ccw device without breaking
> this code.  You've defined in the uapi that region index zero is always
> VFIO_CCW_CONFIG_REGION_INDEX and this code only depends on that, no
> matter what additional regions might be added.  That's done below.
> 
Right! Thanks for pointing out. I will fix.

> > +
> > +    ret = vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info);
> > +    if (ret) {
> > +        error_setg(errp, "vfio: Error getting config info: %d", ret);
> > +        return;
> > +    }
> > +
> > +    vcdev->io_region_size = info->size;
> > +    if (sizeof(*vcdev->io_region) != vcdev->io_region_size) {
> > +        error_setg(errp, "vfio: Unexpected size of the I/O region");
> > +        return;
> > +    }
> > +    vcdev->io_region_offset = info->offset;
> > +    vcdev->io_region = g_malloc0(info->size);
> > +
> > +    g_free(info);
> > +}
> > +
> > +static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
> > +{
> > +    g_free(vcdev->io_region);
> > +}
> > +
> >  static void vfio_put_device(VFIOCCWDevice *vcdev)
> >  {
> >      g_free(vcdev->vdev.name);
> > @@ -144,8 +188,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
> >          goto out_device_err;
> >      }
> >  
> > +    vfio_ccw_get_region(vcdev, errp);
> > +    if (*errp) {
> > +        goto out_region_err;
> > +    }
> > +
> >      return;
> >  
> > +out_region_err:
> > +    vfio_put_device(vcdev);
> >  out_device_err:
> >      vfio_ccw_put_group(group, path);
> >  out_group_err:
> > @@ -166,6 +217,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
> >          cdc->unrealize(cdev, errp);
> >      }
> >  
> > +    vfio_ccw_put_region(vcdev);
> >      vfio_put_device(vcdev);
> >      vfio_put_group(group);
> >  }
> 

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 08/12] vfio/ccw: get io region info
  2017-01-17 22:49     ` [Qemu-devel] " Alex Williamson
  (?)
  (?)
@ 2017-01-18  5:22     ` Dong Jia Shi
  2017-01-18  5:51       ` Dong Jia Shi
  2017-01-18  5:51       ` [Qemu-devel] " Dong Jia Shi
  -1 siblings, 2 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-18  5:22 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Dong Jia Shi, kvm, linux-s390, qemu-devel, renxiaof,
	cornelia.huck, borntraeger, agraf, pmorel, pasic, wkywang

* Alex Williamson <alex.williamson@redhat.com> [2017-01-17 15:49:34 -0700]:

> On Thu, 12 Jan 2017 08:25:09 +0100
> Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> 
> > vfio-ccw provides an MMIO region for I/O operations. We fetch its
> > information via ioctls here, then we can use it performing I/O
> > instructions and retrieving I/O results later on.
> > 
> > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > ---
> >  hw/vfio/ccw.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 52 insertions(+)
> > 
> > diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> > index 881010b..93394c2 100644
> > --- a/hw/vfio/ccw.c
> > +++ b/hw/vfio/ccw.c
> > @@ -21,11 +21,15 @@
> >  #include "hw/vfio/vfio-common.h"
> >  #include "hw/s390x/s390-ccw.h"
> >  #include "hw/s390x/ccw-device.h"
> > +#include "standard-headers/asm-s390/vfio_ccw.h"
> >  
> >  #define TYPE_VFIO_CCW "vfio-ccw"
> >  typedef struct VFIOCCWDevice {
> >      S390CCWDevice cdev;
> >      VFIODevice vdev;
> > +    uint64_t io_region_size;
> > +    uint64_t io_region_offset;
> > +    struct ccw_io_region *io_region;
> >  } VFIOCCWDevice;
> >  
> >  static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> > @@ -50,6 +54,46 @@ static void vfio_ccw_reset(DeviceState *dev)
> >      ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
> >  }
> >  
> > +static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
> > +{
> > +    VFIODevice *vdev = &vcdev->vdev;
> > +    struct vfio_region_info *info;
> > +    int ret;
> > +
> > +    /* Sanity check device */
> > +    if (!(vdev->flags & VFIO_DEVICE_FLAGS_CCW)) {
> > +        error_setg(errp, "vfio: Um, this isn't a vfio-ccw device");
> > +        return;
> > +    }
> > +
> > +    if (vdev->num_regions != VFIO_CCW_NUM_REGIONS) {
> > +        error_setg(errp, "vfio: Unexpected number of the I/O region %u",
> > +                   vdev->num_regions);
> > +        return;
> > +    }
> 
> I think you want < here, not !=, otherwise you we can never add another
> region to describe something new on a vfio-ccw device without breaking
> this code.  You've defined in the uapi that region index zero is always
> VFIO_CCW_CONFIG_REGION_INDEX and this code only depends on that, no
> matter what additional regions might be added.  That's done below.
> 
Right! Thanks for pointing out. I will fix.

> > +
> > +    ret = vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info);
> > +    if (ret) {
> > +        error_setg(errp, "vfio: Error getting config info: %d", ret);
> > +        return;
> > +    }
> > +
> > +    vcdev->io_region_size = info->size;
> > +    if (sizeof(*vcdev->io_region) != vcdev->io_region_size) {
> > +        error_setg(errp, "vfio: Unexpected size of the I/O region");
> > +        return;
> > +    }
> > +    vcdev->io_region_offset = info->offset;
> > +    vcdev->io_region = g_malloc0(info->size);
> > +
> > +    g_free(info);
> > +}
> > +
> > +static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
> > +{
> > +    g_free(vcdev->io_region);
> > +}
> > +
> >  static void vfio_put_device(VFIOCCWDevice *vcdev)
> >  {
> >      g_free(vcdev->vdev.name);
> > @@ -144,8 +188,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
> >          goto out_device_err;
> >      }
> >  
> > +    vfio_ccw_get_region(vcdev, errp);
> > +    if (*errp) {
> > +        goto out_region_err;
> > +    }
> > +
> >      return;
> >  
> > +out_region_err:
> > +    vfio_put_device(vcdev);
> >  out_device_err:
> >      vfio_ccw_put_group(group, path);
> >  out_group_err:
> > @@ -166,6 +217,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
> >          cdc->unrealize(cdev, errp);
> >      }
> >  
> > +    vfio_ccw_put_region(vcdev);
> >      vfio_put_device(vcdev);
> >      vfio_put_group(group);
> >  }
> 

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 08/12] vfio/ccw: get io region info
  2017-01-18  5:22     ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-18  5:51       ` Dong Jia Shi
  2017-01-18  5:51       ` [Qemu-devel] " Dong Jia Shi
  1 sibling, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-18  5:51 UTC (permalink / raw)
  To: Alex Williamson, Dong Jia Shi, kvm, linux-s390, qemu-devel,
	renxiaof, cornelia.huck, borntraeger, agraf, pmorel, pasic,
	wkywang

* Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> [2017-01-18 13:22:56 +0800]:

> * Alex Williamson <alex.williamson@redhat.com> [2017-01-17 15:49:34 -0700]:
> 
> > On Thu, 12 Jan 2017 08:25:09 +0100
> > Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> > 
> > > vfio-ccw provides an MMIO region for I/O operations. We fetch its
> > > information via ioctls here, then we can use it performing I/O
> > > instructions and retrieving I/O results later on.
> > > 
> > > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > ---
> > >  hw/vfio/ccw.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 52 insertions(+)
> > > 
> > > diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> > > index 881010b..93394c2 100644
> > > --- a/hw/vfio/ccw.c
> > > +++ b/hw/vfio/ccw.c
> > > @@ -21,11 +21,15 @@
> > >  #include "hw/vfio/vfio-common.h"
> > >  #include "hw/s390x/s390-ccw.h"
> > >  #include "hw/s390x/ccw-device.h"
> > > +#include "standard-headers/asm-s390/vfio_ccw.h"
> > >  
> > >  #define TYPE_VFIO_CCW "vfio-ccw"
> > >  typedef struct VFIOCCWDevice {
> > >      S390CCWDevice cdev;
> > >      VFIODevice vdev;
> > > +    uint64_t io_region_size;
> > > +    uint64_t io_region_offset;
> > > +    struct ccw_io_region *io_region;
> > >  } VFIOCCWDevice;
> > >  
> > >  static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> > > @@ -50,6 +54,46 @@ static void vfio_ccw_reset(DeviceState *dev)
> > >      ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
> > >  }
> > >  
> > > +static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
> > > +{
> > > +    VFIODevice *vdev = &vcdev->vdev;
> > > +    struct vfio_region_info *info;
> > > +    int ret;
> > > +
> > > +    /* Sanity check device */
> > > +    if (!(vdev->flags & VFIO_DEVICE_FLAGS_CCW)) {
> > > +        error_setg(errp, "vfio: Um, this isn't a vfio-ccw device");
> > > +        return;
> > > +    }
> > > +
> > > +    if (vdev->num_regions != VFIO_CCW_NUM_REGIONS) {
> > > +        error_setg(errp, "vfio: Unexpected number of the I/O region %u",
> > > +                   vdev->num_regions);
> > > +        return;
> > > +    }
> > 
> > I think you want < here, not !=, otherwise you we can never add another
> > region to describe something new on a vfio-ccw device without breaking
> > this code.  You've defined in the uapi that region index zero is always
> > VFIO_CCW_CONFIG_REGION_INDEX and this code only depends on that, no
> > matter what additional regions might be added.  That's done below.
> > 
> Right! Thanks for pointing out. I will fix.
> 
Let me make it clear. I will change it to:
    if (vdev->num_regions < VFIO_CCW_CONFIG_REGION_INDEX + 1) {
        ... ...
    }

> > > +
> > > +    ret = vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info);
> > > +    if (ret) {
> > > +        error_setg(errp, "vfio: Error getting config info: %d", ret);
> > > +        return;
> > > +    }
> > > +
> > > +    vcdev->io_region_size = info->size;
> > > +    if (sizeof(*vcdev->io_region) != vcdev->io_region_size) {
> > > +        error_setg(errp, "vfio: Unexpected size of the I/O region");
> > > +        return;
> > > +    }
> > > +    vcdev->io_region_offset = info->offset;
> > > +    vcdev->io_region = g_malloc0(info->size);
> > > +
> > > +    g_free(info);
> > > +}
> > > +
> > > +static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
> > > +{
> > > +    g_free(vcdev->io_region);
> > > +}
> > > +
> > >  static void vfio_put_device(VFIOCCWDevice *vcdev)
> > >  {
> > >      g_free(vcdev->vdev.name);
> > > @@ -144,8 +188,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
> > >          goto out_device_err;
> > >      }
> > >  
> > > +    vfio_ccw_get_region(vcdev, errp);
> > > +    if (*errp) {
> > > +        goto out_region_err;
> > > +    }
> > > +
> > >      return;
> > >  
> > > +out_region_err:
> > > +    vfio_put_device(vcdev);
> > >  out_device_err:
> > >      vfio_ccw_put_group(group, path);
> > >  out_group_err:
> > > @@ -166,6 +217,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
> > >          cdc->unrealize(cdev, errp);
> > >      }
> > >  
> > > +    vfio_ccw_put_region(vcdev);
> > >      vfio_put_device(vcdev);
> > >      vfio_put_group(group);
> > >  }
> > 
> 
> -- 
> Dong Jia

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 08/12] vfio/ccw: get io region info
  2017-01-18  5:22     ` [Qemu-devel] " Dong Jia Shi
  2017-01-18  5:51       ` Dong Jia Shi
@ 2017-01-18  5:51       ` Dong Jia Shi
  1 sibling, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-18  5:51 UTC (permalink / raw)
  To: Alex Williamson, Dong Jia Shi, kvm, linux-s390, qemu-devel,
	renxiaof, cornelia.huck, borntraeger, agraf, pmorel, pasic,
	wkywang

* Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> [2017-01-18 13:22:56 +0800]:

> * Alex Williamson <alex.williamson@redhat.com> [2017-01-17 15:49:34 -0700]:
> 
> > On Thu, 12 Jan 2017 08:25:09 +0100
> > Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> > 
> > > vfio-ccw provides an MMIO region for I/O operations. We fetch its
> > > information via ioctls here, then we can use it performing I/O
> > > instructions and retrieving I/O results later on.
> > > 
> > > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > ---
> > >  hw/vfio/ccw.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 52 insertions(+)
> > > 
> > > diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> > > index 881010b..93394c2 100644
> > > --- a/hw/vfio/ccw.c
> > > +++ b/hw/vfio/ccw.c
> > > @@ -21,11 +21,15 @@
> > >  #include "hw/vfio/vfio-common.h"
> > >  #include "hw/s390x/s390-ccw.h"
> > >  #include "hw/s390x/ccw-device.h"
> > > +#include "standard-headers/asm-s390/vfio_ccw.h"
> > >  
> > >  #define TYPE_VFIO_CCW "vfio-ccw"
> > >  typedef struct VFIOCCWDevice {
> > >      S390CCWDevice cdev;
> > >      VFIODevice vdev;
> > > +    uint64_t io_region_size;
> > > +    uint64_t io_region_offset;
> > > +    struct ccw_io_region *io_region;
> > >  } VFIOCCWDevice;
> > >  
> > >  static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> > > @@ -50,6 +54,46 @@ static void vfio_ccw_reset(DeviceState *dev)
> > >      ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
> > >  }
> > >  
> > > +static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
> > > +{
> > > +    VFIODevice *vdev = &vcdev->vdev;
> > > +    struct vfio_region_info *info;
> > > +    int ret;
> > > +
> > > +    /* Sanity check device */
> > > +    if (!(vdev->flags & VFIO_DEVICE_FLAGS_CCW)) {
> > > +        error_setg(errp, "vfio: Um, this isn't a vfio-ccw device");
> > > +        return;
> > > +    }
> > > +
> > > +    if (vdev->num_regions != VFIO_CCW_NUM_REGIONS) {
> > > +        error_setg(errp, "vfio: Unexpected number of the I/O region %u",
> > > +                   vdev->num_regions);
> > > +        return;
> > > +    }
> > 
> > I think you want < here, not !=, otherwise you we can never add another
> > region to describe something new on a vfio-ccw device without breaking
> > this code.  You've defined in the uapi that region index zero is always
> > VFIO_CCW_CONFIG_REGION_INDEX and this code only depends on that, no
> > matter what additional regions might be added.  That's done below.
> > 
> Right! Thanks for pointing out. I will fix.
> 
Let me make it clear. I will change it to:
    if (vdev->num_regions < VFIO_CCW_CONFIG_REGION_INDEX + 1) {
        ... ...
    }

> > > +
> > > +    ret = vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info);
> > > +    if (ret) {
> > > +        error_setg(errp, "vfio: Error getting config info: %d", ret);
> > > +        return;
> > > +    }
> > > +
> > > +    vcdev->io_region_size = info->size;
> > > +    if (sizeof(*vcdev->io_region) != vcdev->io_region_size) {
> > > +        error_setg(errp, "vfio: Unexpected size of the I/O region");
> > > +        return;
> > > +    }
> > > +    vcdev->io_region_offset = info->offset;
> > > +    vcdev->io_region = g_malloc0(info->size);
> > > +
> > > +    g_free(info);
> > > +}
> > > +
> > > +static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
> > > +{
> > > +    g_free(vcdev->io_region);
> > > +}
> > > +
> > >  static void vfio_put_device(VFIOCCWDevice *vcdev)
> > >  {
> > >      g_free(vcdev->vdev.name);
> > > @@ -144,8 +188,15 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
> > >          goto out_device_err;
> > >      }
> > >  
> > > +    vfio_ccw_get_region(vcdev, errp);
> > > +    if (*errp) {
> > > +        goto out_region_err;
> > > +    }
> > > +
> > >      return;
> > >  
> > > +out_region_err:
> > > +    vfio_put_device(vcdev);
> > >  out_device_err:
> > >      vfio_ccw_put_group(group, path);
> > >  out_group_err:
> > > @@ -166,6 +217,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
> > >          cdc->unrealize(cdev, errp);
> > >      }
> > >  
> > > +    vfio_ccw_put_region(vcdev);
> > >      vfio_put_device(vcdev);
> > >      vfio_put_group(group);
> > >  }
> > 
> 
> -- 
> Dong Jia

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 09/12] vfio/ccw: get irqs info and set the eventfd fd
  2017-01-17 22:53     ` [Qemu-devel] " Alex Williamson
  (?)
@ 2017-01-18  5:55     ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-18  5:55 UTC (permalink / raw)
  To: Alex Williamson
  Cc: linux-s390, pasic, kvm, pmorel, qemu-devel, borntraeger,
	renxiaof, wkywang, cornelia.huck, Dong Jia Shi, agraf

* Alex Williamson <alex.williamson@redhat.com> [2017-01-17 15:53:13 -0700]:

> On Thu, 12 Jan 2017 08:25:10 +0100
> Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> 
> > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > 
> > vfio-ccw resorts to the eventfd mechanism to communicate with userspace.
> > We fetch the irqs info via the ioctl VFIO_DEVICE_GET_IRQ_INFO,
> > register a event notifier to get the eventfd fd which is sent
> > to kernel via the ioctl VFIO_DEVICE_SET_IRQS, then we can implement
> > read operation once kernel sends the signal.
> > 
> > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > ---
> >  hw/vfio/ccw.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 102 insertions(+)
> > 
> > diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> > index 93394c2..c6bfce7 100644
> > --- a/hw/vfio/ccw.c
> > +++ b/hw/vfio/ccw.c
> > @@ -21,6 +21,7 @@
> >  #include "hw/vfio/vfio-common.h"
> >  #include "hw/s390x/s390-ccw.h"
> >  #include "hw/s390x/ccw-device.h"
> > +#include "qemu/error-report.h"
> >  #include "standard-headers/asm-s390/vfio_ccw.h"
> >  
> >  #define TYPE_VFIO_CCW "vfio-ccw"
> > @@ -30,6 +31,7 @@ typedef struct VFIOCCWDevice {
> >      uint64_t io_region_size;
> >      uint64_t io_region_offset;
> >      struct ccw_io_region *io_region;
> > +    EventNotifier io_notifier;
> >  } VFIOCCWDevice;
> >  
> >  static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> > @@ -54,6 +56,98 @@ static void vfio_ccw_reset(DeviceState *dev)
> >      ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
> >  }
> >  
> > +static void vfio_ccw_io_notifier_handler(void *opaque)
> > +{
> > +    VFIOCCWDevice *vcdev = opaque;
> > +
> > +    if (!event_notifier_test_and_clear(&vcdev->io_notifier)) {
> > +        return;
> > +    }
> > +}
> > +
> > +static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
> > +{
> > +    VFIODevice *vdev = &vcdev->vdev;
> > +    struct vfio_irq_info *irq_info;
> > +    struct vfio_irq_set *irq_set;
> > +    size_t argsz;
> > +    int32_t *pfd;
> > +
> > +    if (vdev->num_irqs != VFIO_CCW_NUM_IRQS) {
> > +        error_setg(errp, "vfio: unexpected number of io irqs %u",
> > +                   vdev->num_irqs);
> > +        return;
> > +    }
> 
> Same issue here as with region info, we may find reasons to add new
> interrupts in the kernel, it's happened for PCI support with things
> like device error recovery and requests to release the device.  Don't
> lock us into never expanding these, just make sure that the index that
> this implementation depends on is here.
> 
Ok. Will change it to:
    if (vdev->num_irqs < VFIO_CCW_IO_IRQ_INDEX + 1) {
        ... ...
    }

> > +
> > +    argsz = sizeof(*irq_set);
> > +    irq_info = g_malloc0(argsz);
> > +    irq_info->index = VFIO_CCW_IO_IRQ_INDEX;
> > +    irq_info->argsz = argsz;
> > +    if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
> > +              irq_info) < 0 || irq_info->count < 1) {
> > +        error_setg(errp, "vfio: Error getting irq info");
> > +        goto get_error;
> > +    }
> > +
> > +    if (event_notifier_init(&vcdev->io_notifier, 0)) {
> > +        error_setg(errp, "vfio: Unable to init event notifier for IO");
> > +        goto get_error;
> > +    }
> > +
> > +    argsz = sizeof(*irq_set) + sizeof(*pfd);
> > +    irq_set = g_malloc0(argsz);
> > +    irq_set->argsz = argsz;
> > +    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
> > +                     VFIO_IRQ_SET_ACTION_TRIGGER;
> > +    irq_set->index = VFIO_CCW_IO_IRQ_INDEX;
> > +    irq_set->start = 0;
> > +    irq_set->count = 1;
> > +    pfd = (int32_t *) &irq_set->data;
> > +
> > +    *pfd = event_notifier_get_fd(&vcdev->io_notifier);
> > +    qemu_set_fd_handler(*pfd, vfio_ccw_io_notifier_handler, NULL, vcdev);
> > +    if (ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
> > +        error_setg(errp, "vfio: Failed to set up io notification");
> > +        qemu_set_fd_handler(*pfd, NULL, NULL, vcdev);
> > +        event_notifier_cleanup(&vcdev->io_notifier);
> > +        goto set_error;
> > +    }
> > +
> > +set_error:
> > +    g_free(irq_set);
> > +
> > +get_error:
> > +    g_free(irq_info);
> > +}
> > +
[...]

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 09/12] vfio/ccw: get irqs info and set the eventfd fd
  2017-01-17 22:53     ` [Qemu-devel] " Alex Williamson
  (?)
  (?)
@ 2017-01-18  5:55     ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-18  5:55 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Dong Jia Shi, kvm, linux-s390, qemu-devel, renxiaof,
	cornelia.huck, borntraeger, agraf, pmorel, pasic, wkywang

* Alex Williamson <alex.williamson@redhat.com> [2017-01-17 15:53:13 -0700]:

> On Thu, 12 Jan 2017 08:25:10 +0100
> Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> 
> > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > 
> > vfio-ccw resorts to the eventfd mechanism to communicate with userspace.
> > We fetch the irqs info via the ioctl VFIO_DEVICE_GET_IRQ_INFO,
> > register a event notifier to get the eventfd fd which is sent
> > to kernel via the ioctl VFIO_DEVICE_SET_IRQS, then we can implement
> > read operation once kernel sends the signal.
> > 
> > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > ---
> >  hw/vfio/ccw.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 102 insertions(+)
> > 
> > diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
> > index 93394c2..c6bfce7 100644
> > --- a/hw/vfio/ccw.c
> > +++ b/hw/vfio/ccw.c
> > @@ -21,6 +21,7 @@
> >  #include "hw/vfio/vfio-common.h"
> >  #include "hw/s390x/s390-ccw.h"
> >  #include "hw/s390x/ccw-device.h"
> > +#include "qemu/error-report.h"
> >  #include "standard-headers/asm-s390/vfio_ccw.h"
> >  
> >  #define TYPE_VFIO_CCW "vfio-ccw"
> > @@ -30,6 +31,7 @@ typedef struct VFIOCCWDevice {
> >      uint64_t io_region_size;
> >      uint64_t io_region_offset;
> >      struct ccw_io_region *io_region;
> > +    EventNotifier io_notifier;
> >  } VFIOCCWDevice;
> >  
> >  static void vfio_ccw_compute_needs_reset(VFIODevice *vdev)
> > @@ -54,6 +56,98 @@ static void vfio_ccw_reset(DeviceState *dev)
> >      ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
> >  }
> >  
> > +static void vfio_ccw_io_notifier_handler(void *opaque)
> > +{
> > +    VFIOCCWDevice *vcdev = opaque;
> > +
> > +    if (!event_notifier_test_and_clear(&vcdev->io_notifier)) {
> > +        return;
> > +    }
> > +}
> > +
> > +static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
> > +{
> > +    VFIODevice *vdev = &vcdev->vdev;
> > +    struct vfio_irq_info *irq_info;
> > +    struct vfio_irq_set *irq_set;
> > +    size_t argsz;
> > +    int32_t *pfd;
> > +
> > +    if (vdev->num_irqs != VFIO_CCW_NUM_IRQS) {
> > +        error_setg(errp, "vfio: unexpected number of io irqs %u",
> > +                   vdev->num_irqs);
> > +        return;
> > +    }
> 
> Same issue here as with region info, we may find reasons to add new
> interrupts in the kernel, it's happened for PCI support with things
> like device error recovery and requests to release the device.  Don't
> lock us into never expanding these, just make sure that the index that
> this implementation depends on is here.
> 
Ok. Will change it to:
    if (vdev->num_irqs < VFIO_CCW_IO_IRQ_INDEX + 1) {
        ... ...
    }

> > +
> > +    argsz = sizeof(*irq_set);
> > +    irq_info = g_malloc0(argsz);
> > +    irq_info->index = VFIO_CCW_IO_IRQ_INDEX;
> > +    irq_info->argsz = argsz;
> > +    if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
> > +              irq_info) < 0 || irq_info->count < 1) {
> > +        error_setg(errp, "vfio: Error getting irq info");
> > +        goto get_error;
> > +    }
> > +
> > +    if (event_notifier_init(&vcdev->io_notifier, 0)) {
> > +        error_setg(errp, "vfio: Unable to init event notifier for IO");
> > +        goto get_error;
> > +    }
> > +
> > +    argsz = sizeof(*irq_set) + sizeof(*pfd);
> > +    irq_set = g_malloc0(argsz);
> > +    irq_set->argsz = argsz;
> > +    irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD |
> > +                     VFIO_IRQ_SET_ACTION_TRIGGER;
> > +    irq_set->index = VFIO_CCW_IO_IRQ_INDEX;
> > +    irq_set->start = 0;
> > +    irq_set->count = 1;
> > +    pfd = (int32_t *) &irq_set->data;
> > +
> > +    *pfd = event_notifier_get_fd(&vcdev->io_notifier);
> > +    qemu_set_fd_handler(*pfd, vfio_ccw_io_notifier_handler, NULL, vcdev);
> > +    if (ioctl(vdev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) {
> > +        error_setg(errp, "vfio: Failed to set up io notification");
> > +        qemu_set_fd_handler(*pfd, NULL, NULL, vcdev);
> > +        event_notifier_cleanup(&vcdev->io_notifier);
> > +        goto set_error;
> > +    }
> > +
> > +set_error:
> > +    g_free(irq_set);
> > +
> > +get_error:
> > +    g_free(irq_info);
> > +}
> > +
[...]

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
  2017-01-18  2:51     ` [Qemu-devel] " Dong Jia Shi
@ 2017-01-18 12:41         ` Cornelia Huck
  0 siblings, 0 replies; 55+ messages in thread
From: Cornelia Huck @ 2017-01-18 12:41 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: Alex Williamson, kvm, linux-s390, qemu-devel, renxiaof,
	borntraeger, agraf, pmorel, pasic, wkywang

On Wed, 18 Jan 2017 10:51:17 +0800
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> * Alex Williamson <alex.williamson@redhat.com> [2017-01-17 14:51:42 -0700]:
> 
> > On Thu, 12 Jan 2017 08:25:03 +0100
> > Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> > 
> > > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > 
> > > This is a placeholder for a linux-headers update.
> > > 
> > > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > ---
> > >  include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
> > >  linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
> > >  2 files changed, 45 insertions(+)
> > >  create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h
> > > 
> > > diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
> > > new file mode 100644
> > > index 0000000..cddc09b
> > > --- /dev/null
> > > +++ b/include/standard-headers/asm-s390/vfio_ccw.h
> > > @@ -0,0 +1,28 @@
> > > +/*
> > > + * Interfaces for vfio-ccw
> > > + *
> > > + * Copyright IBM Corp. 2017
> > > + *
> > > + * This program is free software; you can redistribute it and/or modify
> > > + * it under the terms of the GNU General Public License (version 2 only)
> > > + * as published by the Free Software Foundation.
> > > + *
> > > + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> > > + */
> > > +
> > > +#ifndef _VFIO_CCW_H_
> > > +#define _VFIO_CCW_H_
> > > +
> > > +#include "standard-headers/linux/types.h"
> > > +
> > > +struct ccw_io_region {
> > > +#define ORB_AREA_SIZE 12
> > > +	uint8_t  orb_area[ORB_AREA_SIZE];
> > > +#define SCSW_AREA_SIZE 12
> > > +	uint8_t  scsw_area[SCSW_AREA_SIZE];
> > > +#define IRB_AREA_SIZE 96
> > > +	uint8_t  irb_area[IRB_AREA_SIZE];
> > > +	uint32_t ret_code;
> > > +} QEMU_PACKED;
> > > +
> > > +#endif
> > 
> > This is really part of the uapi for the vfio-ccw mdev device, isn't it?
> Yes, it is.
> 
> > Should it really be buried in asm-s390 in the kernel?
> > 
> We had an internal discussion on this question before, since we think
> this interface is strongly s390 dependent, we put it here. What do you
> suggest? Thanks,

As there are already architecture-specific definitions in the common
file, having everything in the same file is probably better. I'm
certainly not against moving it out from asm-s390.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
@ 2017-01-18 12:41         ` Cornelia Huck
  0 siblings, 0 replies; 55+ messages in thread
From: Cornelia Huck @ 2017-01-18 12:41 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: Alex Williamson, kvm, linux-s390, qemu-devel, renxiaof,
	borntraeger, agraf, pmorel, pasic, wkywang

On Wed, 18 Jan 2017 10:51:17 +0800
Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:

> * Alex Williamson <alex.williamson@redhat.com> [2017-01-17 14:51:42 -0700]:
> 
> > On Thu, 12 Jan 2017 08:25:03 +0100
> > Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> > 
> > > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > 
> > > This is a placeholder for a linux-headers update.
> > > 
> > > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > ---
> > >  include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
> > >  linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
> > >  2 files changed, 45 insertions(+)
> > >  create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h
> > > 
> > > diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
> > > new file mode 100644
> > > index 0000000..cddc09b
> > > --- /dev/null
> > > +++ b/include/standard-headers/asm-s390/vfio_ccw.h
> > > @@ -0,0 +1,28 @@
> > > +/*
> > > + * Interfaces for vfio-ccw
> > > + *
> > > + * Copyright IBM Corp. 2017
> > > + *
> > > + * This program is free software; you can redistribute it and/or modify
> > > + * it under the terms of the GNU General Public License (version 2 only)
> > > + * as published by the Free Software Foundation.
> > > + *
> > > + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> > > + */
> > > +
> > > +#ifndef _VFIO_CCW_H_
> > > +#define _VFIO_CCW_H_
> > > +
> > > +#include "standard-headers/linux/types.h"
> > > +
> > > +struct ccw_io_region {
> > > +#define ORB_AREA_SIZE 12
> > > +	uint8_t  orb_area[ORB_AREA_SIZE];
> > > +#define SCSW_AREA_SIZE 12
> > > +	uint8_t  scsw_area[SCSW_AREA_SIZE];
> > > +#define IRB_AREA_SIZE 96
> > > +	uint8_t  irb_area[IRB_AREA_SIZE];
> > > +	uint32_t ret_code;
> > > +} QEMU_PACKED;
> > > +
> > > +#endif
> > 
> > This is really part of the uapi for the vfio-ccw mdev device, isn't it?
> Yes, it is.
> 
> > Should it really be buried in asm-s390 in the kernel?
> > 
> We had an internal discussion on this question before, since we think
> this interface is strongly s390 dependent, we put it here. What do you
> suggest? Thanks,

As there are already architecture-specific definitions in the common
file, having everything in the same file is probably better. I'm
certainly not against moving it out from asm-s390.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
  2017-01-18 12:41         ` [Qemu-devel] " Cornelia Huck
@ 2017-01-18 20:43           ` Alex Williamson
  -1 siblings, 0 replies; 55+ messages in thread
From: Alex Williamson @ 2017-01-18 20:43 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: linux-s390, pasic, kvm, pmorel, qemu-devel, borntraeger,
	renxiaof, wkywang, Dong Jia Shi, agraf

On Wed, 18 Jan 2017 13:41:47 +0100
Cornelia Huck <cornelia.huck@de.ibm.com> wrote:

> On Wed, 18 Jan 2017 10:51:17 +0800
> Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> 
> > * Alex Williamson <alex.williamson@redhat.com> [2017-01-17 14:51:42 -0700]:
> >   
> > > On Thu, 12 Jan 2017 08:25:03 +0100
> > > Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> > >   
> > > > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > > 
> > > > This is a placeholder for a linux-headers update.
> > > > 
> > > > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > > ---
> > > >  include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
> > > >  linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
> > > >  2 files changed, 45 insertions(+)
> > > >  create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h
> > > > 
> > > > diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
> > > > new file mode 100644
> > > > index 0000000..cddc09b
> > > > --- /dev/null
> > > > +++ b/include/standard-headers/asm-s390/vfio_ccw.h
> > > > @@ -0,0 +1,28 @@
> > > > +/*
> > > > + * Interfaces for vfio-ccw
> > > > + *
> > > > + * Copyright IBM Corp. 2017
> > > > + *
> > > > + * This program is free software; you can redistribute it and/or modify
> > > > + * it under the terms of the GNU General Public License (version 2 only)
> > > > + * as published by the Free Software Foundation.
> > > > + *
> > > > + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> > > > + */
> > > > +
> > > > +#ifndef _VFIO_CCW_H_
> > > > +#define _VFIO_CCW_H_
> > > > +
> > > > +#include "standard-headers/linux/types.h"
> > > > +
> > > > +struct ccw_io_region {
> > > > +#define ORB_AREA_SIZE 12
> > > > +	uint8_t  orb_area[ORB_AREA_SIZE];
> > > > +#define SCSW_AREA_SIZE 12
> > > > +	uint8_t  scsw_area[SCSW_AREA_SIZE];
> > > > +#define IRB_AREA_SIZE 96
> > > > +	uint8_t  irb_area[IRB_AREA_SIZE];
> > > > +	uint32_t ret_code;
> > > > +} QEMU_PACKED;
> > > > +
> > > > +#endif  
> > > 
> > > This is really part of the uapi for the vfio-ccw mdev device, isn't it?  
> > Yes, it is.
> >   
> > > Should it really be buried in asm-s390 in the kernel?
> > >   
> > We had an internal discussion on this question before, since we think
> > this interface is strongly s390 dependent, we put it here. What do you
> > suggest? Thanks,  
> 
> As there are already architecture-specific definitions in the common
> file, having everything in the same file is probably better. I'm
> certainly not against moving it out from asm-s390.

As soon as we use it for the interface definition to the vfio region, I
think it makes sense for it to move to uapi.  It's not really
architecture specific as much as it is device specific, for a device
which happens to only appear on s390 hardware.  Putting it in uapi
should also make sure people think twice about changing it.  Thanks,

Alex

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
@ 2017-01-18 20:43           ` Alex Williamson
  0 siblings, 0 replies; 55+ messages in thread
From: Alex Williamson @ 2017-01-18 20:43 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: Dong Jia Shi, kvm, linux-s390, qemu-devel, renxiaof, borntraeger,
	agraf, pmorel, pasic, wkywang

On Wed, 18 Jan 2017 13:41:47 +0100
Cornelia Huck <cornelia.huck@de.ibm.com> wrote:

> On Wed, 18 Jan 2017 10:51:17 +0800
> Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> 
> > * Alex Williamson <alex.williamson@redhat.com> [2017-01-17 14:51:42 -0700]:
> >   
> > > On Thu, 12 Jan 2017 08:25:03 +0100
> > > Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> > >   
> > > > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > > 
> > > > This is a placeholder for a linux-headers update.
> > > > 
> > > > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > > ---
> > > >  include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
> > > >  linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
> > > >  2 files changed, 45 insertions(+)
> > > >  create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h
> > > > 
> > > > diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
> > > > new file mode 100644
> > > > index 0000000..cddc09b
> > > > --- /dev/null
> > > > +++ b/include/standard-headers/asm-s390/vfio_ccw.h
> > > > @@ -0,0 +1,28 @@
> > > > +/*
> > > > + * Interfaces for vfio-ccw
> > > > + *
> > > > + * Copyright IBM Corp. 2017
> > > > + *
> > > > + * This program is free software; you can redistribute it and/or modify
> > > > + * it under the terms of the GNU General Public License (version 2 only)
> > > > + * as published by the Free Software Foundation.
> > > > + *
> > > > + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> > > > + */
> > > > +
> > > > +#ifndef _VFIO_CCW_H_
> > > > +#define _VFIO_CCW_H_
> > > > +
> > > > +#include "standard-headers/linux/types.h"
> > > > +
> > > > +struct ccw_io_region {
> > > > +#define ORB_AREA_SIZE 12
> > > > +	uint8_t  orb_area[ORB_AREA_SIZE];
> > > > +#define SCSW_AREA_SIZE 12
> > > > +	uint8_t  scsw_area[SCSW_AREA_SIZE];
> > > > +#define IRB_AREA_SIZE 96
> > > > +	uint8_t  irb_area[IRB_AREA_SIZE];
> > > > +	uint32_t ret_code;
> > > > +} QEMU_PACKED;
> > > > +
> > > > +#endif  
> > > 
> > > This is really part of the uapi for the vfio-ccw mdev device, isn't it?  
> > Yes, it is.
> >   
> > > Should it really be buried in asm-s390 in the kernel?
> > >   
> > We had an internal discussion on this question before, since we think
> > this interface is strongly s390 dependent, we put it here. What do you
> > suggest? Thanks,  
> 
> As there are already architecture-specific definitions in the common
> file, having everything in the same file is probably better. I'm
> certainly not against moving it out from asm-s390.

As soon as we use it for the interface definition to the vfio region, I
think it makes sense for it to move to uapi.  It's not really
architecture specific as much as it is device specific, for a device
which happens to only appear on s390 hardware.  Putting it in uapi
should also make sure people think twice about changing it.  Thanks,

Alex

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
  2017-01-18 20:43           ` [Qemu-devel] " Alex Williamson
  (?)
  (?)
@ 2017-01-19  1:54           ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-19  1:54 UTC (permalink / raw)
  To: Alex Williamson
  Cc: linux-s390, pasic, kvm, pmorel, qemu-devel, borntraeger,
	renxiaof, wkywang, Cornelia Huck, Dong Jia Shi, agraf

* Alex Williamson <alex.williamson@redhat.com> [2017-01-18 13:43:32 -0700]:

> On Wed, 18 Jan 2017 13:41:47 +0100
> Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> 
> > On Wed, 18 Jan 2017 10:51:17 +0800
> > Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> > 
> > > * Alex Williamson <alex.williamson@redhat.com> [2017-01-17 14:51:42 -0700]:
> > >   
> > > > On Thu, 12 Jan 2017 08:25:03 +0100
> > > > Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> > > >   
> > > > > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > > > 
> > > > > This is a placeholder for a linux-headers update.
> > > > > 
> > > > > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > > > ---
> > > > >  include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
> > > > >  linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
> > > > >  2 files changed, 45 insertions(+)
> > > > >  create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h
> > > > > 
> > > > > diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
> > > > > new file mode 100644
> > > > > index 0000000..cddc09b
> > > > > --- /dev/null
> > > > > +++ b/include/standard-headers/asm-s390/vfio_ccw.h
> > > > > @@ -0,0 +1,28 @@
> > > > > +/*
> > > > > + * Interfaces for vfio-ccw
> > > > > + *
> > > > > + * Copyright IBM Corp. 2017
> > > > > + *
> > > > > + * This program is free software; you can redistribute it and/or modify
> > > > > + * it under the terms of the GNU General Public License (version 2 only)
> > > > > + * as published by the Free Software Foundation.
> > > > > + *
> > > > > + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> > > > > + */
> > > > > +
> > > > > +#ifndef _VFIO_CCW_H_
> > > > > +#define _VFIO_CCW_H_
> > > > > +
> > > > > +#include "standard-headers/linux/types.h"
> > > > > +
> > > > > +struct ccw_io_region {
> > > > > +#define ORB_AREA_SIZE 12
> > > > > +	uint8_t  orb_area[ORB_AREA_SIZE];
> > > > > +#define SCSW_AREA_SIZE 12
> > > > > +	uint8_t  scsw_area[SCSW_AREA_SIZE];
> > > > > +#define IRB_AREA_SIZE 96
> > > > > +	uint8_t  irb_area[IRB_AREA_SIZE];
> > > > > +	uint32_t ret_code;
> > > > > +} QEMU_PACKED;
> > > > > +
> > > > > +#endif  
> > > > 
> > > > This is really part of the uapi for the vfio-ccw mdev device, isn't it?  
> > > Yes, it is.
> > >   
> > > > Should it really be buried in asm-s390 in the kernel?
> > > >   
> > > We had an internal discussion on this question before, since we think
> > > this interface is strongly s390 dependent, we put it here. What do you
> > > suggest? Thanks,  
> > 
> > As there are already architecture-specific definitions in the common
> > file, having everything in the same file is probably better. I'm
> > certainly not against moving it out from asm-s390.
> 
> As soon as we use it for the interface definition to the vfio region, I
> think it makes sense for it to move to uapi.  It's not really
> architecture specific as much as it is device specific, for a device
> which happens to only appear on s390 hardware.  Putting it in uapi
> should also make sure people think twice about changing it.  Thanks,
> 
> Alex
> 
Fair enough. Let's move it to include/uapi/linux/vfio_ccw.h.

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw
  2017-01-18 20:43           ` [Qemu-devel] " Alex Williamson
  (?)
@ 2017-01-19  1:54           ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-01-19  1:54 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Cornelia Huck, Dong Jia Shi, kvm, linux-s390, qemu-devel,
	renxiaof, borntraeger, agraf, pmorel, pasic, wkywang

* Alex Williamson <alex.williamson@redhat.com> [2017-01-18 13:43:32 -0700]:

> On Wed, 18 Jan 2017 13:41:47 +0100
> Cornelia Huck <cornelia.huck@de.ibm.com> wrote:
> 
> > On Wed, 18 Jan 2017 10:51:17 +0800
> > Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> > 
> > > * Alex Williamson <alex.williamson@redhat.com> [2017-01-17 14:51:42 -0700]:
> > >   
> > > > On Thu, 12 Jan 2017 08:25:03 +0100
> > > > Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> wrote:
> > > >   
> > > > > From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > > > 
> > > > > This is a placeholder for a linux-headers update.
> > > > > 
> > > > > Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> > > > > ---
> > > > >  include/standard-headers/asm-s390/vfio_ccw.h | 28 ++++++++++++++++++++++++++++
> > > > >  linux-headers/linux/vfio.h                   | 17 +++++++++++++++++
> > > > >  2 files changed, 45 insertions(+)
> > > > >  create mode 100644 include/standard-headers/asm-s390/vfio_ccw.h
> > > > > 
> > > > > diff --git a/include/standard-headers/asm-s390/vfio_ccw.h b/include/standard-headers/asm-s390/vfio_ccw.h
> > > > > new file mode 100644
> > > > > index 0000000..cddc09b
> > > > > --- /dev/null
> > > > > +++ b/include/standard-headers/asm-s390/vfio_ccw.h
> > > > > @@ -0,0 +1,28 @@
> > > > > +/*
> > > > > + * Interfaces for vfio-ccw
> > > > > + *
> > > > > + * Copyright IBM Corp. 2017
> > > > > + *
> > > > > + * This program is free software; you can redistribute it and/or modify
> > > > > + * it under the terms of the GNU General Public License (version 2 only)
> > > > > + * as published by the Free Software Foundation.
> > > > > + *
> > > > > + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
> > > > > + */
> > > > > +
> > > > > +#ifndef _VFIO_CCW_H_
> > > > > +#define _VFIO_CCW_H_
> > > > > +
> > > > > +#include "standard-headers/linux/types.h"
> > > > > +
> > > > > +struct ccw_io_region {
> > > > > +#define ORB_AREA_SIZE 12
> > > > > +	uint8_t  orb_area[ORB_AREA_SIZE];
> > > > > +#define SCSW_AREA_SIZE 12
> > > > > +	uint8_t  scsw_area[SCSW_AREA_SIZE];
> > > > > +#define IRB_AREA_SIZE 96
> > > > > +	uint8_t  irb_area[IRB_AREA_SIZE];
> > > > > +	uint32_t ret_code;
> > > > > +} QEMU_PACKED;
> > > > > +
> > > > > +#endif  
> > > > 
> > > > This is really part of the uapi for the vfio-ccw mdev device, isn't it?  
> > > Yes, it is.
> > >   
> > > > Should it really be buried in asm-s390 in the kernel?
> > > >   
> > > We had an internal discussion on this question before, since we think
> > > this interface is strongly s390 dependent, we put it here. What do you
> > > suggest? Thanks,  
> > 
> > As there are already architecture-specific definitions in the common
> > file, having everything in the same file is probably better. I'm
> > certainly not against moving it out from asm-s390.
> 
> As soon as we use it for the interface definition to the vfio region, I
> think it makes sense for it to move to uapi.  It's not really
> architecture specific as much as it is device specific, for a device
> which happens to only appear on s390 hardware.  Putting it in uapi
> should also make sure people think twice about changing it.  Thanks,
> 
> Alex
> 
Fair enough. Let's move it to include/uapi/linux/vfio_ccw.h.

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [PATCH RFC v2 03/12] s390x/css: add s390-map-css machine option
  2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
  (?)
  (?)
@ 2017-02-17  2:08   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-02-17  2:08 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: linux-s390, pasic, kvm, pmorel, qemu-devel, borntraeger,
	alex.williamson, renxiaof, wkywang, cornelia.huck, agraf

* Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> [2017-01-12 08:25:04 +0100]:

> From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> 
> We want to support real (i.e. not virtual) channel devices
> even for guests that do not support MCSS-E (where guests may
> see devices from any channel subsystem image at once). As all
> virtio-ccw devices are in css 0xfe (and show up in the default
> css 0 for guests not activating MCSS-E), we need an option to
> map e.g. passed-through subchannels from their real css (0-3,
> or 0 for hosts not activating MCSS-E) into the default css.
> This will be exploited in a later patch.

After some brainstorming, we decided to change this interface a bit.

The first thing is that, we agreed that "s390-squash-mcss" is a better
name than "s390-map-css". The new name denotes that it is trying to
accommodate the devices from multiple channel subsystems into a
non-mcsse-e system, and the word "suqash" is more accurate about what
is happening internally.

The second thing is, we should never map/squash a vfio-ccw device into
css 0xfe, which is reserved for virtio device only. So when squashing,
we need to do it the other way around (i.e. have virtio devices at
0.x.xxxx instead of fe.x.xxxx to accommodate non-mcsse-e).

> 
> Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
[...]

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

* Re: [Qemu-devel] [PATCH RFC v2 03/12] s390x/css: add s390-map-css machine option
  2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
  (?)
@ 2017-02-17  2:08   ` Dong Jia Shi
  -1 siblings, 0 replies; 55+ messages in thread
From: Dong Jia Shi @ 2017-02-17  2:08 UTC (permalink / raw)
  To: Dong Jia Shi
  Cc: kvm, linux-s390, qemu-devel, renxiaof, cornelia.huck,
	borntraeger, agraf, alex.williamson, pmorel, pasic, wkywang

* Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> [2017-01-12 08:25:04 +0100]:

> From: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
> 
> We want to support real (i.e. not virtual) channel devices
> even for guests that do not support MCSS-E (where guests may
> see devices from any channel subsystem image at once). As all
> virtio-ccw devices are in css 0xfe (and show up in the default
> css 0 for guests not activating MCSS-E), we need an option to
> map e.g. passed-through subchannels from their real css (0-3,
> or 0 for hosts not activating MCSS-E) into the default css.
> This will be exploited in a later patch.

After some brainstorming, we decided to change this interface a bit.

The first thing is that, we agreed that "s390-squash-mcss" is a better
name than "s390-map-css". The new name denotes that it is trying to
accommodate the devices from multiple channel subsystems into a
non-mcsse-e system, and the word "suqash" is more accurate about what
is happening internally.

The second thing is, we should never map/squash a vfio-ccw device into
css 0xfe, which is reserved for virtio device only. So when squashing,
we need to do it the other way around (i.e. have virtio devices at
0.x.xxxx instead of fe.x.xxxx to accommodate non-mcsse-e).

> 
> Signed-off-by: Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
[...]

-- 
Dong Jia

^ permalink raw reply	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2017-02-17  2:08 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-12  7:25 [PATCH RFC v2 00/12] basic channel IO passthrough infrastructure based on vfio Dong Jia Shi
2017-01-12  7:25 ` [Qemu-devel] " Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 01/12] update-linux-headers: add asm-s390/vfio_ccw.h Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 02/12] vfio: linux-headers update for vfio-ccw Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-01-17 21:51   ` Alex Williamson
2017-01-17 21:51     ` [Qemu-devel] " Alex Williamson
2017-01-18  2:51     ` Dong Jia Shi
2017-01-18  2:51     ` [Qemu-devel] " Dong Jia Shi
2017-01-18 12:41       ` Cornelia Huck
2017-01-18 12:41         ` [Qemu-devel] " Cornelia Huck
2017-01-18 20:43         ` Alex Williamson
2017-01-18 20:43           ` [Qemu-devel] " Alex Williamson
2017-01-19  1:54           ` Dong Jia Shi
2017-01-19  1:54           ` Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 03/12] s390x/css: add s390-map-css machine option Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-02-17  2:08   ` Dong Jia Shi
2017-02-17  2:08   ` Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 04/12] s390x/css: realize css_sch_build_schib Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 05/12] s390x/css: realize css_create_sch Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 06/12] s390x/css: device support for s390-ccw passthrough Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 07/12] vfio/ccw: vfio based subchannel passthrough driver Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-01-17 22:49   ` Alex Williamson
2017-01-17 22:49     ` [Qemu-devel] " Alex Williamson
2017-01-18  3:22     ` Dong Jia Shi
2017-01-18  3:22     ` [Qemu-devel] " Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 08/12] vfio/ccw: get io region info Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-01-17 22:49   ` Alex Williamson
2017-01-17 22:49     ` [Qemu-devel] " Alex Williamson
2017-01-18  5:22     ` Dong Jia Shi
2017-01-18  5:22     ` [Qemu-devel] " Dong Jia Shi
2017-01-18  5:51       ` Dong Jia Shi
2017-01-18  5:51       ` [Qemu-devel] " Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 09/12] vfio/ccw: get irqs info and set the eventfd fd Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-01-17 22:53   ` Alex Williamson
2017-01-17 22:53     ` [Qemu-devel] " Alex Williamson
2017-01-18  5:55     ` Dong Jia Shi
2017-01-18  5:55     ` [Qemu-devel] " Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 10/12] s390x/css: introduce and realize ccw-request callback Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 11/12] s390x/css: ccws translation infrastructure Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-01-12  7:25 ` [PATCH RFC v2 12/12] vfio/ccw: update sense data if a unit check is pending Dong Jia Shi
2017-01-12  7:25   ` [Qemu-devel] " Dong Jia Shi
2017-01-12  8:00 ` [Qemu-devel] [PATCH RFC v2 00/12] basic channel IO passthrough infrastructure based on vfio no-reply
2017-01-12  8:00   ` no-reply
2017-01-12  8:00   ` no-reply

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.