Hi Jason,

On 10/24/25 1:09 AM, Jason Gunthorpe wrote:
> 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
in a
> the function signature to consolidate more code.
>
> Signed-off-by: Jason Gunthorpe <[email protected]>
> ---
>  drivers/vfio/pci/vfio_pci_core.c | 9 ++++++---
>  drivers/vfio/vfio_main.c         | 7 +++++++
>  include/linux/vfio.h             | 2 ++
>  include/linux/vfio_pci_core.h    | 2 ++
>  4 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/vfio/pci/vfio_pci_core.c 
> b/drivers/vfio/pci/vfio_pci_core.c
> index 7dcf5439dedc9d..1dc350003f075c 100644
> --- a/drivers/vfio/pci/vfio_pci_core.c
> +++ b/drivers/vfio/pci/vfio_pci_core.c
> @@ -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:
> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> index 38c8e9350a60ec..a390163ce706c4 100644
> --- a/drivers/vfio/vfio_main.c
> +++ b/drivers/vfio/vfio_main.c
> @@ -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
> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
> index eb563f538dee51..be5fcf8432e8d5 100644
> --- a/include/linux/vfio.h
> +++ b/include/linux/vfio.h
> @@ -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);
> diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
> index f541044e42a2ad..160bc2e31ece75 100644
> --- a/include/linux/vfio_pci_core.h
> +++ b/include/linux/vfio_pci_core.h
> @@ -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);
looks like an inconsistent naming. all other functions declared here
have "_core".

The change of proto + export of vfio_pci_ioctl_get_region_info could
have been put in a separate patch than the one introducing the
get_region_info cb especially since the change is not documented in the
commit msg

Thanks

Eric
>  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,

Reply via email to