s390: vfio-ap: implement VFIO_DEVICE_GET_INFO ioctl
authorTony Krowiak <akrowiak@linux.ibm.com>
Tue, 25 Sep 2018 23:16:27 +0000 (19:16 -0400)
committerChristian Borntraeger <borntraeger@de.ibm.com>
Fri, 28 Sep 2018 13:50:11 +0000 (15:50 +0200)
Adds support for the VFIO_DEVICE_GET_INFO ioctl to the VFIO
AP Matrix device driver. This is a minimal implementation,
as vfio-ap does not use I/O regions.

Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Acked-by: Halil Pasic <pasic@linux.ibm.com>
Tested-by: Michael Mueller <mimu@linux.ibm.com>
Tested-by: Farhan Ali <alifm@linux.ibm.com>
Tested-by: Pierre Morel <pmorel@linux.ibm.com>
Message-Id: <20180925231641.4954-13-akrowiak@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
drivers/s390/crypto/vfio_ap_ops.c
include/uapi/linux/vfio.h

index 1fd0beefeda63aa0f5c27cfa61d24994d6257463..974cf06d8a5c6ef0b6f4b835970bb9c5a3872902 100644 (file)
@@ -855,6 +855,43 @@ static void vfio_ap_mdev_release(struct mdev_device *mdev)
        module_put(THIS_MODULE);
 }
 
+static int vfio_ap_mdev_get_device_info(unsigned long arg)
+{
+       unsigned long minsz;
+       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;
+
+       info.flags = VFIO_DEVICE_FLAGS_AP;
+       info.num_regions = 0;
+       info.num_irqs = 0;
+
+       return copy_to_user((void __user *)arg, &info, minsz);
+}
+
+static ssize_t vfio_ap_mdev_ioctl(struct mdev_device *mdev,
+                                   unsigned int cmd, unsigned long arg)
+{
+       int ret;
+
+       switch (cmd) {
+       case VFIO_DEVICE_GET_INFO:
+               ret = vfio_ap_mdev_get_device_info(arg);
+               break;
+       default:
+               ret = -EOPNOTSUPP;
+               break;
+       }
+
+       return ret;
+}
+
 static const struct mdev_parent_ops vfio_ap_matrix_ops = {
        .owner                  = THIS_MODULE,
        .supported_type_groups  = vfio_ap_mdev_type_groups,
@@ -863,6 +900,7 @@ static const struct mdev_parent_ops vfio_ap_matrix_ops = {
        .remove                 = vfio_ap_mdev_remove,
        .open                   = vfio_ap_mdev_open,
        .release                = vfio_ap_mdev_release,
+       .ioctl                  = vfio_ap_mdev_ioctl,
 };
 
 int vfio_ap_mdev_register(void)
index bfbe2be8f36927dd4c7bc40d341f0830e7f54835..f378b9802d8b5d2276387406d57b084e3ebd3211 100644 (file)
@@ -200,6 +200,7 @@ struct vfio_device_info {
 #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 */
+#define VFIO_DEVICE_FLAGS_AP   (1 << 5)        /* vfio-ap device */
        __u32   num_regions;    /* Max region index + 1 */
        __u32   num_irqs;       /* Max IRQ index + 1 */
 };