Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfio: ccw: introduce ccw_io_region

To 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.

Reviewed-by: Pierre Morel <pmorel@linux.vnet.ibm.com>
Signed-off-by: Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
Message-Id: <20170317031743.40128-8-bjsdjshi@linux.vnet.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>

authored by

Dong Jia Shi and committed by
Cornelia Huck
060d2b5a 84cd8fc4

+75
+47
drivers/s390/cio/vfio_ccw_ops.c
··· 127 127 &private->nb); 128 128 } 129 129 130 + static ssize_t vfio_ccw_mdev_read(struct mdev_device *mdev, 131 + char __user *buf, 132 + size_t count, 133 + loff_t *ppos) 134 + { 135 + struct vfio_ccw_private *private; 136 + struct ccw_io_region *region; 137 + 138 + if (*ppos + count > sizeof(*region)) 139 + return -EINVAL; 140 + 141 + private = dev_get_drvdata(mdev_parent_dev(mdev)); 142 + if (!private) 143 + return -ENODEV; 144 + 145 + region = &private->io_region; 146 + if (copy_to_user(buf, (void *)region + *ppos, count)) 147 + return -EFAULT; 148 + 149 + return count; 150 + } 151 + 152 + static ssize_t vfio_ccw_mdev_write(struct mdev_device *mdev, 153 + const char __user *buf, 154 + size_t count, 155 + loff_t *ppos) 156 + { 157 + struct vfio_ccw_private *private; 158 + struct ccw_io_region *region; 159 + 160 + if (*ppos + count > sizeof(*region)) 161 + return -EINVAL; 162 + 163 + private = dev_get_drvdata(mdev_parent_dev(mdev)); 164 + if (!private) 165 + return -ENODEV; 166 + 167 + region = &private->io_region; 168 + if (copy_from_user((void *)region + *ppos, buf, count)) 169 + return -EFAULT; 170 + region->ret_code = 0; 171 + 172 + return count; 173 + } 174 + 130 175 static const struct mdev_parent_ops vfio_ccw_mdev_ops = { 131 176 .owner = THIS_MODULE, 132 177 .supported_type_groups = mdev_type_groups, ··· 179 134 .remove = vfio_ccw_mdev_remove, 180 135 .open = vfio_ccw_mdev_open, 181 136 .release = vfio_ccw_mdev_release, 137 + .read = vfio_ccw_mdev_read, 138 + .write = vfio_ccw_mdev_write, 182 139 }; 183 140 184 141 int vfio_ccw_mdev_reg(struct subchannel *sch)
+4
drivers/s390/cio/vfio_ccw_private.h
··· 10 10 #ifndef _VFIO_CCW_PRIVATE_H_ 11 11 #define _VFIO_CCW_PRIVATE_H_ 12 12 13 + #include <linux/vfio_ccw.h> 14 + 13 15 #include "css.h" 14 16 15 17 /** ··· 21 19 * @avail: available for creating a mediated device 22 20 * @mdev: pointer to the mediated device 23 21 * @nb: notifier for vfio events 22 + * @io_region: MMIO region to input/output I/O arguments/results 24 23 */ 25 24 struct vfio_ccw_private { 26 25 struct subchannel *sch; ··· 29 26 atomic_t avail; 30 27 struct mdev_device *mdev; 31 28 struct notifier_block nb; 29 + struct ccw_io_region io_region; 32 30 } __aligned(8); 33 31 34 32 extern int vfio_ccw_mdev_reg(struct subchannel *sch);
+24
include/uapi/linux/vfio_ccw.h
··· 1 + /* 2 + * Interfaces for vfio-ccw 3 + * 4 + * Copyright IBM Corp. 2017 5 + * 6 + * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> 7 + */ 8 + 9 + #ifndef _VFIO_CCW_H_ 10 + #define _VFIO_CCW_H_ 11 + 12 + #include <linux/types.h> 13 + 14 + struct ccw_io_region { 15 + #define ORB_AREA_SIZE 12 16 + __u8 orb_area[ORB_AREA_SIZE]; 17 + #define SCSW_AREA_SIZE 12 18 + __u8 scsw_area[SCSW_AREA_SIZE]; 19 + #define IRB_AREA_SIZE 96 20 + __u8 irb_area[IRB_AREA_SIZE]; 21 + __u32 ret_code; 22 + } __packed; 23 + 24 + #endif