basic vfio-ccw infrastructure
Subsystems (7)
v4 cover basic vfio-ccw infrastructure
vfio-ccw: the basic infrastructure
==================================
Introduction
------------
Here we describe the vfio support for I/O subchannel devices for Linux/s390. Motivation for vfio-ccw is to passthrough subchannels to a virtual machine, while vfio is the means.
Different than other hardware architectures, s390 has defined a unified I/O access method, which is so called Channel I/O. It has its own access patterns:
- Channel programs run asynchronously on a separate (co)processor.
- The channel subsystem will access any memory designated by the caller in the channel program directly, i.e. there is no iommu involved.
Thus when we introduce vfio support for these devices, we realize it with a mediated device (mdev) implementation. The vfio mdev will be added to an iommu group, so as to make itself able to be managed by the vfio framework. And we add read/write callbacks for special vfio I/O regions to pass the channel programs from the mdev to its parent device (the real I/O subchannel device) to do further address translation and to perform I/O instructions.
This document does not intend to explain the s390 I/O architecture in every detail. More information/reference could be found here:
- A good start to know Channel I/O in general:
https://en.wikipedia.org/wiki/Channel_I/O
- s390 architecture:
s390 Principles of Operation manual (IBM Form. No. SA22-7832)
- The existing Qemu code which implements a simple emulated channel subsystem could also be a good reference. It makes it easier to follow the flow.
qemu/hw/s390x/css.c
For vfio mediated device framework:
- Documentation/vfio-mediated-device.txt
Motivation of vfio-ccw
----------------------
Currently, a guest virtualized via qemu/kvm on s390 only sees paravirtualized virtio devices via the "Virtio Over Channel I/O (virtio-ccw)" transport. This makes virtio devices discoverable via standard operating system algorithms for handling channel devices.
However this is not enough. On s390 for the majority of devices, which use the standard Channel I/O based mechanism, we also need to provide the functionality of passing through them to a Qemu virtual machine. This includes devices that don't have a virtio counterpart (e.g. tape drives) or that have specific characteristics which guests want to exploit.
For passing a device to a guest, we want to use the same interface as everybody else, namely vfio. Thus, we would like to introduce vfio support for channel devices. And we would like to name this new vfio device "vfio-ccw".
Access patterns of CCW devices
------------------------------
s390 architecture has implemented a so called channel subsystem, that provides a unified view of the devices physically attached to the systems. Though the s390 hardware platform knows about a huge variety of different peripheral attachments like disk devices (aka. DASDs), tapes, communication controllers, etc. They can all be accessed by a well defined access method and they are presenting I/O completion a unified
way: I/O interruptions.
All I/O requires the use of channel command words (CCWs). A CCW is an instruction to a specialized I/O channel processor. A channel program is a sequence of CCWs which are executed by the I/O channel subsystem. To issue a channel program to the channel subsystem, it is required to build an operation request block (ORB), which can be used to point out the format of the CCW and other control information to the system. The operating system signals the I/O channel subsystem to begin executing the channel program with a SSCH (start sub-channel) instruction. The central processor is then free to proceed with non-I/O instructions until interrupted. The I/O completion result is received by the interrupt handler in the form of interrupt response block (IRB).
Back to vfio-ccw, in short:
- ORBs and channel programs are built in guest kernel (with guest physical addresses).
- ORBs and channel programs are passed to the host kernel.
- Host kernel translates the guest physical addresses to real addresses and starts the I/O with issuing a privileged Channel I/O instruction (e.g SSCH).
- channel programs run asynchronously on a separate processor.
- I/O completion will be signaled to the host with I/O interruptions. And it will be copied as IRB to user space to pass it back to the guest.
Physical vfio ccw device and its child mdev
-------------------------------------------
As mentioned above, we realize vfio-ccw with a mdev implementation.
Channel I/O does not have IOMMU hardware support, so the physical vfio-ccw device does not have an IOMMU level translation or isolation.
Sub-channel I/O instructions are all privileged instructions, When handling the I/O instruction interception, vfio-ccw has the software policing and translation how the channel program is programmed before it gets sent to hardware.
Within this implementation, we have two drivers for two types of devices:
- The vfio_ccw driver for the physical subchannel device. This is an I/O subchannel driver for the real subchannel device. It realizes a group of callbacks and registers to the mdev framework as a parent (physical) device. As a consequence, mdev provides vfio_ccw a generic interface (sysfs) to create mdev devices. A vfio mdev could be created by vfio_ccw then and added to the mediated bus. It is the vfio device that added to an IOMMU group and a vfio group. vfio_ccw also provides an I/O region to accept channel program request from user space and store I/O interrupt result for user space to retrieve. To notify user space an I/O completion, it offers an interface to setup an eventfd fd for asynchronous signaling.
- The vfio_mdev driver for the mediated vfio ccw device. This is provided by the mdev framework. It is a vfio device driver for the mdev that created by vfio_ccw.
It realize a group of vfio device driver callbacks, adds itself to a vfio group, and registers itself to the mdev framework as a mdev driver.
It uses a vfio iommu backend that uses the existing map and unmap ioctls, but rather than programming them into an IOMMU for a device, it simply stores the translations for use by later requests. This means that a device programmed in a VM with guest physical addresses can have the vfio kernel convert that address to process virtual address, pin the page and program the hardware with the host physical address in one step.
For a mdev, the vfio iommu backend will not pin the pages during the VFIO_IOMMU_MAP_DMA ioctl. Mdev framework will only maintain a database of the iova<->vaddr mappings in this operation. And they export a vfio_pin_pages and a vfio_unpin_pages interfaces from the vfio iommu backend for the physical devices to pin and unpin pages by demand.
Below is a high Level block diagram.
+-------------+ | | | +---------+ | mdev_register_driver() +--------------+ | | Mdev | +<-----------------------+ | | | bus | | | vfio_mdev.ko | | | driver | +----------------------->+ |<-> VFIO user | +---------+ | probe()/remove() +--------------+ APIs | | | MDEV CORE | | MODULE | | mdev.ko | | +---------+ | mdev_register_device() +--------------+ | |Physical | +<-----------------------+ | | | device | | | vfio_ccw.ko |<-> subchannel | |interface| +----------------------->+ | device | +---------+ | callback +--------------+ +-------------+
The process of how these work together.
1. vfio_ccw.ko drives the physical I/O subchannel, and registers the physical device (with callbacks) to mdev framework.
When vfio_ccw probing the subchannel device, it registers device pointer and callbacks to the mdev framework. Mdev related file nodes under the device node in sysfs would be created for the subchannel device, namely 'mdev_create', 'mdev_destroy' and 'mdev_supported_types'.
2. Create a mediated vfio ccw device.
Use the 'mdev_create' sysfs file, we need to manually create one (and only one for our case) mediated device.
3. vfio_mdev.ko drives the mediated ccw device.
vfio_mdev is also the vfio device drvier. It will probe the mdev and add it to an iommu_group and a vfio_group. Then we could pass through the mdev to a guest.
vfio-ccw I/O region
-------------------
An I/O region is used to accept channel program request from user space and store I/O interrupt result for user space to retrieve. The defination of the region is:
struct ccw_io_region {
#define ORB_AREA_SIZE 12 __u8 orb_area[ORB_AREA_SIZE]; #define SCSW_AREA_SIZE 12 __u8 scsw_area[SCSW_AREA_SIZE]; #define IRB_AREA_SIZE 96 __u8 irb_area[IRB_AREA_SIZE]; __u32 ret_code; } __packed;
While starting an I/O request, orb_area should be filled with the guest ORB, and scsw_area should be filled with the SCSW of the Virtual Subchannel.
irb_area stores the I/O result.
ret_code stores a return code for each access of the region.
vfio-ccw patches overview
-------------------------
For now, our patches are rebased on the latest mdev implementation. vfio-ccw follows what vfio-pci did on the s390 paltform and uses vfio-iommu-type1 as the vfio iommu backend. It's a good start to launch the code review for vfio-ccw. Note that the implementation is far from complete yet; but we'd like to get feedback for the general architecture.
* CCW translation APIs
- Description:
These introduce a group of APIs (start with 'cp_') to do CCW translation. The CCWs passed in by a user space program are organized with their guest physical memory addresses. These APIs will copy the CCWs into the kernel space, and assemble a runnable kernel channel program by updating the guest physical addresses with their corresponding host physical addresses.
- Patches:
vfio: ccw: introduce channel program interfaces
* vfio_ccw device driver
- Description:
The following patches utilizes the CCW translation APIs and introduce vfio_ccw, which is the driver for the I/O subchannel devices you want to pass through.
vfio_ccw implements the following vfio ioctls:
VFIO_DEVICE_GET_INFO
VFIO_DEVICE_GET_IRQ_INFO
VFIO_DEVICE_GET_REGION_INFO
VFIO_DEVICE_RESET
VFIO_DEVICE_SET_IRQS
This provides an I/O region, so that the user space program can pass a channel program to the kernel, to do further CCW translation before issuing them to a real device.
This also provides the SET_IRQ ioctl to setup an event notifier to notify the user space program the I/O completion in an asynchronous way.
- Patches:
vfio: ccw: basic implementation for vfio_ccw driver
vfio: ccw: introduce ccw_io_region
vfio: ccw: realize VFIO_DEVICE_GET_REGION_INFO ioctl
vfio: ccw: realize VFIO_DEVICE_RESET ioctl
vfio: ccw: realize VFIO_DEVICE_G(S)ET_IRQ_INFO ioctls
The user of vfio-ccw is not limited to Qemu, while Qemu is definitely a good example to get understand how these patches work. Here is a little bit more detail how an I/O request triggered by the Qemu guest will be handled (without error handling).
Explanation:
Q1-Q7: Qemu side process.
K1-K5: Kernel side process.
Q1. Get I/O region info during initialization.
Q2. Setup event notifier and handler to handle I/O completion.
... ...
Q3. Intercept a ssch instruction.
Q4. Write the guest channel program and ORB to the I/O region.
K1. Copy from guest to kernel.
K2. Translate the guest channel program to a host kernel space
channel program, which becomes runnable for a real device.
K3. With the necessary information contained in the orb passed in
by Qemu, issue the ccwchain to the device.
K4. Return the ssch CC code.
Q5. Return the CC code to the guest.
... ...
K5. Interrupt handler gets the I/O result and write the result to
the I/O region.
K6. Signal Qemu to retrieve the result.
Q6. Get the signal and event handler reads out the result from the I/O
region.
Q7. Update the irb for the guest.
Limitations
-----------
The current vfio-ccw implementation focuses on supporting basic commands needed to implement block device functionality (read/write) of DASD/ECKD device only. Some commands may need special handling in the future, for example, anything related to path grouping.
DASD is a kind of storage device. While ECKD is a data recording format. More information for DASD and ECKD could be found here:
https://en.wikipedia.org/wiki/Direct-access_storage_device
https://en.wikipedia.org/wiki/Count_key_data
Together with the corresponding work in Qemu, we can bring the passed through DASD/ECKD device online in a guest now and use it as a block device.
Reference
---------
1. ESA/s390 Principles of Operation manual (IBM Form. No. SA22-7832)
2. ESA/390 Common I/O Device Commands manual (IBM Form. No. SA22-7204)
3. https://en.wikipedia.org/wiki/Channel_I/O
4. Documentation/s390/cds.txt
5. Documentation/vfio.txt
6. Documentation/vfio-mediated-device.txt
Change log
----------
v3 -> v4:
1. Patch 1 and 2: Cc the maintainers.
2. Patch 4:
To handle the cio cancel correctly, replace wait_for_completion with wait_for_completion_timeout.
Cosmetic modification for prompts, comments and typos. Return -ENODEV for QDIO subchannel when probing.
3. Patch 7:
Fix build test error:
Missing UAPI file arch/s390/include/uapi/asm/vfio_ccw.h.
4. Patch 11:
Remove VFIO_IRQ_INFO_NORESIZE flag in vfio_ccw_mdev_get_irq_info.
5. Patch 15:
Remove the config entry for CCW0, and the #ifdefs. Move struct ccw0 to cio.h.
Make the ccw0->ccw1 translation more compliant to the PoP book.
6. Patch 16:
Add vfio-ccw maintainers in MAINTAINERS.
v2 -> v3:
1. Adopt the newest mdev interfaces.
2. Move vfio_ccw.h to uapi.
3. Add a atomic_t avil variable in vfio_ccw_private to denotes the available mdev instance number of the subchannel.
4. Patch 11: correct the usage of VFIO_CCW_NUM_IRQS.
5. Remove license statements.
6. Cosmetic rewording of commit message and comments.
v1 -> v2:
1. Rebase the implementation to the mdev framework approach.
2. Introduce a MMIO I/O region to handle I/O requests and results.
Dong Jia Shi (16):
s390: cio: introduce cio_cancel_halt_clear
s390: cio: export more interfaces
vfio: ccw: define device_api strings
vfio: ccw: basic implementation for vfio_ccw driver
vfio: ccw: introduce channel program interfaces
vfio: ccw: register vfio_ccw to the mediated device framework
vfio: ccw: introduce ccw_io_region
vfio: ccw: handle ccw command request
vfio: ccw: realize VFIO_DEVICE_GET_REGION_INFO ioctl
vfio: ccw: realize VFIO_DEVICE_RESET ioctl
vfio: ccw: realize VFIO_DEVICE_G(S)ET_IRQ_INFO ioctls
vfio: ccw: return I/O results asynchronously
vfio: ccw: introduce a finite state machine
docs: add documentation for vfio-ccw
vfio: ccw: introduce support for ccw0
MAINTAINERS: Add vfio-ccw maintainers
Documentation/s390/00-INDEX | 2 + Documentation/s390/vfio-ccw.txt | 303 +++++++++++++ MAINTAINERS | 10 + arch/s390/Kconfig | 10 + arch/s390/include/asm/cio.h | 18 + arch/s390/include/asm/isc.h | 1 + drivers/iommu/Kconfig | 8 + drivers/s390/cio/Makefile | 3 + drivers/s390/cio/cio.c | 69 +++ drivers/s390/cio/cio.h | 1 + drivers/s390/cio/device_fsm.c | 54 +-- drivers/s390/cio/vfio_ccw_cp.c | 842 ++++++++++++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_cp.h | 42 ++ drivers/s390/cio/vfio_ccw_drv.c | 308 +++++++++++++ drivers/s390/cio/vfio_ccw_fsm.c | 207 +++++++++ drivers/s390/cio/vfio_ccw_ops.c | 447 +++++++++++++++++++ drivers/s390/cio/vfio_ccw_private.h | 96 ++++ include/uapi/linux/vfio.h | 18 + include/uapi/linux/vfio_ccw.h | 24 + 19 files changed, 2417 insertions(+), 46 deletions(-) create mode 100644 Documentation/s390/vfio-ccw.txt create mode 100644 drivers/s390/cio/vfio_ccw_cp.c create mode 100644 drivers/s390/cio/vfio_ccw_cp.h create mode 100644 drivers/s390/cio/vfio_ccw_drv.c create mode 100644 drivers/s390/cio/vfio_ccw_fsm.c create mode 100644 drivers/s390/cio/vfio_ccw_ops.c create mode 100644 drivers/s390/cio/vfio_ccw_private.h create mode 100644 include/uapi/linux/vfio_ccw.h
Signature · 1 line
2.8.4
PATCH v4 1/16 s390: cio: introduce cio_cancel_halt_clear
For future code reuse purpose, this decouples the cio code with the ccw device specific parts from ccw_device_cancel_halt_clear, and makes a new common I/O interface named cio_cancel_halt_clear.
--- drivers/s390/cio/cio.c | 59 +++++++++++++++++++++++++++++++++++++++++++ drivers/s390/cio/cio.h | 1 + drivers/s390/cio/device_fsm.c | 54 ++++++--------------------------------- 3 files changed, 68 insertions(+), 46 deletions(-)
drivers/s390/cio/cio.c +59 -0
@@ -309,6 +309,65 @@ cio_cancel (struct subchannel *sch) } } +/** +* cio_cancel_halt_clear - Cancel running I/O by performing cancel, halt +* and clear ordinally if subchannel is valid. +* @sch: subchannel on which to perform the cancel_halt_clear operation +* @iretry: the number of the times remained to retry the next operation +* +* This should be called repeatedly since halt/clear are asynchronous +* operations. We do one try with cio_cancel, two tries with cio_halt, +* 255 tries with cio_clear. The caller should initialize @iretry with +* the value 255 for its first call to this, and keep using the same +* @iretry in the subsequent calls until it gets a non -EBUSY return. +* +* Returns 0 if device now idle, -ENODEV for device not operational, +* -EBUSY if an interrupt is expected (either from halt/clear or from a +* status pending), and -EIO if out of retries. +*/ +int cio_cancel_halt_clear (struct subchannel *sch,int *iretry) +{ +int ret; + +if (cio_update_schib (sch)) +return -ENODEV ; +if (!sch->schib.pmcw.ena) +/* Not operational -> done. */ +return 0 ; +/* Stage 1: cancel io. */ +if (!(scsw_actl (&sch->schib.scsw) &SCSW_ACTL_HALT_PEND ) && + !(scsw_actl (&sch->schib.scsw) &SCSW_ACTL_CLEAR_PEND )) { +if (!scsw_is_tm (&sch->schib.scsw)) { + ret =cio_cancel (sch); +if (ret != -EINVAL ) +return ret; + } +/* +* Cancel io unsuccessful or not applicable (transport mode). +* Continue with asynchronous instructions. +*/ + *iretry =3 ;/* 3 halt retries. */ + } +/* Stage 2: halt io. */ +if (!(scsw_actl (&sch->schib.scsw) &SCSW_ACTL_CLEAR_PEND )) { +if (*iretry) { + *iretry -=1 ; + ret =cio_halt (sch); +if (ret != -EBUSY ) +return (ret ==0 ) ? -EBUSY : ret; + } +/* Halt io unsuccessful. */ + *iretry =255 ;/* 255 clear retries. */ + } +/* Stage 3: clear io. */ +if (*iretry) { + *iretry -=1 ; + ret =cio_clear (sch); +return (ret ==0 ) ? -EBUSY : ret; + } +/* Function was unsuccessful */ +return -EIO ; +}static void cio_apply_config (struct subchannel *sch,struct schib *schib) {
drivers/s390/cio/cio.h +1 -0
@@ -123,6 +123,7 @@ extern int cio_enable_subchannel(struct subchannel *, u32);extern int cio_disable_subchannel (struct subchannel *);extern int cio_cancel (struct subchannel *);extern int cio_clear (struct subchannel *); +extern int cio_cancel_halt_clear (struct subchannel *,int *);extern int cio_resume (struct subchannel *);extern int cio_halt (struct subchannel *);extern int cio_start (struct subchannel *,struct ccw1 *,__u8 );
drivers/s390/cio/device_fsm.c +8 -46
66 lines not on this page · raw message
Signature · 1 line
2.8.4
PATCH v4 2/16 s390: cio: export more interfaces
In reply to Dong Jia ShiExport the common I/O interfaces those are needed by an I/O subchannel driver to actually talk to the subchannel.
--- drivers/s390/cio/cio.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/s390/cio/cio.c +10 -0
@@ -170,12 +170,14 @@ cio_start_key (struct subchannel *sch, /* subchannel structure */return ccode; } } +EXPORT_SYMBOL_GPL (cio_start_key);int cio_start (struct subchannel *sch,struct ccw1 *cpa,__u8 lpm) {return cio_start_key (sch, cpa, lpm,PAGE_DEFAULT_KEY ); } +EXPORT_SYMBOL_GPL (cio_start);/* * resume suspended I/O operation
@@ -208,6 +210,7 @@ cio_resume (struct subchannel *sch)return -ENODEV ; } } +EXPORT_SYMBOL_GPL (cio_resume);/* * halt I/O operation
@@ -241,6 +244,7 @@ cio_halt(struct subchannel *sch)return -ENODEV ; } } +EXPORT_SYMBOL_GPL (cio_halt);/* * Clear I/O operation
@@ -271,6 +275,7 @@ cio_clear(struct subchannel *sch)return -ENODEV ; } } +EXPORT_SYMBOL_GPL (cio_clear);/* * Function: cio_cancel
@@ -308,6 +313,7 @@ cio_cancel (struct subchannel *sch)return -ENODEV ; } } +EXPORT_SYMBOL_GPL (cio_cancel);/** * cio_cancel_halt_clear - Cancel running I/O by performing cancel, halt
@@ -368,6 +374,7 @@ int cio_cancel_halt_clear(struct subchannel *sch, int *iretry)/* Function was unsuccessful */ return -EIO ; } +EXPORT_SYMBOL_GPL (cio_cancel_halt_clear);static void cio_apply_config (struct subchannel *sch,struct schib *schib) {
@@ -441,6 +448,7 @@ int cio_commit_config(struct subchannel *sch) }return ret; } +EXPORT_SYMBOL_GPL (cio_commit_config);/** * cio_update_schib - Perform stsch and update schib if subchannel is valid.
@@ -1046,6 +1054,7 @@ int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key)return cio_start_handle_notoper (sch, lpm); } } +EXPORT_SYMBOL_GPL (cio_tm_start_key);/** * cio_tm_intrg - perform interrogate function
@@ -1071,3 +1080,4 @@ int cio_tm_intrg(struct subchannel *sch)return -ENODEV ; } } +EXPORT_SYMBOL_GPL (cio_tm_intrg);
Signature · 1 line
2.8.4
PATCH v4 3/16 vfio: ccw: define device_api strings
In reply to Dong Jia ShiDefine vfio-ccw device API strings. CCW vendor driver using mediated device framework should use this string for device_api attribute.
--- include/uapi/linux/vfio.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/vfio.h +1 -0
@@ -212,6 +212,7 @@ struct vfio_device_info {#define VFIO_DEVICE_API_PCI_STRING "vfio-pci"#define VFIO_DEVICE_API_PLATFORM_STRING "vfio-platform"#define VFIO_DEVICE_API_AMBA_STRING "vfio-amba" +#define VFIO_DEVICE_API_CCW_STRING "vfio-ccw"/** * VFIO_DEVICE_GET_REGION_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 8,
Signature · 1 line
2.8.4
PATCH v4 4/16 vfio: ccw: basic implementation for vfio_ccw driver
In reply to Dong Jia ShiTo make vfio support subchannel devices, we need a css driver for the vfio subchannels. This patch adds a basic vfio-ccw subchannel driver for this purpose.
To enable VFIO for vfio-ccw, enable S390_CCW_IOMMU config option and configure VFIO as required.
--- arch/s390/Kconfig | 10 ++ arch/s390/include/asm/isc.h | 1 + drivers/iommu/Kconfig | 8 ++ drivers/s390/cio/Makefile | 3 + drivers/s390/cio/vfio_ccw_drv.c | 262 ++++++++++++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_private.h | 25 ++++ 6 files changed, 309 insertions(+) create mode 100644 drivers/s390/cio/vfio_ccw_drv.c create mode 100644 drivers/s390/cio/vfio_ccw_private.h
arch/s390/Kconfig +10 -0
@@ -672,6 +672,16 @@ config EADM_SCH To compile this driver as a module, choose M here: the module will be called eadm_sch. +config VFIO_CCW + def_tristate n + prompt "Support for VFIO-CCW subchannels" + depends on S390_CCW_IOMMU && VFIO + help + This driver allows usage of I/O subchannels via VFIO-CCW. + + To compile this driver as a module, choose M here: the + module will be called vfio_ccw. + endmenu menu "Dump support"
arch/s390/include/asm/isc.h +1 -0
@@ -16,6 +16,7 @@#define CONSOLE_ISC 1/* console I/O subchannel */ #define EADM_SCH_ISC 4/* EADM subchannels */ #define CHSC_SCH_ISC 7/* CHSC subchannels */ +#define VFIO_CCW_ISC IO_SCH_ISC/* VFIO-CCW I/O subchannels */ /* Adapter interrupts. */ #define QDIO_AIRQ_ISC IO_SCH_ISC/* I/O subchannel in qdio mode */ #define PCI_ISC 2/* PCI I/O subchannels */
drivers/iommu/Kconfig +8 -0
@@ -327,6 +327,14 @@ config S390_IOMMU help Support for the IOMMU API for s390 PCI devices. +config S390_CCW_IOMMU + bool "S390 CCW IOMMU Support" + depends on S390 && CCW + select IOMMU_API + help + Enables bits of IOMMU API required by VFIO. The iommu_ops + is not implemented as it is not necessary for VFIO. + config MTK_IOMMU bool "MTK IOMMU Support" depends on ARM || ARM64
drivers/s390/cio/Makefile +3 -0
@@ -17,3 +17,6 @@ obj-$(CONFIG_CCWGROUP) += ccwgroup.o qdio-objs := qdio_main.o qdio_thinint.o qdio_debug.o qdio_setup.o obj-$(CONFIG_QDIO) += qdio.o + +vfio_ccw-objs += vfio_ccw_drv.o +obj-$(CONFIG_VFIO_CCW) += vfio_ccw.o
drivers/s390/cio/vfio_ccw_drv.c new file +262 -0
262 lines not on this page · raw message
drivers/s390/cio/vfio_ccw_private.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Private stuff for vfio_ccw driver +* +* Copyright IBM Corp. 2017 +* +* Author(s): Dong Jia Shi <[email protected]> +* Xiao Feng Ren <[email protected]> +*/ + +#ifndef _VFIO_CCW_PRIVATE_H_ +#define _VFIO_CCW_PRIVATE_H_ + +#include "css.h" + +/** +* struct vfio_ccw_private +* @sch: pointer to the subchannel +* @completion: synchronization helper of the I/O completion +*/ +struct vfio_ccw_private { +struct subchannel *sch; +struct completion *completion; +}__aligned(8) ; + +#endif
Signature · 1 line
2.8.4
PATCH v4 5/16 vfio: ccw: introduce channel program interfaces
In reply to Dong Jia ShiIntroduce ccwchain structure and helper functions that can be used to handle a channel program issued from a virtual machine.
The following limitations apply:
1. Supports only prefetch enabled mode.
2. Supports idal(c64) ccw chaining.
3. Supports 4k idaw.
4. Supports ccw1.
5. Supports direct ccw chaining by translating them to idal ccws.
CCW translation requires to leverage the vfio_(un)pin_pages interfaces to pin/unpin sets of mem pages frequently. Currently we have a lack of support to do this in an efficient way. So we introduce pfn_array data structure and helper functions to handle pin/unpin operations here.
--- drivers/s390/cio/Makefile | 2 +- drivers/s390/cio/vfio_ccw_cp.c | 816 +++++++++++++++++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_cp.h | 42 +++ 3 files changed, 859 insertions(+), 1 deletion(-) create mode 100644 drivers/s390/cio/vfio_ccw_cp.c create mode 100644 drivers/s390/cio/vfio_ccw_cp.h
drivers/s390/cio/Makefile +1 -1
@@ -18,5 +18,5 @@ obj-$(CONFIG_CCWGROUP) += ccwgroup.o qdio-objs := qdio_main.o qdio_thinint.o qdio_debug.o qdio_setup.o obj-$(CONFIG_QDIO) += qdio.o -vfio_ccw-objs += vfio_ccw_drv.o +vfio_ccw-objs += vfio_ccw_drv.o vfio_ccw_cp.o obj-$(CONFIG_VFIO_CCW) += vfio_ccw.o
drivers/s390/cio/vfio_ccw_cp.c new file +816 -0
816 lines not on this page · raw message
drivers/s390/cio/vfio_ccw_cp.h new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.8.4
PATCH v4 6/16 vfio: ccw: register vfio_ccw to the mediated device framework
In reply to Dong Jia ShiTo make vfio support subchannel devices, we need to leverage the mediated device framework to create a mediated device for the subchannel device.
This registers the subchannel device to the mediated device framework during probe to enable mediated device creation.
--- arch/s390/Kconfig | 2 +- drivers/s390/cio/Makefile | 2 +- drivers/s390/cio/vfio_ccw_drv.c | 12 ++- drivers/s390/cio/vfio_ccw_ops.c | 147 ++++++++++++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_private.h | 11 +++ 5 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 drivers/s390/cio/vfio_ccw_ops.c
arch/s390/Kconfig +1 -1
@@ -675,7 +675,7 @@ config EADM_SCH config VFIO_CCW def_tristate n prompt "Support for VFIO-CCW subchannels" - depends on S390_CCW_IOMMU && VFIO + depends on S390_CCW_IOMMU && VFIO_MDEV help This driver allows usage of I/O subchannels via VFIO-CCW.
drivers/s390/cio/Makefile +1 -1
@@ -18,5 +18,5 @@ obj-$(CONFIG_CCWGROUP) += ccwgroup.o qdio-objs := qdio_main.o qdio_thinint.o qdio_debug.o qdio_setup.o obj-$(CONFIG_QDIO) += qdio.o -vfio_ccw-objs += vfio_ccw_drv.o vfio_ccw_cp.o +vfio_ccw-objs += vfio_ccw_drv.o vfio_ccw_cp.o vfio_ccw_ops.o obj-$(CONFIG_VFIO_CCW) += vfio_ccw.o
drivers/s390/cio/vfio_ccw_drv.c +11 -1
@@ -19,7 +19,7 @@/* * Helpers */ -static int vfio_ccw_sch_quiesce (struct subchannel *sch) +int vfio_ccw_sch_quiesce (struct subchannel *sch) {struct vfio_ccw_private *private =dev_get_drvdata (&sch->dev);DECLARE_COMPLETION_ONSTACK (completion);
@@ -152,8 +152,16 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)if (ret) goto out_disable; + ret =vfio_ccw_mdev_reg (sch); +if (ret) + goto out_rm_group; + +atomic_set (&private->avail,1 ); +return 0 ; +out_rm_group: +sysfs_remove_group (&sch->dev.kobj, &vfio_subchannel_attr_group); out_disable:cio_disable_subchannel (sch); out_free:
@@ -168,6 +176,8 @@ static int vfio_ccw_sch_remove(struct subchannel *sch)vfio_ccw_sch_quiesce (sch); +vfio_ccw_mdev_unreg (sch); +sysfs_remove_group (&sch->dev.kobj, &vfio_subchannel_attr_group);dev_set_drvdata (&sch->dev,NULL );
drivers/s390/cio/vfio_ccw_ops.c new file +147 -0
147 lines not on this page · raw message
drivers/s390/cio/vfio_ccw_private.h +11 -0
@@ -16,10 +16,21 @@* struct vfio_ccw_private * @sch: pointer to the subchannel * @completion: synchronization helper of the I/O completion +* @avail: available for creating a mediated device +* @mdev: pointer to the mediated device +* @nb: notifier for vfio events */ struct vfio_ccw_private {struct subchannel *sch;struct completion *completion; +atomic_t avail; +struct mdev_device *mdev; +struct notifier_block nb; }__aligned(8) ; +extern int vfio_ccw_mdev_reg (struct subchannel *sch); +extern void vfio_ccw_mdev_unreg (struct subchannel *sch); + +extern int vfio_ccw_sch_quiesce (struct subchannel *sch); +#endif
Signature · 1 line
2.8.4
PATCH v4 7/16 vfio: ccw: introduce ccw_io_region
In reply to Dong Jia ShiTo provide user-space a set of interfaces to:
1. pass in a ccw program to perform an I/O operation.
2. read back I/O results of the completed I/O operations. We introduce an MMIO region for the vfio-ccw device here.
This region is defined to content:
1. areas to store arguments that an ssch required.
2. areas to store the I/O results.
Using pwrite/pread to the device on this region, a user-space program could write/read data to/from the vfio-ccw device.
--- drivers/s390/cio/vfio_ccw_ops.c | 47 +++++++++++++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_private.h | 4 ++++ include/uapi/linux/vfio_ccw.h | 24 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 include/uapi/linux/vfio_ccw.h
drivers/s390/cio/vfio_ccw_ops.c +47 -0
@@ -127,6 +127,51 @@ void vfio_ccw_mdev_release(struct mdev_device *mdev) &private->nb); } +static ssize_t vfio_ccw_mdev_read (struct mdev_device *mdev, +char __user *buf, +size_t count, +loff_t *ppos) +{ +struct vfio_ccw_private *private; +struct ccw_io_region *region; + +if (*ppos + count >sizeof (*region)) +return -EINVAL ; + + private =dev_get_drvdata (mdev_parent_dev (mdev)); +if (!private) +return -ENODEV ; + + region = &private->io_region; +if (copy_to_user (buf, (void *)region + *ppos, count)) +return -EFAULT ; + +return count; +} + +static ssize_t vfio_ccw_mdev_write (struct mdev_device *mdev, +const char __user *buf, +size_t count, +loff_t *ppos) +{ +struct vfio_ccw_private *private; +struct ccw_io_region *region; + +if (*ppos + count >sizeof (*region)) +return -EINVAL ; + + private =dev_get_drvdata (mdev_parent_dev (mdev)); +if (!private) +return -ENODEV ; + + region = &private->io_region; +if (copy_from_user ((void *)region + *ppos, buf, count)) +return -EFAULT ; + region->ret_code =0 ; + +return count; +} +static const struct mdev_parent_ops vfio_ccw_mdev_ops = { .owner =THIS_MODULE , .supported_type_groups = mdev_type_groups,
@@ -134,6 +179,8 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = { .remove = vfio_ccw_mdev_remove, .open = vfio_ccw_mdev_open, .release = vfio_ccw_mdev_release, + .read = vfio_ccw_mdev_read, + .write = vfio_ccw_mdev_write, };int vfio_ccw_mdev_reg (struct subchannel *sch)
drivers/s390/cio/vfio_ccw_private.h +4 -0
@@ -10,6 +10,8 @@#ifndef _VFIO_CCW_PRIVATE_H_#define _VFIO_CCW_PRIVATE_H_ +#include <linux/vfio_ccw.h> +#include "css.h" /**
@@ -19,6 +21,7 @@* @avail: available for creating a mediated device * @mdev: pointer to the mediated device * @nb: notifier for vfio events +* @io_region: MMIO region to input/output I/O arguments/results */ struct vfio_ccw_private {struct subchannel *sch;
@@ -26,6 +29,7 @@ struct vfio_ccw_private {atomic_t avail;struct mdev_device *mdev;struct notifier_block nb; +struct ccw_io_region io_region; }__aligned(8) ;extern int vfio_ccw_mdev_reg (struct subchannel *sch);
include/uapi/linux/vfio_ccw.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* Interfaces for vfio-ccw +* +* Copyright IBM Corp. 2017 +* +* Author(s): Dong Jia Shi <[email protected]> +*/ + +#ifndef _VFIO_CCW_H_ +#define _VFIO_CCW_H_ + +#include <linux/types.h> + +struct ccw_io_region { +#define ORB_AREA_SIZE 12 +__u8 orb_area[ORB_AREA_SIZE ]; +#define SCSW_AREA_SIZE 12 +__u8 scsw_area[SCSW_AREA_SIZE ]; +#define IRB_AREA_SIZE 96 +__u8 irb_area[IRB_AREA_SIZE ]; +__u32 ret_code; +} __packed; + +#endif
Signature · 1 line
2.8.4
PATCH v4 8/16 vfio: ccw: handle ccw command request
In reply to Dong Jia ShiWe implement the basic ccw command handling infrastructure here:
1. Translate the ccw commands.
2. Issue the translated ccw commands to the device.
3. Once we get the execution result, update the guest SCSW with it.
--- drivers/s390/cio/vfio_ccw_drv.c | 114 ++++++++++++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_ops.c | 24 ++++++-- drivers/s390/cio/vfio_ccw_private.h | 14 +++++ 3 files changed, 148 insertions(+), 4 deletions(-)
drivers/s390/cio/vfio_ccw_drv.c +114 -0
@@ -11,9 +11,13 @@#include <linux/init.h> #include <linux/device.h> #include <linux/slab.h> +#include <linux/uuid.h> +#include <linux/mdev.h> #include <asm/isc.h> +#include "ioasm.h" +#include "css.h" #include "vfio_ccw_private.h" /*
@@ -59,6 +63,109 @@ int vfio_ccw_sch_quiesce(struct subchannel *sch)return ret; } +static int doing_io (struct vfio_ccw_private *private,u32 intparm) +{ +return (private->intparm == intparm); +} + +static int vfio_ccw_sch_io_helper (struct vfio_ccw_private *private) +{ +struct subchannel *sch; +union orb *orb; +int ccode; +__u8 lpm; +u32 intparm; + + sch = private->sch; + + orb =cp_get_orb (&private->cp, (u32 )(addr_t )sch, sch->lpm); + +/* Issue "Start Subchannel" */ + ccode =ssch (sch->schid, orb); + +switch (ccode) { +case 0 : +/* +* Initialize device status information +*/ + sch->schib.scsw.cmd.actl |=SCSW_ACTL_START_PEND ; +break ; +case 1 :/* Status pending */ +case 2 :/* Busy */ +return -EBUSY ; +case 3 :/* Device/path not operational */ + { + lpm = orb->cmd.lpm; +if (lpm !=0 ) + sch->lpm &= ~lpm; +else + sch->lpm =0 ; + +if (cio_update_schib (sch)) +return -ENODEV ; + +return sch->lpm ? -EACCES : -ENODEV ; + } +default : +return ccode; + } + + intparm = (u32 )(addr_t )sch; + private->intparm =0 ; +wait_event (private->wait_q,doing_io (private, intparm)); + +if (scsw_is_solicited (&private->irb.scsw)) +cp_update_scsw (&private->cp, &private->irb.scsw); + +return 0 ; +} + +/* Deal with the ccw command request from the userspace. */ +int vfio_ccw_sch_cmd_request (struct vfio_ccw_private *private) +{ +struct mdev_device *mdev = private->mdev; +union orb *orb; +union scsw *scsw = &private->scsw; +struct irb *irb = &private->irb; +struct ccw_io_region *io_region = &private->io_region; +int ret; + +memcpy (scsw, io_region->scsw_area,sizeof (*scsw)); + +if (scsw->cmd.fctl &SCSW_FCTL_START_FUNC ) { + orb = (union orb *)io_region->orb_area; + + ret =cp_init (&private->cp,mdev_dev (mdev), orb); +if (ret) +return ret; + + ret =cp_prefetch (&private->cp); +if (ret) { +cp_free (&private->cp); +return ret; + } + +/* Start channel program and wait for I/O interrupt. */ + ret =vfio_ccw_sch_io_helper (private); +if (!ret) { +/* Get irb info and copy it to irb_area. */ +memcpy (io_region->irb_area, irb,sizeof (*irb)); + } + +cp_free (&private->cp); + }else if (scsw->cmd.fctl &SCSW_FCTL_HALT_FUNC ) { +/* XXX: Handle halt. */ + ret = -EOPNOTSUPP ; + }else if (scsw->cmd.fctl &SCSW_FCTL_CLEAR_FUNC ) { +/* XXX: Handle clear. */ + ret = -EOPNOTSUPP ; + }else { + ret = -EOPNOTSUPP ; + } + +return ret; +} +/* * Sysfs interfaces */
@@ -113,12 +220,18 @@ static struct attribute_group vfio_subchannel_attr_group = {static void vfio_ccw_sch_irq (struct subchannel *sch) {struct vfio_ccw_private *private =dev_get_drvdata (&sch->dev); +struct irb *irb;inc_irq_stat (IRQIO_CIO );if (!private)return ; + irb =this_cpu_ptr (&cio_irb); +memcpy (&private->irb, irb,sizeof (*irb)); + private->intparm = (u32 )(addr_t )sch; +wake_up (&private->wait_q); +if (private->completion)complete (private->completion); }
@@ -156,6 +269,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)if (ret) goto out_rm_group; +init_waitqueue_head (&private->wait_q);atomic_set (&private->avail,1 );return 0 ;
drivers/s390/cio/vfio_ccw_ops.c +20 -4
@@ -23,12 +23,25 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb,return NOTIFY_STOP ;/* -* TODO: * Vendor drivers MUST unpin pages in response to an * invalidation. */ -if (action ==VFIO_IOMMU_NOTIFY_DMA_UNMAP ) -return NOTIFY_BAD ; +if (action ==VFIO_IOMMU_NOTIFY_DMA_UNMAP ) { +struct vfio_iommu_type1_dma_unmap *unmap = data; +struct subchannel *sch = private->sch; + +if (!cp_iova_pinned (&private->cp, unmap->iova)) +return NOTIFY_OK ; + +if (vfio_ccw_sch_quiesce (sch)) +return NOTIFY_BAD ; + +if (cio_enable_subchannel (sch, (u32 )(unsigned long )sch)) +return NOTIFY_BAD ; + +cp_free (&private->cp); +return NOTIFY_OK ; + }return NOTIFY_DONE ; }
@@ -167,7 +180,10 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, region = &private->io_region;if (copy_from_user ((void *)region + *ppos, buf, count))return -EFAULT ; - region->ret_code =0 ; + + region->ret_code =vfio_ccw_sch_cmd_request (private); +if (region->ret_code !=0 ) +return region->ret_code;return count; }
drivers/s390/cio/vfio_ccw_private.h +14 -0
@@ -10,9 +10,11 @@#ifndef _VFIO_CCW_PRIVATE_H_#define _VFIO_CCW_PRIVATE_H_ +#include <linux/completion.h> #include <linux/vfio_ccw.h> #include "css.h" +#include "vfio_ccw_cp.h" /** * struct vfio_ccw_private
@@ -22,6 +24,11 @@* @mdev: pointer to the mediated device * @nb: notifier for vfio events * @io_region: MMIO region to input/output I/O arguments/results +* @wait_q: wait for interrupt +* @intparm: record current interrupt parameter, used for wait interrupt +* @cp: channel program for the current I/O operation +* @irb: irb info received from interrupt +* @scsw: scsw info */ struct vfio_ccw_private {struct subchannel *sch;
@@ -30,11 +37,18 @@ struct vfio_ccw_private {struct mdev_device *mdev;struct notifier_block nb;struct ccw_io_region io_region; + +wait_queue_head_t wait_q; +u32 intparm; +struct channel_program cp; +struct irb irb; + union scsw scsw; }__aligned(8) ;extern int vfio_ccw_mdev_reg (struct subchannel *sch);extern void vfio_ccw_mdev_unreg (struct subchannel *sch);extern int vfio_ccw_sch_quiesce (struct subchannel *sch); +extern int vfio_ccw_sch_cmd_request (struct vfio_ccw_private *private);#endif
Signature · 1 line
2.8.4
PATCH v4 9/16 vfio: ccw: realize VFIO_DEVICE_GET_REGION_INFO ioctl
In reply to Dong Jia ShiIntroduce device information about vfio-ccw: VFIO_DEVICE_FLAGS_CCW. Realize VFIO_DEVICE_GET_REGION_INFO ioctl for vfio-ccw.
--- drivers/s390/cio/vfio_ccw_ops.c | 78 +++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 11 ++++++ 2 files changed, 89 insertions(+)
drivers/s390/cio/vfio_ccw_ops.c +78 -0
@@ -188,6 +188,83 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,return count; } +static int vfio_ccw_mdev_get_device_info (struct vfio_device_info *info) +{ + info->flags =VFIO_DEVICE_FLAGS_CCW ; + info->num_regions =VFIO_CCW_NUM_REGIONS ; + info->num_irqs =0 ; + +return 0 ; +} + +static int vfio_ccw_mdev_get_region_info (struct vfio_region_info *info, +u16 *cap_type_id, +void **cap_type) +{ +switch (info->index) { +case VFIO_CCW_CONFIG_REGION_INDEX : + info->offset =0 ; + info->size =sizeof (struct ccw_io_region ); + info->flags =VFIO_REGION_INFO_FLAG_READ + |VFIO_REGION_INFO_FLAG_WRITE ; +return 0 ; +default : +return -EINVAL ; + } +} + +static ssize_t vfio_ccw_mdev_ioctl (struct mdev_device *mdev, +unsigned int cmd, +unsigned long arg) +{ +int ret =0 ; +unsigned long minsz; + +switch (cmd) { +case VFIO_DEVICE_GET_INFO : + { +struct vfio_device_info info; + + minsz = offsetofend(struct vfio_device_info, num_irqs); + +if (copy_from_user (&info, (void __user *)arg, minsz)) +return -EFAULT ; + +if (info.argsz < minsz) +return -EINVAL ; + + ret =vfio_ccw_mdev_get_device_info (&info); +if (ret) +return ret; + +return copy_to_user ((void __user *)arg, &info, minsz); + } +case VFIO_DEVICE_GET_REGION_INFO : + { +struct vfio_region_info info; +u16 cap_type_id =0 ; +void *cap_type =NULL ; + + minsz = offsetofend(struct vfio_region_info, offset); + +if (copy_from_user (&info, (void __user *)arg, minsz)) +return -EFAULT ; + +if (info.argsz < minsz) +return -EINVAL ; + + ret =vfio_ccw_mdev_get_region_info (&info, &cap_type_id, + &cap_type); +if (ret) +return ret; + +return copy_to_user ((void __user *)arg, &info, minsz); + } +default : +return -ENOTTY ; + } +} +static const struct mdev_parent_ops vfio_ccw_mdev_ops = { .owner =THIS_MODULE , .supported_type_groups = mdev_type_groups,
@@ -197,6 +274,7 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = { .release = vfio_ccw_mdev_release, .read = vfio_ccw_mdev_read, .write = vfio_ccw_mdev_write, + .ioctl = vfio_ccw_mdev_ioctl, };int vfio_ccw_mdev_reg (struct subchannel *sch)
include/uapi/linux/vfio.h +11 -0
@@ -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 */ };
@@ -447,6 +448,16 @@ enum { VFIO_PCI_NUM_IRQS }; +/* +* The vfio-ccw bus driver makes use of the following fixed region. +* Unimplemented regions return a size of zero. +*/ + +enum { +VFIO_CCW_CONFIG_REGION_INDEX , +VFIO_CCW_NUM_REGIONS +}; +/** * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IORW(VFIO_TYPE, VFIO_BASE + 12, * struct vfio_pci_hot_reset_info)
Signature · 1 line
2.8.4
PATCH v4 10/16 vfio: ccw: realize VFIO_DEVICE_RESET ioctl
In reply to Dong Jia ShiIntroduce VFIO_DEVICE_RESET ioctl for vfio-ccw to make it possible to hot-reset the device.
We try to achieve a reset by first disabling the subchannel and then enabling it again: this should clear all state at the subchannel.
--- drivers/s390/cio/vfio_ccw_ops.c | 47 +++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 14 deletions(-)
drivers/s390/cio/vfio_ccw_ops.c +33 -14
@@ -12,6 +12,32 @@#include "vfio_ccw_private.h" +static int vfio_ccw_mdev_reset (struct mdev_device *mdev) +{ +struct vfio_ccw_private *private; +struct subchannel *sch; +int ret; + + private =dev_get_drvdata (mdev_parent_dev (mdev)); +if (!private) +return -ENODEV ; + + sch = private->sch; +/* +* TODO: +* In the cureent stage, some things like "no I/O running" and "no +* interrupt pending" are clear, but we are not sure what other state +* we need to care about. +* There are still a lot more instructions need to be handled. We +* should come back here later. +*/ + ret =vfio_ccw_sch_quiesce (sch); +if (ret) +return ret; + +return cio_enable_subchannel (sch, (u32 )(unsigned long )sch); +} +static int vfio_ccw_mdev_notifier (struct notifier_block *nb,unsigned long action,void *data)
@@ -28,15 +54,11 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb,*/ if (action ==VFIO_IOMMU_NOTIFY_DMA_UNMAP ) {struct vfio_iommu_type1_dma_unmap *unmap = data; -struct subchannel *sch = private->sch;if (!cp_iova_pinned (&private->cp, unmap->iova))return NOTIFY_OK ; -if (vfio_ccw_sch_quiesce (sch)) -return NOTIFY_BAD ; - -if (cio_enable_subchannel (sch, (u32 )(unsigned long )sch)) +if (vfio_ccw_mdev_reset (private->mdev))return NOTIFY_BAD ;cp_free (&private->cp);
@@ -100,16 +122,11 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)static int vfio_ccw_mdev_remove (struct mdev_device *mdev) { -struct vfio_ccw_private *private; -struct subchannel *sch; +struct vfio_ccw_private *private = +dev_get_drvdata (mdev_parent_dev (mdev));int ret; - private =dev_get_drvdata (mdev_parent_dev (mdev)); - sch = private->sch; - ret =vfio_ccw_sch_quiesce (sch); -if (ret) -return ret; - ret =cio_enable_subchannel (sch, (u32 )(unsigned long )sch); + ret =vfio_ccw_mdev_reset (mdev);if (ret)return ret;
@@ -190,7 +207,7 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,static int vfio_ccw_mdev_get_device_info (struct vfio_device_info *info) { - info->flags =VFIO_DEVICE_FLAGS_CCW ; + info->flags =VFIO_DEVICE_FLAGS_CCW |VFIO_DEVICE_FLAGS_RESET ; info->num_regions =VFIO_CCW_NUM_REGIONS ; info->num_irqs =0 ;
@@ -260,6 +277,8 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,return copy_to_user ((void __user *)arg, &info, minsz); } +case VFIO_DEVICE_RESET : +return vfio_ccw_mdev_reset (mdev);default :return -ENOTTY ; }
Signature · 1 line
2.8.4
PATCH v4 11/16 vfio: ccw: realize VFIO_DEVICE_G(S)ET_IRQ_INFO ioctls
In reply to Dong Jia ShiRealize VFIO_DEVICE_GET_IRQ_INFO ioctl to retrieve VFIO_CCW_IO_IRQ information.
Realize VFIO_DEVICE_SET_IRQS ioctl to set an eventfd fd for VFIO_CCW_IO_IRQ. Once a write operation to the ccw_io_region was performed, trigger a signal on this fd.
--- drivers/s390/cio/vfio_ccw_ops.c | 123 +++++++++++++++++++++++++++++++++++- drivers/s390/cio/vfio_ccw_private.h | 4 ++ include/uapi/linux/vfio.h | 10 ++- 3 files changed, 134 insertions(+), 3 deletions(-)
drivers/s390/cio/vfio_ccw_ops.c +122 -1
@@ -202,6 +202,9 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,if (region->ret_code !=0 )return region->ret_code; +if (private->io_trigger) +eventfd_signal (private->io_trigger,1 ); +return count; }
@@ -209,7 +212,7 @@ static int vfio_ccw_mdev_get_device_info(struct vfio_device_info *info) { info->flags =VFIO_DEVICE_FLAGS_CCW |VFIO_DEVICE_FLAGS_RESET ; info->num_regions =VFIO_CCW_NUM_REGIONS ; - info->num_irqs =0 ; + info->num_irqs =VFIO_CCW_NUM_IRQS ;return 0 ; }
@@ -230,6 +233,83 @@ static int vfio_ccw_mdev_get_region_info(struct vfio_region_info *info, } } +int vfio_ccw_mdev_get_irq_info (struct vfio_irq_info *info) +{ +if (info->index !=VFIO_CCW_IO_IRQ_INDEX ) +return -EINVAL ; + + info->count =1 ; + info->flags =VFIO_IRQ_INFO_EVENTFD ; + +return 0 ; +} + +static int vfio_ccw_mdev_set_irqs (struct mdev_device *mdev, +uint32_t flags, +void __user *data) +{ +struct vfio_ccw_private *private; +struct eventfd_ctx **ctx; + +if (!(flags &VFIO_IRQ_SET_ACTION_TRIGGER )) +return -EINVAL ; + + private =dev_get_drvdata (mdev_parent_dev (mdev)); +if (!private) +return -ENODEV ; + + ctx = &private->io_trigger; + +switch (flags &VFIO_IRQ_SET_DATA_TYPE_MASK ) { +case VFIO_IRQ_SET_DATA_NONE : + { +if (*ctx) +eventfd_signal (*ctx,1 ); +return 0 ; + } +case VFIO_IRQ_SET_DATA_BOOL : + { +uint8_t trigger; + +if (get_user (trigger, (uint8_t __user *)data)) +return -EFAULT ; + +if (trigger && *ctx) +eventfd_signal (*ctx,1 ); +return 0 ; + } +case VFIO_IRQ_SET_DATA_EVENTFD : + { +int32_t fd; + +if (get_user (fd, (int32_t __user *)data)) +return -EFAULT ; + +if (fd ==-1 ) { +if (*ctx) +eventfd_ctx_put (*ctx); + *ctx =NULL ; + }else if (fd >=0 ) { +struct eventfd_ctx *efdctx; + + efdctx =eventfd_ctx_fdget (fd); +if (IS_ERR (efdctx)) +return PTR_ERR (efdctx); + +if (*ctx) +eventfd_ctx_put (*ctx); + + *ctx = efdctx; + }else +return -EINVAL ; + +return 0 ; + } +default : +return -EINVAL ; + } +} +static ssize_t vfio_ccw_mdev_ioctl (struct mdev_device *mdev,unsigned int cmd,unsigned long arg)
@@ -277,6 +357,47 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,return copy_to_user ((void __user *)arg, &info, minsz); } +case VFIO_DEVICE_GET_IRQ_INFO : + { +struct vfio_irq_info info; + + minsz = offsetofend(struct vfio_irq_info, count); + +if (copy_from_user (&info, (void __user *)arg, minsz)) +return -EFAULT ; + +if (info.argsz < minsz || info.index >=VFIO_CCW_NUM_IRQS ) +return -EINVAL ; + + ret =vfio_ccw_mdev_get_irq_info (&info); +if (ret) +return ret; + +if (info.count ==-1 ) +return -EINVAL ; + +return copy_to_user ((void __user *)arg, &info, minsz); + } +case VFIO_DEVICE_SET_IRQS : + { +struct vfio_irq_set hdr; +size_t data_size; +void __user *data; + + minsz = offsetofend(struct vfio_irq_set, count); + +if (copy_from_user (&hdr, (void __user *)arg, minsz)) +return -EFAULT ; + + ret =vfio_set_irqs_validate_and_prepare (&hdr,1 , +VFIO_CCW_NUM_IRQS , + &data_size); +if (ret) +return ret; + + data = (void __user *)(arg + minsz); +return vfio_ccw_mdev_set_irqs (mdev, hdr.flags, data); + }case VFIO_DEVICE_RESET :return vfio_ccw_mdev_reset (mdev);default :
drivers/s390/cio/vfio_ccw_private.h +4 -0
@@ -11,6 +11,7 @@#define _VFIO_CCW_PRIVATE_H_#include <linux/completion.h> +#include <linux/eventfd.h> #include <linux/vfio_ccw.h> #include "css.h"
@@ -29,6 +30,7 @@* @cp: channel program for the current I/O operation * @irb: irb info received from interrupt * @scsw: scsw info +* @io_trigger: eventfd ctx for signaling userspace I/O results */ struct vfio_ccw_private {struct subchannel *sch;
@@ -43,6 +45,8 @@ struct vfio_ccw_private {struct channel_program cp;struct irb irb;union scsw scsw; + +struct eventfd_ctx *io_trigger; }__aligned(8) ;extern int vfio_ccw_mdev_reg (struct subchannel *sch);
include/uapi/linux/vfio.h +8 -2
@@ -449,8 +449,9 @@ enum { };/* -* The vfio-ccw bus driver makes use of the following fixed region. -* Unimplemented regions return a size of zero. +* 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 {
@@ -458,6 +459,11 @@ enum { 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)
Signature · 1 line
2.8.4
PATCH v4 12/16 vfio: ccw: return I/O results asynchronously
In reply to Dong Jia ShiIntroduce a singlethreaded workqueue to handle the I/O interrupts. With the work added to this queue, we store the I/O results to the io_region of the subchannel, then signal the userspace program to handle the results.
--- drivers/s390/cio/vfio_ccw_drv.c | 58 ++++++++++++++++++++++--------------- drivers/s390/cio/vfio_ccw_ops.c | 3 -- drivers/s390/cio/vfio_ccw_private.h | 7 ++--- 3 files changed, 37 insertions(+), 31 deletions(-)
drivers/s390/cio/vfio_ccw_drv.c +34 -24
@@ -20,6 +20,8 @@#include "css.h" #include "vfio_ccw_private.h" +struct workqueue_struct *vfio_ccw_work_q; +/* * Helpers */
@@ -52,6 +54,7 @@ int vfio_ccw_sch_quiesce(struct subchannel *sch)spin_lock_irq (sch->lock); private->completion =NULL ; +flush_workqueue (vfio_ccw_work_q); ret =cio_cancel_halt_clear (sch, &iretry); };
@@ -63,18 +66,12 @@ int vfio_ccw_sch_quiesce(struct subchannel *sch)return ret; } -static int doing_io (struct vfio_ccw_private *private,u32 intparm) -{ -return (private->intparm == intparm); -} -static int vfio_ccw_sch_io_helper (struct vfio_ccw_private *private) {struct subchannel *sch;union orb *orb;int ccode;__u8 lpm; -u32 intparm; sch = private->sch;
@@ -89,7 +86,7 @@ static int vfio_ccw_sch_io_helper(struct vfio_ccw_private *private)* Initialize device status information */ sch->schib.scsw.cmd.actl |=SCSW_ACTL_START_PEND ; -break ; +return 0 ;case 1 :/* Status pending */ case 2 :/* Busy */ return -EBUSY ;
@@ -109,15 +106,26 @@ static int vfio_ccw_sch_io_helper(struct vfio_ccw_private *private)default :return ccode; } +} - intparm = (u32 )(addr_t )sch; - private->intparm =0 ; -wait_event (private->wait_q,doing_io (private, intparm)); +static void vfio_ccw_sch_io_todo (struct work_struct *work) +{ +struct vfio_ccw_private *private; +struct subchannel *sch; +struct irb *irb; -if (scsw_is_solicited (&private->irb.scsw)) -cp_update_scsw (&private->cp, &private->irb.scsw); + private = container_of(work, struct vfio_ccw_private, io_work); + irb = &private->irb; + sch = private->sch; -return 0 ; +if (scsw_is_solicited (&irb->scsw)) { +cp_update_scsw (&private->cp, &irb->scsw); +cp_free (&private->cp); + } +memcpy (private->io_region.irb_area, irb,sizeof (*irb)); + +if (private->io_trigger) +eventfd_signal (private->io_trigger,1 ); }/* Deal with the ccw command request from the userspace. */
@@ -126,7 +134,6 @@ int vfio_ccw_sch_cmd_request(struct vfio_ccw_private *private)struct mdev_device *mdev = private->mdev;union orb *orb;union scsw *scsw = &private->scsw; -struct irb *irb = &private->irb;struct ccw_io_region *io_region = &private->io_region;int ret;
@@ -147,12 +154,8 @@ int vfio_ccw_sch_cmd_request(struct vfio_ccw_private *private)/* Start channel program and wait for I/O interrupt. */ ret =vfio_ccw_sch_io_helper (private); -if (!ret) { -/* Get irb info and copy it to irb_area. */ -memcpy (io_region->irb_area, irb,sizeof (*irb)); - } - -cp_free (&private->cp); +if (!ret) +cp_free (&private->cp); }else if (scsw->cmd.fctl &SCSW_FCTL_HALT_FUNC ) {/* XXX: Handle halt. */ ret = -EOPNOTSUPP ;
@@ -229,8 +232,8 @@ static void vfio_ccw_sch_irq(struct subchannel *sch) irb =this_cpu_ptr (&cio_irb);memcpy (&private->irb, irb,sizeof (*irb)); - private->intparm = (u32 )(addr_t )sch; -wake_up (&private->wait_q); + +queue_work (vfio_ccw_work_q, &private->io_work);if (private->completion)complete (private->completion);
@@ -269,7 +272,7 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)if (ret) goto out_rm_group; -init_waitqueue_head (&private->wait_q); +INIT_WORK (&private->io_work, vfio_ccw_sch_io_todo);atomic_set (&private->avail,1 );return 0 ;
@@ -367,10 +370,16 @@ static int __init vfio_ccw_sch_init(void) {int ret; + vfio_ccw_work_q =create_singlethread_workqueue ("vfio-ccw" ); +if (!vfio_ccw_work_q) +return -ENOMEM ; +isc_register (VFIO_CCW_ISC ); ret =css_driver_register (&vfio_ccw_sch_driver); -if (ret) +if (ret) {isc_unregister (VFIO_CCW_ISC ); +destroy_workqueue (vfio_ccw_work_q); + }return ret; }
@@ -379,6 +388,7 @@ static void __exit vfio_ccw_sch_exit(void) {css_driver_unregister (&vfio_ccw_sch_driver);isc_unregister (VFIO_CCW_ISC ); +destroy_workqueue (vfio_ccw_work_q); }module_init (vfio_ccw_sch_init);module_exit (vfio_ccw_sch_exit);
drivers/s390/cio/vfio_ccw_ops.c +0 -3
@@ -202,9 +202,6 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,if (region->ret_code !=0 )return region->ret_code; -if (private->io_trigger) -eventfd_signal (private->io_trigger,1 ); -return count; }
drivers/s390/cio/vfio_ccw_private.h +3 -4
@@ -12,6 +12,7 @@#include <linux/completion.h> #include <linux/eventfd.h> +#include <linux/workqueue.h> #include <linux/vfio_ccw.h> #include "css.h"
@@ -25,12 +26,11 @@* @mdev: pointer to the mediated device * @nb: notifier for vfio events * @io_region: MMIO region to input/output I/O arguments/results -* @wait_q: wait for interrupt -* @intparm: record current interrupt parameter, used for wait interrupt * @cp: channel program for the current I/O operation * @irb: irb info received from interrupt * @scsw: scsw info * @io_trigger: eventfd ctx for signaling userspace I/O results +* @io_work: work for deferral process of I/O handling */ struct vfio_ccw_private {struct subchannel *sch;
@@ -40,13 +40,12 @@ struct vfio_ccw_private {struct notifier_block nb;struct ccw_io_region io_region; -wait_queue_head_t wait_q; -u32 intparm;struct channel_program cp;struct irb irb;union scsw scsw;struct eventfd_ctx *io_trigger; +struct work_struct io_work; }__aligned(8) ;extern int vfio_ccw_mdev_reg (struct subchannel *sch);
Signature · 1 line
2.8.4
PATCH v4 13/16 vfio: ccw: introduce a finite state machine
In reply to Dong Jia ShiThe current implementation doesn't check if the subchannel is in a proper device state when handling an event. Let's introduce a finite state machine to manage the state/event change.
--- drivers/s390/cio/Makefile | 2 +- drivers/s390/cio/vfio_ccw_drv.c | 116 +++----------------- drivers/s390/cio/vfio_ccw_fsm.c | 207 ++++++++++++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_ops.c | 28 ++++- drivers/s390/cio/vfio_ccw_private.h | 41 ++++++- 5 files changed, 287 insertions(+), 107 deletions(-) create mode 100644 drivers/s390/cio/vfio_ccw_fsm.c
drivers/s390/cio/Makefile +1 -1
@@ -18,5 +18,5 @@ obj-$(CONFIG_CCWGROUP) += ccwgroup.o qdio-objs := qdio_main.o qdio_thinint.o qdio_debug.o qdio_setup.o obj-$(CONFIG_QDIO) += qdio.o -vfio_ccw-objs += vfio_ccw_drv.o vfio_ccw_cp.o vfio_ccw_ops.o +vfio_ccw-objs += vfio_ccw_drv.o vfio_ccw_cp.o vfio_ccw_ops.o vfio_ccw_fsm.o obj-$(CONFIG_VFIO_CCW) += vfio_ccw.o
drivers/s390/cio/vfio_ccw_drv.c +14 -102
169 lines not on this page · raw message
drivers/s390/cio/vfio_ccw_fsm.c new file +207 -0
207 lines not on this page · raw message
drivers/s390/cio/vfio_ccw_ops.c +25 -3
@@ -35,7 +35,11 @@ static int vfio_ccw_mdev_reset(struct mdev_device *mdev)if (ret)return ret; -return cio_enable_subchannel (sch, (u32 )(unsigned long )sch); + ret =cio_enable_subchannel (sch, (u32 )(unsigned long )sch); +if (!ret) + private->state =VFIO_CCW_STATE_IDLE ; + +return ret; } static int vfio_ccw_mdev_notifier(struct notifier_block *nb,
@@ -112,10 +116,14 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev)struct vfio_ccw_private *private =dev_get_drvdata (mdev_parent_dev (mdev)); +if (private->state ==VFIO_CCW_STATE_NOT_OPER ) +return -ENODEV ; +if (atomic_dec_if_positive (&private->avail) <0 )return -EPERM ; private->mdev = mdev; + private->state =VFIO_CCW_STATE_IDLE ;return 0 ; }
@@ -126,10 +134,20 @@ static int vfio_ccw_mdev_remove(struct mdev_device *mdev)dev_get_drvdata (mdev_parent_dev (mdev));int ret; +if (!private) + goto out; + +if ((private->state ==VFIO_CCW_STATE_NOT_OPER ) || + (private->state ==VFIO_CCW_STATE_STANDBY )) + goto out; + ret =vfio_ccw_mdev_reset (mdev);if (ret)return ret; + private->state =VFIO_CCW_STATE_STANDBY ; + +out: private->mdev =NULL ;atomic_inc (&private->avail);
@@ -193,14 +211,18 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, private =dev_get_drvdata (mdev_parent_dev (mdev));if (!private)return -ENODEV ; +if (private->state !=VFIO_CCW_STATE_IDLE ) +return -EACCES ; region = &private->io_region;if (copy_from_user ((void *)region + *ppos, buf, count))return -EFAULT ; - region->ret_code =vfio_ccw_sch_cmd_request (private); -if (region->ret_code !=0 ) +vfio_ccw_fsm_event (private,VFIO_CCW_EVENT_IO_REQ ); +if (region->ret_code !=0 ) { + private->state =VFIO_CCW_STATE_IDLE ;return region->ret_code; + }return count; }
drivers/s390/cio/vfio_ccw_private.h +40 -1
58 lines not on this page · raw message
Signature · 1 line
2.8.4
PATCH v4 14/16 docs: add documentation for vfio-ccw
In reply to Dong Jia ShiAdd file Documentation/s390/vfio-ccw.txt that includes details of vfio-ccw.
--- Documentation/s390/00-INDEX | 2 + Documentation/s390/vfio-ccw.txt | 303 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 305 insertions(+) create mode 100644 Documentation/s390/vfio-ccw.txt
Documentation/s390/00-INDEX +2 -0
@@ -22,5 +22,7 @@ qeth.txt - HiperSockets Bridge Port Support. s390dbf.txt - information on using the s390 debug feature. +vfio-ccw.txt + information on the vfio-ccw I/O subchannel driver. zfcpdump.txt - information on the s390 SCSI dump tool.
Documentation/s390/vfio-ccw.txt new file +303 -0
303 lines not on this page · raw message
Signature · 1 line
2.8.4
PATCH v4 15/16 vfio: ccw: introduce support for ccw0
In reply to Dong Jia ShiAlthough Linux does not use format-0 channel command words (CCW0) these are a non-optional part of the platform spec, and for the sake of platform compliance, and possibly some non-Linux guests, we have to support CCW0.
Making the kernel execute a format 0 channel program is too much hassle because we would need to allocate and use memory which can be addressed by 24 bit physical addresses (because of CCW0.cda). So we implement CCW0 support by translating the channel program into an equivalent CCW1 program instead.
Based upon an orginal patch by Kai Yue Wang.
--- arch/s390/include/asm/cio.h | 18 ++++++++++++++++++ drivers/s390/cio/vfio_ccw_cp.c | 32 +++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 3 deletions(-)
arch/s390/include/asm/cio.h +18 -0
@@ -33,6 +33,24 @@ struct ccw1 {__u32 cda; } __attribute__ ((packed,aligned(8))); +/** +* struct ccw0 - channel command word +* @cmd_code: command code +* @cda: data address +* @flags: flags, like IDA addressing, etc. +* @reserved: will be ignored +* @count: byte count +* +* The format-0 ccw structure. +*/ +struct ccw0 { +__u8 cmd_code; +__u32 cda :24 ; +__u8 flags; +__u8 reserved; +__u16 count; +} __packed__aligned(8) ; +#define CCW_FLAG_DC 0x80#define CCW_FLAG_CC 0x40#define CCW_FLAG_SLI 0x20
drivers/s390/cio/vfio_ccw_cp.c +29 -3
@@ -247,7 +247,34 @@ static long copy_ccw_from_iova(struct channel_program *cp, struct ccw1 *to, u64 iova, unsigned long len) { - return copy_from_iova(cp->mdev, to, iova, len * sizeof(struct ccw1)); + struct ccw0 ccw0; +struct ccw1 *pccw1; +int ret; +int i; + + ret =copy_from_iova (cp->mdev, to, iova, len *sizeof (struct ccw1 )); +if (ret) +return ret; + +if (!cp->orb.cmd.fmt) { + pccw1 = to; +for (i =0 ; i < len; i++) { + ccw0 = *(struct ccw0 *)pccw1; +if ((pccw1->cmd_code &0x0f ) ==CCW_CMD_TIC ) { + pccw1->cmd_code =CCW_CMD_TIC ; + pccw1->flags =0 ; + pccw1->count =0 ; + }else { + pccw1->cmd_code = ccw0.cmd_code; + pccw1->flags = ccw0.flags; + pccw1->count = ccw0.count; + } + pccw1->cda = ccw0.cda; + pccw1++; + } + } + +return ret; }/*
@@ -616,9 +643,8 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb)* Only support prefetch enable mode now. * Only support 64bit addressing idal. * Only support 4k IDAW. -* Only support ccw1. */ -if (!orb->cmd.pfch || !orb->cmd.c64 || orb->cmd.i2k || !orb->cmd.fmt) +if (!orb->cmd.pfch || !orb->cmd.c64 || orb->cmd.i2k)return -EOPNOTSUPP ;INIT_LIST_HEAD (&cp->ccwchain_list);
Signature · 1 line
2.8.4
PATCH v4 16/16 MAINTAINERS: Add vfio-ccw maintainers
In reply to Dong Jia ShiAdd Cornelia Huck and myself as the vfio-ccw driver maintainers.
--- MAINTAINERS | 10 ++++++++++ 1 file changed, 10 insertions(+)
MAINTAINERS +10 -0
@@ -10859,6 +10859,16 @@ W: http://www.ibm.com/developerworks/linux/linux390/ S: Supported F: drivers/iommu/s390-iommu.c +S390 VFIO-CCW DRIVER +M: Cornelia Huck <[email protected]> +M: Dong Jia Shi <[email protected]> +L: [email protected] +L: [email protected] +S: Supported +F: drivers/s390/cio/vfio_ccw* +F: Documentation/s390/vfio-ccw.txt +F: include/uapi/linux/vfio_ccw.h + S3C24XX SD/MMC Driver M: Ben Dooks <[email protected]> L: [email protected] (moderated for non-subscribers)
Signature · 1 line
2.8.4
Re: [PATCH v4 01/16] s390: cio: introduce cio_cancel_halt_clear
In reply to Dong Jia ShiQuoted 3 lines · Dong Jia Shi
For future code reuse purpose, this decouples the cio code with the ccw device specific parts from
ccw_device_cancel_halt_clear, and makes a new common I/O interface namedcio_cancel_halt_clear.
What would the user of cio_cancel_halt_clear be?
Sebastian
Re: [PATCH v4 02/16] s390: cio: export more interfaces
In reply to Dong Jia ShiQuoted 2 lines · Dong Jia Shi
Export the common I/O interfaces those are needed by an I/O subchannel driver to actually talk to the subchannel.
Which I/O subchannel driver are you talking about? I know of just one and it can't be build as a module.
Sebastian
Re: [Qemu-devel] [PATCH v4 01/16] s390: cio: introduce cio_cancel_halt_clear
In reply to Sebastian OttQuoted 6 lines · Sebastian Ott
Quoted 3 lines · Dong Jia Shi
For future code reuse purpose, this decouples the cio code with the ccw device specific parts from
ccw_device_cancel_halt_clear, and makes a new common I/O interface namedcio_cancel_halt_clear.What would the user of
cio_cancel_halt_clearbe?
Hi Sebastian,
We are trying to introduce a new I/O subchannel driver to enable usage of I/O subchannels via VFIO-CCW, so we can passthru a subchannel to a KVM guest. And that new vfio-ccw subchannel driver is the user. :>
Quoted 2 lines
Sebastian
Signature · 1 line
Dong Jia
Re: [Qemu-devel] [PATCH v4 02/16] s390: cio: export more interfaces
In reply to Sebastian OttQuoted 6 lines · Sebastian Ott
Quoted 2 lines · Dong Jia Shi
Export the common I/O interfaces those are needed by an I/O subchannel driver to actually talk to the subchannel.
Which I/O subchannel driver are you talking about? I know of just one and it can't be build as a module.
As I replied to you in another email, there will be a new I/O subchannel driver which is named as vfio-ccw subchannel driver. That driver could be built as a module, thus it needs these interfaces be exported.
Quoted 2 lines
Sebastian
Signature · 1 line
Dong Jia
Re: [PATCH v4 01/16] s390: cio: introduce cio_cancel_halt_clear
In reply to Dong Jia ShiQuoted 7 lines · Dong Jia Shi
Quoted 5 lines · Sebastian Ott
Quoted 3 lines · Dong Jia Shi
For future code reuse purpose, this decouples the cio code with the ccw device specific parts from
ccw_device_cancel_halt_clear, and makes a new common I/O interface namedcio_cancel_halt_clear.
Quoted 6 lines
Quoted 1 line
What would the user of
cio_cancel_halt_clearbe?Hi Sebastian,
We are trying to introduce a new I/O subchannel driver to enable usage of I/O subchannels via VFIO-CCW, so we can passthru a subchannel to a KVM guest. And that new vfio-ccw subchannel driver is the user. :>
OK, thanks for the explanation. May I suggest that you put these patches in the series that actually introduces the new subchannel driver.
Sebastian
Re: [Qemu-devel] [PATCH v4 01/16] s390: cio: introduce cio_cancel_halt_clear
Quoted 9 lines · Sebastian Ott
Quoted 8 lines · Dong Jia Shi
Quoted 6 lines · Sebastian Ott
Quoted 3 lines · Dong Jia Shi
For future code reuse purpose, this decouples the cio code with the ccw device specific parts from
ccw_device_cancel_halt_clear, and makes a new common I/O interface namedcio_cancel_halt_clear.What would the user of
cio_cancel_halt_clearbe?
Quoted 9 lines
Quoted 5 lines
Hi Sebastian,
We are trying to introduce a new I/O subchannel driver to enable usage of I/O subchannels via VFIO-CCW, so we can passthru a subchannel to a KVM guest. And that new vfio-ccw subchannel driver is the user. :>
OK, thanks for the explanation. May I suggest that you put these patches in the series that actually introduces the new subchannel driver.
Hi Sebastian,
For your reference, information of the current patch series could be found by searching/accessing:
Subject: [PATCH v4 00/16] basic vfio-ccw infrastructure
Message-Id: <[email protected]>
https://www.mail-archive.com/[email protected]/msg438029.html
I could put you on Cc, if you would like to recieve updates of the whole patch series.
Quoted 1 line
Sebastian
Signature · 1 line
Dong Jia
Re: [PATCH v4 14/16] docs: add documentation for vfio-ccw
In reply to Dong Jia ShiQuoted 218 lines · On Fri, 17 Mar 2017 04:17:41 +0100 Dong Jia Shi <[email protected]>…
Add file
Documentation/s390/vfio-ccw.txtthat includes details of vfio-ccw.Acked-by Pierre Morel <[email protected]>Signed-off-by Dong Jia Shi <[email protected]>--- Documentation/s390/00-INDEX | 2 + Documentation/s390/vfio-ccw.txt | 303 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 305 insertions(+) create mode 100644 Documentation/s390/vfio-ccw.txtDocumentation/s390/00-INDEX +2
-0@@ -22,5 +22,7 @@ qeth.txt - HiperSockets Bridge Port Support. s390dbf.txt - information on using the s390 debug feature. +vfio-ccw.txt + information on the vfio-ccw I/O subchannel driver. zfcpdump.txt - information on the s390 SCSI dump tool.Documentation/s390/vfio-ccw.txt new file +189
-0@@ -0,0 +1,303 @@ +vfio-ccw: the basic infrastructure +================================== + +Introduction +------------ + +Here we describe the vfio support for I/O subchannel devices for +Linux/s390. Motivation for vfio-ccw is to passthrough subchannels to a +virtual machine, while vfio is the means. + +Different than other hardware architectures, s390 has defined a unified +I/O access method, which is so called Channel I/O. It has its own access +patterns: +- Channel programs run asynchronously on a separate (co)processor. +- The channel subsystem will access any memory designated by the caller + in the channel program directly, i.e. there is no iommu involved. +Thus when we introduce vfio support for these devices, we realize it +with a mediated device (mdev) implementation. The vfio mdev will be +added to an iommu group, so as to make itself able to be managed by the +vfio framework. And we add read/write callbacks for special vfio I/O +regions to pass the channel programs from the mdev to its parent device +(the real I/O subchannel device) to do further address translation and +to perform I/O instructions. + +This document does not intend to explain the s390 I/O architecture in +every detail. More information/reference could be found here: +- A good start to know Channel I/O in general: + https://en.wikipedia.org/wiki/Channel_I/O +- s390 architecture: + s390 Principles of Operation manual (IBM Form. No. SA22-7832) +- The existing Qemu code which implements a simple emulated channel + subsystem could also be a good reference. It makes it easier to follow + the flow. + qemu/hw/s390x/css.c + +For vfio mediated device framework: +- Documentation/vfio-mediated-device.txt + +Motivation of vfio-ccw +---------------------- + +Currently, a guest virtualized via qemu/kvm on s390 only sees +paravirtualized virtio devices via the "Virtio Over Channel I/O +(virtio-ccw)" transport. This makes virtio devices discoverable via +standard operating system algorithms for handling channel devices. + +However this is not enough. On s390 for the majority of devices, which +use the standard Channel I/O based mechanism, we also need to provide +the functionality of passing through them to a Qemu virtual machine. +This includes devices that don't have a virtio counterpart (e.g. tape +drives) or that have specific characteristics which guests want to +exploit. + +For passing a device to a guest, we want to use the same interface as +everybody else, namely vfio. Thus, we would like to introduce vfio +support for channel devices. And we would like to name this new vfio +device "vfio-ccw". + +Access patterns of CCW devices +------------------------------ + +s390 architecture has implemented a so called channel subsystem, that +provides a unified view of the devices physically attached to the +systems. Though the s390 hardware platform knows about a huge variety of +different peripheral attachments like disk devices (aka. DASDs), tapes, +communication controllers, etc. They can all be accessed by a well +defined access method and they are presenting I/O completion a unified +way: I/O interruptions. + +All I/O requires the use of channel command words (CCWs). A CCW is an +instruction to a specialized I/O channel processor. A channel program is +a sequence of CCWs which are executed by the I/O channel subsystem. To +issue a channel program to the channel subsystem, it is required to +build an operation request block (ORB), which can be used to point out +the format of the CCW and other control information to the system. The +operating system signals the I/O channel subsystem to begin executing +the channel program with a SSCH (start sub-channel) instruction. The +central processor is then free to proceed with non-I/O instructions +until interrupted. The I/O completion result is received by the +interrupt handler in the form of interrupt response block (IRB). + +Back to vfio-ccw, in short: +- ORBs and channel programs are built in guest kernel (with guest + physical addresses). +- ORBs and channel programs are passed to the host kernel. +- Host kernel translates the guest physical addresses to real addresses + and starts the I/O with issuing a privileged Channel I/O instruction + (e.g SSCH). +- channel programs run asynchronously on a separate processor. +- I/O completion will be signaled to the host with I/O interruptions. + And it will be copied as IRB to user space to pass it back to the + guest. + +Physical vfio ccw device and its child mdev +------------------------------------------- + +As mentioned above, we realize vfio-ccw with a mdev implementation. + +Channel I/O does not have IOMMU hardware support, so the physical +vfio-ccw device does not have an IOMMU level translation or isolation. + +Sub-channel I/O instructions are all privileged instructions, When +handling the I/O instruction interception, vfio-ccw has the software +policing and translation how the channel program is programmed before +it gets sent to hardware. + +Within this implementation, we have two drivers for two types of +devices: +- The vfio_ccw driver for the physical subchannel device. + This is an I/O subchannel driver for the real subchannel device. It + realizes a group of callbacks and registers to the mdev framework as a + parent (physical) device. As a consequence, mdev provides vfio_ccw a + generic interface (sysfs) to create mdev devices. A vfio mdev could be + created by vfio_ccw then and added to the mediated bus. It is the vfio + device that added to an IOMMU group and a vfio group. + vfio_ccw also provides an I/O region to accept channel program + request from user space and store I/O interrupt result for user + space to retrieve. To notify user space an I/O completion, it offers + an interface to setup an eventfd fd for asynchronous signaling. + +- The vfio_mdev driver for the mediated vfio ccw device. + This is provided by the mdev framework. It is a vfio device driver for + the mdev that created by vfio_ccw. + It realize a group of vfio device driver callbacks, adds itself to a + vfio group, and registers itself to the mdev framework as a mdev + driver. + It uses a vfio iommu backend that uses the existing map and unmap + ioctls, but rather than programming them into an IOMMU for a device, + it simply stores the translations for use by later requests. This + means that a device programmed in a VM with guest physical addresses + can have the vfio kernel convert that address to process virtual + address, pin the page and program the hardware with the host physical + address in one step. + For a mdev, the vfio iommu backend will not pin the pages during the + VFIO_IOMMU_MAP_DMA ioctl. Mdev framework will only maintain a database + of the iova<->vaddr mappings in this operation. And they export a + vfio_pin_pages and a vfio_unpin_pages interfaces from the vfio iommu + backend for the physical devices to pin and unpin pages by demand. + +Below is a high Level block diagram. + + +-------------+ + | | + | +---------+ | mdev_register_driver() +--------------+ + | | Mdev | +<-----------------------+ | + | | bus | | | vfio_mdev.ko | + | | driver | +----------------------->+ |<-> VFIO user + | +---------+ | probe()/remove() +--------------+ APIs + | | + | MDEV CORE | + | MODULE | + | mdev.ko | + | +---------+ | mdev_register_device() +--------------+ + | |Physical | +<-----------------------+ | + | | device | | | vfio_ccw.ko |<-> subchannel + | |interface| +----------------------->+ | device + | +---------+ | callback +--------------+ + +-------------+ + +The process of how these work together. +1. vfio_ccw.ko drives the physical I/O subchannel, and registers the + physical device (with callbacks) to mdev framework. + When vfio_ccw probing the subchannel device, it registers device + pointer and callbacks to the mdev framework. Mdev related file nodes + under the device node in sysfs would be created for the subchannel + device, namely 'mdev_create', 'mdev_destroy' and + 'mdev_supported_types'. +2. Create a mediated vfio ccw device. + Use the 'mdev_create' sysfs file, we need to manually create one (and + only one for our case) mediated device. +3. vfio_mdev.ko drives the mediated ccw device. + vfio_mdev is also the vfio device drvier. It will probe the mdev and + add it to an iommu_group and a vfio_group. Then we could pass through + the mdev to a guest. + +vfio-ccw I/O region +------------------- + +An I/O region is used to accept channel program request from user +space and store I/O interrupt result for user space to retrieve. The +defination of the region is: + +struct ccw_io_region { +#define ORB_AREA_SIZE 12 + __u8 orb_area[ORB_AREA_SIZE]; +#define SCSW_AREA_SIZE 12 + __u8 scsw_area[SCSW_AREA_SIZE]; +#define IRB_AREA_SIZE 96 + __u8 irb_area[IRB_AREA_SIZE];
Documentation/s390/vfio-ccw.txt line 199
Quoted 10 lines
Documentation/s390/vfio-ccw.txt new file +10
-0+ __u32 ret_code; +} __packed; + +While starting an I/O request, orb_area should be filled with the +guest ORB, and scsw_area should be filled with the SCSW of the Virtual +Subchannel. + +irb_area stores the I/O result. + +ret_code stores a return code for each access of the region.
Pardon if these questions expose my lack of familiarity with S390:
So I/O requests are asynchronous, the user is notified via interrupt when completed, can more than one request be queued at a time? The communication format doesn't seem like it'd easily support that. Is it possible? A future enhancement that we should design for now?
I'm also a little unclear what sort of I/O a user has access to via this interface and how the kernel polices that access. For instance, are multiple tape or disk devices available through a single I/O channel? How does the user configure which devices a user has access to when creating the vfio-ccw device?
Otherwise I think the interface looks great. Thanks,
Alex
Re: [PATCH v4 11/16] vfio: ccw: realize VFIO_DEVICE_G(S)ET_IRQ_INFO ioctls
In reply to Dong Jia ShiQuoted 217 lines · On Fri, 17 Mar 2017 04:17:38 +0100 Dong Jia Shi <[email protected]>…
Realize
VFIO_DEVICE_GET_IRQ_INFOioctl to retrieveVFIO_CCW_IO_IRQinformation.Realize
VFIO_DEVICE_SET_IRQSioctl to set an eventfd fd forVFIO_CCW_IO_IRQ. Once a write operation to theccw_io_regionwas performed, trigger a signal on this fd.Reviewed-by Pierre Morel <[email protected]>Signed-off-by Dong Jia Shi <[email protected]>--- drivers/s390/cio/vfio_ccw_ops.c | 123 +++++++++++++++++++++++++++++++++++- drivers/s390/cio/vfio_ccw_private.h | 4 ++ include/uapi/linux/vfio.h | 10 ++- 3 files changed, 134 insertions(+), 3 deletions(-)drivers/s390/cio/vfio_ccw_ops.c +122
-1@@ -202,6 +202,9 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,if (region->ret_code !=0 )return region->ret_code; +if (private->io_trigger) +eventfd_signal (private->io_trigger,1 ); +return count; }@@ -209,7 +212,7 @@ static int vfio_ccw_mdev_get_device_info(struct vfio_device_info *info) { info->flags =VFIO_DEVICE_FLAGS_CCW |VFIO_DEVICE_FLAGS_RESET ; info->num_regions =VFIO_CCW_NUM_REGIONS ; - info->num_irqs =0 ; + info->num_irqs =VFIO_CCW_NUM_IRQS ;return 0 ; }@@ -230,6 +233,83 @@ static int vfio_ccw_mdev_get_region_info(struct vfio_region_info *info, } } +int vfio_ccw_mdev_get_irq_info (struct vfio_irq_info *info) +{ +if (info->index !=VFIO_CCW_IO_IRQ_INDEX ) +return -EINVAL ; + + info->count =1 ; + info->flags =VFIO_IRQ_INFO_EVENTFD ; + +return 0 ; +} + +static int vfio_ccw_mdev_set_irqs (struct mdev_device *mdev, +uint32_t flags, +void __user *data) +{ +struct vfio_ccw_private *private; +struct eventfd_ctx **ctx; + +if (!(flags &VFIO_IRQ_SET_ACTION_TRIGGER )) +return -EINVAL ; + + private =dev_get_drvdata (mdev_parent_dev (mdev)); +if (!private) +return -ENODEV ; + + ctx = &private->io_trigger; + +switch (flags &VFIO_IRQ_SET_DATA_TYPE_MASK ) { +case VFIO_IRQ_SET_DATA_NONE : + { +if (*ctx) +eventfd_signal (*ctx,1 ); +return 0 ; + } +case VFIO_IRQ_SET_DATA_BOOL : + { +uint8_t trigger; + +if (get_user (trigger, (uint8_t __user *)data)) +return -EFAULT ; + +if (trigger && *ctx) +eventfd_signal (*ctx,1 ); +return 0 ; + } +case VFIO_IRQ_SET_DATA_EVENTFD : + { +int32_t fd; + +if (get_user (fd, (int32_t __user *)data)) +return -EFAULT ; + +if (fd ==-1 ) { +if (*ctx) +eventfd_ctx_put (*ctx); + *ctx =NULL ; + }else if (fd >=0 ) { +struct eventfd_ctx *efdctx; + + efdctx =eventfd_ctx_fdget (fd); +if (IS_ERR (efdctx)) +return PTR_ERR (efdctx); + +if (*ctx) +eventfd_ctx_put (*ctx); + + *ctx = efdctx; + }else +return -EINVAL ; + +return 0 ; + } +default : +return -EINVAL ; + } +} +static ssize_t vfio_ccw_mdev_ioctl (struct mdev_device *mdev,unsigned int cmd,unsigned long arg)@@ -277,6 +357,47 @@ static ssize_t vfio_ccw_mdev_ioctl(struct mdev_device *mdev,return copy_to_user ((void __user *)arg, &info, minsz); } +case VFIO_DEVICE_GET_IRQ_INFO : + { +struct vfio_irq_info info; + + minsz = offsetofend(struct vfio_irq_info, count); + +if (copy_from_user (&info, (void __user *)arg, minsz)) +return -EFAULT ; + +if (info.argsz < minsz || info.index >=VFIO_CCW_NUM_IRQS ) +return -EINVAL ; + + ret =vfio_ccw_mdev_get_irq_info (&info); +if (ret) +return ret; + +if (info.count ==-1 ) +return -EINVAL ; + +return copy_to_user ((void __user *)arg, &info, minsz); + } +case VFIO_DEVICE_SET_IRQS : + { +struct vfio_irq_set hdr; +size_t data_size; +void __user *data; + + minsz = offsetofend(struct vfio_irq_set, count); + +if (copy_from_user (&hdr, (void __user *)arg, minsz)) +return -EFAULT ; + + ret =vfio_set_irqs_validate_and_prepare (&hdr,1 , +VFIO_CCW_NUM_IRQS , + &data_size); +if (ret) +return ret; + + data = (void __user *)(arg + minsz); +return vfio_ccw_mdev_set_irqs (mdev, hdr.flags, data); + }case VFIO_DEVICE_RESET :return vfio_ccw_mdev_reset (mdev);default :drivers/s390/cio/vfio_ccw_private.h +4
-0@@ -11,6 +11,7 @@#define _VFIO_CCW_PRIVATE_H_#include <linux/completion.h> +#include <linux/eventfd.h> #include <linux/vfio_ccw.h> #include "css.h" @@ -29,6 +30,7 @@* @cp: channel program for the current I/O operation * @irb: irb info received from interrupt * @scsw: scsw info +* @io_trigger: eventfd ctx for signaling userspace I/O results */ struct vfio_ccw_private {struct subchannel *sch;@@ -43,6 +45,8 @@ struct vfio_ccw_private {struct channel_program cp;struct irb irb;union scsw scsw; + +struct eventfd_ctx *io_trigger; }__aligned(8) ;extern int vfio_ccw_mdev_reg (struct subchannel *sch);include/uapi/linux/vfio.h +3
-2@@ -449,8 +449,9 @@ enum { };/* -* The vfio-ccw bus driver makes use of the following fixed region. -* Unimplemented regions return a size of zero. +* 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 {@@ -458,6 +459,11 @@ enum {VFIO_CCW_NUM_REGIONS
include/uapi/linux/vfio.h enum { · line 469
Quoted 10 lines
include/uapi/linux/vfio.h +5
-0}; +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)
Re: [PATCH v4 09/16] vfio: ccw: realize VFIO_DEVICE_GET_REGION_INFO ioctl
In reply to Dong Jia ShiQuoted 125 lines · On Fri, 17 Mar 2017 04:17:36 +0100 Dong Jia Shi <[email protected]>…
Introduce device information about vfio-ccw:
VFIO_DEVICE_FLAGS_CCW. RealizeVFIO_DEVICE_GET_REGION_INFOioctl for vfio-ccw.Reviewed-by Pierre Morel <[email protected]>Signed-off-by Dong Jia Shi <[email protected]>--- drivers/s390/cio/vfio_ccw_ops.c | 78 +++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 11 ++++++ 2 files changed, 89 insertions(+)drivers/s390/cio/vfio_ccw_ops.c +78
-0@@ -188,6 +188,83 @@ static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev,return count; } +static int vfio_ccw_mdev_get_device_info (struct vfio_device_info *info) +{ + info->flags =VFIO_DEVICE_FLAGS_CCW ; + info->num_regions =VFIO_CCW_NUM_REGIONS ; + info->num_irqs =0 ; + +return 0 ; +} + +static int vfio_ccw_mdev_get_region_info (struct vfio_region_info *info, +u16 *cap_type_id, +void **cap_type) +{ +switch (info->index) { +case VFIO_CCW_CONFIG_REGION_INDEX : + info->offset =0 ; + info->size =sizeof (struct ccw_io_region ); + info->flags =VFIO_REGION_INFO_FLAG_READ + |VFIO_REGION_INFO_FLAG_WRITE ; +return 0 ; +default : +return -EINVAL ; + } +} + +static ssize_t vfio_ccw_mdev_ioctl (struct mdev_device *mdev, +unsigned int cmd, +unsigned long arg) +{ +int ret =0 ; +unsigned long minsz; + +switch (cmd) { +case VFIO_DEVICE_GET_INFO : + { +struct vfio_device_info info; + + minsz = offsetofend(struct vfio_device_info, num_irqs); + +if (copy_from_user (&info, (void __user *)arg, minsz)) +return -EFAULT ; + +if (info.argsz < minsz) +return -EINVAL ; + + ret =vfio_ccw_mdev_get_device_info (&info); +if (ret) +return ret; + +return copy_to_user ((void __user *)arg, &info, minsz); + } +case VFIO_DEVICE_GET_REGION_INFO : + { +struct vfio_region_info info; +u16 cap_type_id =0 ; +void *cap_type =NULL ; + + minsz = offsetofend(struct vfio_region_info, offset); + +if (copy_from_user (&info, (void __user *)arg, minsz)) +return -EFAULT ; + +if (info.argsz < minsz) +return -EINVAL ; + + ret =vfio_ccw_mdev_get_region_info (&info, &cap_type_id, + &cap_type); +if (ret) +return ret; + +return copy_to_user ((void __user *)arg, &info, minsz); + } +default : +return -ENOTTY ; + } +} +static const struct mdev_parent_ops vfio_ccw_mdev_ops = { .owner =THIS_MODULE , .supported_type_groups = mdev_type_groups,@@ -197,6 +274,7 @@ static const struct mdev_parent_ops vfio_ccw_mdev_ops = { .release = vfio_ccw_mdev_release, .read = vfio_ccw_mdev_read, .write = vfio_ccw_mdev_write, + .ioctl = vfio_ccw_mdev_ioctl, };int vfio_ccw_mdev_reg (struct subchannel *sch)include/uapi/linux/vfio.h +4
-0@@ -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 */ };@@ -447,6 +448,16 @@ enum { VFIO_PCI_NUM_IRQS }; +/* +* The vfio-ccw bus driver makes use of the following fixed region. +* Unimplemented regions return a size of zero.
include/uapi/linux/vfio.h enum { · line 463
Quoted 10 lines
include/uapi/linux/vfio.h +7
-0+*/ + +enum { +VFIO_CCW_CONFIG_REGION_INDEX , +VFIO_CCW_NUM_REGIONS +}; +/** * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IORW(VFIO_TYPE, VFIO_BASE + 12, * struct vfio_pci_hot_reset_info)
Re: [PATCH v4 03/16] vfio: ccw: define device_api strings
In reply to Dong Jia ShiQuoted 14 lines · On Fri, 17 Mar 2017 04:17:30 +0100 Dong Jia Shi <[email protected]>…
Define vfio-ccw device API strings. CCW vendor driver using mediated device framework should use this string for
device_apiattribute.Reviewed-by Pierre Morel <[email protected]>Signed-off-by Dong Jia Shi <[email protected]>--- include/uapi/linux/vfio.h | 1 + 1 file changed, 1 insertion(+)include/uapi/linux/vfio.h +0
-0
include/uapi/linux/vfio.h struct vfio_device_info { · line 218
Quoted 7 lines
include/uapi/linux/vfio.h +1
-0@@ -212,6 +212,7 @@ struct vfio_device_info {#define VFIO_DEVICE_API_PCI_STRING "vfio-pci"#define VFIO_DEVICE_API_PLATFORM_STRING "vfio-platform"#define VFIO_DEVICE_API_AMBA_STRING "vfio-amba" +#define VFIO_DEVICE_API_CCW_STRING "vfio-ccw"/** * VFIO_DEVICE_GET_REGION_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 8,
Re: [Qemu-devel] [PATCH v4 11/16] vfio: ccw: realize VFIO_DEVICE_G(S)ET_IRQ_INFO ioctls
In reply to Alex Williamson* Alex Williamson <[email protected]> [2017-03-21 12:47:24 -0600]:
[...]
Quoted 4 lines
Quoted 4 lines
include/uapi/linux/vfio.h +0
-0@@ -458,6 +459,11 @@ enum { VFIO_CCW_NUM_REGIONS };
Quoted 12 lines
include/uapi/linux/vfio.h enum { · line 469
Quoted 8 lines
include/uapi/linux/vfio.h +5
-0+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) Acked-by Alex Williamson <[email protected]>
Hi Alex,
Thanks for all the Acked-bys. :>
Signature · 1 line
Dong Jia
Re: [Qemu-devel] [PATCH v4 14/16] docs: add documentation for vfio-ccw
In reply to Alex Williamson* Alex Williamson <[email protected]> [2017-03-21 12:47:16 -0600]:
[...]
Quoted 16 lines
Quoted 16 lines
Documentation/s390/vfio-ccw.txt new file +16
-0+vfio-ccw I/O region +------------------- + +An I/O region is used to accept channel program request from user +space and store I/O interrupt result for user space to retrieve. The +defination of the region is: + +struct ccw_io_region { +#define ORB_AREA_SIZE 12 + __u8 orb_area[ORB_AREA_SIZE]; +#define SCSW_AREA_SIZE 12 + __u8 scsw_area[SCSW_AREA_SIZE]; +#define IRB_AREA_SIZE 96 + __u8 irb_area[IRB_AREA_SIZE]; + __u32 ret_code; +} __packed;
Quoted 8 lines
Documentation/s390/vfio-ccw.txt line 199
Quoted 8 lines
Documentation/s390/vfio-ccw.txt new file +8
-0+ +While starting an I/O request, orb_area should be filled with the +guest ORB, and scsw_area should be filled with the SCSW of the Virtual +Subchannel. + +irb_area stores the I/O result. + +ret_code stores a return code for each access of the region.
Hi Alex,
Quoted 5 lines
Pardon if these questions expose my lack of familiarity with S390:
So I/O requests are asynchronous, the user is notified via interrupt when completed, can more than one request be queued at a time?
The answer is no. The subchannel will stay in a state that prohibiting from a new request if there is processing for a previous request ongoing. And we need to issue an explit I/O instruction to retrieve and (or) clear the pending interruption before issue another I/O request.
Quoted 2 lines
The communication format doesn't seem like it'd easily support that. Is it possible? A future enhancement that we should design for now?
As the above statements said, it's not possible.
Quoted 5 lines
I'm also a little unclear what sort of I/O a user has access to via this interface and how the kernel polices that access. For instance, are multiple tape or disk devices available through a single I/O channel?
No. An I/O subchannel is dedicated to one device, and...
Quoted 2 lines
How does the user configure which devices a user has access to when creating the vfio-ccw device?
...this mapping is usually determined/configured before the machine startup by the administrtor of the upper level hypervisor. So when creating the vfio-ccw device, we do not configure/modify this mapping. When the guest I/O subchannel driver probing, it will issue a SENSE command on the subchannel to recognize/find what kind of device is behind the subchannel, and then it uses corresponding CCW device driver serving the I/O device.
@Conny, please correct me if my understanding is not right.
Quoted 2 lines
Otherwise I think the interface looks great. Thanks,
This is good news. :>
Thanks!
Quoted 3 lines
Alex
Signature · 1 line
Dong Jia Shi
Re: [PATCH v4 01/16] s390: cio: introduce cio_cancel_halt_clear
In reply to Dong Jia ShiQuoted 8 lines · Dong Jia Shi
For future code reuse purpose, this decouples the cio code with the ccw device specific parts from
ccw_device_cancel_halt_clear, and makes a new common I/O interface namedcio_cancel_halt_clear.Reviewed-by Pierre Morel <[email protected]>Signed-off-by Dong Jia Shi <[email protected]>Cc Sebastian Ott <[email protected]>Cc Peter Oberparleiter <[email protected]>
[...]
Quoted 8 lines
+/**
+ *cio_cancel_halt_clear- Cancel running I/O by performing cancel, halt
+ * and clear ordinally if subchannel is valid.
+ * @sch: subchannel on which to perform thecancel_halt_clearoperation
+ * @iretry: the number of the times remained to retry the next operation
+ *
+ * This should be called repeatedly since halt/clear are asynchronous
+ * operations. We do one try withcio_cancel, two tries withcio_halt,
^
threeRe: [PATCH v4 02/16] s390: cio: export more interfaces
In reply to Dong Jia ShiQuoted 8 lines · Dong Jia Shi
Export the common I/O interfaces those are needed by an I/O subchannel driver to actually talk to the subchannel.
Reviewed-by Pierre Morel <[email protected]>Signed-off-by Dong Jia Shi <[email protected]>Cc Sebastian Ott <[email protected]>Cc Peter Oberparleiter <[email protected]>---
Re: [Qemu-devel] [PATCH v4 02/16] s390: cio: export more interfaces
Quoted 11 lines · Sebastian Ott
Quoted 8 lines · Dong Jia Shi
Export the common I/O interfaces those are needed by an I/O subchannel driver to actually talk to the subchannel.
Reviewed-by Pierre Morel <[email protected]>Signed-off-by Dong Jia Shi <[email protected]>Cc Sebastian Ott <[email protected]>Cc Peter Oberparleiter <[email protected]>---
Acked-by Sebastian Ott <[email protected]>
Hi Sebastian,
Thanks for all of your acks!
Signature · 1 line
Dong Jia Shi
Re: [Qemu-devel] [PATCH v4 01/16] s390: cio: introduce cio_cancel_halt_clear
In reply to Sebastian OttQuoted 18 lines · Sebastian Ott
Quoted 8 lines · Dong Jia Shi
For future code reuse purpose, this decouples the cio code with the ccw device specific parts from
ccw_device_cancel_halt_clear, and makes a new common I/O interface namedcio_cancel_halt_clear.Reviewed-by Pierre Morel <[email protected]>Signed-off-by Dong Jia Shi <[email protected]>Cc Sebastian Ott <[email protected]>Cc Peter Oberparleiter <[email protected]>[...]
Quoted 8 lines
+/**
+ *cio_cancel_halt_clear- Cancel running I/O by performing cancel, halt
+ * and clear ordinally if subchannel is valid.
+ * @sch: subchannel on which to perform thecancel_halt_clearoperation
+ * @iretry: the number of the times remained to retry the next operation
+ *
+ * This should be called repeatedly since halt/clear are asynchronous
+ * operations. We do one try withcio_cancel, two tries withcio_halt,
Quoted 2 lines
^
threeOk. Nice catch!
Quoted 2 lines
Acked-by Sebastian Ott <[email protected]>
Thanks.
Signature · 1 line
Dong Jia Shi
Re: [PATCH v4 14/16] docs: add documentation for vfio-ccw
In reply to Dong Jia ShiQuoted 61 lines · On Wed, 22 Mar 2017 10:34:22 +0800 Dong Jia Shi <[email protected]>…
* Alex Williamson <[email protected]> [2017-03-21 12:47:16 -0600]:
[...]
Quoted 16 lines
Quoted 16 lines
Documentation/s390/vfio-ccw.txt new file +16
-0+vfio-ccw I/O region +------------------- + +An I/O region is used to accept channel program request from user +space and store I/O interrupt result for user space to retrieve. The +defination of the region is: + +struct ccw_io_region { +#define ORB_AREA_SIZE 12 + __u8 orb_area[ORB_AREA_SIZE]; +#define SCSW_AREA_SIZE 12 + __u8 scsw_area[SCSW_AREA_SIZE]; +#define IRB_AREA_SIZE 96 + __u8 irb_area[IRB_AREA_SIZE]; + __u32 ret_code; +} __packed;Quoted 8 lines
Documentation/s390/vfio-ccw.txt line 199
Quoted 8 lines
Documentation/s390/vfio-ccw.txt new file +8
-0+ +While starting an I/O request, orb_area should be filled with the +guest ORB, and scsw_area should be filled with the SCSW of the Virtual +Subchannel. + +irb_area stores the I/O result. + +ret_code stores a return code for each access of the region.Hi Alex,
Quoted 5 lines
Pardon if these questions expose my lack of familiarity with S390:
So I/O requests are asynchronous, the user is notified via interrupt when completed, can more than one request be queued at a time?
The answer is no. The subchannel will stay in a state that prohibiting from a new request if there is processing for a previous request ongoing. And we need to issue an explit I/O instruction to retrieve and (or) clear the pending interruption before issue another I/O request.
Quoted 2 lines
The communication format doesn't seem like it'd easily support that. Is it possible? A future enhancement that we should design for now?
As the above statements said, it's not possible.
Quoted 5 lines
I'm also a little unclear what sort of I/O a user has access to via this interface and how the kernel polices that access. For instance, are multiple tape or disk devices available through a single I/O channel?
No. An I/O subchannel is dedicated to one device, and...
Quoted 2 lines
How does the user configure which devices a user has access to when creating the vfio-ccw device?
...this mapping is usually determined/configured before the machine startup by the administrtor of the upper level hypervisor. So when creating the vfio-ccw device, we do not configure/modify this mapping. When the guest I/O subchannel driver probing, it will issue a SENSE command on the subchannel to recognize/find what kind of device is behind the subchannel, and then it uses corresponding CCW device driver serving the I/O device.
Quoted 1 line
@Conny, please correct me if my understanding is not right.
No, it's fine.
FWIW:
https://virtualpenguins.blogspot.com/2017/02/channel-io-demystified.html
(I plan to write more in the future.)
Quoted 10 lines
Quoted 3 lines
Otherwise I think the interface looks great. Thanks,
This is good news. :>
Thanks!
Quoted 3 lines
Alex
Quoted 38 lines · On Fri, 17 Mar 2017 04:17:27 +0100 Dong Jia Shi <[email protected]>…
Dong Jia Shi (16):
s390: cio: introducecio_cancel_halt_clear
s390: cio: export more interfaces
vfio: ccw: definedevice_apistrings
vfio: ccw: basic implementation forvfio_ccwdriver
vfio: ccw: introduce channel program interfaces
vfio: ccw: registervfio_ccwto the mediated device framework
vfio: ccw: introduceccw_io_region
vfio: ccw: handle ccw command request
vfio: ccw: realizeVFIO_DEVICE_GET_REGION_INFOioctl
vfio: ccw: realizeVFIO_DEVICE_RESETioctl
vfio: ccw: realize VFIO_DEVICE_G(S)ET_IRQ_INFO ioctls
vfio: ccw: return I/O results asynchronously
vfio: ccw: introduce a finite state machine
docs: add documentation for vfio-ccw
vfio: ccw: introduce support for ccw0
MAINTAINERS: Add vfio-ccw maintainersDocumentation/s390/00-INDEX | 2 + Documentation/s390/vfio-ccw.txt | 303 +++++++++++++ MAINTAINERS | 10 + arch/s390/Kconfig | 10 + arch/s390/include/asm/cio.h | 18 + arch/s390/include/asm/isc.h | 1 + drivers/iommu/Kconfig | 8 + drivers/s390/cio/Makefile | 3 + drivers/s390/cio/cio.c | 69 +++ drivers/s390/cio/cio.h | 1 + drivers/s390/cio/device_fsm.c | 54 +-- drivers/s390/cio/vfio_ccw_cp.c | 842 ++++++++++++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_cp.h | 42 ++ drivers/s390/cio/vfio_ccw_drv.c | 308 +++++++++++++ drivers/s390/cio/vfio_ccw_fsm.c | 207 +++++++++ drivers/s390/cio/vfio_ccw_ops.c | 447 +++++++++++++++++++ drivers/s390/cio/vfio_ccw_private.h | 96 ++++ include/uapi/linux/vfio.h | 18 + include/uapi/linux/vfio_ccw.h | 24 + 19 files changed, 2417 insertions(+), 46 deletions(-)
Quoted 9 lines
create mode 100644 Documentation/s390/vfio-ccw.txt create mode 100644 drivers/s390/cio/vfio_ccw_cp.c create mode 100644 drivers/s390/cio/vfio_ccw_cp.h create mode 100644 drivers/s390/cio/vfio_ccw_drv.c create mode 100644 drivers/s390/cio/vfio_ccw_fsm.c create mode 100644 drivers/s390/cio/vfio_ccw_ops.c create mode 100644 drivers/s390/cio/vfio_ccw_private.h create mode 100644 include/uapi/linux/vfio_ccw.h
Patch set looks good to me, and I think we should target it for the next merge window (the interface looks fine, and we can iron out any other things later.)
Question: Which tree should this go through? Vfio or kvm/s390?
Quoted 51 lines · Cornelia Huck
Quoted 38 lines · On Fri, 17 Mar 2017 04:17:27 +0100 Dong Jia Shi <[email protected]>…
Dong Jia Shi (16):
s390: cio: introducecio_cancel_halt_clear
s390: cio: export more interfaces
vfio: ccw: definedevice_apistrings
vfio: ccw: basic implementation forvfio_ccwdriver
vfio: ccw: introduce channel program interfaces
vfio: ccw: registervfio_ccwto the mediated device framework
vfio: ccw: introduceccw_io_region
vfio: ccw: handle ccw command request
vfio: ccw: realizeVFIO_DEVICE_GET_REGION_INFOioctl
vfio: ccw: realizeVFIO_DEVICE_RESETioctl
vfio: ccw: realize VFIO_DEVICE_G(S)ET_IRQ_INFO ioctls
vfio: ccw: return I/O results asynchronously
vfio: ccw: introduce a finite state machine
docs: add documentation for vfio-ccw
vfio: ccw: introduce support for ccw0
MAINTAINERS: Add vfio-ccw maintainersDocumentation/s390/00-INDEX | 2 + Documentation/s390/vfio-ccw.txt | 303 +++++++++++++ MAINTAINERS | 10 + arch/s390/Kconfig | 10 + arch/s390/include/asm/cio.h | 18 + arch/s390/include/asm/isc.h | 1 + drivers/iommu/Kconfig | 8 + drivers/s390/cio/Makefile | 3 + drivers/s390/cio/cio.c | 69 +++ drivers/s390/cio/cio.h | 1 + drivers/s390/cio/device_fsm.c | 54 +-- drivers/s390/cio/vfio_ccw_cp.c | 842 ++++++++++++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_cp.h | 42 ++ drivers/s390/cio/vfio_ccw_drv.c | 308 +++++++++++++ drivers/s390/cio/vfio_ccw_fsm.c | 207 +++++++++ drivers/s390/cio/vfio_ccw_ops.c | 447 +++++++++++++++++++ drivers/s390/cio/vfio_ccw_private.h | 96 ++++ include/uapi/linux/vfio.h | 18 + include/uapi/linux/vfio_ccw.h | 24 + 19 files changed, 2417 insertions(+), 46 deletions(-)Quoted 9 lines
create mode 100644 Documentation/s390/vfio-ccw.txt create mode 100644 drivers/s390/cio/vfio_ccw_cp.c create mode 100644 drivers/s390/cio/vfio_ccw_cp.h create mode 100644 drivers/s390/cio/vfio_ccw_drv.c create mode 100644 drivers/s390/cio/vfio_ccw_fsm.c create mode 100644 drivers/s390/cio/vfio_ccw_ops.c create mode 100644 drivers/s390/cio/vfio_ccw_private.h create mode 100644 include/uapi/linux/vfio_ccw.h
Quoted 5 lines
Patch set looks good to me, and I think we should target it for the next merge window (the interface looks fine, and we can iron out any other things later.)
Question: Which tree should this go through? Vfio or kvm/s390?
Reading todays MAINTAINERS file this would go via Martins tree, after the last patch it will be separate. I can certainly carry that via the kvms390 tree, but Alex is certainly the final maintainer.
So what about having a new repository under
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/
e.g. vfio.git that will then queue the patches for Alex to take?
Re: [Qemu-devel] [PATCH v4 14/16] docs: add documentation for vfio-ccw
In reply to Cornelia Huck* Cornelia Huck <[email protected]> [2017-03-28 10:16:23 +0200]:
[...]
Quoted 4 lines
Quoted 2 lines
@Conny, please correct me if my understanding is not right.
No, it's fine.
Thanks!
Quoted 5 lines
FWIW:
https://virtualpenguins.blogspot.com/2017/02/channel-io-demystified.html(I plan to write more in the future.)
That's a very good sharing.
Quoted 1 line
[...]
Signature · 1 line
Dong Jia Shi
Quoted 6 lines · On Tue, 28 Mar 2017 10:39:40 +0200 Christian Borntraeger…
Quoted 4 lines · Cornelia Huck
Patch set looks good to me, and I think we should target it for the next merge window (the interface looks fine, and we can iron out any other things later.)
Quoted 8 lines
Quoted 1 line
Question: Which tree should this go through? Vfio or kvm/s390?
Reading todays
MAINTAINERSfile this would go via Martins tree, after the last patch it will be separate. I can certainly carry that via the kvms390 tree, but Alex is certainly the final maintainer.
So what about having a new repository under
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/
e.g. vfio.git that will then queue the patches for Alex to take?
Whatever we decide:
Patches with collected acks pushed out to
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/vfio-ccw.git vfio-ccw-v0
Quoted 56 lines · On Tue, 28 Mar 2017 10:39:40 +0200 Christian Borntraeger…
Quoted 55 lines · Cornelia Huck
Quoted 38 lines · On Fri, 17 Mar 2017 04:17:27 +0100 Dong Jia Shi <[email protected]>…
Dong Jia Shi (16):
s390: cio: introducecio_cancel_halt_clear
s390: cio: export more interfaces
vfio: ccw: definedevice_apistrings
vfio: ccw: basic implementation forvfio_ccwdriver
vfio: ccw: introduce channel program interfaces
vfio: ccw: registervfio_ccwto the mediated device framework
vfio: ccw: introduceccw_io_region
vfio: ccw: handle ccw command request
vfio: ccw: realizeVFIO_DEVICE_GET_REGION_INFOioctl
vfio: ccw: realizeVFIO_DEVICE_RESETioctl
vfio: ccw: realize VFIO_DEVICE_G(S)ET_IRQ_INFO ioctls
vfio: ccw: return I/O results asynchronously
vfio: ccw: introduce a finite state machine
docs: add documentation for vfio-ccw
vfio: ccw: introduce support for ccw0
MAINTAINERS: Add vfio-ccw maintainersDocumentation/s390/00-INDEX | 2 + Documentation/s390/vfio-ccw.txt | 303 +++++++++++++ MAINTAINERS | 10 + arch/s390/Kconfig | 10 + arch/s390/include/asm/cio.h | 18 + arch/s390/include/asm/isc.h | 1 + drivers/iommu/Kconfig | 8 + drivers/s390/cio/Makefile | 3 + drivers/s390/cio/cio.c | 69 +++ drivers/s390/cio/cio.h | 1 + drivers/s390/cio/device_fsm.c | 54 +-- drivers/s390/cio/vfio_ccw_cp.c | 842 ++++++++++++++++++++++++++++++++++++ drivers/s390/cio/vfio_ccw_cp.h | 42 ++ drivers/s390/cio/vfio_ccw_drv.c | 308 +++++++++++++ drivers/s390/cio/vfio_ccw_fsm.c | 207 +++++++++ drivers/s390/cio/vfio_ccw_ops.c | 447 +++++++++++++++++++ drivers/s390/cio/vfio_ccw_private.h | 96 ++++ include/uapi/linux/vfio.h | 18 + include/uapi/linux/vfio_ccw.h | 24 + 19 files changed, 2417 insertions(+), 46 deletions(-)Quoted 9 lines
create mode 100644 Documentation/s390/vfio-ccw.txt create mode 100644 drivers/s390/cio/vfio_ccw_cp.c create mode 100644 drivers/s390/cio/vfio_ccw_cp.h create mode 100644 drivers/s390/cio/vfio_ccw_drv.c create mode 100644 drivers/s390/cio/vfio_ccw_fsm.c create mode 100644 drivers/s390/cio/vfio_ccw_ops.c create mode 100644 drivers/s390/cio/vfio_ccw_private.h create mode 100644 include/uapi/linux/vfio_ccw.hPatch set looks good to me, and I think we should target it for the next merge window (the interface looks fine, and we can iron out any other things later.)
Quoted 8 lines
Quoted 1 line
Question: Which tree should this go through? Vfio or kvm/s390?
Reading todays
MAINTAINERSfile this would go via Martins tree, after the last patch it will be separate. I can certainly carry that via the kvms390 tree, but Alex is certainly the final maintainer.
So what about having a new repository under
https://git.kernel.org/pub/scm/linux/kernel/git/kvms390/
e.g. vfio.git that will then queue the patches for Alex to take?
I would think this should be merged through s390 trees, I don't claim any sort of maintainership for each individual mdev vendor driver (perhaps with the exception of the mtty sample driver). I think I've acked all the (relatively minor) bits where this series updates the vfio core code. Thanks,
Alex