From 274250c30158f60aefb46088a7bb0d711061226c Mon Sep 17 00:00:00 2001 From: Xiao Feng Ren Date: Wed, 17 May 2017 02:48:03 +0200 Subject: s390x/css: add s390-squash-mcss machine option 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 squash both the virtio subchannels and 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 Signed-off-by: Dong Jia Shi Message-Id: <20170517004813.58227-4-bjsdjshi@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- include/hw/s390x/s390-virtio-ccw.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/hw') diff --git a/include/hw/s390x/s390-virtio-ccw.h b/include/hw/s390x/s390-virtio-ccw.h index 7b8a3e4..3027555f 100644 --- a/include/hw/s390x/s390-virtio-ccw.h +++ b/include/hw/s390x/s390-virtio-ccw.h @@ -29,6 +29,7 @@ typedef struct S390CcwMachineState { bool aes_key_wrap; bool dea_key_wrap; uint8_t loadparm[8]; + bool s390_squash_mcss; } S390CcwMachineState; typedef struct S390CcwMachineClass { -- cgit v1.1 From 8f3cf0128cbac1ac19be8515dc184edb88dd5fb1 Mon Sep 17 00:00:00 2001 From: Xiao Feng Ren Date: Wed, 17 May 2017 02:48:04 +0200 Subject: s390x/css: realize css_sch_build_schib The S390 virtual css support already has a mechanism to build a virtual subchannel information block (schib) 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. Reviewed-by: Pierre Morel Signed-off-by: Xiao Feng Ren Signed-off-by: Dong Jia Shi Message-Id: <20170517004813.58227-5-bjsdjshi@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- include/hw/s390x/css.h | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'include/hw') diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index e61fa74..e59a115 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -95,6 +95,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; @@ -116,6 +134,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); unsigned int css_find_free_chpid(uint8_t cssid); uint16_t css_build_subchannel_id(SubchDev *sch); void css_reset(void); @@ -164,23 +183,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) extern PropertyInfo css_devid_ro_propinfo; -- cgit v1.1 From 817d4a6bc8bc6c2ad57ffdbab1a33c9b930ddde4 Mon Sep 17 00:00:00 2001 From: Dong Jia Shi Date: Wed, 17 May 2017 02:48:05 +0200 Subject: s390x/css: realize css_create_sch 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 reconstruct css_create_virtual_sch to a new css_create_sch function to handle all these cases and do allocation and initialization of the subchannel according to the device type and machine configuration. Reviewed-by: Pierre Morel Signed-off-by: Dong Jia Shi Message-Id: <20170517004813.58227-6-bjsdjshi@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- include/hw/s390x/css-bridge.h | 1 + include/hw/s390x/css.h | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'include/hw') diff --git a/include/hw/s390x/css-bridge.h b/include/hw/s390x/css-bridge.h index 5a0203b..cf08604 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 squash_mcss; } VirtualCssBus; #define TYPE_VIRTUAL_CSS_BUS "virtual-css-bus" diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index e59a115..60ff83e 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -192,16 +192,25 @@ extern PropertyInfo css_devid_ro_propinfo; /** * Create a subchannel for the given bus id. * - * If @p bus_id is valid, verify that it uses the virtual channel - * subsystem id and is not already in use, and find a free subchannel - * id for it. If @p bus_id is not valid, find a free subchannel id and - * device number across all subchannel sets. If either of the former - * actions succeed, 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. + * If @p bus_id is valid, and @p squash_mcss is true, verify that it is + * not already in use in the default css, and find a free devno from the + * default css image for it. + * If @p bus_id is valid, and @p squash_mcss is false, verify that it is + * not already in use, and find a free devno for it. + * If @p bus_id is not valid, and if either @p squash_mcss or @p is_virtual + * is true, find a free subchannel id and device number across all + * subchannel sets from the default css image. + * If @p bus_id is not valid, and if both @p squash_mcss and @p is_virtual + * are false, find a non-full css image and find a free subchannel id and + * device number across all subchannel sets from it. + * + * If either of the former actions succeed, 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_virtual_sch(CssDevId bus_id, Error **errp); +SubchDev *css_create_sch(CssDevId bus_id, bool is_virtual, bool squash_mcss, + Error **errp); #endif -- cgit v1.1 From a8eac9431ad060012348908f93d6421ae3c97300 Mon Sep 17 00:00:00 2001 From: Dong Jia Shi Date: Wed, 17 May 2017 02:48:06 +0200 Subject: s390x/css: device support for s390-ccw passthrough 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. Reviewed-by: Eric Auger Signed-off-by: Dong Jia Shi Message-Id: <20170517004813.58227-7-bjsdjshi@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- include/hw/s390x/s390-ccw.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 include/hw/s390x/s390-ccw.h (limited to 'include/hw') diff --git a/include/hw/s390x/s390-ccw.h b/include/hw/s390x/s390-ccw.h new file mode 100644 index 0000000..b58d8e9 --- /dev/null +++ b/include/hw/s390x/s390-ccw.h @@ -0,0 +1,38 @@ +/* + * s390 CCW Assignment Support + * + * Copyright 2017 IBM Corp. + * Author(s): Dong Jia Shi + * Xiao Feng Ren + * + * 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; + char *mdevid; +} S390CCWDevice; + +typedef struct S390CCWDeviceClass { + CCWDeviceClass parent_class; + void (*realize)(S390CCWDevice *dev, char *sysfsdev, Error **errp); + void (*unrealize)(S390CCWDevice *dev, Error **errp); +} S390CCWDeviceClass; + +#endif -- cgit v1.1 From 1dcac3e15263674bb9c84feed6b35bb1f7bc1c6b Mon Sep 17 00:00:00 2001 From: Xiao Feng Ren Date: Wed, 17 May 2017 02:48:07 +0200 Subject: vfio/ccw: vfio based subchannel passthrough driver 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,sysfsdev=$mdev_file_path,devno=xx.x.xxxx' Reviewed-by: Eric Auger Acked-by: Alex Williamson Signed-off-by: Xiao Feng Ren Signed-off-by: Dong Jia Shi Message-Id: <20170517004813.58227-8-bjsdjshi@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- include/hw/vfio/vfio-common.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/hw') 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 { -- cgit v1.1 From 8ca2b376b47fff58f7ab6f16d86a66d4af3a2be2 Mon Sep 17 00:00:00 2001 From: Xiao Feng Ren Date: Wed, 17 May 2017 02:48:10 +0200 Subject: s390x/css: introduce and realize ccw-request callback 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. Acked-by: Alex Williamson Signed-off-by: Xiao Feng Ren Signed-off-by: Dong Jia Shi Message-Id: <20170517004813.58227-11-bjsdjshi@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- include/hw/s390x/css.h | 2 ++ include/hw/s390x/s390-ccw.h | 1 + 2 files changed, 3 insertions(+) (limited to 'include/hw') diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index 60ff83e..a932f91 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -137,6 +137,8 @@ void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type); int css_sch_build_schib(SubchDev *sch, CssDevId *dev_id); unsigned int css_find_free_chpid(uint8_t cssid); 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); diff --git a/include/hw/s390x/s390-ccw.h b/include/hw/s390x/s390-ccw.h index b58d8e9..9f45cf1 100644 --- a/include/hw/s390x/s390-ccw.h +++ b/include/hw/s390x/s390-ccw.h @@ -33,6 +33,7 @@ typedef struct S390CCWDeviceClass { CCWDeviceClass parent_class; void (*realize)(S390CCWDevice *dev, char *sysfsdev, Error **errp); void (*unrealize)(S390CCWDevice *dev, Error **errp); + int (*handle_request) (ORB *, SCSW *, void *); } S390CCWDeviceClass; #endif -- cgit v1.1 From bab482d7405f9fe3cac9c213d60f9ca9442c047b Mon Sep 17 00:00:00 2001 From: Xiao Feng Ren Date: Wed, 17 May 2017 02:48:11 +0200 Subject: s390x/css: ccw translation infrastructure 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 Signed-off-by: Dong Jia Shi Message-Id: <20170517004813.58227-12-bjsdjshi@linux.vnet.ibm.com> Signed-off-by: Cornelia Huck --- include/hw/s390x/css.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/hw') diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index a932f91..596a2f2 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -91,6 +91,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; }; @@ -148,6 +149,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); typedef enum { CSS_IO_ADAPTER_VIRTIO = 0, -- cgit v1.1