]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vfio: Provide a get_region_info op
authorJason Gunthorpe <jgg@nvidia.com>
Fri, 7 Nov 2025 17:41:17 +0000 (13:41 -0400)
committerAlex Williamson <alex@shazbot.org>
Wed, 12 Nov 2025 21:58:23 +0000 (14:58 -0700)
Instead of hooking the general ioctl op, have the core code directly
decode VFIO_DEVICE_GET_REGION_INFO and call an op just for it.

This is intended to allow mechanical changes to the drivers to pull their
VFIO_DEVICE_GET_REGION_INFO int oa function. Later patches will improve
the function signature to consolidate more code.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Pranjal Shrivastava <praan@google.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/1-v2-2a9e24d62f1b+e10a-vfio_get_region_info_op_jgg@nvidia.com
Signed-off-by: Alex Williamson <alex@shazbot.org>
drivers/vfio/pci/vfio_pci_core.c
drivers/vfio/vfio_main.c
include/linux/vfio.h
include/linux/vfio_pci_core.h

index 7dcf5439dedc9df1dad5d37c5f89c4de46b31789..1dc350003f075c577fb96cccf6efd02a09a4468d 100644 (file)
@@ -996,9 +996,11 @@ static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev,
        return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
 }
 
-static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
-                                         struct vfio_region_info __user *arg)
+int vfio_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
+                                  struct vfio_region_info __user *arg)
 {
+       struct vfio_pci_core_device *vdev =
+               container_of(core_vdev, struct vfio_pci_core_device, vdev);
        unsigned long minsz = offsetofend(struct vfio_region_info, offset);
        struct pci_dev *pdev = vdev->pdev;
        struct vfio_region_info info;
@@ -1132,6 +1134,7 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
 
        return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
 }
+EXPORT_SYMBOL_GPL(vfio_pci_ioctl_get_region_info);
 
 static int vfio_pci_ioctl_get_irq_info(struct vfio_pci_core_device *vdev,
                                       struct vfio_irq_info __user *arg)
@@ -1458,7 +1461,7 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
        case VFIO_DEVICE_GET_PCI_HOT_RESET_INFO:
                return vfio_pci_ioctl_get_pci_hot_reset_info(vdev, uarg);
        case VFIO_DEVICE_GET_REGION_INFO:
-               return vfio_pci_ioctl_get_region_info(vdev, uarg);
+               return vfio_pci_ioctl_get_region_info(core_vdev, uarg);
        case VFIO_DEVICE_IOEVENTFD:
                return vfio_pci_ioctl_ioeventfd(vdev, uarg);
        case VFIO_DEVICE_PCI_HOT_RESET:
index 38c8e9350a60ecae779a879f9db5daf05773ad8d..a390163ce706c44d097ab7ac596bfad7e8c6af7c 100644 (file)
@@ -1296,7 +1296,14 @@ static long vfio_device_fops_unl_ioctl(struct file *filep,
                ret = vfio_ioctl_device_feature(device, uptr);
                break;
 
+       case VFIO_DEVICE_GET_REGION_INFO:
+               if (!device->ops->get_region_info)
+                       goto ioctl_fallback;
+               ret = device->ops->get_region_info(device, uptr);
+               break;
+
        default:
+ioctl_fallback:
                if (unlikely(!device->ops->ioctl))
                        ret = -EINVAL;
                else
index eb563f538dee519c8930d55bfc5f84bdc99bf44f..be5fcf8432e8d5ed696272aa4f9d4297058c774d 100644 (file)
@@ -132,6 +132,8 @@ struct vfio_device_ops {
                         size_t count, loff_t *size);
        long    (*ioctl)(struct vfio_device *vdev, unsigned int cmd,
                         unsigned long arg);
+       int     (*get_region_info)(struct vfio_device *vdev,
+                                  struct vfio_region_info __user *arg);
        int     (*mmap)(struct vfio_device *vdev, struct vm_area_struct *vma);
        void    (*request)(struct vfio_device *vdev, unsigned int count);
        int     (*match)(struct vfio_device *vdev, char *buf);
index f541044e42a2ad3d3658ef25786324621bc9180a..160bc2e31ece755c3011358eb16b48123be5ede6 100644 (file)
@@ -115,6 +115,8 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
                unsigned long arg);
 int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags,
                                void __user *arg, size_t argsz);
+int vfio_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
+                                  struct vfio_region_info __user *arg);
 ssize_t vfio_pci_core_read(struct vfio_device *core_vdev, char __user *buf,
                size_t count, loff_t *ppos);
 ssize_t vfio_pci_core_write(struct vfio_device *core_vdev, const char __user *buf,