intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op
@ 2025-10-23 23:09 Jason Gunthorpe
  2025-10-23 23:09 ` [PATCH 01/22] vfio: Provide a get_region_info op Jason Gunthorpe
                   ` (24 more replies)
  0 siblings, 25 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

There is alot of duplicated code in the drivers for processing
VFIO_DEVICE_GET_REGION_INFO. Introduce a new op get_region_info_caps()
which provides a struct vfio_info_cap and handles the cap chain logic
to write the caps back to userspace and remove all of this duplication
from drivers.

This is done in two steps, the first is a largely mechanical introduction
of the get_region_info(). These patches are best viewed with the diff
option to ignore whitespace (-b) as most of the lines are re-indending
things.

Then drivers are updated to remove the duplicate cap related code. Some
drivers are converted to use vfio_info_add_capability() instead of open
coding a version of it.

This is on github: https://github.com/jgunthorpe/linux/commits/vfio_get_region_info_op

Jason Gunthorpe (22):
  vfio: Provide a get_region_info op
  vfio/hisi: Convert to the get_region_info op
  vfio/virtio: Convert to the get_region_info op
  vfio/nvgrace: Convert to the get_region_info op
  vfio/pci: Fill in the missing get_region_info ops
  vfio/mtty: Provide a get_region_info op
  vfio/mdpy: Provide a get_region_info op
  vfio/mbochs: Provide a get_region_info op
  vfio/platform: Provide a get_region_info op
  vfio/fsl: Provide a get_region_info op
  vfio/cdx: Provide a get_region_info op
  vfio/ccw: Provide a get_region_info op
  vfio/gvt: Provide a get_region_info op
  vfio: Require drivers to implement get_region_info
  vfio: Add get_region_info_caps op
  vfio/mbochs: Convert mbochs to use vfio_info_add_capability()
  vfio/gvt: Convert to get_region_info_caps
  vfio/ccw: Convert to get_region_info_caps
  vfio/pci: Convert all PCI drivers to get_region_info_caps
  vfio/platform: Convert to get_region_info_caps
  vfio: Move the remaining drivers to get_region_info_caps
  vfio: Remove the get_region_info op

 drivers/gpu/drm/i915/gvt/kvmgt.c              | 272 ++++++++----------
 drivers/s390/cio/vfio_ccw_ops.c               |  45 +--
 drivers/vfio/cdx/main.c                       |  29 +-
 drivers/vfio/fsl-mc/vfio_fsl_mc.c             |  43 ++-
 .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c    |  54 ++--
 drivers/vfio/pci/mlx5/main.c                  |   1 +
 drivers/vfio/pci/nvgrace-gpu/main.c           |  53 +---
 drivers/vfio/pci/pds/vfio_dev.c               |   1 +
 drivers/vfio/pci/qat/main.c                   |   1 +
 drivers/vfio/pci/vfio_pci.c                   |   1 +
 drivers/vfio/pci/vfio_pci_core.c              | 110 +++----
 drivers/vfio/pci/virtio/common.h              |   5 +-
 drivers/vfio/pci/virtio/legacy_io.c           |  38 +--
 drivers/vfio/pci/virtio/main.c                |   5 +-
 drivers/vfio/platform/vfio_amba.c             |   1 +
 drivers/vfio/platform/vfio_platform.c         |   1 +
 drivers/vfio/platform/vfio_platform_common.c  |  40 ++-
 drivers/vfio/platform/vfio_platform_private.h |   3 +
 drivers/vfio/vfio_main.c                      |  45 +++
 include/linux/vfio.h                          |   4 +
 include/linux/vfio_pci_core.h                 |   3 +
 samples/vfio-mdev/mbochs.c                    |  71 ++---
 samples/vfio-mdev/mdpy.c                      |  34 +--
 samples/vfio-mdev/mtty.c                      |  33 +--
 24 files changed, 363 insertions(+), 530 deletions(-)


base-commit: 211ddde0823f1442e4ad052a2f30f050145ccada
-- 
2.43.0


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH 01/22] vfio: Provide a get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  5:57   ` Pranjal Shrivastava
  2025-11-03 14:17   ` Eric Auger
  2025-10-23 23:09 ` [PATCH 02/22] vfio/hisi: Convert to the " Jason Gunthorpe
                   ` (23 subsequent siblings)
  24 siblings, 2 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

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.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 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);
 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,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 02/22] vfio/hisi: Convert to the get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
  2025-10-23 23:09 ` [PATCH 01/22] vfio: Provide a get_region_info op Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-10-28  1:55   ` liulongfang
  2025-11-03  6:06   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 03/22] vfio/virtio: " Jason Gunthorpe
                   ` (22 subsequent siblings)
  24 siblings, 2 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Change the function signature of hisi_acc_vfio_pci_ioctl()
and re-indent it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c    | 57 +++++++++----------
 1 file changed, 27 insertions(+), 30 deletions(-)

diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
index fde33f54e99ec5..f06dcfcf09599f 100644
--- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
+++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
@@ -1324,43 +1324,39 @@ static ssize_t hisi_acc_vfio_pci_read(struct vfio_device *core_vdev,
 	return vfio_pci_core_read(core_vdev, buf, new_count, ppos);
 }
 
-static long hisi_acc_vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
-				    unsigned long arg)
+static int hisi_acc_vfio_get_region(struct vfio_device *core_vdev,
+				    struct vfio_region_info __user *arg)
 {
-	if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
-		struct vfio_pci_core_device *vdev =
-			container_of(core_vdev, struct vfio_pci_core_device, vdev);
-		struct pci_dev *pdev = vdev->pdev;
-		struct vfio_region_info info;
-		unsigned long minsz;
+	struct vfio_pci_core_device *vdev =
+		container_of(core_vdev, struct vfio_pci_core_device, vdev);
+	struct pci_dev *pdev = vdev->pdev;
+	struct vfio_region_info info;
+	unsigned long minsz;
 
-		minsz = offsetofend(struct vfio_region_info, offset);
+	minsz = offsetofend(struct vfio_region_info, offset);
 
-		if (copy_from_user(&info, (void __user *)arg, minsz))
-			return -EFAULT;
+	if (copy_from_user(&info, arg, minsz))
+		return -EFAULT;
 
-		if (info.argsz < minsz)
-			return -EINVAL;
+	if (info.argsz < minsz)
+		return -EINVAL;
 
-		if (info.index == VFIO_PCI_BAR2_REGION_INDEX) {
-			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
+	if (info.index != VFIO_PCI_BAR2_REGION_INDEX)
+		return vfio_pci_ioctl_get_region_info(core_vdev, arg);
 
-			/*
-			 * ACC VF dev BAR2 region consists of both functional
-			 * register space and migration control register space.
-			 * Report only the functional region to Guest.
-			 */
-			info.size = pci_resource_len(pdev, info.index) / 2;
+	info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
 
-			info.flags = VFIO_REGION_INFO_FLAG_READ |
-					VFIO_REGION_INFO_FLAG_WRITE |
-					VFIO_REGION_INFO_FLAG_MMAP;
+	/*
+	 * ACC VF dev BAR2 region consists of both functional
+	 * register space and migration control register space.
+	 * Report only the functional region to Guest.
+	 */
+	info.size = pci_resource_len(pdev, info.index) / 2;
 
-			return copy_to_user((void __user *)arg, &info, minsz) ?
-					    -EFAULT : 0;
-		}
-	}
-	return vfio_pci_core_ioctl(core_vdev, cmd, arg);
+	info.flags = VFIO_REGION_INFO_FLAG_READ | VFIO_REGION_INFO_FLAG_WRITE |
+		     VFIO_REGION_INFO_FLAG_MMAP;
+
+	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
 }
 
 static int hisi_acc_vf_debug_check(struct seq_file *seq, struct vfio_device *vdev)
@@ -1557,7 +1553,8 @@ static const struct vfio_device_ops hisi_acc_vfio_pci_migrn_ops = {
 	.release = vfio_pci_core_release_dev,
 	.open_device = hisi_acc_vfio_pci_open_device,
 	.close_device = hisi_acc_vfio_pci_close_device,
-	.ioctl = hisi_acc_vfio_pci_ioctl,
+	.ioctl = vfio_pci_core_ioctl,
+	.get_region_info = hisi_acc_vfio_get_region,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = hisi_acc_vfio_pci_read,
 	.write = hisi_acc_vfio_pci_write,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 03/22] vfio/virtio: Convert to the get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
  2025-10-23 23:09 ` [PATCH 01/22] vfio: Provide a get_region_info op Jason Gunthorpe
  2025-10-23 23:09 ` [PATCH 02/22] vfio/hisi: Convert to the " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  6:21   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 04/22] vfio/nvgrace: " Jason Gunthorpe
                   ` (21 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Remove virtiovf_vfio_pci_core_ioctl() and change the signature of
virtiovf_pci_ioctl_get_region_info().

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/pci/virtio/common.h    |  4 +---
 drivers/vfio/pci/virtio/legacy_io.c | 20 ++++----------------
 drivers/vfio/pci/virtio/main.c      |  3 ++-
 3 files changed, 7 insertions(+), 20 deletions(-)

diff --git a/drivers/vfio/pci/virtio/common.h b/drivers/vfio/pci/virtio/common.h
index c7d7e27af386e9..a10f2d92cb6238 100644
--- a/drivers/vfio/pci/virtio/common.h
+++ b/drivers/vfio/pci/virtio/common.h
@@ -109,10 +109,8 @@ void virtiovf_migration_reset_done(struct pci_dev *pdev);
 
 #ifdef CONFIG_VIRTIO_VFIO_PCI_ADMIN_LEGACY
 int virtiovf_open_legacy_io(struct virtiovf_pci_core_device *virtvdev);
-long virtiovf_vfio_pci_core_ioctl(struct vfio_device *core_vdev,
-				  unsigned int cmd, unsigned long arg);
 int virtiovf_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
-				       unsigned int cmd, unsigned long arg);
+				       struct vfio_region_info __user *arg);
 ssize_t virtiovf_pci_core_write(struct vfio_device *core_vdev,
 				const char __user *buf, size_t count,
 				loff_t *ppos);
diff --git a/drivers/vfio/pci/virtio/legacy_io.c b/drivers/vfio/pci/virtio/legacy_io.c
index 832af5ba267c49..d735d5c4bd7775 100644
--- a/drivers/vfio/pci/virtio/legacy_io.c
+++ b/drivers/vfio/pci/virtio/legacy_io.c
@@ -281,15 +281,14 @@ ssize_t virtiovf_pci_core_write(struct vfio_device *core_vdev, const char __user
 }
 
 int virtiovf_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
-				       unsigned int cmd, unsigned long arg)
+				       struct vfio_region_info __user *arg)
 {
 	struct virtiovf_pci_core_device *virtvdev = container_of(
 		core_vdev, struct virtiovf_pci_core_device, core_device.vdev);
 	unsigned long minsz = offsetofend(struct vfio_region_info, offset);
-	void __user *uarg = (void __user *)arg;
 	struct vfio_region_info info = {};
 
-	if (copy_from_user(&info, uarg, minsz))
+	if (copy_from_user(&info, arg, minsz))
 		return -EFAULT;
 
 	if (info.argsz < minsz)
@@ -301,20 +300,9 @@ int virtiovf_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
 		info.size = virtvdev->bar0_virtual_buf_size;
 		info.flags = VFIO_REGION_INFO_FLAG_READ |
 			     VFIO_REGION_INFO_FLAG_WRITE;
-		return copy_to_user(uarg, &info, minsz) ? -EFAULT : 0;
+		return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
 	default:
-		return vfio_pci_core_ioctl(core_vdev, cmd, arg);
-	}
-}
-
-long virtiovf_vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
-				  unsigned long arg)
-{
-	switch (cmd) {
-	case VFIO_DEVICE_GET_REGION_INFO:
-		return virtiovf_pci_ioctl_get_region_info(core_vdev, cmd, arg);
-	default:
-		return vfio_pci_core_ioctl(core_vdev, cmd, arg);
+		return vfio_pci_ioctl_get_region_info(core_vdev, arg);
 	}
 }
 
diff --git a/drivers/vfio/pci/virtio/main.c b/drivers/vfio/pci/virtio/main.c
index 8084f3e36a9f70..92b525e52abe4d 100644
--- a/drivers/vfio/pci/virtio/main.c
+++ b/drivers/vfio/pci/virtio/main.c
@@ -108,7 +108,8 @@ static const struct vfio_device_ops virtiovf_vfio_pci_tran_lm_ops = {
 	.release = virtiovf_pci_core_release_dev,
 	.open_device = virtiovf_pci_open_device,
 	.close_device = virtiovf_pci_close_device,
-	.ioctl = virtiovf_vfio_pci_core_ioctl,
+	.ioctl = vfio_pci_core_ioctl,
+	.get_region_info = virtiovf_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = virtiovf_pci_core_read,
 	.write = virtiovf_pci_core_write,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 04/22] vfio/nvgrace: Convert to the get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (2 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 03/22] vfio/virtio: " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  6:41   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 05/22] vfio/pci: Fill in the missing get_region_info ops Jason Gunthorpe
                   ` (20 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Change the signature of nvgrace_gpu_ioctl_get_region_info()

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/pci/nvgrace-gpu/main.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c b/drivers/vfio/pci/nvgrace-gpu/main.c
index e346392b72f6ab..d3a5253473e002 100644
--- a/drivers/vfio/pci/nvgrace-gpu/main.c
+++ b/drivers/vfio/pci/nvgrace-gpu/main.c
@@ -205,9 +205,9 @@ static int nvgrace_gpu_mmap(struct vfio_device *core_vdev,
 	return 0;
 }
 
-static long
+static int
 nvgrace_gpu_ioctl_get_region_info(struct vfio_device *core_vdev,
-				  unsigned long arg)
+				  struct vfio_region_info __user *arg)
 {
 	struct nvgrace_gpu_pci_core_device *nvdev =
 		container_of(core_vdev, struct nvgrace_gpu_pci_core_device,
@@ -220,7 +220,7 @@ nvgrace_gpu_ioctl_get_region_info(struct vfio_device *core_vdev,
 	u32 size;
 	int ret;
 
-	if (copy_from_user(&info, (void __user *)arg, minsz))
+	if (copy_from_user(&info, arg, minsz))
 		return -EFAULT;
 
 	if (info.argsz < minsz)
@@ -232,8 +232,7 @@ nvgrace_gpu_ioctl_get_region_info(struct vfio_device *core_vdev,
 	 */
 	memregion = nvgrace_gpu_memregion(info.index, nvdev);
 	if (!memregion)
-		return vfio_pci_core_ioctl(core_vdev,
-					   VFIO_DEVICE_GET_REGION_INFO, arg);
+		return vfio_pci_ioctl_get_region_info(core_vdev, arg);
 
 	size = struct_size(sparse, areas, 1);
 
@@ -285,16 +284,13 @@ nvgrace_gpu_ioctl_get_region_info(struct vfio_device *core_vdev,
 		}
 		kfree(caps.buf);
 	}
-	return copy_to_user((void __user *)arg, &info, minsz) ?
-			    -EFAULT : 0;
+	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
 }
 
 static long nvgrace_gpu_ioctl(struct vfio_device *core_vdev,
 			      unsigned int cmd, unsigned long arg)
 {
 	switch (cmd) {
-	case VFIO_DEVICE_GET_REGION_INFO:
-		return nvgrace_gpu_ioctl_get_region_info(core_vdev, arg);
 	case VFIO_DEVICE_IOEVENTFD:
 		return -ENOTTY;
 	case VFIO_DEVICE_RESET:
@@ -690,6 +686,7 @@ static const struct vfio_device_ops nvgrace_gpu_pci_ops = {
 	.open_device	= nvgrace_gpu_open_device,
 	.close_device	= nvgrace_gpu_close_device,
 	.ioctl		= nvgrace_gpu_ioctl,
+	.get_region_info = nvgrace_gpu_ioctl_get_region_info,
 	.device_feature	= vfio_pci_core_ioctl_feature,
 	.read		= nvgrace_gpu_read,
 	.write		= nvgrace_gpu_write,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 05/22] vfio/pci: Fill in the missing get_region_info ops
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (3 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 04/22] vfio/nvgrace: " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  6:43   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 06/22] vfio/mtty: Provide a get_region_info op Jason Gunthorpe
                   ` (19 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Now that every variant driver provides a get_region_info op remove the
ioctl based dispatch from vfio_pci_core_ioctl().

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 1 +
 drivers/vfio/pci/mlx5/main.c                   | 1 +
 drivers/vfio/pci/nvgrace-gpu/main.c            | 1 +
 drivers/vfio/pci/pds/vfio_dev.c                | 1 +
 drivers/vfio/pci/qat/main.c                    | 1 +
 drivers/vfio/pci/vfio_pci.c                    | 1 +
 drivers/vfio/pci/vfio_pci_core.c               | 2 --
 drivers/vfio/pci/virtio/main.c                 | 2 ++
 8 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
index f06dcfcf09599f..99e67e3dda3498 100644
--- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
+++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
@@ -1574,6 +1574,7 @@ static const struct vfio_device_ops hisi_acc_vfio_pci_ops = {
 	.open_device = hisi_acc_vfio_pci_open_device,
 	.close_device = vfio_pci_core_close_device,
 	.ioctl = vfio_pci_core_ioctl,
+	.get_region_info = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c
index 7ec47e736a8e5a..b7f941f8047ea4 100644
--- a/drivers/vfio/pci/mlx5/main.c
+++ b/drivers/vfio/pci/mlx5/main.c
@@ -1366,6 +1366,7 @@ static const struct vfio_device_ops mlx5vf_pci_ops = {
 	.open_device = mlx5vf_pci_open_device,
 	.close_device = mlx5vf_pci_close_device,
 	.ioctl = vfio_pci_core_ioctl,
+	.get_region_info = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c b/drivers/vfio/pci/nvgrace-gpu/main.c
index d3a5253473e002..cab743a30dc35d 100644
--- a/drivers/vfio/pci/nvgrace-gpu/main.c
+++ b/drivers/vfio/pci/nvgrace-gpu/main.c
@@ -707,6 +707,7 @@ static const struct vfio_device_ops nvgrace_gpu_pci_core_ops = {
 	.open_device	= nvgrace_gpu_open_device,
 	.close_device	= vfio_pci_core_close_device,
 	.ioctl		= vfio_pci_core_ioctl,
+	.get_region_info = vfio_pci_ioctl_get_region_info,
 	.device_feature	= vfio_pci_core_ioctl_feature,
 	.read		= vfio_pci_core_read,
 	.write		= vfio_pci_core_write,
diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c
index f3ccb0008f6752..1946bc75d99b49 100644
--- a/drivers/vfio/pci/pds/vfio_dev.c
+++ b/drivers/vfio/pci/pds/vfio_dev.c
@@ -195,6 +195,7 @@ static const struct vfio_device_ops pds_vfio_ops = {
 	.open_device = pds_vfio_open_device,
 	.close_device = pds_vfio_close_device,
 	.ioctl = vfio_pci_core_ioctl,
+	.get_region_info = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
diff --git a/drivers/vfio/pci/qat/main.c b/drivers/vfio/pci/qat/main.c
index a19b68043eb2e7..8452d9c1d11d3a 100644
--- a/drivers/vfio/pci/qat/main.c
+++ b/drivers/vfio/pci/qat/main.c
@@ -609,6 +609,7 @@ static const struct vfio_device_ops qat_vf_pci_ops = {
 	.open_device = qat_vf_pci_open_device,
 	.close_device = qat_vf_pci_close_device,
 	.ioctl = vfio_pci_core_ioctl,
+	.get_region_info = vfio_pci_ioctl_get_region_info,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
 	.mmap = vfio_pci_core_mmap,
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index ac10f14417f2f3..2d9122efc10baa 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -132,6 +132,7 @@ static const struct vfio_device_ops vfio_pci_ops = {
 	.open_device	= vfio_pci_open_device,
 	.close_device	= vfio_pci_core_close_device,
 	.ioctl		= vfio_pci_core_ioctl,
+	.get_region_info = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read		= vfio_pci_core_read,
 	.write		= vfio_pci_core_write,
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 1dc350003f075c..f21d9026068c37 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1460,8 +1460,6 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
 		return vfio_pci_ioctl_get_irq_info(vdev, uarg);
 	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(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/pci/virtio/main.c b/drivers/vfio/pci/virtio/main.c
index 92b525e52abe4d..d68096bc525215 100644
--- a/drivers/vfio/pci/virtio/main.c
+++ b/drivers/vfio/pci/virtio/main.c
@@ -88,6 +88,7 @@ static const struct vfio_device_ops virtiovf_vfio_pci_lm_ops = {
 	.open_device = virtiovf_pci_open_device,
 	.close_device = virtiovf_pci_close_device,
 	.ioctl = vfio_pci_core_ioctl,
+	.get_region_info = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
@@ -131,6 +132,7 @@ static const struct vfio_device_ops virtiovf_vfio_pci_ops = {
 	.open_device = virtiovf_pci_open_device,
 	.close_device = vfio_pci_core_close_device,
 	.ioctl = vfio_pci_core_ioctl,
+	.get_region_info = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 06/22] vfio/mtty: Provide a get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (4 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 05/22] vfio/pci: Fill in the missing get_region_info ops Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  7:17   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 07/22] vfio/mdpy: " Jason Gunthorpe
                   ` (18 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Move it out of mtty_ioctl() and re-indent it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 samples/vfio-mdev/mtty.c | 53 ++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
index 59eefe2fed10ca..b27f9b93471bc5 100644
--- a/samples/vfio-mdev/mtty.c
+++ b/samples/vfio-mdev/mtty.c
@@ -1785,6 +1785,34 @@ static int mtty_get_device_info(struct vfio_device_info *dev_info)
 	return 0;
 }
 
+static int mtty_ioctl_get_region_info(struct vfio_device *vdev,
+				      struct vfio_region_info __user *arg)
+{
+	struct mdev_state *mdev_state =
+		container_of(vdev, struct mdev_state, vdev);
+	struct vfio_region_info info;
+	void *cap_type = NULL;
+	u16 cap_type_id = 0;
+	unsigned long minsz;
+	int ret;
+
+	minsz = offsetofend(struct vfio_region_info, offset);
+
+	if (copy_from_user(&info, arg, minsz))
+		return -EFAULT;
+
+	if (info.argsz < minsz)
+		return -EINVAL;
+
+	ret = mtty_get_region_info(mdev_state, &info, &cap_type_id, &cap_type);
+	if (ret)
+		return ret;
+
+	if (copy_to_user(arg, &info, minsz))
+		return -EFAULT;
+	return 0;
+}
+
 static long mtty_ioctl(struct vfio_device *vdev, unsigned int cmd,
 			unsigned long arg)
 {
@@ -1817,30 +1845,6 @@ static long mtty_ioctl(struct vfio_device *vdev, unsigned int cmd,
 
 		return 0;
 	}
-	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 = mtty_get_region_info(mdev_state, &info, &cap_type_id,
-					   &cap_type);
-		if (ret)
-			return ret;
-
-		if (copy_to_user((void __user *)arg, &info, minsz))
-			return -EFAULT;
-
-		return 0;
-	}
 
 	case VFIO_DEVICE_GET_IRQ_INFO:
 	{
@@ -1949,6 +1953,7 @@ static const struct vfio_device_ops mtty_dev_ops = {
 	.read = mtty_read,
 	.write = mtty_write,
 	.ioctl = mtty_ioctl,
+	.get_region_info = mtty_ioctl_get_region_info,
 	.bind_iommufd	= vfio_iommufd_emulated_bind,
 	.unbind_iommufd	= vfio_iommufd_emulated_unbind,
 	.attach_ioas	= vfio_iommufd_emulated_attach_ioas,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 07/22] vfio/mdpy: Provide a get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (5 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 06/22] vfio/mtty: Provide a get_region_info op Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  7:18   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 08/22] vfio/mbochs: " Jason Gunthorpe
                   ` (17 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Move it out of mdpy_ioctl() and re-indent it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 samples/vfio-mdev/mdpy.c | 53 ++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c
index 8104831ae125be..0c65ed22173862 100644
--- a/samples/vfio-mdev/mdpy.c
+++ b/samples/vfio-mdev/mdpy.c
@@ -512,6 +512,34 @@ static int mdpy_query_gfx_plane(struct mdev_state *mdev_state,
 	return 0;
 }
 
+static int mdpy_ioctl_get_region_info(struct vfio_device *vdev,
+				      struct vfio_region_info __user *arg)
+{
+	struct mdev_state *mdev_state =
+		container_of(vdev, struct mdev_state, vdev);
+	struct vfio_region_info info;
+	void *cap_type = NULL;
+	u16 cap_type_id = 0;
+	unsigned long minsz;
+	int ret;
+
+	minsz = offsetofend(struct vfio_region_info, offset);
+
+	if (copy_from_user(&info, arg, minsz))
+		return -EFAULT;
+
+	if (info.argsz < minsz)
+		return -EINVAL;
+
+	ret = mdpy_get_region_info(mdev_state, &info, &cap_type_id, &cap_type);
+	if (ret)
+		return ret;
+
+	if (copy_to_user(arg, &info, minsz))
+		return -EFAULT;
+	return 0;
+}
+
 static long mdpy_ioctl(struct vfio_device *vdev, unsigned int cmd,
 		       unsigned long arg)
 {
@@ -544,30 +572,6 @@ static long mdpy_ioctl(struct vfio_device *vdev, unsigned int cmd,
 
 		return 0;
 	}
-	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 = mdpy_get_region_info(mdev_state, &info, &cap_type_id,
-					   &cap_type);
-		if (ret)
-			return ret;
-
-		if (copy_to_user((void __user *)arg, &info, minsz))
-			return -EFAULT;
-
-		return 0;
-	}
 
 	case VFIO_DEVICE_GET_IRQ_INFO:
 	{
@@ -665,6 +669,7 @@ static const struct vfio_device_ops mdpy_dev_ops = {
 	.read = mdpy_read,
 	.write = mdpy_write,
 	.ioctl = mdpy_ioctl,
+	.get_region_info = mdpy_ioctl_get_region_info,
 	.mmap = mdpy_mmap,
 	.bind_iommufd	= vfio_iommufd_emulated_bind,
 	.unbind_iommufd	= vfio_iommufd_emulated_unbind,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 08/22] vfio/mbochs: Provide a get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (6 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 07/22] vfio/mdpy: " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  7:19   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 09/22] vfio/platform: " Jason Gunthorpe
                   ` (16 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Move it out of mbochs_ioctl() and re-indent it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 samples/vfio-mdev/mbochs.c | 56 +++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 25 deletions(-)

diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c
index 18623ba666e33f..7f889b31fa2ce2 100644
--- a/samples/vfio-mdev/mbochs.c
+++ b/samples/vfio-mdev/mbochs.c
@@ -1185,13 +1185,42 @@ static int mbochs_get_gfx_dmabuf(struct mdev_state *mdev_state, u32 id)
 	return dma_buf_fd(dmabuf->buf, 0);
 }
 
+static int mbochs_ioctl_get_region_info(struct vfio_device *vdev,
+					struct vfio_region_info __user *arg)
+{
+	struct mdev_state *mdev_state =
+		container_of(vdev, struct mdev_state, vdev);
+	struct vfio_region_info_ext info;
+	unsigned long minsz, outsz;
+	int ret;
+
+	minsz = offsetofend(typeof(info), base.offset);
+
+	if (copy_from_user(&info, arg, minsz))
+		return -EFAULT;
+
+	outsz = info.base.argsz;
+	if (outsz < minsz)
+		return -EINVAL;
+	if (outsz > sizeof(info))
+		return -EINVAL;
+
+	ret = mbochs_get_region_info(mdev_state, &info);
+	if (ret)
+		return ret;
+
+	if (copy_to_user(arg, &info, outsz))
+		return -EFAULT;
+	return 0;
+}
+
 static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd,
 			 unsigned long arg)
 {
 	struct mdev_state *mdev_state =
 		container_of(vdev, struct mdev_state, vdev);
 	int ret = 0;
-	unsigned long minsz, outsz;
+	unsigned long minsz;
 
 	switch (cmd) {
 	case VFIO_DEVICE_GET_INFO:
@@ -1215,30 +1244,6 @@ static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd,
 
 		return 0;
 	}
-	case VFIO_DEVICE_GET_REGION_INFO:
-	{
-		struct vfio_region_info_ext info;
-
-		minsz = offsetofend(typeof(info), base.offset);
-
-		if (copy_from_user(&info, (void __user *)arg, minsz))
-			return -EFAULT;
-
-		outsz = info.base.argsz;
-		if (outsz < minsz)
-			return -EINVAL;
-		if (outsz > sizeof(info))
-			return -EINVAL;
-
-		ret = mbochs_get_region_info(mdev_state, &info);
-		if (ret)
-			return ret;
-
-		if (copy_to_user((void __user *)arg, &info, outsz))
-			return -EFAULT;
-
-		return 0;
-	}
 
 	case VFIO_DEVICE_GET_IRQ_INFO:
 	{
@@ -1376,6 +1381,7 @@ static const struct vfio_device_ops mbochs_dev_ops = {
 	.read = mbochs_read,
 	.write = mbochs_write,
 	.ioctl = mbochs_ioctl,
+	.get_region_info = mbochs_ioctl_get_region_info,
 	.mmap = mbochs_mmap,
 	.bind_iommufd	= vfio_iommufd_emulated_bind,
 	.unbind_iommufd	= vfio_iommufd_emulated_unbind,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 09/22] vfio/platform: Provide a get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (7 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 08/22] vfio/mbochs: " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  7:14   ` Pranjal Shrivastava
                     ` (2 more replies)
  2025-10-23 23:09 ` [PATCH 10/22] vfio/fsl: " Jason Gunthorpe
                   ` (15 subsequent siblings)
  24 siblings, 3 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Move it out of vfio_platform_ioctl() and re-indent it. Add it to all
platform drivers.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/platform/vfio_amba.c             |  1 +
 drivers/vfio/platform/vfio_platform.c         |  1 +
 drivers/vfio/platform/vfio_platform_common.c  | 50 +++++++++++--------
 drivers/vfio/platform/vfio_platform_private.h |  2 +
 4 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/drivers/vfio/platform/vfio_amba.c b/drivers/vfio/platform/vfio_amba.c
index 9f5c527baa8a36..d600deaf23b6d7 100644
--- a/drivers/vfio/platform/vfio_amba.c
+++ b/drivers/vfio/platform/vfio_amba.c
@@ -115,6 +115,7 @@ static const struct vfio_device_ops vfio_amba_ops = {
 	.open_device	= vfio_platform_open_device,
 	.close_device	= vfio_platform_close_device,
 	.ioctl		= vfio_platform_ioctl,
+	.get_region_info = vfio_platform_ioctl_get_region_info,
 	.read		= vfio_platform_read,
 	.write		= vfio_platform_write,
 	.mmap		= vfio_platform_mmap,
diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c
index 512533501eb7f3..0e85c914b65105 100644
--- a/drivers/vfio/platform/vfio_platform.c
+++ b/drivers/vfio/platform/vfio_platform.c
@@ -101,6 +101,7 @@ static const struct vfio_device_ops vfio_platform_ops = {
 	.open_device	= vfio_platform_open_device,
 	.close_device	= vfio_platform_close_device,
 	.ioctl		= vfio_platform_ioctl,
+	.get_region_info = vfio_platform_ioctl_get_region_info,
 	.read		= vfio_platform_read,
 	.write		= vfio_platform_write,
 	.mmap		= vfio_platform_mmap,
diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
index 3bf1043cd7957c..3ebd50fb78fbb7 100644
--- a/drivers/vfio/platform/vfio_platform_common.c
+++ b/drivers/vfio/platform/vfio_platform_common.c
@@ -272,6 +272,34 @@ int vfio_platform_open_device(struct vfio_device *core_vdev)
 }
 EXPORT_SYMBOL_GPL(vfio_platform_open_device);
 
+int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
+					struct vfio_region_info __user *arg)
+{
+	struct vfio_platform_device *vdev =
+		container_of(core_vdev, struct vfio_platform_device, vdev);
+	struct vfio_region_info info;
+	unsigned long minsz;
+
+	minsz = offsetofend(struct vfio_region_info, offset);
+
+	if (copy_from_user(&info, arg, minsz))
+		return -EFAULT;
+
+	if (info.argsz < minsz)
+		return -EINVAL;
+
+	if (info.index >= vdev->num_regions)
+		return -EINVAL;
+
+	/* map offset to the physical address  */
+	info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
+	info.size = vdev->regions[info.index].size;
+	info.flags = vdev->regions[info.index].flags;
+
+	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
+}
+EXPORT_SYMBOL_GPL(vfio_platform_ioctl_get_region_info);
+
 long vfio_platform_ioctl(struct vfio_device *core_vdev,
 			 unsigned int cmd, unsigned long arg)
 {
@@ -300,28 +328,6 @@ long vfio_platform_ioctl(struct vfio_device *core_vdev,
 		return copy_to_user((void __user *)arg, &info, minsz) ?
 			-EFAULT : 0;
 
-	} else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
-		struct vfio_region_info info;
-
-		minsz = offsetofend(struct vfio_region_info, offset);
-
-		if (copy_from_user(&info, (void __user *)arg, minsz))
-			return -EFAULT;
-
-		if (info.argsz < minsz)
-			return -EINVAL;
-
-		if (info.index >= vdev->num_regions)
-			return -EINVAL;
-
-		/* map offset to the physical address  */
-		info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
-		info.size = vdev->regions[info.index].size;
-		info.flags = vdev->regions[info.index].flags;
-
-		return copy_to_user((void __user *)arg, &info, minsz) ?
-			-EFAULT : 0;
-
 	} else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) {
 		struct vfio_irq_info info;
 
diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h
index 8d8fab51684909..a6008320e77bae 100644
--- a/drivers/vfio/platform/vfio_platform_private.h
+++ b/drivers/vfio/platform/vfio_platform_private.h
@@ -85,6 +85,8 @@ int vfio_platform_open_device(struct vfio_device *core_vdev);
 void vfio_platform_close_device(struct vfio_device *core_vdev);
 long vfio_platform_ioctl(struct vfio_device *core_vdev,
 			 unsigned int cmd, unsigned long arg);
+int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
+					struct vfio_region_info __user *arg);
 ssize_t vfio_platform_read(struct vfio_device *core_vdev,
 			   char __user *buf, size_t count,
 			   loff_t *ppos);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 10/22] vfio/fsl: Provide a get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (8 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 09/22] vfio/platform: " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  7:30   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 11/22] vfio/cdx: " Jason Gunthorpe
                   ` (14 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Move it out of vfio_fsl_mc_ioctl() and re-indent it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/fsl-mc/vfio_fsl_mc.c | 55 +++++++++++++++++--------------
 1 file changed, 31 insertions(+), 24 deletions(-)

diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
index 76ccbab0e3d642..438ea4da120e63 100644
--- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c
+++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
@@ -117,6 +117,36 @@ static void vfio_fsl_mc_close_device(struct vfio_device *core_vdev)
 	fsl_mc_cleanup_irq_pool(mc_cont);
 }
 
+static int vfio_fsl_mc_get_region_info(struct vfio_device *core_vdev,
+				       struct vfio_region_info __user *arg)
+{
+	struct vfio_fsl_mc_device *vdev =
+		container_of(core_vdev, struct vfio_fsl_mc_device, vdev);
+	struct fsl_mc_device *mc_dev = vdev->mc_dev;
+	struct vfio_region_info info;
+	unsigned long minsz;
+
+	minsz = offsetofend(struct vfio_region_info, offset);
+
+	if (copy_from_user(&info, arg, minsz))
+		return -EFAULT;
+
+	if (info.argsz < minsz)
+		return -EINVAL;
+
+	if (info.index >= mc_dev->obj_desc.region_count)
+		return -EINVAL;
+
+	/* map offset to the physical address  */
+	info.offset = VFIO_FSL_MC_INDEX_TO_OFFSET(info.index);
+	info.size = vdev->regions[info.index].size;
+	info.flags = vdev->regions[info.index].flags;
+
+	if (copy_to_user(arg, &info, minsz))
+		return -EFAULT;
+	return 0;
+}
+
 static long vfio_fsl_mc_ioctl(struct vfio_device *core_vdev,
 			      unsigned int cmd, unsigned long arg)
 {
@@ -149,30 +179,6 @@ static long vfio_fsl_mc_ioctl(struct vfio_device *core_vdev,
 		return copy_to_user((void __user *)arg, &info, minsz) ?
 			-EFAULT : 0;
 	}
-	case VFIO_DEVICE_GET_REGION_INFO:
-	{
-		struct vfio_region_info info;
-
-		minsz = offsetofend(struct vfio_region_info, offset);
-
-		if (copy_from_user(&info, (void __user *)arg, minsz))
-			return -EFAULT;
-
-		if (info.argsz < minsz)
-			return -EINVAL;
-
-		if (info.index >= mc_dev->obj_desc.region_count)
-			return -EINVAL;
-
-		/* map offset to the physical address  */
-		info.offset = VFIO_FSL_MC_INDEX_TO_OFFSET(info.index);
-		info.size = vdev->regions[info.index].size;
-		info.flags = vdev->regions[info.index].flags;
-
-		if (copy_to_user((void __user *)arg, &info, minsz))
-			return -EFAULT;
-		return 0;
-	}
 	case VFIO_DEVICE_GET_IRQ_INFO:
 	{
 		struct vfio_irq_info info;
@@ -589,6 +595,7 @@ static const struct vfio_device_ops vfio_fsl_mc_ops = {
 	.open_device	= vfio_fsl_mc_open_device,
 	.close_device	= vfio_fsl_mc_close_device,
 	.ioctl		= vfio_fsl_mc_ioctl,
+	.get_region_info = vfio_fsl_mc_get_region_info,
 	.read		= vfio_fsl_mc_read,
 	.write		= vfio_fsl_mc_write,
 	.mmap		= vfio_fsl_mc_mmap,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 11/22] vfio/cdx: Provide a get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (9 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 10/22] vfio/fsl: " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  7:31   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 12/22] vfio/ccw: " Jason Gunthorpe
                   ` (13 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Change the signature of vfio_cdx_ioctl_get_region_info() and hook it to
the op.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/cdx/main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/vfio/cdx/main.c b/drivers/vfio/cdx/main.c
index 5dd5f5ad768653..506d849139d35a 100644
--- a/drivers/vfio/cdx/main.c
+++ b/drivers/vfio/cdx/main.c
@@ -129,9 +129,11 @@ static int vfio_cdx_ioctl_get_info(struct vfio_cdx_device *vdev,
 	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
 }
 
-static int vfio_cdx_ioctl_get_region_info(struct vfio_cdx_device *vdev,
+static int vfio_cdx_ioctl_get_region_info(struct vfio_device *core_vdev,
 					  struct vfio_region_info __user *arg)
 {
+	struct vfio_cdx_device *vdev =
+		container_of(core_vdev, struct vfio_cdx_device, vdev);
 	unsigned long minsz = offsetofend(struct vfio_region_info, offset);
 	struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
 	struct vfio_region_info info;
@@ -219,8 +221,6 @@ static long vfio_cdx_ioctl(struct vfio_device *core_vdev,
 	switch (cmd) {
 	case VFIO_DEVICE_GET_INFO:
 		return vfio_cdx_ioctl_get_info(vdev, uarg);
-	case VFIO_DEVICE_GET_REGION_INFO:
-		return vfio_cdx_ioctl_get_region_info(vdev, uarg);
 	case VFIO_DEVICE_GET_IRQ_INFO:
 		return vfio_cdx_ioctl_get_irq_info(vdev, uarg);
 	case VFIO_DEVICE_SET_IRQS:
@@ -284,6 +284,7 @@ static const struct vfio_device_ops vfio_cdx_ops = {
 	.open_device	= vfio_cdx_open_device,
 	.close_device	= vfio_cdx_close_device,
 	.ioctl		= vfio_cdx_ioctl,
+	.get_region_info = vfio_cdx_ioctl_get_region_info,
 	.device_feature = vfio_cdx_ioctl_feature,
 	.mmap		= vfio_cdx_mmap,
 	.bind_iommufd	= vfio_iommufd_physical_bind,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 12/22] vfio/ccw: Provide a get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (10 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 11/22] vfio/cdx: " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-10-23 23:09 ` [PATCH 13/22] vfio/gvt: " Jason Gunthorpe
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Move it out of vfio_ccw_mdev_ioctl() and re-indent it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/s390/cio/vfio_ccw_ops.c | 44 +++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
index ea532a8a4a0c29..6d46e0bc76df15 100644
--- a/drivers/s390/cio/vfio_ccw_ops.c
+++ b/drivers/s390/cio/vfio_ccw_ops.c
@@ -504,6 +504,31 @@ void vfio_ccw_unregister_dev_regions(struct vfio_ccw_private *private)
 	private->region = NULL;
 }
 
+static int
+vfio_ccw_mdev_ioctl_get_region_info(struct vfio_device *vdev,
+				    struct vfio_region_info __user *arg)
+{
+	struct vfio_ccw_private *private =
+		container_of(vdev, struct vfio_ccw_private, vdev);
+	struct vfio_region_info info;
+	unsigned long minsz;
+	int ret;
+
+	minsz = offsetofend(struct vfio_region_info, offset);
+
+	if (copy_from_user(&info, arg, minsz))
+		return -EFAULT;
+
+	if (info.argsz < minsz)
+		return -EINVAL;
+
+	ret = vfio_ccw_mdev_get_region_info(private, &info, arg);
+	if (ret)
+		return ret;
+
+	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
+}
+
 static ssize_t vfio_ccw_mdev_ioctl(struct vfio_device *vdev,
 				   unsigned int cmd,
 				   unsigned long arg)
@@ -532,24 +557,6 @@ static ssize_t vfio_ccw_mdev_ioctl(struct vfio_device *vdev,
 
 		return copy_to_user((void __user *)arg, &info, minsz) ? -EFAULT : 0;
 	}
-	case VFIO_DEVICE_GET_REGION_INFO:
-	{
-		struct vfio_region_info info;
-
-		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(private, &info, arg);
-		if (ret)
-			return ret;
-
-		return copy_to_user((void __user *)arg, &info, minsz) ? -EFAULT : 0;
-	}
 	case VFIO_DEVICE_GET_IRQ_INFO:
 	{
 		struct vfio_irq_info info;
@@ -627,6 +634,7 @@ static const struct vfio_device_ops vfio_ccw_dev_ops = {
 	.read = vfio_ccw_mdev_read,
 	.write = vfio_ccw_mdev_write,
 	.ioctl = vfio_ccw_mdev_ioctl,
+	.get_region_info = vfio_ccw_mdev_ioctl_get_region_info,
 	.request = vfio_ccw_mdev_request,
 	.dma_unmap = vfio_ccw_dma_unmap,
 	.bind_iommufd = vfio_iommufd_emulated_bind,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 13/22] vfio/gvt: Provide a get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (11 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 12/22] vfio/ccw: " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-10-24 10:12   ` Jani Nikula
  2025-10-23 23:09 ` [PATCH 14/22] vfio: Require drivers to implement get_region_info Jason Gunthorpe
                   ` (11 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Move it out of intel_vgpu_ioctl() and re-indent it.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/gpu/drm/i915/gvt/kvmgt.c | 301 +++++++++++++++----------------
 1 file changed, 150 insertions(+), 151 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index 69830a5c49d3fd..6b47e33078eb52 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -1140,6 +1140,155 @@ static int intel_vgpu_set_irqs(struct intel_vgpu *vgpu, u32 flags,
 	return func(vgpu, index, start, count, flags, data);
 }
 
+static int intel_vgpu_get_region_info(struct vfio_device *vfio_dev,
+				      struct vfio_region_info __user *arg)
+{
+	struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
+	struct vfio_region_info_cap_sparse_mmap *sparse = NULL;
+	struct intel_vgpu *vgpu = vfio_dev_to_vgpu(vfio_dev);
+	struct vfio_region_info info;
+	unsigned long minsz;
+	int nr_areas = 1;
+	int cap_type_id;
+	unsigned int i;
+	int ret;
+
+	minsz = offsetofend(struct vfio_region_info, offset);
+
+	if (copy_from_user(&info, arg, minsz))
+		return -EFAULT;
+
+	if (info.argsz < minsz)
+		return -EINVAL;
+
+	switch (info.index) {
+	case VFIO_PCI_CONFIG_REGION_INDEX:
+		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
+		info.size = vgpu->gvt->device_info.cfg_space_size;
+		info.flags = VFIO_REGION_INFO_FLAG_READ |
+			     VFIO_REGION_INFO_FLAG_WRITE;
+		break;
+	case VFIO_PCI_BAR0_REGION_INDEX:
+		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
+		info.size = vgpu->cfg_space.bar[info.index].size;
+		if (!info.size) {
+			info.flags = 0;
+			break;
+		}
+
+		info.flags = VFIO_REGION_INFO_FLAG_READ |
+			     VFIO_REGION_INFO_FLAG_WRITE;
+		break;
+	case VFIO_PCI_BAR1_REGION_INDEX:
+		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
+		info.size = 0;
+		info.flags = 0;
+		break;
+	case VFIO_PCI_BAR2_REGION_INDEX:
+		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
+		info.flags = VFIO_REGION_INFO_FLAG_CAPS |
+			     VFIO_REGION_INFO_FLAG_MMAP |
+			     VFIO_REGION_INFO_FLAG_READ |
+			     VFIO_REGION_INFO_FLAG_WRITE;
+		info.size = gvt_aperture_sz(vgpu->gvt);
+
+		sparse = kzalloc(struct_size(sparse, areas, nr_areas),
+				 GFP_KERNEL);
+		if (!sparse)
+			return -ENOMEM;
+
+		sparse->header.id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
+		sparse->header.version = 1;
+		sparse->nr_areas = nr_areas;
+		cap_type_id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
+		sparse->areas[0].offset =
+			PAGE_ALIGN(vgpu_aperture_offset(vgpu));
+		sparse->areas[0].size = vgpu_aperture_sz(vgpu);
+		break;
+
+	case VFIO_PCI_BAR3_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
+		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
+		info.size = 0;
+		info.flags = 0;
+
+		gvt_dbg_core("get region info bar:%d\n", info.index);
+		break;
+
+	case VFIO_PCI_ROM_REGION_INDEX:
+	case VFIO_PCI_VGA_REGION_INDEX:
+		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
+		info.size = 0;
+		info.flags = 0;
+
+		gvt_dbg_core("get region info index:%d\n", info.index);
+		break;
+	default: {
+		struct vfio_region_info_cap_type cap_type = {
+			.header.id = VFIO_REGION_INFO_CAP_TYPE,
+			.header.version = 1
+		};
+
+		if (info.index >= VFIO_PCI_NUM_REGIONS + vgpu->num_regions)
+			return -EINVAL;
+		info.index = array_index_nospec(
+			info.index, VFIO_PCI_NUM_REGIONS + vgpu->num_regions);
+
+		i = info.index - VFIO_PCI_NUM_REGIONS;
+
+		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
+		info.size = vgpu->region[i].size;
+		info.flags = vgpu->region[i].flags;
+
+		cap_type.type = vgpu->region[i].type;
+		cap_type.subtype = vgpu->region[i].subtype;
+
+		ret = vfio_info_add_capability(&caps, &cap_type.header,
+					       sizeof(cap_type));
+		if (ret)
+			return ret;
+	}
+	}
+
+	if ((info.flags & VFIO_REGION_INFO_FLAG_CAPS) && sparse) {
+		switch (cap_type_id) {
+		case VFIO_REGION_INFO_CAP_SPARSE_MMAP:
+			ret = vfio_info_add_capability(
+				&caps, &sparse->header,
+				struct_size(sparse, areas, sparse->nr_areas));
+			if (ret) {
+				kfree(sparse);
+				return ret;
+			}
+			break;
+		default:
+			kfree(sparse);
+			return -EINVAL;
+		}
+	}
+
+	if (caps.size) {
+		info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
+		if (info.argsz < sizeof(info) + caps.size) {
+			info.argsz = sizeof(info) + caps.size;
+			info.cap_offset = 0;
+		} else {
+			vfio_info_cap_shift(&caps, sizeof(info));
+			if (copy_to_user((void __user *)arg + sizeof(info),
+					 caps.buf, caps.size)) {
+				kfree(caps.buf);
+				kfree(sparse);
+				return -EFAULT;
+			}
+			info.cap_offset = sizeof(info);
+		}
+
+		kfree(caps.buf);
+	}
+
+	kfree(sparse);
+	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
+}
+
 static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,
 			     unsigned long arg)
 {
@@ -1168,157 +1317,6 @@ static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,
 		return copy_to_user((void __user *)arg, &info, minsz) ?
 			-EFAULT : 0;
 
-	} else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
-		struct vfio_region_info info;
-		struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
-		unsigned int i;
-		int ret;
-		struct vfio_region_info_cap_sparse_mmap *sparse = NULL;
-		int nr_areas = 1;
-		int cap_type_id;
-
-		minsz = offsetofend(struct vfio_region_info, offset);
-
-		if (copy_from_user(&info, (void __user *)arg, minsz))
-			return -EFAULT;
-
-		if (info.argsz < minsz)
-			return -EINVAL;
-
-		switch (info.index) {
-		case VFIO_PCI_CONFIG_REGION_INDEX:
-			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-			info.size = vgpu->gvt->device_info.cfg_space_size;
-			info.flags = VFIO_REGION_INFO_FLAG_READ |
-				     VFIO_REGION_INFO_FLAG_WRITE;
-			break;
-		case VFIO_PCI_BAR0_REGION_INDEX:
-			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-			info.size = vgpu->cfg_space.bar[info.index].size;
-			if (!info.size) {
-				info.flags = 0;
-				break;
-			}
-
-			info.flags = VFIO_REGION_INFO_FLAG_READ |
-				     VFIO_REGION_INFO_FLAG_WRITE;
-			break;
-		case VFIO_PCI_BAR1_REGION_INDEX:
-			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-			info.size = 0;
-			info.flags = 0;
-			break;
-		case VFIO_PCI_BAR2_REGION_INDEX:
-			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-			info.flags = VFIO_REGION_INFO_FLAG_CAPS |
-					VFIO_REGION_INFO_FLAG_MMAP |
-					VFIO_REGION_INFO_FLAG_READ |
-					VFIO_REGION_INFO_FLAG_WRITE;
-			info.size = gvt_aperture_sz(vgpu->gvt);
-
-			sparse = kzalloc(struct_size(sparse, areas, nr_areas),
-					 GFP_KERNEL);
-			if (!sparse)
-				return -ENOMEM;
-
-			sparse->header.id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
-			sparse->header.version = 1;
-			sparse->nr_areas = nr_areas;
-			cap_type_id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
-			sparse->areas[0].offset =
-					PAGE_ALIGN(vgpu_aperture_offset(vgpu));
-			sparse->areas[0].size = vgpu_aperture_sz(vgpu);
-			break;
-
-		case VFIO_PCI_BAR3_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
-			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-			info.size = 0;
-			info.flags = 0;
-
-			gvt_dbg_core("get region info bar:%d\n", info.index);
-			break;
-
-		case VFIO_PCI_ROM_REGION_INDEX:
-		case VFIO_PCI_VGA_REGION_INDEX:
-			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-			info.size = 0;
-			info.flags = 0;
-
-			gvt_dbg_core("get region info index:%d\n", info.index);
-			break;
-		default:
-			{
-				struct vfio_region_info_cap_type cap_type = {
-					.header.id = VFIO_REGION_INFO_CAP_TYPE,
-					.header.version = 1 };
-
-				if (info.index >= VFIO_PCI_NUM_REGIONS +
-						vgpu->num_regions)
-					return -EINVAL;
-				info.index =
-					array_index_nospec(info.index,
-							VFIO_PCI_NUM_REGIONS +
-							vgpu->num_regions);
-
-				i = info.index - VFIO_PCI_NUM_REGIONS;
-
-				info.offset =
-					VFIO_PCI_INDEX_TO_OFFSET(info.index);
-				info.size = vgpu->region[i].size;
-				info.flags = vgpu->region[i].flags;
-
-				cap_type.type = vgpu->region[i].type;
-				cap_type.subtype = vgpu->region[i].subtype;
-
-				ret = vfio_info_add_capability(&caps,
-							&cap_type.header,
-							sizeof(cap_type));
-				if (ret)
-					return ret;
-			}
-		}
-
-		if ((info.flags & VFIO_REGION_INFO_FLAG_CAPS) && sparse) {
-			switch (cap_type_id) {
-			case VFIO_REGION_INFO_CAP_SPARSE_MMAP:
-				ret = vfio_info_add_capability(&caps,
-					&sparse->header,
-					struct_size(sparse, areas,
-						    sparse->nr_areas));
-				if (ret) {
-					kfree(sparse);
-					return ret;
-				}
-				break;
-			default:
-				kfree(sparse);
-				return -EINVAL;
-			}
-		}
-
-		if (caps.size) {
-			info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
-			if (info.argsz < sizeof(info) + caps.size) {
-				info.argsz = sizeof(info) + caps.size;
-				info.cap_offset = 0;
-			} else {
-				vfio_info_cap_shift(&caps, sizeof(info));
-				if (copy_to_user((void __user *)arg +
-						  sizeof(info), caps.buf,
-						  caps.size)) {
-					kfree(caps.buf);
-					kfree(sparse);
-					return -EFAULT;
-				}
-				info.cap_offset = sizeof(info);
-			}
-
-			kfree(caps.buf);
-		}
-
-		kfree(sparse);
-		return copy_to_user((void __user *)arg, &info, minsz) ?
-			-EFAULT : 0;
 	} else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) {
 		struct vfio_irq_info info;
 
@@ -1475,6 +1473,7 @@ static const struct vfio_device_ops intel_vgpu_dev_ops = {
 	.write		= intel_vgpu_write,
 	.mmap		= intel_vgpu_mmap,
 	.ioctl		= intel_vgpu_ioctl,
+	.get_region_info = intel_vgpu_get_region_info,
 	.dma_unmap	= intel_vgpu_dma_unmap,
 	.bind_iommufd	= vfio_iommufd_emulated_bind,
 	.unbind_iommufd = vfio_iommufd_emulated_unbind,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 14/22] vfio: Require drivers to implement get_region_info
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (12 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 13/22] vfio/gvt: " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  7:39   ` Pranjal Shrivastava
  2025-11-03  9:55   ` Mostafa Saleh
  2025-10-23 23:09 ` [PATCH 15/22] vfio: Add get_region_info_caps op Jason Gunthorpe
                   ` (10 subsequent siblings)
  24 siblings, 2 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Remove the fallback through the ioctl callback, no drivers use this now.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/vfio_main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index a390163ce706c4..f056e82ba35075 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -1297,13 +1297,13 @@ static long vfio_device_fops_unl_ioctl(struct file *filep,
 		break;
 
 	case VFIO_DEVICE_GET_REGION_INFO:
-		if (!device->ops->get_region_info)
-			goto ioctl_fallback;
-		ret = device->ops->get_region_info(device, uptr);
+		if (unlikely(!device->ops->get_region_info))
+			ret = -EINVAL;
+		else
+			ret = device->ops->get_region_info(device, uptr);
 		break;
 
 	default:
-ioctl_fallback:
 		if (unlikely(!device->ops->ioctl))
 			ret = -EINVAL;
 		else
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 15/22] vfio: Add get_region_info_caps op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (13 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 14/22] vfio: Require drivers to implement get_region_info Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03 10:16   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 16/22] vfio/mbochs: Convert mbochs to use vfio_info_add_capability() Jason Gunthorpe
                   ` (9 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

This op does the copy to/from user for the info and can return back
a cap chain through a vfio_info_cap * result.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/vfio_main.c | 54 +++++++++++++++++++++++++++++++++++++---
 include/linux/vfio.h     |  4 +++
 2 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index f056e82ba35075..82e7d79b1f9fe2 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -1259,6 +1259,55 @@ static int vfio_ioctl_device_feature(struct vfio_device *device,
 	}
 }
 
+static long vfio_get_region_info(struct vfio_device *device,
+				 struct vfio_region_info __user *arg)
+{
+	unsigned long minsz = offsetofend(struct vfio_region_info, offset);
+	struct vfio_region_info info = {};
+	int ret;
+
+	if (copy_from_user(&info, arg, minsz))
+		return -EFAULT;
+	if (info.argsz < minsz)
+		return -EINVAL;
+
+	if (device->ops->get_region_info_caps) {
+		struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
+
+		ret = device->ops->get_region_info_caps(device, &info, &caps);
+		if (ret)
+			return ret;
+
+		if (caps.size) {
+			info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
+			if (info.argsz < sizeof(info) + caps.size) {
+				info.argsz = sizeof(info) + caps.size;
+				info.cap_offset = 0;
+			} else {
+				vfio_info_cap_shift(&caps, sizeof(info));
+				if (copy_to_user(arg + 1, caps.buf,
+						 caps.size)) {
+					kfree(caps.buf);
+					return -EFAULT;
+				}
+				info.cap_offset = sizeof(info);
+			}
+			kfree(caps.buf);
+		}
+
+		if (copy_to_user(arg, &info, minsz))
+			return -EFAULT;
+	} else if (device->ops->get_region_info) {
+		ret = device->ops->get_region_info(device, arg);
+		if (ret)
+			return ret;
+	} else {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static long vfio_device_fops_unl_ioctl(struct file *filep,
 				       unsigned int cmd, unsigned long arg)
 {
@@ -1297,10 +1346,7 @@ static long vfio_device_fops_unl_ioctl(struct file *filep,
 		break;
 
 	case VFIO_DEVICE_GET_REGION_INFO:
-		if (unlikely(!device->ops->get_region_info))
-			ret = -EINVAL;
-		else
-			ret = device->ops->get_region_info(device, uptr);
+		ret = vfio_get_region_info(device, uptr);
 		break;
 
 	default:
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index be5fcf8432e8d5..6311ddc837701d 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -21,6 +21,7 @@ struct kvm;
 struct iommufd_ctx;
 struct iommufd_device;
 struct iommufd_access;
+struct vfio_info_cap;
 
 /*
  * VFIO devices can be placed in a set, this allows all devices to share this
@@ -134,6 +135,9 @@ struct vfio_device_ops {
 			 unsigned long arg);
 	int	(*get_region_info)(struct vfio_device *vdev,
 				   struct vfio_region_info __user *arg);
+	int	(*get_region_info_caps)(struct vfio_device *vdev,
+					struct vfio_region_info *info,
+					struct vfio_info_cap *caps);
 	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);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 16/22] vfio/mbochs: Convert mbochs to use vfio_info_add_capability()
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (14 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 15/22] vfio: Add get_region_info_caps op Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-10-23 23:09 ` [PATCH 17/22] vfio/gvt: Convert to get_region_info_caps Jason Gunthorpe
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

This driver open codes the cap chain manipulations. Instead use
vfio_info_add_capability() and the get_region_info_caps() op.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 samples/vfio-mdev/mbochs.c | 75 ++++++++++++--------------------------
 1 file changed, 23 insertions(+), 52 deletions(-)

diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c
index 7f889b31fa2ce2..a4228a67014c2a 100644
--- a/samples/vfio-mdev/mbochs.c
+++ b/samples/vfio-mdev/mbochs.c
@@ -143,11 +143,6 @@ static struct mdev_parent mbochs_parent;
 static atomic_t mbochs_avail_mbytes;
 static const struct vfio_device_ops mbochs_dev_ops;
 
-struct vfio_region_info_ext {
-	struct vfio_region_info          base;
-	struct vfio_region_info_cap_type type;
-};
-
 struct mbochs_mode {
 	u32 drm_format;
 	u32 bytepp;
@@ -1033,10 +1028,12 @@ static int mbochs_dmabuf_export(struct mbochs_dmabuf *dmabuf)
 	return 0;
 }
 
-static int mbochs_get_region_info(struct mdev_state *mdev_state,
-				  struct vfio_region_info_ext *ext)
+static int mbochs_get_region_info(struct vfio_device *vdev,
+				  struct vfio_region_info *region_info,
+				  struct vfio_info_cap *caps)
 {
-	struct vfio_region_info *region_info = &ext->base;
+	struct mdev_state *mdev_state =
+		container_of(vdev, struct mdev_state, vdev);
 
 	if (region_info->index >= MBOCHS_NUM_REGIONS)
 		return -EINVAL;
@@ -1061,20 +1058,23 @@ static int mbochs_get_region_info(struct mdev_state *mdev_state,
 		region_info->flags  = (VFIO_REGION_INFO_FLAG_READ  |
 				       VFIO_REGION_INFO_FLAG_WRITE);
 		break;
-	case MBOCHS_EDID_REGION_INDEX:
-		ext->base.argsz = sizeof(*ext);
-		ext->base.offset = MBOCHS_EDID_OFFSET;
-		ext->base.size = MBOCHS_EDID_SIZE;
-		ext->base.flags = (VFIO_REGION_INFO_FLAG_READ  |
-				   VFIO_REGION_INFO_FLAG_WRITE |
-				   VFIO_REGION_INFO_FLAG_CAPS);
-		ext->base.cap_offset = offsetof(typeof(*ext), type);
-		ext->type.header.id = VFIO_REGION_INFO_CAP_TYPE;
-		ext->type.header.version = 1;
-		ext->type.header.next = 0;
-		ext->type.type = VFIO_REGION_TYPE_GFX;
-		ext->type.subtype = VFIO_REGION_SUBTYPE_GFX_EDID;
-		break;
+	case MBOCHS_EDID_REGION_INDEX: {
+		struct vfio_region_info_cap_type cap_type = {
+			.header.id = VFIO_REGION_INFO_CAP_TYPE,
+			.header.version = 1,
+			.type = VFIO_REGION_TYPE_GFX,
+			.subtype = VFIO_REGION_SUBTYPE_GFX_EDID,
+		};
+
+		region_info->offset = MBOCHS_EDID_OFFSET;
+		region_info->size = MBOCHS_EDID_SIZE;
+		region_info->flags = (VFIO_REGION_INFO_FLAG_READ |
+				      VFIO_REGION_INFO_FLAG_WRITE |
+				      VFIO_REGION_INFO_FLAG_CAPS);
+
+		return vfio_info_add_capability(caps, &cap_type.header,
+						sizeof(cap_type));
+	}
 	default:
 		region_info->size   = 0;
 		region_info->offset = 0;
@@ -1185,35 +1185,6 @@ static int mbochs_get_gfx_dmabuf(struct mdev_state *mdev_state, u32 id)
 	return dma_buf_fd(dmabuf->buf, 0);
 }
 
-static int mbochs_ioctl_get_region_info(struct vfio_device *vdev,
-					struct vfio_region_info __user *arg)
-{
-	struct mdev_state *mdev_state =
-		container_of(vdev, struct mdev_state, vdev);
-	struct vfio_region_info_ext info;
-	unsigned long minsz, outsz;
-	int ret;
-
-	minsz = offsetofend(typeof(info), base.offset);
-
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
-
-	outsz = info.base.argsz;
-	if (outsz < minsz)
-		return -EINVAL;
-	if (outsz > sizeof(info))
-		return -EINVAL;
-
-	ret = mbochs_get_region_info(mdev_state, &info);
-	if (ret)
-		return ret;
-
-	if (copy_to_user(arg, &info, outsz))
-		return -EFAULT;
-	return 0;
-}
-
 static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd,
 			 unsigned long arg)
 {
@@ -1381,7 +1352,7 @@ static const struct vfio_device_ops mbochs_dev_ops = {
 	.read = mbochs_read,
 	.write = mbochs_write,
 	.ioctl = mbochs_ioctl,
-	.get_region_info = mbochs_ioctl_get_region_info,
+	.get_region_info_caps = mbochs_get_region_info,
 	.mmap = mbochs_mmap,
 	.bind_iommufd	= vfio_iommufd_emulated_bind,
 	.unbind_iommufd	= vfio_iommufd_emulated_unbind,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 17/22] vfio/gvt: Convert to get_region_info_caps
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (15 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 16/22] vfio/mbochs: Convert mbochs to use vfio_info_add_capability() Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-10-23 23:09 ` [PATCH 18/22] vfio/ccw: " Jason Gunthorpe
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Remove the duplicate code and change info to a pointer.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/gpu/drm/i915/gvt/kvmgt.c | 113 ++++++++++++-------------------
 1 file changed, 42 insertions(+), 71 deletions(-)

diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index 6b47e33078eb52..b307535dfc9743 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -1141,56 +1141,46 @@ static int intel_vgpu_set_irqs(struct intel_vgpu *vgpu, u32 flags,
 }
 
 static int intel_vgpu_get_region_info(struct vfio_device *vfio_dev,
-				      struct vfio_region_info __user *arg)
+				      struct vfio_region_info *info,
+				      struct vfio_info_cap *caps)
 {
-	struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
 	struct vfio_region_info_cap_sparse_mmap *sparse = NULL;
 	struct intel_vgpu *vgpu = vfio_dev_to_vgpu(vfio_dev);
-	struct vfio_region_info info;
-	unsigned long minsz;
 	int nr_areas = 1;
 	int cap_type_id;
 	unsigned int i;
 	int ret;
 
-	minsz = offsetofend(struct vfio_region_info, offset);
-
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
-
-	if (info.argsz < minsz)
-		return -EINVAL;
-
-	switch (info.index) {
+	switch (info->index) {
 	case VFIO_PCI_CONFIG_REGION_INDEX:
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.size = vgpu->gvt->device_info.cfg_space_size;
-		info.flags = VFIO_REGION_INFO_FLAG_READ |
-			     VFIO_REGION_INFO_FLAG_WRITE;
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->size = vgpu->gvt->device_info.cfg_space_size;
+		info->flags = VFIO_REGION_INFO_FLAG_READ |
+			      VFIO_REGION_INFO_FLAG_WRITE;
 		break;
 	case VFIO_PCI_BAR0_REGION_INDEX:
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.size = vgpu->cfg_space.bar[info.index].size;
-		if (!info.size) {
-			info.flags = 0;
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->size = vgpu->cfg_space.bar[info->index].size;
+		if (!info->size) {
+			info->flags = 0;
 			break;
 		}
 
-		info.flags = VFIO_REGION_INFO_FLAG_READ |
-			     VFIO_REGION_INFO_FLAG_WRITE;
+		info->flags = VFIO_REGION_INFO_FLAG_READ |
+			      VFIO_REGION_INFO_FLAG_WRITE;
 		break;
 	case VFIO_PCI_BAR1_REGION_INDEX:
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.size = 0;
-		info.flags = 0;
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->size = 0;
+		info->flags = 0;
 		break;
 	case VFIO_PCI_BAR2_REGION_INDEX:
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.flags = VFIO_REGION_INFO_FLAG_CAPS |
-			     VFIO_REGION_INFO_FLAG_MMAP |
-			     VFIO_REGION_INFO_FLAG_READ |
-			     VFIO_REGION_INFO_FLAG_WRITE;
-		info.size = gvt_aperture_sz(vgpu->gvt);
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->flags = VFIO_REGION_INFO_FLAG_CAPS |
+			      VFIO_REGION_INFO_FLAG_MMAP |
+			      VFIO_REGION_INFO_FLAG_READ |
+			      VFIO_REGION_INFO_FLAG_WRITE;
+		info->size = gvt_aperture_sz(vgpu->gvt);
 
 		sparse = kzalloc(struct_size(sparse, areas, nr_areas),
 				 GFP_KERNEL);
@@ -1207,20 +1197,20 @@ static int intel_vgpu_get_region_info(struct vfio_device *vfio_dev,
 		break;
 
 	case VFIO_PCI_BAR3_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.size = 0;
-		info.flags = 0;
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->size = 0;
+		info->flags = 0;
 
-		gvt_dbg_core("get region info bar:%d\n", info.index);
+		gvt_dbg_core("get region info bar:%d\n", info->index);
 		break;
 
 	case VFIO_PCI_ROM_REGION_INDEX:
 	case VFIO_PCI_VGA_REGION_INDEX:
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.size = 0;
-		info.flags = 0;
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->size = 0;
+		info->flags = 0;
 
-		gvt_dbg_core("get region info index:%d\n", info.index);
+		gvt_dbg_core("get region info index:%d\n", info->index);
 		break;
 	default: {
 		struct vfio_region_info_cap_type cap_type = {
@@ -1228,32 +1218,32 @@ static int intel_vgpu_get_region_info(struct vfio_device *vfio_dev,
 			.header.version = 1
 		};
 
-		if (info.index >= VFIO_PCI_NUM_REGIONS + vgpu->num_regions)
+		if (info->index >= VFIO_PCI_NUM_REGIONS + vgpu->num_regions)
 			return -EINVAL;
-		info.index = array_index_nospec(
-			info.index, VFIO_PCI_NUM_REGIONS + vgpu->num_regions);
+		info->index = array_index_nospec(
+			info->index, VFIO_PCI_NUM_REGIONS + vgpu->num_regions);
 
-		i = info.index - VFIO_PCI_NUM_REGIONS;
+		i = info->index - VFIO_PCI_NUM_REGIONS;
 
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.size = vgpu->region[i].size;
-		info.flags = vgpu->region[i].flags;
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->size = vgpu->region[i].size;
+		info->flags = vgpu->region[i].flags;
 
 		cap_type.type = vgpu->region[i].type;
 		cap_type.subtype = vgpu->region[i].subtype;
 
-		ret = vfio_info_add_capability(&caps, &cap_type.header,
+		ret = vfio_info_add_capability(caps, &cap_type.header,
 					       sizeof(cap_type));
 		if (ret)
 			return ret;
 	}
 	}
 
-	if ((info.flags & VFIO_REGION_INFO_FLAG_CAPS) && sparse) {
+	if ((info->flags & VFIO_REGION_INFO_FLAG_CAPS) && sparse) {
 		switch (cap_type_id) {
 		case VFIO_REGION_INFO_CAP_SPARSE_MMAP:
 			ret = vfio_info_add_capability(
-				&caps, &sparse->header,
+				caps, &sparse->header,
 				struct_size(sparse, areas, sparse->nr_areas));
 			if (ret) {
 				kfree(sparse);
@@ -1266,27 +1256,8 @@ static int intel_vgpu_get_region_info(struct vfio_device *vfio_dev,
 		}
 	}
 
-	if (caps.size) {
-		info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
-		if (info.argsz < sizeof(info) + caps.size) {
-			info.argsz = sizeof(info) + caps.size;
-			info.cap_offset = 0;
-		} else {
-			vfio_info_cap_shift(&caps, sizeof(info));
-			if (copy_to_user((void __user *)arg + sizeof(info),
-					 caps.buf, caps.size)) {
-				kfree(caps.buf);
-				kfree(sparse);
-				return -EFAULT;
-			}
-			info.cap_offset = sizeof(info);
-		}
-
-		kfree(caps.buf);
-	}
-
 	kfree(sparse);
-	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
+	return 0;
 }
 
 static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,
@@ -1473,7 +1444,7 @@ static const struct vfio_device_ops intel_vgpu_dev_ops = {
 	.write		= intel_vgpu_write,
 	.mmap		= intel_vgpu_mmap,
 	.ioctl		= intel_vgpu_ioctl,
-	.get_region_info = intel_vgpu_get_region_info,
+	.get_region_info_caps = intel_vgpu_get_region_info,
 	.dma_unmap	= intel_vgpu_dma_unmap,
 	.bind_iommufd	= vfio_iommufd_emulated_bind,
 	.unbind_iommufd = vfio_iommufd_emulated_unbind,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 18/22] vfio/ccw: Convert to get_region_info_caps
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (16 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 17/22] vfio/gvt: Convert to get_region_info_caps Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-10-28  7:09   ` Tian, Kevin
  2025-10-23 23:09 ` [PATCH 19/22] vfio/pci: Convert all PCI drivers " Jason Gunthorpe
                   ` (6 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Remove the duplicate code and change info to a pointer.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/s390/cio/vfio_ccw_ops.c | 53 ++++-----------------------------
 1 file changed, 6 insertions(+), 47 deletions(-)

diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
index 6d46e0bc76df15..4f63ca3c99cdf0 100644
--- a/drivers/s390/cio/vfio_ccw_ops.c
+++ b/drivers/s390/cio/vfio_ccw_ops.c
@@ -313,10 +313,12 @@ static int vfio_ccw_mdev_get_device_info(struct vfio_ccw_private *private,
 	return 0;
 }
 
-static int vfio_ccw_mdev_get_region_info(struct vfio_ccw_private *private,
+static int vfio_ccw_mdev_get_region_info(struct vfio_device *vdev,
 					 struct vfio_region_info *info,
-					 unsigned long arg)
+					 struct vfio_info_cap *caps)
 {
+	struct vfio_ccw_private *private =
+		container_of(vdev, struct vfio_ccw_private, vdev);
 	int i;
 
 	switch (info->index) {
@@ -328,7 +330,6 @@ static int vfio_ccw_mdev_get_region_info(struct vfio_ccw_private *private,
 		return 0;
 	default: /* all other regions are handled via capability chain */
 	{
-		struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
 		struct vfio_region_info_cap_type cap_type = {
 			.header.id = VFIO_REGION_INFO_CAP_TYPE,
 			.header.version = 1 };
@@ -351,27 +352,10 @@ static int vfio_ccw_mdev_get_region_info(struct vfio_ccw_private *private,
 		cap_type.type = private->region[i].type;
 		cap_type.subtype = private->region[i].subtype;
 
-		ret = vfio_info_add_capability(&caps, &cap_type.header,
+		ret = vfio_info_add_capability(caps, &cap_type.header,
 					       sizeof(cap_type));
 		if (ret)
 			return ret;
-
-		info->flags |= VFIO_REGION_INFO_FLAG_CAPS;
-		if (info->argsz < sizeof(*info) + caps.size) {
-			info->argsz = sizeof(*info) + caps.size;
-			info->cap_offset = 0;
-		} else {
-			vfio_info_cap_shift(&caps, sizeof(*info));
-			if (copy_to_user((void __user *)arg + sizeof(*info),
-					 caps.buf, caps.size)) {
-				kfree(caps.buf);
-				return -EFAULT;
-			}
-			info->cap_offset = sizeof(*info);
-		}
-
-		kfree(caps.buf);
-
 	}
 	}
 	return 0;
@@ -504,31 +488,6 @@ void vfio_ccw_unregister_dev_regions(struct vfio_ccw_private *private)
 	private->region = NULL;
 }
 
-static int
-vfio_ccw_mdev_ioctl_get_region_info(struct vfio_device *vdev,
-				    struct vfio_region_info __user *arg)
-{
-	struct vfio_ccw_private *private =
-		container_of(vdev, struct vfio_ccw_private, vdev);
-	struct vfio_region_info info;
-	unsigned long minsz;
-	int ret;
-
-	minsz = offsetofend(struct vfio_region_info, offset);
-
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
-
-	if (info.argsz < minsz)
-		return -EINVAL;
-
-	ret = vfio_ccw_mdev_get_region_info(private, &info, arg);
-	if (ret)
-		return ret;
-
-	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
-}
-
 static ssize_t vfio_ccw_mdev_ioctl(struct vfio_device *vdev,
 				   unsigned int cmd,
 				   unsigned long arg)
@@ -634,7 +593,7 @@ static const struct vfio_device_ops vfio_ccw_dev_ops = {
 	.read = vfio_ccw_mdev_read,
 	.write = vfio_ccw_mdev_write,
 	.ioctl = vfio_ccw_mdev_ioctl,
-	.get_region_info = vfio_ccw_mdev_ioctl_get_region_info,
+	.get_region_info_caps = vfio_ccw_mdev_get_region_info,
 	.request = vfio_ccw_mdev_request,
 	.dma_unmap = vfio_ccw_dma_unmap,
 	.bind_iommufd = vfio_iommufd_emulated_bind,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 19/22] vfio/pci: Convert all PCI drivers to get_region_info_caps
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (17 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 18/22] vfio/ccw: " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-10-28 17:08   ` Brett Creeley
  2025-11-03 10:25   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 20/22] vfio/platform: Convert " Jason Gunthorpe
                   ` (5 subsequent siblings)
  24 siblings, 2 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Since the core function signature changes it has to flow up to all
drivers.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c    |  30 ++---
 drivers/vfio/pci/mlx5/main.c                  |   2 +-
 drivers/vfio/pci/nvgrace-gpu/main.c           |  51 ++-------
 drivers/vfio/pci/pds/vfio_dev.c               |   2 +-
 drivers/vfio/pci/qat/main.c                   |   2 +-
 drivers/vfio/pci/vfio_pci.c                   |   2 +-
 drivers/vfio/pci/vfio_pci_core.c              | 103 +++++++-----------
 drivers/vfio/pci/virtio/common.h              |   3 +-
 drivers/vfio/pci/virtio/legacy_io.c           |  26 ++---
 drivers/vfio/pci/virtio/main.c                |   6 +-
 include/linux/vfio_pci_core.h                 |   3 +-
 11 files changed, 80 insertions(+), 150 deletions(-)

diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
index 99e67e3dda3498..0d575bd5ce67c4 100644
--- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
+++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
@@ -1325,38 +1325,28 @@ static ssize_t hisi_acc_vfio_pci_read(struct vfio_device *core_vdev,
 }
 
 static int hisi_acc_vfio_get_region(struct vfio_device *core_vdev,
-				    struct vfio_region_info __user *arg)
+				    struct vfio_region_info *info,
+				    struct vfio_info_cap *caps)
 {
 	struct vfio_pci_core_device *vdev =
 		container_of(core_vdev, struct vfio_pci_core_device, vdev);
 	struct pci_dev *pdev = vdev->pdev;
-	struct vfio_region_info info;
-	unsigned long minsz;
 
-	minsz = offsetofend(struct vfio_region_info, offset);
+	if (info->index != VFIO_PCI_BAR2_REGION_INDEX)
+		return vfio_pci_ioctl_get_region_info(core_vdev, info, caps);
 
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
-
-	if (info.argsz < minsz)
-		return -EINVAL;
-
-	if (info.index != VFIO_PCI_BAR2_REGION_INDEX)
-		return vfio_pci_ioctl_get_region_info(core_vdev, arg);
-
-	info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
+	info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
 
 	/*
 	 * ACC VF dev BAR2 region consists of both functional
 	 * register space and migration control register space.
 	 * Report only the functional region to Guest.
 	 */
-	info.size = pci_resource_len(pdev, info.index) / 2;
+	info->size = pci_resource_len(pdev, info->index) / 2;
 
-	info.flags = VFIO_REGION_INFO_FLAG_READ | VFIO_REGION_INFO_FLAG_WRITE |
+	info->flags = VFIO_REGION_INFO_FLAG_READ | VFIO_REGION_INFO_FLAG_WRITE |
 		     VFIO_REGION_INFO_FLAG_MMAP;
-
-	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
+	return 0;
 }
 
 static int hisi_acc_vf_debug_check(struct seq_file *seq, struct vfio_device *vdev)
@@ -1554,7 +1544,7 @@ static const struct vfio_device_ops hisi_acc_vfio_pci_migrn_ops = {
 	.open_device = hisi_acc_vfio_pci_open_device,
 	.close_device = hisi_acc_vfio_pci_close_device,
 	.ioctl = vfio_pci_core_ioctl,
-	.get_region_info = hisi_acc_vfio_get_region,
+	.get_region_info_caps = hisi_acc_vfio_get_region,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = hisi_acc_vfio_pci_read,
 	.write = hisi_acc_vfio_pci_write,
@@ -1574,7 +1564,7 @@ static const struct vfio_device_ops hisi_acc_vfio_pci_ops = {
 	.open_device = hisi_acc_vfio_pci_open_device,
 	.close_device = vfio_pci_core_close_device,
 	.ioctl = vfio_pci_core_ioctl,
-	.get_region_info = vfio_pci_ioctl_get_region_info,
+	.get_region_info_caps = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
diff --git a/drivers/vfio/pci/mlx5/main.c b/drivers/vfio/pci/mlx5/main.c
index b7f941f8047ea4..9c5970411d07a1 100644
--- a/drivers/vfio/pci/mlx5/main.c
+++ b/drivers/vfio/pci/mlx5/main.c
@@ -1366,7 +1366,7 @@ static const struct vfio_device_ops mlx5vf_pci_ops = {
 	.open_device = mlx5vf_pci_open_device,
 	.close_device = mlx5vf_pci_close_device,
 	.ioctl = vfio_pci_core_ioctl,
-	.get_region_info = vfio_pci_ioctl_get_region_info,
+	.get_region_info_caps = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c b/drivers/vfio/pci/nvgrace-gpu/main.c
index cab743a30dc35d..5a6f77d5c81e0f 100644
--- a/drivers/vfio/pci/nvgrace-gpu/main.c
+++ b/drivers/vfio/pci/nvgrace-gpu/main.c
@@ -205,34 +205,25 @@ static int nvgrace_gpu_mmap(struct vfio_device *core_vdev,
 	return 0;
 }
 
-static int
-nvgrace_gpu_ioctl_get_region_info(struct vfio_device *core_vdev,
-				  struct vfio_region_info __user *arg)
+static int nvgrace_gpu_ioctl_get_region_info(struct vfio_device *core_vdev,
+					     struct vfio_region_info *info,
+					     struct vfio_info_cap *caps)
 {
 	struct nvgrace_gpu_pci_core_device *nvdev =
 		container_of(core_vdev, struct nvgrace_gpu_pci_core_device,
 			     core_device.vdev);
-	unsigned long minsz = offsetofend(struct vfio_region_info, offset);
-	struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
 	struct vfio_region_info_cap_sparse_mmap *sparse;
-	struct vfio_region_info info;
 	struct mem_region *memregion;
 	u32 size;
 	int ret;
 
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
-
-	if (info.argsz < minsz)
-		return -EINVAL;
-
 	/*
 	 * Request to determine the BAR region information. Send the
 	 * GPU memory information.
 	 */
-	memregion = nvgrace_gpu_memregion(info.index, nvdev);
+	memregion = nvgrace_gpu_memregion(info->index, nvdev);
 	if (!memregion)
-		return vfio_pci_ioctl_get_region_info(core_vdev, arg);
+		return vfio_pci_ioctl_get_region_info(core_vdev, info, caps);
 
 	size = struct_size(sparse, areas, 1);
 
@@ -251,40 +242,22 @@ nvgrace_gpu_ioctl_get_region_info(struct vfio_device *core_vdev,
 	sparse->header.id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
 	sparse->header.version = 1;
 
-	ret = vfio_info_add_capability(&caps, &sparse->header, size);
+	ret = vfio_info_add_capability(caps, &sparse->header, size);
 	kfree(sparse);
 	if (ret)
 		return ret;
 
-	info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
+	info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
 	/*
 	 * The region memory size may not be power-of-2 aligned.
 	 * Given that the memory is a BAR and may not be
 	 * aligned, roundup to the next power-of-2.
 	 */
-	info.size = memregion->bar_size;
-	info.flags = VFIO_REGION_INFO_FLAG_READ |
+	info->size = memregion->bar_size;
+	info->flags = VFIO_REGION_INFO_FLAG_READ |
 		     VFIO_REGION_INFO_FLAG_WRITE |
 		     VFIO_REGION_INFO_FLAG_MMAP;
-
-	if (caps.size) {
-		info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
-		if (info.argsz < sizeof(info) + caps.size) {
-			info.argsz = sizeof(info) + caps.size;
-			info.cap_offset = 0;
-		} else {
-			vfio_info_cap_shift(&caps, sizeof(info));
-			if (copy_to_user((void __user *)arg +
-					 sizeof(info), caps.buf,
-					 caps.size)) {
-				kfree(caps.buf);
-				return -EFAULT;
-			}
-			info.cap_offset = sizeof(info);
-		}
-		kfree(caps.buf);
-	}
-	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
+	return 0;
 }
 
 static long nvgrace_gpu_ioctl(struct vfio_device *core_vdev,
@@ -686,7 +659,7 @@ static const struct vfio_device_ops nvgrace_gpu_pci_ops = {
 	.open_device	= nvgrace_gpu_open_device,
 	.close_device	= nvgrace_gpu_close_device,
 	.ioctl		= nvgrace_gpu_ioctl,
-	.get_region_info = nvgrace_gpu_ioctl_get_region_info,
+	.get_region_info_caps = nvgrace_gpu_ioctl_get_region_info,
 	.device_feature	= vfio_pci_core_ioctl_feature,
 	.read		= nvgrace_gpu_read,
 	.write		= nvgrace_gpu_write,
@@ -707,7 +680,7 @@ static const struct vfio_device_ops nvgrace_gpu_pci_core_ops = {
 	.open_device	= nvgrace_gpu_open_device,
 	.close_device	= vfio_pci_core_close_device,
 	.ioctl		= vfio_pci_core_ioctl,
-	.get_region_info = vfio_pci_ioctl_get_region_info,
+	.get_region_info_caps = vfio_pci_ioctl_get_region_info,
 	.device_feature	= vfio_pci_core_ioctl_feature,
 	.read		= vfio_pci_core_read,
 	.write		= vfio_pci_core_write,
diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c
index 1946bc75d99b49..be103c74e96957 100644
--- a/drivers/vfio/pci/pds/vfio_dev.c
+++ b/drivers/vfio/pci/pds/vfio_dev.c
@@ -195,7 +195,7 @@ static const struct vfio_device_ops pds_vfio_ops = {
 	.open_device = pds_vfio_open_device,
 	.close_device = pds_vfio_close_device,
 	.ioctl = vfio_pci_core_ioctl,
-	.get_region_info = vfio_pci_ioctl_get_region_info,
+	.get_region_info_caps = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
diff --git a/drivers/vfio/pci/qat/main.c b/drivers/vfio/pci/qat/main.c
index 8452d9c1d11d3a..8fbdf7c6d666e1 100644
--- a/drivers/vfio/pci/qat/main.c
+++ b/drivers/vfio/pci/qat/main.c
@@ -609,7 +609,7 @@ static const struct vfio_device_ops qat_vf_pci_ops = {
 	.open_device = qat_vf_pci_open_device,
 	.close_device = qat_vf_pci_close_device,
 	.ioctl = vfio_pci_core_ioctl,
-	.get_region_info = vfio_pci_ioctl_get_region_info,
+	.get_region_info_caps = vfio_pci_ioctl_get_region_info,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
 	.mmap = vfio_pci_core_mmap,
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index 2d9122efc10baa..a3e49d42c771bc 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -132,7 +132,7 @@ static const struct vfio_device_ops vfio_pci_ops = {
 	.open_device	= vfio_pci_open_device,
 	.close_device	= vfio_pci_core_close_device,
 	.ioctl		= vfio_pci_core_ioctl,
-	.get_region_info = vfio_pci_ioctl_get_region_info,
+	.get_region_info_caps = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read		= vfio_pci_core_read,
 	.write		= vfio_pci_core_write,
diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index f21d9026068c37..57c0766fb9f80f 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -997,43 +997,35 @@ static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev,
 }
 
 int vfio_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
-				   struct vfio_region_info __user *arg)
+				   struct vfio_region_info *info,
+				   struct vfio_info_cap *caps)
 {
 	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;
-	struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
 	int i, ret;
 
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
-
-	if (info.argsz < minsz)
-		return -EINVAL;
-
-	switch (info.index) {
+	switch (info->index) {
 	case VFIO_PCI_CONFIG_REGION_INDEX:
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.size = pdev->cfg_size;
-		info.flags = VFIO_REGION_INFO_FLAG_READ |
-			     VFIO_REGION_INFO_FLAG_WRITE;
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->size = pdev->cfg_size;
+		info->flags = VFIO_REGION_INFO_FLAG_READ |
+			      VFIO_REGION_INFO_FLAG_WRITE;
 		break;
 	case VFIO_PCI_BAR0_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.size = pci_resource_len(pdev, info.index);
-		if (!info.size) {
-			info.flags = 0;
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->size = pci_resource_len(pdev, info->index);
+		if (!info->size) {
+			info->flags = 0;
 			break;
 		}
 
-		info.flags = VFIO_REGION_INFO_FLAG_READ |
-			     VFIO_REGION_INFO_FLAG_WRITE;
-		if (vdev->bar_mmap_supported[info.index]) {
-			info.flags |= VFIO_REGION_INFO_FLAG_MMAP;
-			if (info.index == vdev->msix_bar) {
-				ret = msix_mmappable_cap(vdev, &caps);
+		info->flags = VFIO_REGION_INFO_FLAG_READ |
+			      VFIO_REGION_INFO_FLAG_WRITE;
+		if (vdev->bar_mmap_supported[info->index]) {
+			info->flags |= VFIO_REGION_INFO_FLAG_MMAP;
+			if (info->index == vdev->msix_bar) {
+				ret = msix_mmappable_cap(vdev, caps);
 				if (ret)
 					return ret;
 			}
@@ -1045,9 +1037,9 @@ int vfio_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
 		size_t size;
 		u16 cmd;
 
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.flags = 0;
-		info.size = 0;
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->flags = 0;
+		info->size = 0;
 
 		if (pci_resource_start(pdev, PCI_ROM_RESOURCE)) {
 			/*
@@ -1057,16 +1049,17 @@ int vfio_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
 			cmd = vfio_pci_memory_lock_and_enable(vdev);
 			io = pci_map_rom(pdev, &size);
 			if (io) {
-				info.flags = VFIO_REGION_INFO_FLAG_READ;
+				info->flags = VFIO_REGION_INFO_FLAG_READ;
 				/* Report the BAR size, not the ROM size. */
-				info.size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
+				info->size = pci_resource_len(pdev,
+							      PCI_ROM_RESOURCE);
 				pci_unmap_rom(pdev, io);
 			}
 			vfio_pci_memory_unlock_and_restore(vdev, cmd);
 		} else if (pdev->rom && pdev->romlen) {
-			info.flags = VFIO_REGION_INFO_FLAG_READ;
+			info->flags = VFIO_REGION_INFO_FLAG_READ;
 			/* Report BAR size as power of two. */
-			info.size = roundup_pow_of_two(pdev->romlen);
+			info->size = roundup_pow_of_two(pdev->romlen);
 		}
 
 		break;
@@ -1075,10 +1068,10 @@ int vfio_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
 		if (!vdev->has_vga)
 			return -EINVAL;
 
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.size = 0xc0000;
-		info.flags = VFIO_REGION_INFO_FLAG_READ |
-			     VFIO_REGION_INFO_FLAG_WRITE;
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->size = 0xc0000;
+		info->flags = VFIO_REGION_INFO_FLAG_READ |
+			      VFIO_REGION_INFO_FLAG_WRITE;
 
 		break;
 	default: {
@@ -1087,52 +1080,34 @@ int vfio_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
 			.header.version = 1
 		};
 
-		if (info.index >= VFIO_PCI_NUM_REGIONS + vdev->num_regions)
+		if (info->index >= VFIO_PCI_NUM_REGIONS + vdev->num_regions)
 			return -EINVAL;
-		info.index = array_index_nospec(
-			info.index, VFIO_PCI_NUM_REGIONS + vdev->num_regions);
+		info->index = array_index_nospec(
+			info->index, VFIO_PCI_NUM_REGIONS + vdev->num_regions);
 
-		i = info.index - VFIO_PCI_NUM_REGIONS;
+		i = info->index - VFIO_PCI_NUM_REGIONS;
 
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.size = vdev->region[i].size;
-		info.flags = vdev->region[i].flags;
+		info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+		info->size = vdev->region[i].size;
+		info->flags = vdev->region[i].flags;
 
 		cap_type.type = vdev->region[i].type;
 		cap_type.subtype = vdev->region[i].subtype;
 
-		ret = vfio_info_add_capability(&caps, &cap_type.header,
+		ret = vfio_info_add_capability(caps, &cap_type.header,
 					       sizeof(cap_type));
 		if (ret)
 			return ret;
 
 		if (vdev->region[i].ops->add_capability) {
 			ret = vdev->region[i].ops->add_capability(
-				vdev, &vdev->region[i], &caps);
+				vdev, &vdev->region[i], caps);
 			if (ret)
 				return ret;
 		}
 	}
 	}
-
-	if (caps.size) {
-		info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
-		if (info.argsz < sizeof(info) + caps.size) {
-			info.argsz = sizeof(info) + caps.size;
-			info.cap_offset = 0;
-		} else {
-			vfio_info_cap_shift(&caps, sizeof(info));
-			if (copy_to_user(arg + 1, caps.buf, caps.size)) {
-				kfree(caps.buf);
-				return -EFAULT;
-			}
-			info.cap_offset = sizeof(*arg);
-		}
-
-		kfree(caps.buf);
-	}
-
-	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(vfio_pci_ioctl_get_region_info);
 
diff --git a/drivers/vfio/pci/virtio/common.h b/drivers/vfio/pci/virtio/common.h
index a10f2d92cb6238..cb3d5e57d3a3e9 100644
--- a/drivers/vfio/pci/virtio/common.h
+++ b/drivers/vfio/pci/virtio/common.h
@@ -110,7 +110,8 @@ void virtiovf_migration_reset_done(struct pci_dev *pdev);
 #ifdef CONFIG_VIRTIO_VFIO_PCI_ADMIN_LEGACY
 int virtiovf_open_legacy_io(struct virtiovf_pci_core_device *virtvdev);
 int virtiovf_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
-				       struct vfio_region_info __user *arg);
+				       struct vfio_region_info *info,
+				       struct vfio_info_cap *caps);
 ssize_t virtiovf_pci_core_write(struct vfio_device *core_vdev,
 				const char __user *buf, size_t count,
 				loff_t *ppos);
diff --git a/drivers/vfio/pci/virtio/legacy_io.c b/drivers/vfio/pci/virtio/legacy_io.c
index d735d5c4bd7775..1ed349a556291b 100644
--- a/drivers/vfio/pci/virtio/legacy_io.c
+++ b/drivers/vfio/pci/virtio/legacy_io.c
@@ -281,29 +281,19 @@ ssize_t virtiovf_pci_core_write(struct vfio_device *core_vdev, const char __user
 }
 
 int virtiovf_pci_ioctl_get_region_info(struct vfio_device *core_vdev,
-				       struct vfio_region_info __user *arg)
+				       struct vfio_region_info *info,
+				       struct vfio_info_cap *caps)
 {
 	struct virtiovf_pci_core_device *virtvdev = container_of(
 		core_vdev, struct virtiovf_pci_core_device, core_device.vdev);
-	unsigned long minsz = offsetofend(struct vfio_region_info, offset);
-	struct vfio_region_info info = {};
 
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
+	if (info->index != VFIO_PCI_BAR0_REGION_INDEX)
+		return vfio_pci_ioctl_get_region_info(core_vdev, info, caps);
 
-	if (info.argsz < minsz)
-		return -EINVAL;
-
-	switch (info.index) {
-	case VFIO_PCI_BAR0_REGION_INDEX:
-		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
-		info.size = virtvdev->bar0_virtual_buf_size;
-		info.flags = VFIO_REGION_INFO_FLAG_READ |
-			     VFIO_REGION_INFO_FLAG_WRITE;
-		return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
-	default:
-		return vfio_pci_ioctl_get_region_info(core_vdev, arg);
-	}
+	info->offset = VFIO_PCI_INDEX_TO_OFFSET(info->index);
+	info->size = virtvdev->bar0_virtual_buf_size;
+	info->flags = VFIO_REGION_INFO_FLAG_READ | VFIO_REGION_INFO_FLAG_WRITE;
+	return 0;
 }
 
 static int virtiovf_set_notify_addr(struct virtiovf_pci_core_device *virtvdev)
diff --git a/drivers/vfio/pci/virtio/main.c b/drivers/vfio/pci/virtio/main.c
index d68096bc525215..d2e5cbca13c857 100644
--- a/drivers/vfio/pci/virtio/main.c
+++ b/drivers/vfio/pci/virtio/main.c
@@ -88,7 +88,7 @@ static const struct vfio_device_ops virtiovf_vfio_pci_lm_ops = {
 	.open_device = virtiovf_pci_open_device,
 	.close_device = virtiovf_pci_close_device,
 	.ioctl = vfio_pci_core_ioctl,
-	.get_region_info = vfio_pci_ioctl_get_region_info,
+	.get_region_info_caps = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
@@ -110,7 +110,7 @@ static const struct vfio_device_ops virtiovf_vfio_pci_tran_lm_ops = {
 	.open_device = virtiovf_pci_open_device,
 	.close_device = virtiovf_pci_close_device,
 	.ioctl = vfio_pci_core_ioctl,
-	.get_region_info = virtiovf_pci_ioctl_get_region_info,
+	.get_region_info_caps = virtiovf_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = virtiovf_pci_core_read,
 	.write = virtiovf_pci_core_write,
@@ -132,7 +132,7 @@ static const struct vfio_device_ops virtiovf_vfio_pci_ops = {
 	.open_device = virtiovf_pci_open_device,
 	.close_device = vfio_pci_core_close_device,
 	.ioctl = vfio_pci_core_ioctl,
-	.get_region_info = vfio_pci_ioctl_get_region_info,
+	.get_region_info_caps = vfio_pci_ioctl_get_region_info,
 	.device_feature = vfio_pci_core_ioctl_feature,
 	.read = vfio_pci_core_read,
 	.write = vfio_pci_core_write,
diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
index 160bc2e31ece75..e74f94c17fbeb6 100644
--- a/include/linux/vfio_pci_core.h
+++ b/include/linux/vfio_pci_core.h
@@ -116,7 +116,8 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
 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);
+				   struct vfio_region_info *info,
+				   struct vfio_info_cap *caps);
 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,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 20/22] vfio/platform: Convert to get_region_info_caps
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (18 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 19/22] vfio/pci: Convert all PCI drivers " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03  9:57   ` Mostafa Saleh
                     ` (2 more replies)
  2025-10-23 23:09 ` [PATCH 21/22] vfio: Move the remaining drivers " Jason Gunthorpe
                   ` (4 subsequent siblings)
  24 siblings, 3 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Remove the duplicate code and change info to a pointer. caps are not used.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/platform/vfio_amba.c             |  2 +-
 drivers/vfio/platform/vfio_platform.c         |  2 +-
 drivers/vfio/platform/vfio_platform_common.c  | 24 ++++++-------------
 drivers/vfio/platform/vfio_platform_private.h |  3 ++-
 4 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/drivers/vfio/platform/vfio_amba.c b/drivers/vfio/platform/vfio_amba.c
index d600deaf23b6d7..fa754f203b2dfc 100644
--- a/drivers/vfio/platform/vfio_amba.c
+++ b/drivers/vfio/platform/vfio_amba.c
@@ -115,7 +115,7 @@ static const struct vfio_device_ops vfio_amba_ops = {
 	.open_device	= vfio_platform_open_device,
 	.close_device	= vfio_platform_close_device,
 	.ioctl		= vfio_platform_ioctl,
-	.get_region_info = vfio_platform_ioctl_get_region_info,
+	.get_region_info_caps = vfio_platform_ioctl_get_region_info,
 	.read		= vfio_platform_read,
 	.write		= vfio_platform_write,
 	.mmap		= vfio_platform_mmap,
diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c
index 0e85c914b65105..a4d3ace3e02dda 100644
--- a/drivers/vfio/platform/vfio_platform.c
+++ b/drivers/vfio/platform/vfio_platform.c
@@ -101,7 +101,7 @@ static const struct vfio_device_ops vfio_platform_ops = {
 	.open_device	= vfio_platform_open_device,
 	.close_device	= vfio_platform_close_device,
 	.ioctl		= vfio_platform_ioctl,
-	.get_region_info = vfio_platform_ioctl_get_region_info,
+	.get_region_info_caps = vfio_platform_ioctl_get_region_info,
 	.read		= vfio_platform_read,
 	.write		= vfio_platform_write,
 	.mmap		= vfio_platform_mmap,
diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
index 3ebd50fb78fbb7..c2990b7e900fa5 100644
--- a/drivers/vfio/platform/vfio_platform_common.c
+++ b/drivers/vfio/platform/vfio_platform_common.c
@@ -273,30 +273,20 @@ int vfio_platform_open_device(struct vfio_device *core_vdev)
 EXPORT_SYMBOL_GPL(vfio_platform_open_device);
 
 int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
-					struct vfio_region_info __user *arg)
+					struct vfio_region_info *info,
+					struct vfio_info_cap *caps)
 {
 	struct vfio_platform_device *vdev =
 		container_of(core_vdev, struct vfio_platform_device, vdev);
-	struct vfio_region_info info;
-	unsigned long minsz;
 
-	minsz = offsetofend(struct vfio_region_info, offset);
-
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
-
-	if (info.argsz < minsz)
-		return -EINVAL;
-
-	if (info.index >= vdev->num_regions)
+	if (info->index >= vdev->num_regions)
 		return -EINVAL;
 
 	/* map offset to the physical address  */
-	info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
-	info.size = vdev->regions[info.index].size;
-	info.flags = vdev->regions[info.index].flags;
-
-	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
+	info->offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info->index);
+	info->size = vdev->regions[info->index].size;
+	info->flags = vdev->regions[info->index].flags;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(vfio_platform_ioctl_get_region_info);
 
diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h
index a6008320e77bae..05084212a76eb6 100644
--- a/drivers/vfio/platform/vfio_platform_private.h
+++ b/drivers/vfio/platform/vfio_platform_private.h
@@ -86,7 +86,8 @@ void vfio_platform_close_device(struct vfio_device *core_vdev);
 long vfio_platform_ioctl(struct vfio_device *core_vdev,
 			 unsigned int cmd, unsigned long arg);
 int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
-					struct vfio_region_info __user *arg);
+					struct vfio_region_info *info,
+					struct vfio_info_cap *caps);
 ssize_t vfio_platform_read(struct vfio_device *core_vdev,
 			   char __user *buf, size_t count,
 			   loff_t *ppos);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 21/22] vfio: Move the remaining drivers to get_region_info_caps
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (19 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 20/22] vfio/platform: Convert " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03 10:29   ` Pranjal Shrivastava
  2025-10-23 23:09 ` [PATCH 22/22] vfio: Remove the get_region_info op Jason Gunthorpe
                   ` (3 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Remove the duplicate code and change info to a pointer. caps are not used.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/cdx/main.c           | 24 +++++++------------
 drivers/vfio/fsl-mc/vfio_fsl_mc.c | 26 ++++++---------------
 samples/vfio-mdev/mdpy.c          | 39 ++++++-------------------------
 samples/vfio-mdev/mtty.c          | 38 +++++-------------------------
 4 files changed, 28 insertions(+), 99 deletions(-)

diff --git a/drivers/vfio/cdx/main.c b/drivers/vfio/cdx/main.c
index 506d849139d35a..253031b86b60a7 100644
--- a/drivers/vfio/cdx/main.c
+++ b/drivers/vfio/cdx/main.c
@@ -130,29 +130,21 @@ static int vfio_cdx_ioctl_get_info(struct vfio_cdx_device *vdev,
 }
 
 static int vfio_cdx_ioctl_get_region_info(struct vfio_device *core_vdev,
-					  struct vfio_region_info __user *arg)
+					  struct vfio_region_info *info,
+					  struct vfio_info_cap *caps)
 {
 	struct vfio_cdx_device *vdev =
 		container_of(core_vdev, struct vfio_cdx_device, vdev);
-	unsigned long minsz = offsetofend(struct vfio_region_info, offset);
 	struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev);
-	struct vfio_region_info info;
 
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
-
-	if (info.argsz < minsz)
-		return -EINVAL;
-
-	if (info.index >= cdx_dev->res_count)
+	if (info->index >= cdx_dev->res_count)
 		return -EINVAL;
 
 	/* map offset to the physical address */
-	info.offset = vfio_cdx_index_to_offset(info.index);
-	info.size = vdev->regions[info.index].size;
-	info.flags = vdev->regions[info.index].flags;
-
-	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
+	info->offset = vfio_cdx_index_to_offset(info->index);
+	info->size = vdev->regions[info->index].size;
+	info->flags = vdev->regions[info->index].flags;
+	return 0;
 }
 
 static int vfio_cdx_ioctl_get_irq_info(struct vfio_cdx_device *vdev,
@@ -284,7 +276,7 @@ static const struct vfio_device_ops vfio_cdx_ops = {
 	.open_device	= vfio_cdx_open_device,
 	.close_device	= vfio_cdx_close_device,
 	.ioctl		= vfio_cdx_ioctl,
-	.get_region_info = vfio_cdx_ioctl_get_region_info,
+	.get_region_info_caps = vfio_cdx_ioctl_get_region_info,
 	.device_feature = vfio_cdx_ioctl_feature,
 	.mmap		= vfio_cdx_mmap,
 	.bind_iommufd	= vfio_iommufd_physical_bind,
diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
index 438ea4da120e63..61f3f4f407adce 100644
--- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c
+++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c
@@ -118,32 +118,20 @@ static void vfio_fsl_mc_close_device(struct vfio_device *core_vdev)
 }
 
 static int vfio_fsl_mc_get_region_info(struct vfio_device *core_vdev,
-				       struct vfio_region_info __user *arg)
+				       struct vfio_region_info *info,
+				       struct vfio_info_cap *caps)
 {
 	struct vfio_fsl_mc_device *vdev =
 		container_of(core_vdev, struct vfio_fsl_mc_device, vdev);
 	struct fsl_mc_device *mc_dev = vdev->mc_dev;
-	struct vfio_region_info info;
-	unsigned long minsz;
 
-	minsz = offsetofend(struct vfio_region_info, offset);
-
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
-
-	if (info.argsz < minsz)
-		return -EINVAL;
-
-	if (info.index >= mc_dev->obj_desc.region_count)
+	if (info->index >= mc_dev->obj_desc.region_count)
 		return -EINVAL;
 
 	/* map offset to the physical address  */
-	info.offset = VFIO_FSL_MC_INDEX_TO_OFFSET(info.index);
-	info.size = vdev->regions[info.index].size;
-	info.flags = vdev->regions[info.index].flags;
-
-	if (copy_to_user(arg, &info, minsz))
-		return -EFAULT;
+	info->offset = VFIO_FSL_MC_INDEX_TO_OFFSET(info->index);
+	info->size = vdev->regions[info->index].size;
+	info->flags = vdev->regions[info->index].flags;
 	return 0;
 }
 
@@ -595,7 +583,7 @@ static const struct vfio_device_ops vfio_fsl_mc_ops = {
 	.open_device	= vfio_fsl_mc_open_device,
 	.close_device	= vfio_fsl_mc_close_device,
 	.ioctl		= vfio_fsl_mc_ioctl,
-	.get_region_info = vfio_fsl_mc_get_region_info,
+	.get_region_info_caps = vfio_fsl_mc_get_region_info,
 	.read		= vfio_fsl_mc_read,
 	.write		= vfio_fsl_mc_write,
 	.mmap		= vfio_fsl_mc_mmap,
diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c
index 0c65ed22173862..0759bd68edca0d 100644
--- a/samples/vfio-mdev/mdpy.c
+++ b/samples/vfio-mdev/mdpy.c
@@ -435,10 +435,13 @@ static int mdpy_mmap(struct vfio_device *vdev, struct vm_area_struct *vma)
 	return remap_vmalloc_range(vma, mdev_state->memblk, 0);
 }
 
-static int mdpy_get_region_info(struct mdev_state *mdev_state,
-				struct vfio_region_info *region_info,
-				u16 *cap_type_id, void **cap_type)
+static int mdpy_ioctl_get_region_info(struct vfio_device *vdev,
+				      struct vfio_region_info *region_info,
+				      struct vfio_info_cap *caps)
 {
+	struct mdev_state *mdev_state =
+		container_of(vdev, struct mdev_state, vdev);
+
 	if (region_info->index >= VFIO_PCI_NUM_REGIONS &&
 	    region_info->index != MDPY_DISPLAY_REGION)
 		return -EINVAL;
@@ -512,34 +515,6 @@ static int mdpy_query_gfx_plane(struct mdev_state *mdev_state,
 	return 0;
 }
 
-static int mdpy_ioctl_get_region_info(struct vfio_device *vdev,
-				      struct vfio_region_info __user *arg)
-{
-	struct mdev_state *mdev_state =
-		container_of(vdev, struct mdev_state, vdev);
-	struct vfio_region_info info;
-	void *cap_type = NULL;
-	u16 cap_type_id = 0;
-	unsigned long minsz;
-	int ret;
-
-	minsz = offsetofend(struct vfio_region_info, offset);
-
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
-
-	if (info.argsz < minsz)
-		return -EINVAL;
-
-	ret = mdpy_get_region_info(mdev_state, &info, &cap_type_id, &cap_type);
-	if (ret)
-		return ret;
-
-	if (copy_to_user(arg, &info, minsz))
-		return -EFAULT;
-	return 0;
-}
-
 static long mdpy_ioctl(struct vfio_device *vdev, unsigned int cmd,
 		       unsigned long arg)
 {
@@ -669,7 +644,7 @@ static const struct vfio_device_ops mdpy_dev_ops = {
 	.read = mdpy_read,
 	.write = mdpy_write,
 	.ioctl = mdpy_ioctl,
-	.get_region_info = mdpy_ioctl_get_region_info,
+	.get_region_info_caps = mdpy_ioctl_get_region_info,
 	.mmap = mdpy_mmap,
 	.bind_iommufd	= vfio_iommufd_emulated_bind,
 	.unbind_iommufd	= vfio_iommufd_emulated_unbind,
diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
index b27f9b93471bc5..3e029d0cba1ea8 100644
--- a/samples/vfio-mdev/mtty.c
+++ b/samples/vfio-mdev/mtty.c
@@ -1717,10 +1717,12 @@ static int mtty_set_irqs(struct mdev_state *mdev_state, uint32_t flags,
 	return ret;
 }
 
-static int mtty_get_region_info(struct mdev_state *mdev_state,
-			 struct vfio_region_info *region_info,
-			 u16 *cap_type_id, void **cap_type)
+static int mtty_ioctl_get_region_info(struct vfio_device *vdev,
+				      struct vfio_region_info *region_info,
+				      struct vfio_info_cap *caps)
 {
+	struct mdev_state *mdev_state =
+		container_of(vdev, struct mdev_state, vdev);
 	unsigned int size = 0;
 	u32 bar_index;
 
@@ -1785,34 +1787,6 @@ static int mtty_get_device_info(struct vfio_device_info *dev_info)
 	return 0;
 }
 
-static int mtty_ioctl_get_region_info(struct vfio_device *vdev,
-				      struct vfio_region_info __user *arg)
-{
-	struct mdev_state *mdev_state =
-		container_of(vdev, struct mdev_state, vdev);
-	struct vfio_region_info info;
-	void *cap_type = NULL;
-	u16 cap_type_id = 0;
-	unsigned long minsz;
-	int ret;
-
-	minsz = offsetofend(struct vfio_region_info, offset);
-
-	if (copy_from_user(&info, arg, minsz))
-		return -EFAULT;
-
-	if (info.argsz < minsz)
-		return -EINVAL;
-
-	ret = mtty_get_region_info(mdev_state, &info, &cap_type_id, &cap_type);
-	if (ret)
-		return ret;
-
-	if (copy_to_user(arg, &info, minsz))
-		return -EFAULT;
-	return 0;
-}
-
 static long mtty_ioctl(struct vfio_device *vdev, unsigned int cmd,
 			unsigned long arg)
 {
@@ -1953,7 +1927,7 @@ static const struct vfio_device_ops mtty_dev_ops = {
 	.read = mtty_read,
 	.write = mtty_write,
 	.ioctl = mtty_ioctl,
-	.get_region_info = mtty_ioctl_get_region_info,
+	.get_region_info_caps = mtty_ioctl_get_region_info,
 	.bind_iommufd	= vfio_iommufd_emulated_bind,
 	.unbind_iommufd	= vfio_iommufd_emulated_unbind,
 	.attach_ioas	= vfio_iommufd_emulated_attach_ioas,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* [PATCH 22/22] vfio: Remove the get_region_info op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (20 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 21/22] vfio: Move the remaining drivers " Jason Gunthorpe
@ 2025-10-23 23:09 ` Jason Gunthorpe
  2025-11-03 10:52   ` Pranjal Shrivastava
  2025-10-24  0:11 ` ✗ Fi.CI.BUILD: failure for vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Patchwork
                   ` (2 subsequent siblings)
  24 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-10-23 23:09 UTC (permalink / raw)
  To: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

No driver uses it now, all are using get_region_info_caps().

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/vfio_main.c | 50 +++++++++++++++++-----------------------
 include/linux/vfio.h     |  2 --
 2 files changed, 21 insertions(+), 31 deletions(-)

diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index 82e7d79b1f9fe2..f911c1980c9420 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -1263,48 +1263,40 @@ static long vfio_get_region_info(struct vfio_device *device,
 				 struct vfio_region_info __user *arg)
 {
 	unsigned long minsz = offsetofend(struct vfio_region_info, offset);
+	struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
 	struct vfio_region_info info = {};
 	int ret;
 
+	if (unlikely(!device->ops->get_region_info_caps))
+		return -EINVAL;
+
 	if (copy_from_user(&info, arg, minsz))
 		return -EFAULT;
 	if (info.argsz < minsz)
 		return -EINVAL;
 
-	if (device->ops->get_region_info_caps) {
-		struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
+	ret = device->ops->get_region_info_caps(device, &info, &caps);
+	if (ret)
+		return ret;
 
-		ret = device->ops->get_region_info_caps(device, &info, &caps);
-		if (ret)
-			return ret;
-
-		if (caps.size) {
-			info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
-			if (info.argsz < sizeof(info) + caps.size) {
-				info.argsz = sizeof(info) + caps.size;
-				info.cap_offset = 0;
-			} else {
-				vfio_info_cap_shift(&caps, sizeof(info));
-				if (copy_to_user(arg + 1, caps.buf,
-						 caps.size)) {
-					kfree(caps.buf);
-					return -EFAULT;
-				}
-				info.cap_offset = sizeof(info);
+	if (caps.size) {
+		info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
+		if (info.argsz < sizeof(info) + caps.size) {
+			info.argsz = sizeof(info) + caps.size;
+			info.cap_offset = 0;
+		} else {
+			vfio_info_cap_shift(&caps, sizeof(info));
+			if (copy_to_user(arg + 1, caps.buf, caps.size)) {
+				kfree(caps.buf);
+				return -EFAULT;
 			}
-			kfree(caps.buf);
+			info.cap_offset = sizeof(info);
 		}
-
-		if (copy_to_user(arg, &info, minsz))
-			return -EFAULT;
-	} else if (device->ops->get_region_info) {
-		ret = device->ops->get_region_info(device, arg);
-		if (ret)
-			return ret;
-	} else {
-		return -EINVAL;
+		kfree(caps.buf);
 	}
 
+	if (copy_to_user(arg, &info, minsz))
+		return -EFAULT;
 	return 0;
 }
 
diff --git a/include/linux/vfio.h b/include/linux/vfio.h
index 6311ddc837701d..8e1ddb48b9b54e 100644
--- a/include/linux/vfio.h
+++ b/include/linux/vfio.h
@@ -133,8 +133,6 @@ 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	(*get_region_info_caps)(struct vfio_device *vdev,
 					struct vfio_region_info *info,
 					struct vfio_info_cap *caps);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 66+ messages in thread

* ✗ Fi.CI.BUILD: failure for vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (21 preceding siblings ...)
  2025-10-23 23:09 ` [PATCH 22/22] vfio: Remove the get_region_info op Jason Gunthorpe
@ 2025-10-24  0:11 ` Patchwork
  2025-10-28  7:10 ` [PATCH 00/22] " Tian, Kevin
  2025-11-03  9:53 ` Mostafa Saleh
  24 siblings, 0 replies; 66+ messages in thread
From: Patchwork @ 2025-10-24  0:11 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: intel-gfx

== Series Details ==

Series: vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op
URL   : https://patchwork.freedesktop.org/series/156452/
State : failure

== Summary ==

Error: patch https://patchwork.freedesktop.org/api/1.0/series/156452/revisions/1/mbox/ not applied
Applying: vfio: Provide a get_region_info op
Applying: vfio/hisi: Convert to the get_region_info op
Applying: vfio/virtio: Convert to the get_region_info op
Applying: vfio/nvgrace: Convert to the get_region_info op
Applying: vfio/pci: Fill in the missing get_region_info ops
Applying: vfio/mtty: Provide a get_region_info op
Applying: vfio/mdpy: Provide a get_region_info op
Applying: vfio/mbochs: Provide a get_region_info op
Applying: vfio/platform: Provide a get_region_info op
Applying: vfio/fsl: Provide a get_region_info op
Applying: vfio/cdx: Provide a get_region_info op
Applying: vfio/ccw: Provide a get_region_info op
Applying: vfio/gvt: Provide a get_region_info op
Using index info to reconstruct a base tree...
M	drivers/gpu/drm/i915/gvt/kvmgt.c
Falling back to patching base and 3-way merge...
Auto-merging drivers/gpu/drm/i915/gvt/kvmgt.c
CONFLICT (content): Merge conflict in drivers/gpu/drm/i915/gvt/kvmgt.c
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0013 vfio/gvt: Provide a get_region_info op
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Build failed, no error log produced



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 13/22] vfio/gvt: Provide a get_region_info op
  2025-10-23 23:09 ` [PATCH 13/22] vfio/gvt: " Jason Gunthorpe
@ 2025-10-24 10:12   ` Jani Nikula
  0 siblings, 0 replies; 66+ messages in thread
From: Jani Nikula @ 2025-10-24 10:12 UTC (permalink / raw)
  To: Jason Gunthorpe, Alexander Gordeev, David Airlie, Alex Williamson,
	Ankit Agrawal, Christian Borntraeger, Brett Creeley, dri-devel,
	Eric Auger, Eric Farman, Giovanni Cabiddu, Vasily Gorbik,
	Heiko Carstens, intel-gfx, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

On Thu, 23 Oct 2025, Jason Gunthorpe <jgg@nvidia.com> wrote:
> Move it out of intel_vgpu_ioctl() and re-indent it.

Not a huge deal, but this will conflict with 69b4d367fff6
("drm/i915/gvt: Simplify case switch in intel_vgpu_ioctl") in
drm-intel-next.

BR,
Jani.


>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/gpu/drm/i915/gvt/kvmgt.c | 301 +++++++++++++++----------------
>  1 file changed, 150 insertions(+), 151 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index 69830a5c49d3fd..6b47e33078eb52 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -1140,6 +1140,155 @@ static int intel_vgpu_set_irqs(struct intel_vgpu *vgpu, u32 flags,
>  	return func(vgpu, index, start, count, flags, data);
>  }
>  
> +static int intel_vgpu_get_region_info(struct vfio_device *vfio_dev,
> +				      struct vfio_region_info __user *arg)
> +{
> +	struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
> +	struct vfio_region_info_cap_sparse_mmap *sparse = NULL;
> +	struct intel_vgpu *vgpu = vfio_dev_to_vgpu(vfio_dev);
> +	struct vfio_region_info info;
> +	unsigned long minsz;
> +	int nr_areas = 1;
> +	int cap_type_id;
> +	unsigned int i;
> +	int ret;
> +
> +	minsz = offsetofend(struct vfio_region_info, offset);
> +
> +	if (copy_from_user(&info, arg, minsz))
> +		return -EFAULT;
> +
> +	if (info.argsz < minsz)
> +		return -EINVAL;
> +
> +	switch (info.index) {
> +	case VFIO_PCI_CONFIG_REGION_INDEX:
> +		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> +		info.size = vgpu->gvt->device_info.cfg_space_size;
> +		info.flags = VFIO_REGION_INFO_FLAG_READ |
> +			     VFIO_REGION_INFO_FLAG_WRITE;
> +		break;
> +	case VFIO_PCI_BAR0_REGION_INDEX:
> +		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> +		info.size = vgpu->cfg_space.bar[info.index].size;
> +		if (!info.size) {
> +			info.flags = 0;
> +			break;
> +		}
> +
> +		info.flags = VFIO_REGION_INFO_FLAG_READ |
> +			     VFIO_REGION_INFO_FLAG_WRITE;
> +		break;
> +	case VFIO_PCI_BAR1_REGION_INDEX:
> +		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> +		info.size = 0;
> +		info.flags = 0;
> +		break;
> +	case VFIO_PCI_BAR2_REGION_INDEX:
> +		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> +		info.flags = VFIO_REGION_INFO_FLAG_CAPS |
> +			     VFIO_REGION_INFO_FLAG_MMAP |
> +			     VFIO_REGION_INFO_FLAG_READ |
> +			     VFIO_REGION_INFO_FLAG_WRITE;
> +		info.size = gvt_aperture_sz(vgpu->gvt);
> +
> +		sparse = kzalloc(struct_size(sparse, areas, nr_areas),
> +				 GFP_KERNEL);
> +		if (!sparse)
> +			return -ENOMEM;
> +
> +		sparse->header.id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
> +		sparse->header.version = 1;
> +		sparse->nr_areas = nr_areas;
> +		cap_type_id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
> +		sparse->areas[0].offset =
> +			PAGE_ALIGN(vgpu_aperture_offset(vgpu));
> +		sparse->areas[0].size = vgpu_aperture_sz(vgpu);
> +		break;
> +
> +	case VFIO_PCI_BAR3_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
> +		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> +		info.size = 0;
> +		info.flags = 0;
> +
> +		gvt_dbg_core("get region info bar:%d\n", info.index);
> +		break;
> +
> +	case VFIO_PCI_ROM_REGION_INDEX:
> +	case VFIO_PCI_VGA_REGION_INDEX:
> +		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> +		info.size = 0;
> +		info.flags = 0;
> +
> +		gvt_dbg_core("get region info index:%d\n", info.index);
> +		break;
> +	default: {
> +		struct vfio_region_info_cap_type cap_type = {
> +			.header.id = VFIO_REGION_INFO_CAP_TYPE,
> +			.header.version = 1
> +		};
> +
> +		if (info.index >= VFIO_PCI_NUM_REGIONS + vgpu->num_regions)
> +			return -EINVAL;
> +		info.index = array_index_nospec(
> +			info.index, VFIO_PCI_NUM_REGIONS + vgpu->num_regions);
> +
> +		i = info.index - VFIO_PCI_NUM_REGIONS;
> +
> +		info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> +		info.size = vgpu->region[i].size;
> +		info.flags = vgpu->region[i].flags;
> +
> +		cap_type.type = vgpu->region[i].type;
> +		cap_type.subtype = vgpu->region[i].subtype;
> +
> +		ret = vfio_info_add_capability(&caps, &cap_type.header,
> +					       sizeof(cap_type));
> +		if (ret)
> +			return ret;
> +	}
> +	}
> +
> +	if ((info.flags & VFIO_REGION_INFO_FLAG_CAPS) && sparse) {
> +		switch (cap_type_id) {
> +		case VFIO_REGION_INFO_CAP_SPARSE_MMAP:
> +			ret = vfio_info_add_capability(
> +				&caps, &sparse->header,
> +				struct_size(sparse, areas, sparse->nr_areas));
> +			if (ret) {
> +				kfree(sparse);
> +				return ret;
> +			}
> +			break;
> +		default:
> +			kfree(sparse);
> +			return -EINVAL;
> +		}
> +	}
> +
> +	if (caps.size) {
> +		info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
> +		if (info.argsz < sizeof(info) + caps.size) {
> +			info.argsz = sizeof(info) + caps.size;
> +			info.cap_offset = 0;
> +		} else {
> +			vfio_info_cap_shift(&caps, sizeof(info));
> +			if (copy_to_user((void __user *)arg + sizeof(info),
> +					 caps.buf, caps.size)) {
> +				kfree(caps.buf);
> +				kfree(sparse);
> +				return -EFAULT;
> +			}
> +			info.cap_offset = sizeof(info);
> +		}
> +
> +		kfree(caps.buf);
> +	}
> +
> +	kfree(sparse);
> +	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
> +}
> +
>  static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,
>  			     unsigned long arg)
>  {
> @@ -1168,157 +1317,6 @@ static long intel_vgpu_ioctl(struct vfio_device *vfio_dev, unsigned int cmd,
>  		return copy_to_user((void __user *)arg, &info, minsz) ?
>  			-EFAULT : 0;
>  
> -	} else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
> -		struct vfio_region_info info;
> -		struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
> -		unsigned int i;
> -		int ret;
> -		struct vfio_region_info_cap_sparse_mmap *sparse = NULL;
> -		int nr_areas = 1;
> -		int cap_type_id;
> -
> -		minsz = offsetofend(struct vfio_region_info, offset);
> -
> -		if (copy_from_user(&info, (void __user *)arg, minsz))
> -			return -EFAULT;
> -
> -		if (info.argsz < minsz)
> -			return -EINVAL;
> -
> -		switch (info.index) {
> -		case VFIO_PCI_CONFIG_REGION_INDEX:
> -			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> -			info.size = vgpu->gvt->device_info.cfg_space_size;
> -			info.flags = VFIO_REGION_INFO_FLAG_READ |
> -				     VFIO_REGION_INFO_FLAG_WRITE;
> -			break;
> -		case VFIO_PCI_BAR0_REGION_INDEX:
> -			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> -			info.size = vgpu->cfg_space.bar[info.index].size;
> -			if (!info.size) {
> -				info.flags = 0;
> -				break;
> -			}
> -
> -			info.flags = VFIO_REGION_INFO_FLAG_READ |
> -				     VFIO_REGION_INFO_FLAG_WRITE;
> -			break;
> -		case VFIO_PCI_BAR1_REGION_INDEX:
> -			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> -			info.size = 0;
> -			info.flags = 0;
> -			break;
> -		case VFIO_PCI_BAR2_REGION_INDEX:
> -			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> -			info.flags = VFIO_REGION_INFO_FLAG_CAPS |
> -					VFIO_REGION_INFO_FLAG_MMAP |
> -					VFIO_REGION_INFO_FLAG_READ |
> -					VFIO_REGION_INFO_FLAG_WRITE;
> -			info.size = gvt_aperture_sz(vgpu->gvt);
> -
> -			sparse = kzalloc(struct_size(sparse, areas, nr_areas),
> -					 GFP_KERNEL);
> -			if (!sparse)
> -				return -ENOMEM;
> -
> -			sparse->header.id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
> -			sparse->header.version = 1;
> -			sparse->nr_areas = nr_areas;
> -			cap_type_id = VFIO_REGION_INFO_CAP_SPARSE_MMAP;
> -			sparse->areas[0].offset =
> -					PAGE_ALIGN(vgpu_aperture_offset(vgpu));
> -			sparse->areas[0].size = vgpu_aperture_sz(vgpu);
> -			break;
> -
> -		case VFIO_PCI_BAR3_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
> -			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> -			info.size = 0;
> -			info.flags = 0;
> -
> -			gvt_dbg_core("get region info bar:%d\n", info.index);
> -			break;
> -
> -		case VFIO_PCI_ROM_REGION_INDEX:
> -		case VFIO_PCI_VGA_REGION_INDEX:
> -			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> -			info.size = 0;
> -			info.flags = 0;
> -
> -			gvt_dbg_core("get region info index:%d\n", info.index);
> -			break;
> -		default:
> -			{
> -				struct vfio_region_info_cap_type cap_type = {
> -					.header.id = VFIO_REGION_INFO_CAP_TYPE,
> -					.header.version = 1 };
> -
> -				if (info.index >= VFIO_PCI_NUM_REGIONS +
> -						vgpu->num_regions)
> -					return -EINVAL;
> -				info.index =
> -					array_index_nospec(info.index,
> -							VFIO_PCI_NUM_REGIONS +
> -							vgpu->num_regions);
> -
> -				i = info.index - VFIO_PCI_NUM_REGIONS;
> -
> -				info.offset =
> -					VFIO_PCI_INDEX_TO_OFFSET(info.index);
> -				info.size = vgpu->region[i].size;
> -				info.flags = vgpu->region[i].flags;
> -
> -				cap_type.type = vgpu->region[i].type;
> -				cap_type.subtype = vgpu->region[i].subtype;
> -
> -				ret = vfio_info_add_capability(&caps,
> -							&cap_type.header,
> -							sizeof(cap_type));
> -				if (ret)
> -					return ret;
> -			}
> -		}
> -
> -		if ((info.flags & VFIO_REGION_INFO_FLAG_CAPS) && sparse) {
> -			switch (cap_type_id) {
> -			case VFIO_REGION_INFO_CAP_SPARSE_MMAP:
> -				ret = vfio_info_add_capability(&caps,
> -					&sparse->header,
> -					struct_size(sparse, areas,
> -						    sparse->nr_areas));
> -				if (ret) {
> -					kfree(sparse);
> -					return ret;
> -				}
> -				break;
> -			default:
> -				kfree(sparse);
> -				return -EINVAL;
> -			}
> -		}
> -
> -		if (caps.size) {
> -			info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
> -			if (info.argsz < sizeof(info) + caps.size) {
> -				info.argsz = sizeof(info) + caps.size;
> -				info.cap_offset = 0;
> -			} else {
> -				vfio_info_cap_shift(&caps, sizeof(info));
> -				if (copy_to_user((void __user *)arg +
> -						  sizeof(info), caps.buf,
> -						  caps.size)) {
> -					kfree(caps.buf);
> -					kfree(sparse);
> -					return -EFAULT;
> -				}
> -				info.cap_offset = sizeof(info);
> -			}
> -
> -			kfree(caps.buf);
> -		}
> -
> -		kfree(sparse);
> -		return copy_to_user((void __user *)arg, &info, minsz) ?
> -			-EFAULT : 0;
>  	} else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) {
>  		struct vfio_irq_info info;
>  
> @@ -1475,6 +1473,7 @@ static const struct vfio_device_ops intel_vgpu_dev_ops = {
>  	.write		= intel_vgpu_write,
>  	.mmap		= intel_vgpu_mmap,
>  	.ioctl		= intel_vgpu_ioctl,
> +	.get_region_info = intel_vgpu_get_region_info,
>  	.dma_unmap	= intel_vgpu_dma_unmap,
>  	.bind_iommufd	= vfio_iommufd_emulated_bind,
>  	.unbind_iommufd = vfio_iommufd_emulated_unbind,

-- 
Jani Nikula, Intel

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 02/22] vfio/hisi: Convert to the get_region_info op
  2025-10-23 23:09 ` [PATCH 02/22] vfio/hisi: Convert to the " Jason Gunthorpe
@ 2025-10-28  1:55   ` liulongfang
  2025-10-28  7:07     ` Tian, Kevin
  2025-11-03  6:06   ` Pranjal Shrivastava
  1 sibling, 1 reply; 66+ messages in thread
From: liulongfang @ 2025-10-28  1:55 UTC (permalink / raw)
  To: Jason Gunthorpe, Alexander Gordeev, David Airlie, Alex Williamson,
	Ankit Agrawal, Christian Borntraeger, Brett Creeley, dri-devel,
	Eric Auger, Eric Farman, Giovanni Cabiddu, Vasily Gorbik,
	Heiko Carstens, intel-gfx, Jani Nikula, Joonas Lahtinen,
	Kevin Tian, kvm, Kirti Wankhede, linux-s390, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

On 2025/10/24 7:09, Jason Gunthorpe wrote:
> Change the function signature of hisi_acc_vfio_pci_ioctl()
> and re-indent it.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c    | 57 +++++++++----------
>  1 file changed, 27 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> index fde33f54e99ec5..f06dcfcf09599f 100644
> --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> @@ -1324,43 +1324,39 @@ static ssize_t hisi_acc_vfio_pci_read(struct vfio_device *core_vdev,
>  	return vfio_pci_core_read(core_vdev, buf, new_count, ppos);
>  }
>  
> -static long hisi_acc_vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
> -				    unsigned long arg)
> +static int hisi_acc_vfio_get_region(struct vfio_device *core_vdev,
> +				    struct vfio_region_info __user *arg)
>  {
> -	if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
> -		struct vfio_pci_core_device *vdev =
> -			container_of(core_vdev, struct vfio_pci_core_device, vdev);
> -		struct pci_dev *pdev = vdev->pdev;
> -		struct vfio_region_info info;
> -		unsigned long minsz;
> +	struct vfio_pci_core_device *vdev =
> +		container_of(core_vdev, struct vfio_pci_core_device, vdev);
> +	struct pci_dev *pdev = vdev->pdev;
> +	struct vfio_region_info info;
> +	unsigned long minsz;
>  
> -		minsz = offsetofend(struct vfio_region_info, offset);
> +	minsz = offsetofend(struct vfio_region_info, offset);
>  
> -		if (copy_from_user(&info, (void __user *)arg, minsz))
> -			return -EFAULT;
> +	if (copy_from_user(&info, arg, minsz))
> +		return -EFAULT;
>  
> -		if (info.argsz < minsz)
> -			return -EINVAL;
> +	if (info.argsz < minsz)
> +		return -EINVAL;
>  
> -		if (info.index == VFIO_PCI_BAR2_REGION_INDEX) {
> -			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> +	if (info.index != VFIO_PCI_BAR2_REGION_INDEX)
> +		return vfio_pci_ioctl_get_region_info(core_vdev, arg);

Looking at your first patch from my driver implementation code, the vfio_pci_ioctl_get_region_info
function doesn't need to modify the first parameter; it can directly use vdev.

Thanks.
Longfang.

>  
> -			/*
> -			 * ACC VF dev BAR2 region consists of both functional
> -			 * register space and migration control register space.
> -			 * Report only the functional region to Guest.
> -			 */
> -			info.size = pci_resource_len(pdev, info.index) / 2;
> +	info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
>  
> -			info.flags = VFIO_REGION_INFO_FLAG_READ |
> -					VFIO_REGION_INFO_FLAG_WRITE |
> -					VFIO_REGION_INFO_FLAG_MMAP;
> +	/*
> +	 * ACC VF dev BAR2 region consists of both functional
> +	 * register space and migration control register space.
> +	 * Report only the functional region to Guest.
> +	 */
> +	info.size = pci_resource_len(pdev, info.index) / 2;
>  
> -			return copy_to_user((void __user *)arg, &info, minsz) ?
> -					    -EFAULT : 0;
> -		}
> -	}
> -	return vfio_pci_core_ioctl(core_vdev, cmd, arg);
> +	info.flags = VFIO_REGION_INFO_FLAG_READ | VFIO_REGION_INFO_FLAG_WRITE |
> +		     VFIO_REGION_INFO_FLAG_MMAP;
> +
> +	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
>  }
>  
>  static int hisi_acc_vf_debug_check(struct seq_file *seq, struct vfio_device *vdev)
> @@ -1557,7 +1553,8 @@ static const struct vfio_device_ops hisi_acc_vfio_pci_migrn_ops = {
>  	.release = vfio_pci_core_release_dev,
>  	.open_device = hisi_acc_vfio_pci_open_device,
>  	.close_device = hisi_acc_vfio_pci_close_device,
> -	.ioctl = hisi_acc_vfio_pci_ioctl,
> +	.ioctl = vfio_pci_core_ioctl,
> +	.get_region_info = hisi_acc_vfio_get_region,
>  	.device_feature = vfio_pci_core_ioctl_feature,
>  	.read = hisi_acc_vfio_pci_read,
>  	.write = hisi_acc_vfio_pci_write,
> 

^ permalink raw reply	[flat|nested] 66+ messages in thread

* RE: [PATCH 02/22] vfio/hisi: Convert to the get_region_info op
  2025-10-28  1:55   ` liulongfang
@ 2025-10-28  7:07     ` Tian, Kevin
  0 siblings, 0 replies; 66+ messages in thread
From: Tian, Kevin @ 2025-10-28  7:07 UTC (permalink / raw)
  To: liulongfang, Jason Gunthorpe, Alexander Gordeev, David Airlie,
	Alex Williamson, Ankit Agrawal, Christian Borntraeger,
	Brett Creeley, dri-devel@lists.freedesktop.org, Eric Auger,
	Eric Farman, Cabiddu, Giovanni, Vasily Gorbik, Heiko Carstens,
	intel-gfx@lists.freedesktop.org, Jani Nikula, Joonas Lahtinen,
	kvm@vger.kernel.org, Kirti Wankhede, linux-s390@vger.kernel.org,
	Matthew Rosato, Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter,
	Halil Pasic, Pranjal Shrivastava, qat-linux, Vivi, Rodrigo,
	Simona Vetter, Shameer Kolothum, Mostafa Saleh, Sven Schnelle,
	Tvrtko Ursulin, virtualization@lists.linux.dev, Vineeth Vijayan,
	Yishai Hadas, Zhenyu Wang, Zhi Wang
  Cc: patches@lists.linux.dev

> From: liulongfang <liulongfang@huawei.com>
> Sent: Tuesday, October 28, 2025 9:56 AM
> 
> On 2025/10/24 7:09, Jason Gunthorpe wrote:
> > +	if (info.argsz < minsz)
> > +		return -EINVAL;
> >
> > -		if (info.index == VFIO_PCI_BAR2_REGION_INDEX) {
> > -			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> > +	if (info.index != VFIO_PCI_BAR2_REGION_INDEX)
> > +		return vfio_pci_ioctl_get_region_info(core_vdev, arg);
> 
> Looking at your first patch from my driver implementation code, the
> vfio_pci_ioctl_get_region_info
> function doesn't need to modify the first parameter; it can directly use vdev.
> 

it is used by some drivers directly as callback in struct vfio_device_ops,
so the 1st parameter needs to be struct vfio_device.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* RE: [PATCH 18/22] vfio/ccw: Convert to get_region_info_caps
  2025-10-23 23:09 ` [PATCH 18/22] vfio/ccw: " Jason Gunthorpe
@ 2025-10-28  7:09   ` Tian, Kevin
  0 siblings, 0 replies; 66+ messages in thread
From: Tian, Kevin @ 2025-10-28  7:09 UTC (permalink / raw)
  To: Jason Gunthorpe, Alexander Gordeev, David Airlie, Alex Williamson,
	Ankit Agrawal, Christian Borntraeger, Brett Creeley,
	dri-devel@lists.freedesktop.org, Eric Auger, Eric Farman,
	Cabiddu, Giovanni, Vasily Gorbik, Heiko Carstens,
	intel-gfx@lists.freedesktop.org, Jani Nikula, Joonas Lahtinen,
	kvm@vger.kernel.org, Kirti Wankhede, linux-s390@vger.kernel.org,
	Longfang Liu, Matthew Rosato, Nikhil Agarwal, Nipun Gupta,
	Peter Oberparleiter, Halil Pasic, Pranjal Shrivastava, qat-linux,
	Vivi, Rodrigo, Simona Vetter, Shameer Kolothum, Mostafa Saleh,
	Sven Schnelle, Tvrtko Ursulin, virtualization@lists.linux.dev,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang
  Cc: patches@lists.linux.dev

> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Friday, October 24, 2025 7:10 AM
> 
> Remove the duplicate code and change info to a pointer.
> 

nit: in this specific patch 'info' is originally a pointer. 😊

^ permalink raw reply	[flat|nested] 66+ messages in thread

* RE: [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (22 preceding siblings ...)
  2025-10-24  0:11 ` ✗ Fi.CI.BUILD: failure for vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Patchwork
@ 2025-10-28  7:10 ` Tian, Kevin
  2025-11-03  9:53 ` Mostafa Saleh
  24 siblings, 0 replies; 66+ messages in thread
From: Tian, Kevin @ 2025-10-28  7:10 UTC (permalink / raw)
  To: Jason Gunthorpe, Alexander Gordeev, David Airlie, Alex Williamson,
	Ankit Agrawal, Christian Borntraeger, Brett Creeley,
	dri-devel@lists.freedesktop.org, Eric Auger, Eric Farman,
	Cabiddu, Giovanni, Vasily Gorbik, Heiko Carstens,
	intel-gfx@lists.freedesktop.org, Jani Nikula, Joonas Lahtinen,
	kvm@vger.kernel.org, Kirti Wankhede, linux-s390@vger.kernel.org,
	Longfang Liu, Matthew Rosato, Nikhil Agarwal, Nipun Gupta,
	Peter Oberparleiter, Halil Pasic, Pranjal Shrivastava, qat-linux,
	Vivi, Rodrigo, Simona Vetter, Shameer Kolothum, Mostafa Saleh,
	Sven Schnelle, Tvrtko Ursulin, virtualization@lists.linux.dev,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang
  Cc: patches@lists.linux.dev

> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Friday, October 24, 2025 7:09 AM
> 
> There is alot of duplicated code in the drivers for processing
> VFIO_DEVICE_GET_REGION_INFO. Introduce a new op get_region_info_caps()
> which provides a struct vfio_info_cap and handles the cap chain logic
> to write the caps back to userspace and remove all of this duplication
> from drivers.
> 
> This is done in two steps, the first is a largely mechanical introduction
> of the get_region_info(). These patches are best viewed with the diff
> option to ignore whitespace (-b) as most of the lines are re-indending
> things.
> 
> Then drivers are updated to remove the duplicate cap related code. Some
> drivers are converted to use vfio_info_add_capability() instead of open
> coding a version of it.
> 
> This is on github:
> https://github.com/jgunthorpe/linux/commits/vfio_get_region_info_op
> 
> Jason Gunthorpe (22):
>   vfio: Provide a get_region_info op
>   vfio/hisi: Convert to the get_region_info op
>   vfio/virtio: Convert to the get_region_info op
>   vfio/nvgrace: Convert to the get_region_info op
>   vfio/pci: Fill in the missing get_region_info ops
>   vfio/mtty: Provide a get_region_info op
>   vfio/mdpy: Provide a get_region_info op
>   vfio/mbochs: Provide a get_region_info op
>   vfio/platform: Provide a get_region_info op
>   vfio/fsl: Provide a get_region_info op
>   vfio/cdx: Provide a get_region_info op
>   vfio/ccw: Provide a get_region_info op
>   vfio/gvt: Provide a get_region_info op
>   vfio: Require drivers to implement get_region_info
>   vfio: Add get_region_info_caps op
>   vfio/mbochs: Convert mbochs to use vfio_info_add_capability()
>   vfio/gvt: Convert to get_region_info_caps
>   vfio/ccw: Convert to get_region_info_caps
>   vfio/pci: Convert all PCI drivers to get_region_info_caps
>   vfio/platform: Convert to get_region_info_caps
>   vfio: Move the remaining drivers to get_region_info_caps
>   vfio: Remove the get_region_info op
> 

for the entire series:

Reviewed-by: Kevin Tian <kevin.tian@intel.com>

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 19/22] vfio/pci: Convert all PCI drivers to get_region_info_caps
  2025-10-23 23:09 ` [PATCH 19/22] vfio/pci: Convert all PCI drivers " Jason Gunthorpe
@ 2025-10-28 17:08   ` Brett Creeley
  2025-11-03 10:25   ` Pranjal Shrivastava
  1 sibling, 0 replies; 66+ messages in thread
From: Brett Creeley @ 2025-10-28 17:08 UTC (permalink / raw)
  To: Jason Gunthorpe, Alexander Gordeev, David Airlie, Alex Williamson,
	Ankit Agrawal, Christian Borntraeger, Brett Creeley, dri-devel,
	Eric Auger, Eric Farman, Giovanni Cabiddu, Vasily Gorbik,
	Heiko Carstens, intel-gfx, Jani Nikula, Joonas Lahtinen,
	Kevin Tian, kvm, Kirti Wankhede, linux-s390, Longfang Liu,
	Matthew Rosato, Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter,
	Halil Pasic, Pranjal Shrivastava, qat-linux, Rodrigo Vivi,
	Simona Vetter, Shameer Kolothum, Mostafa Saleh, Sven Schnelle,
	Tvrtko Ursulin, virtualization, Vineeth Vijayan, Yishai Hadas,
	Zhenyu Wang, Zhi Wang
  Cc: patches



On 10/23/2025 4:09 PM, Jason Gunthorpe wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
> 
> 
> Since the core function signature changes it has to flow up to all
> drivers.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>   .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c    |  30 ++---
>   drivers/vfio/pci/mlx5/main.c                  |   2 +-
>   drivers/vfio/pci/nvgrace-gpu/main.c           |  51 ++-------
>   drivers/vfio/pci/pds/vfio_dev.c               |   2 +-
>   drivers/vfio/pci/qat/main.c                   |   2 +-
>   drivers/vfio/pci/vfio_pci.c                   |   2 +-
>   drivers/vfio/pci/vfio_pci_core.c              | 103 +++++++-----------
>   drivers/vfio/pci/virtio/common.h              |   3 +-
>   drivers/vfio/pci/virtio/legacy_io.c           |  26 ++---
>   drivers/vfio/pci/virtio/main.c                |   6 +-
>   include/linux/vfio_pci_core.h                 |   3 +-
>   11 files changed, 80 insertions(+), 150 deletions(-)
> 

<snip>

> diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c
> index 1946bc75d99b49..be103c74e96957 100644
> --- a/drivers/vfio/pci/pds/vfio_dev.c
> +++ b/drivers/vfio/pci/pds/vfio_dev.c
> @@ -195,7 +195,7 @@ static const struct vfio_device_ops pds_vfio_ops = {
>          .open_device = pds_vfio_open_device,
>          .close_device = pds_vfio_close_device,
>          .ioctl = vfio_pci_core_ioctl,
> -       .get_region_info = vfio_pci_ioctl_get_region_info,
> +       .get_region_info_caps = vfio_pci_ioctl_get_region_info,
>          .device_feature = vfio_pci_core_ioctl_feature,
>          .read = vfio_pci_core_read,
>          .write = vfio_pci_core_write,

LGTM. Thanks.

Reviewed-by: Brett Creeley <brett.creeley@amd.com>

<snip>

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 01/22] vfio: Provide a get_region_info op
  2025-10-23 23:09 ` [PATCH 01/22] vfio: Provide a get_region_info op Jason Gunthorpe
@ 2025-11-03  5:57   ` Pranjal Shrivastava
  2025-11-03 14:17   ` Eric Auger
  1 sibling, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  5:57 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:15PM -0300, 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
> the function signature to consolidate more code.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  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(-)
> 

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 02/22] vfio/hisi: Convert to the get_region_info op
  2025-10-23 23:09 ` [PATCH 02/22] vfio/hisi: Convert to the " Jason Gunthorpe
  2025-10-28  1:55   ` liulongfang
@ 2025-11-03  6:06   ` Pranjal Shrivastava
  2025-11-03 13:31     ` Jason Gunthorpe
  2025-11-07  1:29     ` liulongfang
  1 sibling, 2 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  6:06 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:16PM -0300, Jason Gunthorpe wrote:
> Change the function signature of hisi_acc_vfio_pci_ioctl()
> and re-indent it.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c    | 57 +++++++++----------
>  1 file changed, 27 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> index fde33f54e99ec5..f06dcfcf09599f 100644
> --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
> @@ -1324,43 +1324,39 @@ static ssize_t hisi_acc_vfio_pci_read(struct vfio_device *core_vdev,
>  	return vfio_pci_core_read(core_vdev, buf, new_count, ppos);
>  }
>  
> -static long hisi_acc_vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
> -				    unsigned long arg)
> +static int hisi_acc_vfio_get_region(struct vfio_device *core_vdev,
> +				    struct vfio_region_info __user *arg)
>  {
> -	if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
> -		struct vfio_pci_core_device *vdev =
> -			container_of(core_vdev, struct vfio_pci_core_device, vdev);
> -		struct pci_dev *pdev = vdev->pdev;
> -		struct vfio_region_info info;
> -		unsigned long minsz;
> +	struct vfio_pci_core_device *vdev =
> +		container_of(core_vdev, struct vfio_pci_core_device, vdev);
> +	struct pci_dev *pdev = vdev->pdev;
> +	struct vfio_region_info info;
> +	unsigned long minsz;
>  
> -		minsz = offsetofend(struct vfio_region_info, offset);
> +	minsz = offsetofend(struct vfio_region_info, offset);
>  
> -		if (copy_from_user(&info, (void __user *)arg, minsz))
> -			return -EFAULT;
> +	if (copy_from_user(&info, arg, minsz))
> +		return -EFAULT;
>  
> -		if (info.argsz < minsz)
> -			return -EINVAL;
> +	if (info.argsz < minsz)
> +		return -EINVAL;
>  
> -		if (info.index == VFIO_PCI_BAR2_REGION_INDEX) {
> -			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> +	if (info.index != VFIO_PCI_BAR2_REGION_INDEX)
> +		return vfio_pci_ioctl_get_region_info(core_vdev, arg);
>  

I'm curious to learn the reason for flipping polarity here? (apart from
readability).

> -			/*
> -			 * ACC VF dev BAR2 region consists of both functional
> -			 * register space and migration control register space.
> -			 * Report only the functional region to Guest.
> -			 */
> -			info.size = pci_resource_len(pdev, info.index) / 2;
> +	info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
>  
> -			info.flags = VFIO_REGION_INFO_FLAG_READ |
> -					VFIO_REGION_INFO_FLAG_WRITE |
> -					VFIO_REGION_INFO_FLAG_MMAP;
> +	/*
> +	 * ACC VF dev BAR2 region consists of both functional
> +	 * register space and migration control register space.
> +	 * Report only the functional region to Guest.
> +	 */
> +	info.size = pci_resource_len(pdev, info.index) / 2;
>  
> -			return copy_to_user((void __user *)arg, &info, minsz) ?
> -					    -EFAULT : 0;
> -		}
> -	}
> -	return vfio_pci_core_ioctl(core_vdev, cmd, arg);
> +	info.flags = VFIO_REGION_INFO_FLAG_READ | VFIO_REGION_INFO_FLAG_WRITE |
> +		     VFIO_REGION_INFO_FLAG_MMAP;
> +
> +	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
>  }
>  
>  static int hisi_acc_vf_debug_check(struct seq_file *seq, struct vfio_device *vdev)
> @@ -1557,7 +1553,8 @@ static const struct vfio_device_ops hisi_acc_vfio_pci_migrn_ops = {
>  	.release = vfio_pci_core_release_dev,
>  	.open_device = hisi_acc_vfio_pci_open_device,
>  	.close_device = hisi_acc_vfio_pci_close_device,
> -	.ioctl = hisi_acc_vfio_pci_ioctl,
> +	.ioctl = vfio_pci_core_ioctl,
> +	.get_region_info = hisi_acc_vfio_get_region,
>  	.device_feature = vfio_pci_core_ioctl_feature,
>  	.read = hisi_acc_vfio_pci_read,
>  	.write = hisi_acc_vfio_pci_write,

The change seems to maintain original functionality and LGTM.
Acked-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 03/22] vfio/virtio: Convert to the get_region_info op
  2025-10-23 23:09 ` [PATCH 03/22] vfio/virtio: " Jason Gunthorpe
@ 2025-11-03  6:21   ` Pranjal Shrivastava
  0 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  6:21 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:17PM -0300, Jason Gunthorpe wrote:
> Remove virtiovf_vfio_pci_core_ioctl() and change the signature of
> virtiovf_pci_ioctl_get_region_info().
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/pci/virtio/common.h    |  4 +---
>  drivers/vfio/pci/virtio/legacy_io.c | 20 ++++----------------
>  drivers/vfio/pci/virtio/main.c      |  3 ++-
>  3 files changed, 7 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/vfio/pci/virtio/common.h b/drivers/vfio/pci/virtio/common.h
> index c7d7e27af386e9..a10f2d92cb6238 100644
> --- a/drivers/vfio/pci/virtio/common.h
> +++ b/drivers/vfio/pci/virtio/common.h
> @@ -109,10 +109,8 @@ void virtiovf_migration_reset_done(struct pci_dev *pdev);
>

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 04/22] vfio/nvgrace: Convert to the get_region_info op
  2025-10-23 23:09 ` [PATCH 04/22] vfio/nvgrace: " Jason Gunthorpe
@ 2025-11-03  6:41   ` Pranjal Shrivastava
  2025-11-03 13:35     ` Ankit Agrawal
  0 siblings, 1 reply; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  6:41 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:18PM -0300, Jason Gunthorpe wrote:
> Change the signature of nvgrace_gpu_ioctl_get_region_info()
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/pci/nvgrace-gpu/main.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 05/22] vfio/pci: Fill in the missing get_region_info ops
  2025-10-23 23:09 ` [PATCH 05/22] vfio/pci: Fill in the missing get_region_info ops Jason Gunthorpe
@ 2025-11-03  6:43   ` Pranjal Shrivastava
  0 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  6:43 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:19PM -0300, Jason Gunthorpe wrote:
> Now that every variant driver provides a get_region_info op remove the
> ioctl based dispatch from vfio_pci_core_ioctl().
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 1 +
>  drivers/vfio/pci/mlx5/main.c                   | 1 +
>  drivers/vfio/pci/nvgrace-gpu/main.c            | 1 +
>  drivers/vfio/pci/pds/vfio_dev.c                | 1 +
>  drivers/vfio/pci/qat/main.c                    | 1 +
>  drivers/vfio/pci/vfio_pci.c                    | 1 +
>  drivers/vfio/pci/vfio_pci_core.c               | 2 --
>  drivers/vfio/pci/virtio/main.c                 | 2 ++
>  8 files changed, 8 insertions(+), 2 deletions(-)
> 

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 09/22] vfio/platform: Provide a get_region_info op
  2025-10-23 23:09 ` [PATCH 09/22] vfio/platform: " Jason Gunthorpe
@ 2025-11-03  7:14   ` Pranjal Shrivastava
  2025-11-03  9:53   ` Mostafa Saleh
  2025-11-03 13:59   ` Eric Auger
  2 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  7:14 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:23PM -0300, Jason Gunthorpe wrote:
> Move it out of vfio_platform_ioctl() and re-indent it. Add it to all
> platform drivers.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/platform/vfio_amba.c             |  1 +
>  drivers/vfio/platform/vfio_platform.c         |  1 +
>  drivers/vfio/platform/vfio_platform_common.c  | 50 +++++++++++--------
>  drivers/vfio/platform/vfio_platform_private.h |  2 +
>  4 files changed, 32 insertions(+), 22 deletions(-)
> 

Moving the GET_REGION_INFO logic to vfio_platform_common.c and exporting
it for both the vfio-amba and vfio-platform drivers to use in the new op
looks correct. LGTM

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 06/22] vfio/mtty: Provide a get_region_info op
  2025-10-23 23:09 ` [PATCH 06/22] vfio/mtty: Provide a get_region_info op Jason Gunthorpe
@ 2025-11-03  7:17   ` Pranjal Shrivastava
  0 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  7:17 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:20PM -0300, Jason Gunthorpe wrote:
> Move it out of mtty_ioctl() and re-indent it.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  samples/vfio-mdev/mtty.c | 53 ++++++++++++++++++++++------------------
>  1 file changed, 29 insertions(+), 24 deletions(-)
> 

Acked-by: Pranjal Shrivastava <praan@google.com>

-Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 07/22] vfio/mdpy: Provide a get_region_info op
  2025-10-23 23:09 ` [PATCH 07/22] vfio/mdpy: " Jason Gunthorpe
@ 2025-11-03  7:18   ` Pranjal Shrivastava
  0 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  7:18 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:21PM -0300, Jason Gunthorpe wrote:
> Move it out of mdpy_ioctl() and re-indent it.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  samples/vfio-mdev/mdpy.c | 53 ++++++++++++++++++++++------------------
>  1 file changed, 29 insertions(+), 24 deletions(-)
> 

Acked-by: Pranjal Shrivastava <praan@google.com>

- Praan


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 08/22] vfio/mbochs: Provide a get_region_info op
  2025-10-23 23:09 ` [PATCH 08/22] vfio/mbochs: " Jason Gunthorpe
@ 2025-11-03  7:19   ` Pranjal Shrivastava
  0 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  7:19 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:22PM -0300, Jason Gunthorpe wrote:
> Move it out of mbochs_ioctl() and re-indent it.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  samples/vfio-mdev/mbochs.c | 56 +++++++++++++++++++++-----------------
>  1 file changed, 31 insertions(+), 25 deletions(-)
> 

Acked-by: Pranjal Shrivastava <praan@google.com>

- Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 10/22] vfio/fsl: Provide a get_region_info op
  2025-10-23 23:09 ` [PATCH 10/22] vfio/fsl: " Jason Gunthorpe
@ 2025-11-03  7:30   ` Pranjal Shrivastava
  0 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  7:30 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:24PM -0300, Jason Gunthorpe wrote:
> Move it out of vfio_fsl_mc_ioctl() and re-indent it.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/fsl-mc/vfio_fsl_mc.c | 55 +++++++++++++++++--------------
>  1 file changed, 31 insertions(+), 24 deletions(-)
> 

Acked-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 11/22] vfio/cdx: Provide a get_region_info op
  2025-10-23 23:09 ` [PATCH 11/22] vfio/cdx: " Jason Gunthorpe
@ 2025-11-03  7:31   ` Pranjal Shrivastava
  0 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  7:31 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:25PM -0300, Jason Gunthorpe wrote:
> Change the signature of vfio_cdx_ioctl_get_region_info() and hook it to
> the op.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/cdx/main.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 14/22] vfio: Require drivers to implement get_region_info
  2025-10-23 23:09 ` [PATCH 14/22] vfio: Require drivers to implement get_region_info Jason Gunthorpe
@ 2025-11-03  7:39   ` Pranjal Shrivastava
  2025-11-05 20:48     ` Alex Williamson
  2025-11-03  9:55   ` Mostafa Saleh
  1 sibling, 1 reply; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03  7:39 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:28PM -0300, Jason Gunthorpe wrote:
> Remove the fallback through the ioctl callback, no drivers use this now.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/vfio_main.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> index a390163ce706c4..f056e82ba35075 100644
> --- a/drivers/vfio/vfio_main.c
> +++ b/drivers/vfio/vfio_main.c
> @@ -1297,13 +1297,13 @@ static long vfio_device_fops_unl_ioctl(struct file *filep,
>  		break;
>  
>  	case VFIO_DEVICE_GET_REGION_INFO:
> -		if (!device->ops->get_region_info)
> -			goto ioctl_fallback;
> -		ret = device->ops->get_region_info(device, uptr);
> +		if (unlikely(!device->ops->get_region_info))
> +			ret = -EINVAL;

Nit: Let's also add a warn/err log here highliting that the device
doesn't populate the get_region_info op?

> +		else
> +			ret = device->ops->get_region_info(device, uptr);
>  		break;
>  
>  	default:
> -ioctl_fallback:
>  		if (unlikely(!device->ops->ioctl))
>  			ret = -EINVAL;
>  		else

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op
  2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
                   ` (23 preceding siblings ...)
  2025-10-28  7:10 ` [PATCH 00/22] " Tian, Kevin
@ 2025-11-03  9:53 ` Mostafa Saleh
  2025-11-05 20:58   ` Alex Williamson
  24 siblings, 1 reply; 66+ messages in thread
From: Mostafa Saleh @ 2025-11-03  9:53 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:14PM -0300, Jason Gunthorpe wrote:
> There is alot of duplicated code in the drivers for processing
> VFIO_DEVICE_GET_REGION_INFO. Introduce a new op get_region_info_caps()
> which provides a struct vfio_info_cap and handles the cap chain logic
> to write the caps back to userspace and remove all of this duplication
> from drivers.
> 
> This is done in two steps, the first is a largely mechanical introduction
> of the get_region_info(). These patches are best viewed with the diff
> option to ignore whitespace (-b) as most of the lines are re-indending
> things.
> 
> Then drivers are updated to remove the duplicate cap related code. Some
> drivers are converted to use vfio_info_add_capability() instead of open
> coding a version of it.

The series as a whole looks good.
However, I got confused walking through it as almost all non-PCI drivers
had to transition to get_region_info then get_region_info_caps then
removing get_region_info completely from core code after introducing
it in this series.

IMO, the series should start with just consolidating PCI based implementation
and then add get_region_info_caps for all drivers at the end.
Anyway, no really strong opinion as the final outcome makes sense.

Thanks,
Mostafa

> 
> This is on github: https://github.com/jgunthorpe/linux/commits/vfio_get_region_info_op
> 
> Jason Gunthorpe (22):
>   vfio: Provide a get_region_info op
>   vfio/hisi: Convert to the get_region_info op
>   vfio/virtio: Convert to the get_region_info op
>   vfio/nvgrace: Convert to the get_region_info op
>   vfio/pci: Fill in the missing get_region_info ops
>   vfio/mtty: Provide a get_region_info op
>   vfio/mdpy: Provide a get_region_info op
>   vfio/mbochs: Provide a get_region_info op
>   vfio/platform: Provide a get_region_info op
>   vfio/fsl: Provide a get_region_info op
>   vfio/cdx: Provide a get_region_info op
>   vfio/ccw: Provide a get_region_info op
>   vfio/gvt: Provide a get_region_info op
>   vfio: Require drivers to implement get_region_info
>   vfio: Add get_region_info_caps op
>   vfio/mbochs: Convert mbochs to use vfio_info_add_capability()
>   vfio/gvt: Convert to get_region_info_caps
>   vfio/ccw: Convert to get_region_info_caps
>   vfio/pci: Convert all PCI drivers to get_region_info_caps
>   vfio/platform: Convert to get_region_info_caps
>   vfio: Move the remaining drivers to get_region_info_caps
>   vfio: Remove the get_region_info op
> 
>  drivers/gpu/drm/i915/gvt/kvmgt.c              | 272 ++++++++----------
>  drivers/s390/cio/vfio_ccw_ops.c               |  45 +--
>  drivers/vfio/cdx/main.c                       |  29 +-
>  drivers/vfio/fsl-mc/vfio_fsl_mc.c             |  43 ++-
>  .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c    |  54 ++--
>  drivers/vfio/pci/mlx5/main.c                  |   1 +
>  drivers/vfio/pci/nvgrace-gpu/main.c           |  53 +---
>  drivers/vfio/pci/pds/vfio_dev.c               |   1 +
>  drivers/vfio/pci/qat/main.c                   |   1 +
>  drivers/vfio/pci/vfio_pci.c                   |   1 +
>  drivers/vfio/pci/vfio_pci_core.c              | 110 +++----
>  drivers/vfio/pci/virtio/common.h              |   5 +-
>  drivers/vfio/pci/virtio/legacy_io.c           |  38 +--
>  drivers/vfio/pci/virtio/main.c                |   5 +-
>  drivers/vfio/platform/vfio_amba.c             |   1 +
>  drivers/vfio/platform/vfio_platform.c         |   1 +
>  drivers/vfio/platform/vfio_platform_common.c  |  40 ++-
>  drivers/vfio/platform/vfio_platform_private.h |   3 +
>  drivers/vfio/vfio_main.c                      |  45 +++
>  include/linux/vfio.h                          |   4 +
>  include/linux/vfio_pci_core.h                 |   3 +
>  samples/vfio-mdev/mbochs.c                    |  71 ++---
>  samples/vfio-mdev/mdpy.c                      |  34 +--
>  samples/vfio-mdev/mtty.c                      |  33 +--
>  24 files changed, 363 insertions(+), 530 deletions(-)
> 
> 
> base-commit: 211ddde0823f1442e4ad052a2f30f050145ccada
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 09/22] vfio/platform: Provide a get_region_info op
  2025-10-23 23:09 ` [PATCH 09/22] vfio/platform: " Jason Gunthorpe
  2025-11-03  7:14   ` Pranjal Shrivastava
@ 2025-11-03  9:53   ` Mostafa Saleh
  2025-11-03 13:59   ` Eric Auger
  2 siblings, 0 replies; 66+ messages in thread
From: Mostafa Saleh @ 2025-11-03  9:53 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:23PM -0300, Jason Gunthorpe wrote:
> Move it out of vfio_platform_ioctl() and re-indent it. Add it to all
> platform drivers.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Mostafa Saleh <smostafa@google.com>

Thanks,
Mostafa

> ---
>  drivers/vfio/platform/vfio_amba.c             |  1 +
>  drivers/vfio/platform/vfio_platform.c         |  1 +
>  drivers/vfio/platform/vfio_platform_common.c  | 50 +++++++++++--------
>  drivers/vfio/platform/vfio_platform_private.h |  2 +
>  4 files changed, 32 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/vfio/platform/vfio_amba.c b/drivers/vfio/platform/vfio_amba.c
> index 9f5c527baa8a36..d600deaf23b6d7 100644
> --- a/drivers/vfio/platform/vfio_amba.c
> +++ b/drivers/vfio/platform/vfio_amba.c
> @@ -115,6 +115,7 @@ static const struct vfio_device_ops vfio_amba_ops = {
>  	.open_device	= vfio_platform_open_device,
>  	.close_device	= vfio_platform_close_device,
>  	.ioctl		= vfio_platform_ioctl,
> +	.get_region_info = vfio_platform_ioctl_get_region_info,
>  	.read		= vfio_platform_read,
>  	.write		= vfio_platform_write,
>  	.mmap		= vfio_platform_mmap,
> diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c
> index 512533501eb7f3..0e85c914b65105 100644
> --- a/drivers/vfio/platform/vfio_platform.c
> +++ b/drivers/vfio/platform/vfio_platform.c
> @@ -101,6 +101,7 @@ static const struct vfio_device_ops vfio_platform_ops = {
>  	.open_device	= vfio_platform_open_device,
>  	.close_device	= vfio_platform_close_device,
>  	.ioctl		= vfio_platform_ioctl,
> +	.get_region_info = vfio_platform_ioctl_get_region_info,
>  	.read		= vfio_platform_read,
>  	.write		= vfio_platform_write,
>  	.mmap		= vfio_platform_mmap,
> diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
> index 3bf1043cd7957c..3ebd50fb78fbb7 100644
> --- a/drivers/vfio/platform/vfio_platform_common.c
> +++ b/drivers/vfio/platform/vfio_platform_common.c
> @@ -272,6 +272,34 @@ int vfio_platform_open_device(struct vfio_device *core_vdev)
>  }
>  EXPORT_SYMBOL_GPL(vfio_platform_open_device);
>  
> +int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
> +					struct vfio_region_info __user *arg)
> +{
> +	struct vfio_platform_device *vdev =
> +		container_of(core_vdev, struct vfio_platform_device, vdev);
> +	struct vfio_region_info info;
> +	unsigned long minsz;
> +
> +	minsz = offsetofend(struct vfio_region_info, offset);
> +
> +	if (copy_from_user(&info, arg, minsz))
> +		return -EFAULT;
> +
> +	if (info.argsz < minsz)
> +		return -EINVAL;
> +
> +	if (info.index >= vdev->num_regions)
> +		return -EINVAL;
> +
> +	/* map offset to the physical address  */
> +	info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
> +	info.size = vdev->regions[info.index].size;
> +	info.flags = vdev->regions[info.index].flags;
> +
> +	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
> +}
> +EXPORT_SYMBOL_GPL(vfio_platform_ioctl_get_region_info);
> +
>  long vfio_platform_ioctl(struct vfio_device *core_vdev,
>  			 unsigned int cmd, unsigned long arg)
>  {
> @@ -300,28 +328,6 @@ long vfio_platform_ioctl(struct vfio_device *core_vdev,
>  		return copy_to_user((void __user *)arg, &info, minsz) ?
>  			-EFAULT : 0;
>  
> -	} else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
> -		struct vfio_region_info info;
> -
> -		minsz = offsetofend(struct vfio_region_info, offset);
> -
> -		if (copy_from_user(&info, (void __user *)arg, minsz))
> -			return -EFAULT;
> -
> -		if (info.argsz < minsz)
> -			return -EINVAL;
> -
> -		if (info.index >= vdev->num_regions)
> -			return -EINVAL;
> -
> -		/* map offset to the physical address  */
> -		info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
> -		info.size = vdev->regions[info.index].size;
> -		info.flags = vdev->regions[info.index].flags;
> -
> -		return copy_to_user((void __user *)arg, &info, minsz) ?
> -			-EFAULT : 0;
> -
>  	} else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) {
>  		struct vfio_irq_info info;
>  
> diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h
> index 8d8fab51684909..a6008320e77bae 100644
> --- a/drivers/vfio/platform/vfio_platform_private.h
> +++ b/drivers/vfio/platform/vfio_platform_private.h
> @@ -85,6 +85,8 @@ int vfio_platform_open_device(struct vfio_device *core_vdev);
>  void vfio_platform_close_device(struct vfio_device *core_vdev);
>  long vfio_platform_ioctl(struct vfio_device *core_vdev,
>  			 unsigned int cmd, unsigned long arg);
> +int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
> +					struct vfio_region_info __user *arg);
>  ssize_t vfio_platform_read(struct vfio_device *core_vdev,
>  			   char __user *buf, size_t count,
>  			   loff_t *ppos);
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 14/22] vfio: Require drivers to implement get_region_info
  2025-10-23 23:09 ` [PATCH 14/22] vfio: Require drivers to implement get_region_info Jason Gunthorpe
  2025-11-03  7:39   ` Pranjal Shrivastava
@ 2025-11-03  9:55   ` Mostafa Saleh
  1 sibling, 0 replies; 66+ messages in thread
From: Mostafa Saleh @ 2025-11-03  9:55 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:28PM -0300, Jason Gunthorpe wrote:
> Remove the fallback through the ioctl callback, no drivers use this now.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Mostafa Saleh <smostafa@google.com>

Thanks,
Mostafa

> ---
>  drivers/vfio/vfio_main.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> index a390163ce706c4..f056e82ba35075 100644
> --- a/drivers/vfio/vfio_main.c
> +++ b/drivers/vfio/vfio_main.c
> @@ -1297,13 +1297,13 @@ static long vfio_device_fops_unl_ioctl(struct file *filep,
>  		break;
>  
>  	case VFIO_DEVICE_GET_REGION_INFO:
> -		if (!device->ops->get_region_info)
> -			goto ioctl_fallback;
> -		ret = device->ops->get_region_info(device, uptr);
> +		if (unlikely(!device->ops->get_region_info))
> +			ret = -EINVAL;
> +		else
> +			ret = device->ops->get_region_info(device, uptr);
>  		break;
>  
>  	default:
> -ioctl_fallback:
>  		if (unlikely(!device->ops->ioctl))
>  			ret = -EINVAL;
>  		else
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 20/22] vfio/platform: Convert to get_region_info_caps
  2025-10-23 23:09 ` [PATCH 20/22] vfio/platform: Convert " Jason Gunthorpe
@ 2025-11-03  9:57   ` Mostafa Saleh
  2025-11-03 10:21   ` Pranjal Shrivastava
  2025-11-03 14:20   ` Eric Auger
  2 siblings, 0 replies; 66+ messages in thread
From: Mostafa Saleh @ 2025-11-03  9:57 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:34PM -0300, Jason Gunthorpe wrote:
> Remove the duplicate code and change info to a pointer. caps are not used.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Mostafa Saleh <smostafa@google.com>

Also, I smoke tested this on Qemu.

Thanks,
Mostafa

> ---
>  drivers/vfio/platform/vfio_amba.c             |  2 +-
>  drivers/vfio/platform/vfio_platform.c         |  2 +-
>  drivers/vfio/platform/vfio_platform_common.c  | 24 ++++++-------------
>  drivers/vfio/platform/vfio_platform_private.h |  3 ++-
>  4 files changed, 11 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/vfio/platform/vfio_amba.c b/drivers/vfio/platform/vfio_amba.c
> index d600deaf23b6d7..fa754f203b2dfc 100644
> --- a/drivers/vfio/platform/vfio_amba.c
> +++ b/drivers/vfio/platform/vfio_amba.c
> @@ -115,7 +115,7 @@ static const struct vfio_device_ops vfio_amba_ops = {
>  	.open_device	= vfio_platform_open_device,
>  	.close_device	= vfio_platform_close_device,
>  	.ioctl		= vfio_platform_ioctl,
> -	.get_region_info = vfio_platform_ioctl_get_region_info,
> +	.get_region_info_caps = vfio_platform_ioctl_get_region_info,
>  	.read		= vfio_platform_read,
>  	.write		= vfio_platform_write,
>  	.mmap		= vfio_platform_mmap,
> diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c
> index 0e85c914b65105..a4d3ace3e02dda 100644
> --- a/drivers/vfio/platform/vfio_platform.c
> +++ b/drivers/vfio/platform/vfio_platform.c
> @@ -101,7 +101,7 @@ static const struct vfio_device_ops vfio_platform_ops = {
>  	.open_device	= vfio_platform_open_device,
>  	.close_device	= vfio_platform_close_device,
>  	.ioctl		= vfio_platform_ioctl,
> -	.get_region_info = vfio_platform_ioctl_get_region_info,
> +	.get_region_info_caps = vfio_platform_ioctl_get_region_info,
>  	.read		= vfio_platform_read,
>  	.write		= vfio_platform_write,
>  	.mmap		= vfio_platform_mmap,
> diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
> index 3ebd50fb78fbb7..c2990b7e900fa5 100644
> --- a/drivers/vfio/platform/vfio_platform_common.c
> +++ b/drivers/vfio/platform/vfio_platform_common.c
> @@ -273,30 +273,20 @@ int vfio_platform_open_device(struct vfio_device *core_vdev)
>  EXPORT_SYMBOL_GPL(vfio_platform_open_device);
>  
>  int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
> -					struct vfio_region_info __user *arg)
> +					struct vfio_region_info *info,
> +					struct vfio_info_cap *caps)
>  {
>  	struct vfio_platform_device *vdev =
>  		container_of(core_vdev, struct vfio_platform_device, vdev);
> -	struct vfio_region_info info;
> -	unsigned long minsz;
>  
> -	minsz = offsetofend(struct vfio_region_info, offset);
> -
> -	if (copy_from_user(&info, arg, minsz))
> -		return -EFAULT;
> -
> -	if (info.argsz < minsz)
> -		return -EINVAL;
> -
> -	if (info.index >= vdev->num_regions)
> +	if (info->index >= vdev->num_regions)
>  		return -EINVAL;
>  
>  	/* map offset to the physical address  */
> -	info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
> -	info.size = vdev->regions[info.index].size;
> -	info.flags = vdev->regions[info.index].flags;
> -
> -	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
> +	info->offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info->index);
> +	info->size = vdev->regions[info->index].size;
> +	info->flags = vdev->regions[info->index].flags;
> +	return 0;
>  }
>  EXPORT_SYMBOL_GPL(vfio_platform_ioctl_get_region_info);
>  
> diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h
> index a6008320e77bae..05084212a76eb6 100644
> --- a/drivers/vfio/platform/vfio_platform_private.h
> +++ b/drivers/vfio/platform/vfio_platform_private.h
> @@ -86,7 +86,8 @@ void vfio_platform_close_device(struct vfio_device *core_vdev);
>  long vfio_platform_ioctl(struct vfio_device *core_vdev,
>  			 unsigned int cmd, unsigned long arg);
>  int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
> -					struct vfio_region_info __user *arg);
> +					struct vfio_region_info *info,
> +					struct vfio_info_cap *caps);
>  ssize_t vfio_platform_read(struct vfio_device *core_vdev,
>  			   char __user *buf, size_t count,
>  			   loff_t *ppos);
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 15/22] vfio: Add get_region_info_caps op
  2025-10-23 23:09 ` [PATCH 15/22] vfio: Add get_region_info_caps op Jason Gunthorpe
@ 2025-11-03 10:16   ` Pranjal Shrivastava
  2025-11-03 11:03     ` Pranjal Shrivastava
  0 siblings, 1 reply; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03 10:16 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:29PM -0300, Jason Gunthorpe wrote:
> This op does the copy to/from user for the info and can return back
> a cap chain through a vfio_info_cap * result.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/vfio_main.c | 54 +++++++++++++++++++++++++++++++++++++---
>  include/linux/vfio.h     |  4 +++
>  2 files changed, 54 insertions(+), 4 deletions(-)

The newly added vfio_get_region_info seems to pull-in common boilerplate
code (like copy_from_user, arg size validation) into the core code,
removing redundancy across all other vfio drivers. LGTM.

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 20/22] vfio/platform: Convert to get_region_info_caps
  2025-10-23 23:09 ` [PATCH 20/22] vfio/platform: Convert " Jason Gunthorpe
  2025-11-03  9:57   ` Mostafa Saleh
@ 2025-11-03 10:21   ` Pranjal Shrivastava
  2025-11-03 14:20   ` Eric Auger
  2 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03 10:21 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:34PM -0300, Jason Gunthorpe wrote:
> Remove the duplicate code and change info to a pointer. caps are not used.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/platform/vfio_amba.c             |  2 +-
>  drivers/vfio/platform/vfio_platform.c         |  2 +-
>  drivers/vfio/platform/vfio_platform_common.c  | 24 ++++++-------------
>  drivers/vfio/platform/vfio_platform_private.h |  3 ++-
>  4 files changed, 11 insertions(+), 20 deletions(-)
>

Removes all the boilerplate (copy_from_user, copy_to_user, argsz
validation) and lets the VFIO core handle it.

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks!
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 19/22] vfio/pci: Convert all PCI drivers to get_region_info_caps
  2025-10-23 23:09 ` [PATCH 19/22] vfio/pci: Convert all PCI drivers " Jason Gunthorpe
  2025-10-28 17:08   ` Brett Creeley
@ 2025-11-03 10:25   ` Pranjal Shrivastava
  1 sibling, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03 10:25 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:33PM -0300, Jason Gunthorpe wrote:
> Since the core function signature changes it has to flow up to all
> drivers.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c    |  30 ++---
>  drivers/vfio/pci/mlx5/main.c                  |   2 +-
>  drivers/vfio/pci/nvgrace-gpu/main.c           |  51 ++-------
>  drivers/vfio/pci/pds/vfio_dev.c               |   2 +-
>  drivers/vfio/pci/qat/main.c                   |   2 +-
>  drivers/vfio/pci/vfio_pci.c                   |   2 +-
>  drivers/vfio/pci/vfio_pci_core.c              | 103 +++++++-----------
>  drivers/vfio/pci/virtio/common.h              |   3 +-
>  drivers/vfio/pci/virtio/legacy_io.c           |  26 ++---
>  drivers/vfio/pci/virtio/main.c                |   6 +-
>  include/linux/vfio_pci_core.h                 |   3 +-
>  11 files changed, 80 insertions(+), 150 deletions(-)
> 

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 21/22] vfio: Move the remaining drivers to get_region_info_caps
  2025-10-23 23:09 ` [PATCH 21/22] vfio: Move the remaining drivers " Jason Gunthorpe
@ 2025-11-03 10:29   ` Pranjal Shrivastava
  0 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03 10:29 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:35PM -0300, Jason Gunthorpe wrote:
> Remove the duplicate code and change info to a pointer. caps are not used.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/cdx/main.c           | 24 +++++++------------
>  drivers/vfio/fsl-mc/vfio_fsl_mc.c | 26 ++++++---------------
>  samples/vfio-mdev/mdpy.c          | 39 ++++++-------------------------
>  samples/vfio-mdev/mtty.c          | 38 +++++-------------------------
>  4 files changed, 28 insertions(+), 99 deletions(-)
> 

Acked-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 22/22] vfio: Remove the get_region_info op
  2025-10-23 23:09 ` [PATCH 22/22] vfio: Remove the get_region_info op Jason Gunthorpe
@ 2025-11-03 10:52   ` Pranjal Shrivastava
  2025-11-07  0:43     ` Jason Gunthorpe
  0 siblings, 1 reply; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03 10:52 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Thu, Oct 23, 2025 at 08:09:36PM -0300, Jason Gunthorpe wrote:
> No driver uses it now, all are using get_region_info_caps().
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/vfio_main.c | 50 +++++++++++++++++-----------------------
>  include/linux/vfio.h     |  2 --
>  2 files changed, 21 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> index 82e7d79b1f9fe2..f911c1980c9420 100644
> --- a/drivers/vfio/vfio_main.c
> +++ b/drivers/vfio/vfio_main.c
> @@ -1263,48 +1263,40 @@ static long vfio_get_region_info(struct vfio_device *device,
>  				 struct vfio_region_info __user *arg)
>  {
>  	unsigned long minsz = offsetofend(struct vfio_region_info, offset);
> +	struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
>  	struct vfio_region_info info = {};
>  	int ret;
>  
> +	if (unlikely(!device->ops->get_region_info_caps))
> +		return -EINVAL;
> +
>  	if (copy_from_user(&info, arg, minsz))
>  		return -EFAULT;
>  	if (info.argsz < minsz)
>  		return -EINVAL;
>  
> -	if (device->ops->get_region_info_caps) {
> -		struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
> +	ret = device->ops->get_region_info_caps(device, &info, &caps);
> +	if (ret)
> +		return ret;

Shall we kfree(caps.buf); before returning?

> -		ret = device->ops->get_region_info_caps(device, &info, &caps);
> -		if (ret)
> -			return ret;
> -
> -		if (caps.size) {
> -			info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
> -			if (info.argsz < sizeof(info) + caps.size) {
> -				info.argsz = sizeof(info) + caps.size;
> -				info.cap_offset = 0;
> -			} else {
> -				vfio_info_cap_shift(&caps, sizeof(info));
> -				if (copy_to_user(arg + 1, caps.buf,
> -						 caps.size)) {
> -					kfree(caps.buf);
> -					return -EFAULT;
> -				}
> -				info.cap_offset = sizeof(info);
> +	if (caps.size) {
> +		info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
> +		if (info.argsz < sizeof(info) + caps.size) {
> +			info.argsz = sizeof(info) + caps.size;
> +			info.cap_offset = 0;
> +		} else {
> +			vfio_info_cap_shift(&caps, sizeof(info));
> +			if (copy_to_user(arg + 1, caps.buf, caps.size)) {
> +				kfree(caps.buf);
> +				return -EFAULT;
>  			}
> -			kfree(caps.buf);
> +			info.cap_offset = sizeof(info);
>  		}
> -
> -		if (copy_to_user(arg, &info, minsz))
> -			return -EFAULT;
> -	} else if (device->ops->get_region_info) {
> -		ret = device->ops->get_region_info(device, arg);
> -		if (ret)
> -			return ret;
> -	} else {
> -		return -EINVAL;
> +		kfree(caps.buf);
>  	}
>  
> +	if (copy_to_user(arg, &info, minsz))
> +		return -EFAULT;
>  	return 0;
>  }
>  
> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
> index 6311ddc837701d..8e1ddb48b9b54e 100644
> --- a/include/linux/vfio.h
> +++ b/include/linux/vfio.h
> @@ -133,8 +133,6 @@ 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	(*get_region_info_caps)(struct vfio_device *vdev,
>  					struct vfio_region_info *info,
>  					struct vfio_info_cap *caps);

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 15/22] vfio: Add get_region_info_caps op
  2025-11-03 10:16   ` Pranjal Shrivastava
@ 2025-11-03 11:03     ` Pranjal Shrivastava
  0 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-03 11:03 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Mon, Nov 03, 2025 at 10:16:56AM +0000, Pranjal Shrivastava wrote:
> On Thu, Oct 23, 2025 at 08:09:29PM -0300, Jason Gunthorpe wrote:
> > This op does the copy to/from user for the info and can return back
> > a cap chain through a vfio_info_cap * result.
> > 
> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > ---
> >  drivers/vfio/vfio_main.c | 54 +++++++++++++++++++++++++++++++++++++---
> >  include/linux/vfio.h     |  4 +++
> >  2 files changed, 54 insertions(+), 4 deletions(-)
> 
> The newly added vfio_get_region_info seems to pull-in common boilerplate
> code (like copy_from_user, arg size validation) into the core code,
> removing redundancy across all other vfio drivers. LGTM.

I missed one thing in this patch (luckily caught it in patch 22):

> diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> index f056e82ba35075..82e7d79b1f9fe2 100644
> --- a/drivers/vfio/vfio_main.c
> +++ b/drivers/vfio/vfio_main.c
> @@ -1259,6 +1259,55 @@ static int vfio_ioctl_device_feature(struct vfio_device *device,
>  	}
>  }
>  
> +static long vfio_get_region_info(struct vfio_device *device,
> +				 struct vfio_region_info __user *arg)
> +{
> +	unsigned long minsz = offsetofend(struct vfio_region_info, offset);
> +	struct vfio_region_info info = {};
> +	int ret;
> +
> +	if (copy_from_user(&info, arg, minsz))
> +		return -EFAULT;
> +	if (info.argsz < minsz)
> +		return -EINVAL;
> +
> +	if (device->ops->get_region_info_caps) {
> +		struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
> +
> +		ret = device->ops->get_region_info_caps(device, &info, &caps);
> +		if (ret)
> +			return ret;

device->ops->get_region_info_caps (via vfio_info_add_capability) can
allocate caps.buf and then return an error for a different reason. The
if (ret) check returns early and the kfree(caps.buf) on the success path
is never reached.

Should we add kfree(caps.buf) to the error path here?
This keeps the allocation and cleanup logic centralized in the core code

Let's either write comment saying that the get_region_info_caps op is required
to free caps.buf before returning error OR add a kfree(caps.buf) here.

> +
> +		if (caps.size) {
> +			info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
> +			if (info.argsz < sizeof(info) + caps.size) {
> +				info.argsz = sizeof(info) + caps.size;
> +				info.cap_offset = 0;
> +			} else {
> +				vfio_info_cap_shift(&caps, sizeof(info));
> +				if (copy_to_user(arg + 1, caps.buf,
> +						 caps.size)) {
> +					kfree(caps.buf);
> +					return -EFAULT;
> +				}
> +				info.cap_offset = sizeof(info);
> +			}
> +			kfree(caps.buf);
> +		}
> +
> +		if (copy_to_user(arg, &info, minsz))
> +			return -EFAULT;
> +	} else if (device->ops->get_region_info) {
> +		ret = device->ops->get_region_info(device, arg);
> +		if (ret)
> +			return ret;

With the above comment addressed,

Reviewed-by: Pranjal Shrivastava <praan@google.com>

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 02/22] vfio/hisi: Convert to the get_region_info op
  2025-11-03  6:06   ` Pranjal Shrivastava
@ 2025-11-03 13:31     ` Jason Gunthorpe
  2025-11-07  1:29     ` liulongfang
  1 sibling, 0 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-11-03 13:31 UTC (permalink / raw)
  To: Pranjal Shrivastava
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Mon, Nov 03, 2025 at 06:06:07AM +0000, Pranjal Shrivastava wrote:
> > -		if (info.index == VFIO_PCI_BAR2_REGION_INDEX) {
> > -			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
> > +	if (info.index != VFIO_PCI_BAR2_REGION_INDEX)
> > +		return vfio_pci_ioctl_get_region_info(core_vdev, arg);
> >  
> 
> I'm curious to learn the reason for flipping polarity here? (apart from
> readability).

Yeah, readability

Jason

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 04/22] vfio/nvgrace: Convert to the get_region_info op
  2025-11-03  6:41   ` Pranjal Shrivastava
@ 2025-11-03 13:35     ` Ankit Agrawal
  0 siblings, 0 replies; 66+ messages in thread
From: Ankit Agrawal @ 2025-11-03 13:35 UTC (permalink / raw)
  To: Pranjal Shrivastava, Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson,
	Christian Borntraeger, Brett Creeley,
	dri-devel@lists.freedesktop.org, Eric Auger, Eric Farman,
	Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx@lists.freedesktop.org, Jani Nikula, Joonas Lahtinen,
	Kevin Tian, kvm@vger.kernel.org, Kirti Wankhede,
	linux-s390@vger.kernel.org, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux@intel.com, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization@lists.linux.dev, Vineeth Vijayan, Yishai Hadas,
	Zhenyu Wang, Zhi Wang, patches@lists.linux.dev

>> Change the signature of nvgrace_gpu_ioctl_get_region_info()
>>
>> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
>> ---
>>  drivers/vfio/pci/nvgrace-gpu/main.c | 15 ++++++---------
>>  1 file changed, 6 insertions(+), 9 deletions(-)
>
>
> Reviewed-by: Pranjal Shrivastava <praan@google.com>

Reviewed-by: Ankit Agrawal <ankita@nvidia.com>

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 09/22] vfio/platform: Provide a get_region_info op
  2025-10-23 23:09 ` [PATCH 09/22] vfio/platform: " Jason Gunthorpe
  2025-11-03  7:14   ` Pranjal Shrivastava
  2025-11-03  9:53   ` Mostafa Saleh
@ 2025-11-03 13:59   ` Eric Auger
  2025-11-03 14:27     ` Jason Gunthorpe
  2 siblings, 1 reply; 66+ messages in thread
From: Eric Auger @ 2025-11-03 13:59 UTC (permalink / raw)
  To: Jason Gunthorpe, Alexander Gordeev, David Airlie, Alex Williamson,
	Ankit Agrawal, Christian Borntraeger, Brett Creeley, dri-devel,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Hi Jason,

On 10/24/25 1:09 AM, Jason Gunthorpe wrote:
> Move it out of vfio_platform_ioctl() and re-indent it. Add it to all
> platform drivers.
>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/platform/vfio_amba.c             |  1 +
>  drivers/vfio/platform/vfio_platform.c         |  1 +
>  drivers/vfio/platform/vfio_platform_common.c  | 50 +++++++++++--------
>  drivers/vfio/platform/vfio_platform_private.h |  2 +
>  4 files changed, 32 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/vfio/platform/vfio_amba.c b/drivers/vfio/platform/vfio_amba.c
> index 9f5c527baa8a36..d600deaf23b6d7 100644
> --- a/drivers/vfio/platform/vfio_amba.c
> +++ b/drivers/vfio/platform/vfio_amba.c
> @@ -115,6 +115,7 @@ static const struct vfio_device_ops vfio_amba_ops = {
>  	.open_device	= vfio_platform_open_device,
>  	.close_device	= vfio_platform_close_device,
>  	.ioctl		= vfio_platform_ioctl,
> +	.get_region_info = vfio_platform_ioctl_get_region_info,
Any rationale behind why using _ioctl naming in some drivers and not in
some others?

>  	.read		= vfio_platform_read,
>  	.write		= vfio_platform_write,
>  	.mmap		= vfio_platform_mmap,
> diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c
> index 512533501eb7f3..0e85c914b65105 100644
> --- a/drivers/vfio/platform/vfio_platform.c
> +++ b/drivers/vfio/platform/vfio_platform.c
> @@ -101,6 +101,7 @@ static const struct vfio_device_ops vfio_platform_ops = {
>  	.open_device	= vfio_platform_open_device,
>  	.close_device	= vfio_platform_close_device,
>  	.ioctl		= vfio_platform_ioctl,
> +	.get_region_info = vfio_platform_ioctl_get_region_info,
>  	.read		= vfio_platform_read,
>  	.write		= vfio_platform_write,
>  	.mmap		= vfio_platform_mmap,
> diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
> index 3bf1043cd7957c..3ebd50fb78fbb7 100644
> --- a/drivers/vfio/platform/vfio_platform_common.c
> +++ b/drivers/vfio/platform/vfio_platform_common.c
> @@ -272,6 +272,34 @@ int vfio_platform_open_device(struct vfio_device *core_vdev)
>  }
>  EXPORT_SYMBOL_GPL(vfio_platform_open_device);
>  
> +int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
> +					struct vfio_region_info __user *arg)
> +{
> +	struct vfio_platform_device *vdev =
> +		container_of(core_vdev, struct vfio_platform_device, vdev);
> +	struct vfio_region_info info;
> +	unsigned long minsz;
> +
> +	minsz = offsetofend(struct vfio_region_info, offset);
> +
> +	if (copy_from_user(&info, arg, minsz))
> +		return -EFAULT;
> +
> +	if (info.argsz < minsz)
> +		return -EINVAL;
> +
> +	if (info.index >= vdev->num_regions)
> +		return -EINVAL;
> +
> +	/* map offset to the physical address  */
> +	info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
> +	info.size = vdev->regions[info.index].size;
> +	info.flags = vdev->regions[info.index].flags;
> +
> +	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
> +}
> +EXPORT_SYMBOL_GPL(vfio_platform_ioctl_get_region_info);
> +
>  long vfio_platform_ioctl(struct vfio_device *core_vdev,
>  			 unsigned int cmd, unsigned long arg)
>  {
> @@ -300,28 +328,6 @@ long vfio_platform_ioctl(struct vfio_device *core_vdev,
>  		return copy_to_user((void __user *)arg, &info, minsz) ?
>  			-EFAULT : 0;
>  
> -	} else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
> -		struct vfio_region_info info;
> -
> -		minsz = offsetofend(struct vfio_region_info, offset);
> -
> -		if (copy_from_user(&info, (void __user *)arg, minsz))
> -			return -EFAULT;
> -
> -		if (info.argsz < minsz)
> -			return -EINVAL;
> -
> -		if (info.index >= vdev->num_regions)
> -			return -EINVAL;
> -
> -		/* map offset to the physical address  */
> -		info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
> -		info.size = vdev->regions[info.index].size;
> -		info.flags = vdev->regions[info.index].flags;
> -
> -		return copy_to_user((void __user *)arg, &info, minsz) ?
> -			-EFAULT : 0;
> -
>  	} else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) {
>  		struct vfio_irq_info info;
>  
> diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h
> index 8d8fab51684909..a6008320e77bae 100644
> --- a/drivers/vfio/platform/vfio_platform_private.h
> +++ b/drivers/vfio/platform/vfio_platform_private.h
> @@ -85,6 +85,8 @@ int vfio_platform_open_device(struct vfio_device *core_vdev);
>  void vfio_platform_close_device(struct vfio_device *core_vdev);
>  long vfio_platform_ioctl(struct vfio_device *core_vdev,
>  			 unsigned int cmd, unsigned long arg);
> +int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
> +					struct vfio_region_info __user *arg);
>  ssize_t vfio_platform_read(struct vfio_device *core_vdev,
>  			   char __user *buf, size_t count,
>  			   loff_t *ppos);
Besides Reviewed-by: Eric Auger <eric.auger@redhat.com>

Thanks

Eric


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 01/22] vfio: Provide a get_region_info op
  2025-10-23 23:09 ` [PATCH 01/22] vfio: Provide a get_region_info op Jason Gunthorpe
  2025-11-03  5:57   ` Pranjal Shrivastava
@ 2025-11-03 14:17   ` Eric Auger
  1 sibling, 0 replies; 66+ messages in thread
From: Eric Auger @ 2025-11-03 14:17 UTC (permalink / raw)
  To: Jason Gunthorpe, Alexander Gordeev, David Airlie, Alex Williamson,
	Ankit Agrawal, Christian Borntraeger, Brett Creeley, dri-devel,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

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 <jgg@nvidia.com>
> ---
>  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,


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 20/22] vfio/platform: Convert to get_region_info_caps
  2025-10-23 23:09 ` [PATCH 20/22] vfio/platform: Convert " Jason Gunthorpe
  2025-11-03  9:57   ` Mostafa Saleh
  2025-11-03 10:21   ` Pranjal Shrivastava
@ 2025-11-03 14:20   ` Eric Auger
  2025-11-07  1:05     ` Jason Gunthorpe
  2 siblings, 1 reply; 66+ messages in thread
From: Eric Auger @ 2025-11-03 14:20 UTC (permalink / raw)
  To: Jason Gunthorpe, Alexander Gordeev, David Airlie, Alex Williamson,
	Ankit Agrawal, Christian Borntraeger, Brett Creeley, dri-devel,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang
  Cc: patches

Hi Jason,

On 10/24/25 1:09 AM, Jason Gunthorpe wrote:
> Remove the duplicate code and change info to a pointer. caps are not used.
>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/platform/vfio_amba.c             |  2 +-
>  drivers/vfio/platform/vfio_platform.c         |  2 +-
>  drivers/vfio/platform/vfio_platform_common.c  | 24 ++++++-------------
>  drivers/vfio/platform/vfio_platform_private.h |  3 ++-
>  4 files changed, 11 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/vfio/platform/vfio_amba.c b/drivers/vfio/platform/vfio_amba.c
> index d600deaf23b6d7..fa754f203b2dfc 100644
> --- a/drivers/vfio/platform/vfio_amba.c
> +++ b/drivers/vfio/platform/vfio_amba.c
> @@ -115,7 +115,7 @@ static const struct vfio_device_ops vfio_amba_ops = {
>  	.open_device	= vfio_platform_open_device,
>  	.close_device	= vfio_platform_close_device,
>  	.ioctl		= vfio_platform_ioctl,
> -	.get_region_info = vfio_platform_ioctl_get_region_info,
> +	.get_region_info_caps = vfio_platform_ioctl_get_region_info,
This would be nicer if called vfio_platform_get_region_info_caps I think
>  	.read		= vfio_platform_read,
>  	.write		= vfio_platform_write,
>  	.mmap		= vfio_platform_mmap,
> diff --git a/drivers/vfio/platform/vfio_platform.c b/drivers/vfio/platform/vfio_platform.c
> index 0e85c914b65105..a4d3ace3e02dda 100644
> --- a/drivers/vfio/platform/vfio_platform.c
> +++ b/drivers/vfio/platform/vfio_platform.c
> @@ -101,7 +101,7 @@ static const struct vfio_device_ops vfio_platform_ops = {
>  	.open_device	= vfio_platform_open_device,
>  	.close_device	= vfio_platform_close_device,
>  	.ioctl		= vfio_platform_ioctl,
> -	.get_region_info = vfio_platform_ioctl_get_region_info,
> +	.get_region_info_caps = vfio_platform_ioctl_get_region_info,
>  	.read		= vfio_platform_read,
>  	.write		= vfio_platform_write,
>  	.mmap		= vfio_platform_mmap,
> diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
> index 3ebd50fb78fbb7..c2990b7e900fa5 100644
> --- a/drivers/vfio/platform/vfio_platform_common.c
> +++ b/drivers/vfio/platform/vfio_platform_common.c
> @@ -273,30 +273,20 @@ int vfio_platform_open_device(struct vfio_device *core_vdev)
>  EXPORT_SYMBOL_GPL(vfio_platform_open_device);
>  
>  int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
> -					struct vfio_region_info __user *arg)
> +					struct vfio_region_info *info,
> +					struct vfio_info_cap *caps)
>  {
>  	struct vfio_platform_device *vdev =
>  		container_of(core_vdev, struct vfio_platform_device, vdev);
> -	struct vfio_region_info info;
> -	unsigned long minsz;
>  
> -	minsz = offsetofend(struct vfio_region_info, offset);
> -
> -	if (copy_from_user(&info, arg, minsz))
> -		return -EFAULT;
> -
> -	if (info.argsz < minsz)
> -		return -EINVAL;
> -
> -	if (info.index >= vdev->num_regions)
> +	if (info->index >= vdev->num_regions)
>  		return -EINVAL;
>  
>  	/* map offset to the physical address  */
> -	info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
> -	info.size = vdev->regions[info.index].size;
> -	info.flags = vdev->regions[info.index].flags;
> -
> -	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
> +	info->offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info->index);
> +	info->size = vdev->regions[info->index].size;
> +	info->flags = vdev->regions[info->index].flags;
> +	return 0;
>  }
>  EXPORT_SYMBOL_GPL(vfio_platform_ioctl_get_region_info);
>  
> diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/platform/vfio_platform_private.h
> index a6008320e77bae..05084212a76eb6 100644
> --- a/drivers/vfio/platform/vfio_platform_private.h
> +++ b/drivers/vfio/platform/vfio_platform_private.h
> @@ -86,7 +86,8 @@ void vfio_platform_close_device(struct vfio_device *core_vdev);
>  long vfio_platform_ioctl(struct vfio_device *core_vdev,
>  			 unsigned int cmd, unsigned long arg);
>  int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev,
> -					struct vfio_region_info __user *arg);
> +					struct vfio_region_info *info,
> +					struct vfio_info_cap *caps);
>  ssize_t vfio_platform_read(struct vfio_device *core_vdev,
>  			   char __user *buf, size_t count,
>  			   loff_t *ppos);
Thanks

Eric


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 09/22] vfio/platform: Provide a get_region_info op
  2025-11-03 13:59   ` Eric Auger
@ 2025-11-03 14:27     ` Jason Gunthorpe
  0 siblings, 0 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-11-03 14:27 UTC (permalink / raw)
  To: Eric Auger
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Farman,
	Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens, intel-gfx,
	Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm, Kirti Wankhede,
	linux-s390, Longfang Liu, Matthew Rosato, Nikhil Agarwal,
	Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang, patches

On Mon, Nov 03, 2025 at 02:59:29PM +0100, Eric Auger wrote:
> Hi Jason,
> 
> On 10/24/25 1:09 AM, Jason Gunthorpe wrote:
> > Move it out of vfio_platform_ioctl() and re-indent it. Add it to all
> > platform drivers.
> >
> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > ---
> >  drivers/vfio/platform/vfio_amba.c             |  1 +
> >  drivers/vfio/platform/vfio_platform.c         |  1 +
> >  drivers/vfio/platform/vfio_platform_common.c  | 50 +++++++++++--------
> >  drivers/vfio/platform/vfio_platform_private.h |  2 +
> >  4 files changed, 32 insertions(+), 22 deletions(-)
> >
> > diff --git a/drivers/vfio/platform/vfio_amba.c b/drivers/vfio/platform/vfio_amba.c
> > index 9f5c527baa8a36..d600deaf23b6d7 100644
> > --- a/drivers/vfio/platform/vfio_amba.c
> > +++ b/drivers/vfio/platform/vfio_amba.c
> > @@ -115,6 +115,7 @@ static const struct vfio_device_ops vfio_amba_ops = {
> >  	.open_device	= vfio_platform_open_device,
> >  	.close_device	= vfio_platform_close_device,
> >  	.ioctl		= vfio_platform_ioctl,
> > +	.get_region_info = vfio_platform_ioctl_get_region_info,

> Any rationale behind why using _ioctl naming in some drivers and not in
> some others?

No, I was making changes sort of in line to the code that was already
there.. The _ioctl_ came from PCI where I had labeled all the sub
functions that broke out of the ioctl function with _ioctl_ to make it
clear they were part of those system calls.

I guess these can have _ioctl_ added in:

drivers/gpu/drm/i915/gvt/kvmgt.c:       .get_region_info_caps = intel_vgpu_get_region_info,
drivers/s390/cio/vfio_ccw_ops.c:        .get_region_info_caps = vfio_ccw_mdev_get_region_info,
drivers/vfio/fsl-mc/vfio_fsl_mc.c:      .get_region_info_caps = vfio_fsl_mc_get_region_info,
drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c: .get_region_info_caps = hisi_acc_vfio_get_region,
samples/vfio-mdev/mbochs.c:     .get_region_info_caps = mbochs_get_region_info,

drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c: .get_region_info_caps = vfio_pci_ioctl_get_region_info,
drivers/vfio/pci/mlx5/main.c:   .get_region_info_caps = vfio_pci_ioctl_get_region_info,
drivers/vfio/pci/nvgrace-gpu/main.c:    .get_region_info_caps = nvgrace_gpu_ioctl_get_region_info,
drivers/vfio/pci/nvgrace-gpu/main.c:    .get_region_info_caps = vfio_pci_ioctl_get_region_info,
drivers/vfio/pci/pds/vfio_dev.c:        .get_region_info_caps = vfio_pci_ioctl_get_region_info,
drivers/vfio/cdx/main.c:        .get_region_info_caps = vfio_cdx_ioctl_get_region_info,
drivers/vfio/pci/qat/main.c:    .get_region_info_caps = vfio_pci_ioctl_get_region_info,
drivers/vfio/pci/vfio_pci.c:    .get_region_info_caps = vfio_pci_ioctl_get_region_info,
drivers/vfio/pci/virtio/main.c: .get_region_info_caps = vfio_pci_ioctl_get_region_info,
drivers/vfio/pci/virtio/main.c: .get_region_info_caps = virtiovf_pci_ioctl_get_region_info,
drivers/vfio/pci/virtio/main.c: .get_region_info_caps = vfio_pci_ioctl_get_region_info,
drivers/vfio/platform/vfio_amba.c:      .get_region_info_caps = vfio_platform_ioctl_get_region_info,
drivers/vfio/platform/vfio_platform.c:  .get_region_info_caps = vfio_platform_ioctl_get_region_info,
samples/vfio-mdev/mdpy.c:       .get_region_info_caps = mdpy_ioctl_get_region_info,
samples/vfio-mdev/mtty.c:       .get_region_info_caps = mtty_ioctl_get_region_info,

Thanks,
Jason

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 14/22] vfio: Require drivers to implement get_region_info
  2025-11-03  7:39   ` Pranjal Shrivastava
@ 2025-11-05 20:48     ` Alex Williamson
  2025-11-05 20:56       ` Jason Gunthorpe
  0 siblings, 1 reply; 66+ messages in thread
From: Alex Williamson @ 2025-11-05 20:48 UTC (permalink / raw)
  To: Pranjal Shrivastava
  Cc: Jason Gunthorpe, Alexander Gordeev, David Airlie, Alex Williamson,
	Ankit Agrawal, Christian Borntraeger, Brett Creeley, dri-devel,
	Eric Auger, Eric Farman, Giovanni Cabiddu, Vasily Gorbik,
	Heiko Carstens, intel-gfx, Jani Nikula, Joonas Lahtinen,
	Kevin Tian, kvm, Kirti Wankhede, linux-s390, Longfang Liu,
	Matthew Rosato, Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter,
	Halil Pasic, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang, patches

On Mon, 3 Nov 2025 07:39:37 +0000
Pranjal Shrivastava <praan@google.com> wrote:

> On Thu, Oct 23, 2025 at 08:09:28PM -0300, Jason Gunthorpe wrote:
> > Remove the fallback through the ioctl callback, no drivers use this now.
> > 
> > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > ---
> >  drivers/vfio/vfio_main.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> > index a390163ce706c4..f056e82ba35075 100644
> > --- a/drivers/vfio/vfio_main.c
> > +++ b/drivers/vfio/vfio_main.c
> > @@ -1297,13 +1297,13 @@ static long vfio_device_fops_unl_ioctl(struct file *filep,
> >  		break;
> >  
> >  	case VFIO_DEVICE_GET_REGION_INFO:
> > -		if (!device->ops->get_region_info)
> > -			goto ioctl_fallback;
> > -		ret = device->ops->get_region_info(device, uptr);
> > +		if (unlikely(!device->ops->get_region_info))
> > +			ret = -EINVAL;  

Nit, typically I would have expected a success oriented flow, ie.

		if (likely(device->ops->get_region_info))
			ret = device->ops->get_region_info(device, uptr);
		else
			ret = -EINVAL;

But it goes away in the next patch, so *shrug*.

> 
> Nit: Let's also add a warn/err log here highliting that the device
> doesn't populate the get_region_info op?

Are devices required to implement regions?  If so, it'd be more
appropriate to fail the device registration in __vfio_register_dev()
for the missing op than wait for an ioctl.  However, here in the device
agnostic layer of vfio, I think the answer leans more towards no, we
could theoretically have a device with no regions.  We also want to be
careful not to introduce a WARN_ON that's user trigger'able.  Thanks,

Alex

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 14/22] vfio: Require drivers to implement get_region_info
  2025-11-05 20:48     ` Alex Williamson
@ 2025-11-05 20:56       ` Jason Gunthorpe
  2025-11-05 21:19         ` Pranjal Shrivastava
  0 siblings, 1 reply; 66+ messages in thread
From: Jason Gunthorpe @ 2025-11-05 20:56 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Pranjal Shrivastava, Alexander Gordeev, David Airlie,
	Alex Williamson, Ankit Agrawal, Christian Borntraeger,
	Brett Creeley, dri-devel, Eric Auger, Eric Farman,
	Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens, intel-gfx,
	Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm, Kirti Wankhede,
	linux-s390, Longfang Liu, Matthew Rosato, Nikhil Agarwal,
	Nipun Gupta, Peter Oberparleiter, Halil Pasic, qat-linux,
	Rodrigo Vivi, Simona Vetter, Shameer Kolothum, Mostafa Saleh,
	Sven Schnelle, Tvrtko Ursulin, virtualization, Vineeth Vijayan,
	Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Wed, Nov 05, 2025 at 01:48:29PM -0700, Alex Williamson wrote:
> On Mon, 3 Nov 2025 07:39:37 +0000
> Pranjal Shrivastava <praan@google.com> wrote:
> 
> > On Thu, Oct 23, 2025 at 08:09:28PM -0300, Jason Gunthorpe wrote:
> > > Remove the fallback through the ioctl callback, no drivers use this now.
> > > 
> > > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > > ---
> > >  drivers/vfio/vfio_main.c | 8 ++++----
> > >  1 file changed, 4 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> > > index a390163ce706c4..f056e82ba35075 100644
> > > --- a/drivers/vfio/vfio_main.c
> > > +++ b/drivers/vfio/vfio_main.c
> > > @@ -1297,13 +1297,13 @@ static long vfio_device_fops_unl_ioctl(struct file *filep,
> > >  		break;
> > >  
> > >  	case VFIO_DEVICE_GET_REGION_INFO:
> > > -		if (!device->ops->get_region_info)
> > > -			goto ioctl_fallback;
> > > -		ret = device->ops->get_region_info(device, uptr);
> > > +		if (unlikely(!device->ops->get_region_info))
> > > +			ret = -EINVAL;  
> 
> Nit, typically I would have expected a success oriented flow, ie.
> 
> 		if (likely(device->ops->get_region_info))
> 			ret = device->ops->get_region_info(device, uptr);
> 		else
> 			ret = -EINVAL;
> 
> But it goes away in the next patch, so *shrug*.

Yeah, still I can edit it..

> > Nit: Let's also add a warn/err log here highliting that the device
> > doesn't populate the get_region_info op?
> 
> Are devices required to implement regions?  If so, it'd be more
> appropriate to fail the device registration in __vfio_register_dev()
> for the missing op than wait for an ioctl.  However, here in the device
> agnostic layer of vfio, I think the answer leans more towards no, we
> could theoretically have a device with no regions.  We also want to be
> careful not to introduce a WARN_ON that's user trigger'able.  Thanks,

Yeah, I had the same thought, so lets leave this. If we do want a warn
it should be in registration.

A device without regions does not seem useful, but also it doesn't
malfunction if someone does want to do that.

Thanks,
Jason

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op
  2025-11-03  9:53 ` Mostafa Saleh
@ 2025-11-05 20:58   ` Alex Williamson
  2025-11-06 20:37     ` Jason Gunthorpe
  0 siblings, 1 reply; 66+ messages in thread
From: Alex Williamson @ 2025-11-05 20:58 UTC (permalink / raw)
  To: Mostafa Saleh, Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Mon, 3 Nov 2025 09:53:04 +0000
Mostafa Saleh <smostafa@google.com> wrote:

> On Thu, Oct 23, 2025 at 08:09:14PM -0300, Jason Gunthorpe wrote:
> > There is alot of duplicated code in the drivers for processing
> > VFIO_DEVICE_GET_REGION_INFO. Introduce a new op get_region_info_caps()
> > which provides a struct vfio_info_cap and handles the cap chain logic
> > to write the caps back to userspace and remove all of this duplication
> > from drivers.
> > 
> > This is done in two steps, the first is a largely mechanical introduction
> > of the get_region_info(). These patches are best viewed with the diff
> > option to ignore whitespace (-b) as most of the lines are re-indending
> > things.
> > 
> > Then drivers are updated to remove the duplicate cap related code. Some
> > drivers are converted to use vfio_info_add_capability() instead of open
> > coding a version of it.  
> 
> The series as a whole looks good.
> However, I got confused walking through it as almost all non-PCI drivers
> had to transition to get_region_info then get_region_info_caps then
> removing get_region_info completely from core code after introducing
> it in this series.
> 
> IMO, the series should start with just consolidating PCI based implementation
> and then add get_region_info_caps for all drivers at the end.
> Anyway, no really strong opinion as the final outcome makes sense.

I agree it was a bit indirect to get there, but the result still makes
sense and I don't think it's worth reworking the series.

I think Eric has some outstanding naming concerns and Praan noted that
either a comment or gratuitous kfree(caps.buf) might be worthwhile to
keep call-outs in check regarding cap buffer leaks.  I don't think we
have any such cases, but it can't hurt to note the policy at least.

Otherwise, LGTM.  Should these be addressed as follow-ups rather than a
re-spin?  Thanks,

Alex

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 14/22] vfio: Require drivers to implement get_region_info
  2025-11-05 20:56       ` Jason Gunthorpe
@ 2025-11-05 21:19         ` Pranjal Shrivastava
  0 siblings, 0 replies; 66+ messages in thread
From: Pranjal Shrivastava @ 2025-11-05 21:19 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alex Williamson, Alexander Gordeev, David Airlie, Alex Williamson,
	Ankit Agrawal, Christian Borntraeger, Brett Creeley, dri-devel,
	Eric Auger, Eric Farman, Giovanni Cabiddu, Vasily Gorbik,
	Heiko Carstens, intel-gfx, Jani Nikula, Joonas Lahtinen,
	Kevin Tian, kvm, Kirti Wankhede, linux-s390, Longfang Liu,
	Matthew Rosato, Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter,
	Halil Pasic, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang, patches

On Wed, Nov 05, 2025 at 04:56:00PM -0400, Jason Gunthorpe wrote:
> On Wed, Nov 05, 2025 at 01:48:29PM -0700, Alex Williamson wrote:
> > On Mon, 3 Nov 2025 07:39:37 +0000
> > Pranjal Shrivastava <praan@google.com> wrote:
> > 
> > > On Thu, Oct 23, 2025 at 08:09:28PM -0300, Jason Gunthorpe wrote:
> > > > Remove the fallback through the ioctl callback, no drivers use this now.
> > > > 
> > > > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> > > > ---
> > > >  drivers/vfio/vfio_main.c | 8 ++++----
> > > >  1 file changed, 4 insertions(+), 4 deletions(-)
> > > > 
> > > > diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> > > > index a390163ce706c4..f056e82ba35075 100644
> > > > --- a/drivers/vfio/vfio_main.c
> > > > +++ b/drivers/vfio/vfio_main.c
> > > > @@ -1297,13 +1297,13 @@ static long vfio_device_fops_unl_ioctl(struct file *filep,
> > > >  		break;
> > > >  
> > > >  	case VFIO_DEVICE_GET_REGION_INFO:
> > > > -		if (!device->ops->get_region_info)
> > > > -			goto ioctl_fallback;
> > > > -		ret = device->ops->get_region_info(device, uptr);
> > > > +		if (unlikely(!device->ops->get_region_info))
> > > > +			ret = -EINVAL;  
> > 
> > Nit, typically I would have expected a success oriented flow, ie.
> > 
> > 		if (likely(device->ops->get_region_info))
> > 			ret = device->ops->get_region_info(device, uptr);
> > 		else
> > 			ret = -EINVAL;
> > 
> > But it goes away in the next patch, so *shrug*.
> 
> Yeah, still I can edit it..
> 
> > > Nit: Let's also add a warn/err log here highliting that the device
> > > doesn't populate the get_region_info op?
> > 
> > Are devices required to implement regions?  If so, it'd be more
> > appropriate to fail the device registration in __vfio_register_dev()
> > for the missing op than wait for an ioctl.  However, here in the device
> > agnostic layer of vfio, I think the answer leans more towards no, we
> > could theoretically have a device with no regions.  We also want to be
> > careful not to introduce a WARN_ON that's user trigger'able.  Thanks,
> 
> Yeah, I had the same thought, so lets leave this. If we do want a warn
> it should be in registration.
> 
> A device without regions does not seem useful, but also it doesn't
> malfunction if someone does want to do that.
> 

I agree with the both of you.. I just thought if we should remind the
user with a log that the dev doesn't expose a region. But I guess we
don't need to worry about that.

> Thanks,
> Jason

Thanks,
Praan

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op
  2025-11-05 20:58   ` Alex Williamson
@ 2025-11-06 20:37     ` Jason Gunthorpe
  0 siblings, 0 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-11-06 20:37 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Mostafa Saleh, Alexander Gordeev, David Airlie, Alex Williamson,
	Ankit Agrawal, Christian Borntraeger, Brett Creeley, dri-devel,
	Eric Auger, Eric Farman, Giovanni Cabiddu, Vasily Gorbik,
	Heiko Carstens, intel-gfx, Jani Nikula, Joonas Lahtinen,
	Kevin Tian, kvm, Kirti Wankhede, linux-s390, Longfang Liu,
	Matthew Rosato, Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter,
	Halil Pasic, Pranjal Shrivastava, qat-linux, Rodrigo Vivi,
	Simona Vetter, Shameer Kolothum, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang, patches

On Wed, Nov 05, 2025 at 01:58:04PM -0700, Alex Williamson wrote:
> On Mon, 3 Nov 2025 09:53:04 +0000
> Mostafa Saleh <smostafa@google.com> wrote:
> 
> > On Thu, Oct 23, 2025 at 08:09:14PM -0300, Jason Gunthorpe wrote:
> > > There is alot of duplicated code in the drivers for processing
> > > VFIO_DEVICE_GET_REGION_INFO. Introduce a new op get_region_info_caps()
> > > which provides a struct vfio_info_cap and handles the cap chain logic
> > > to write the caps back to userspace and remove all of this duplication
> > > from drivers.
> > > 
> > > This is done in two steps, the first is a largely mechanical introduction
> > > of the get_region_info(). These patches are best viewed with the diff
> > > option to ignore whitespace (-b) as most of the lines are re-indending
> > > things.
> > > 
> > > Then drivers are updated to remove the duplicate cap related code. Some
> > > drivers are converted to use vfio_info_add_capability() instead of open
> > > coding a version of it.  
> > 
> > The series as a whole looks good.
> > However, I got confused walking through it as almost all non-PCI drivers
> > had to transition to get_region_info then get_region_info_caps then
> > removing get_region_info completely from core code after introducing
> > it in this series.

This makes it alot easier to read as most of the lines are just
re-indenting code. If you try to do it in one shot the patches would
be much more dense. The stopping point at get_region_info() lets it be
more incremental..

> > IMO, the series should start with just consolidating PCI based implementation
> > and then add get_region_info_caps for all drivers at the end.
> > Anyway, no really strong opinion as the final outcome makes sense.
> 
> I agree it was a bit indirect to get there, but the result still makes
> sense and I don't think it's worth reworking the series.
>
> I think Eric has some outstanding naming concerns and Praan noted that
> either a comment or gratuitous kfree(caps.buf) might be worthwhile to
> keep call-outs in check regarding cap buffer leaks.  I don't think we
> have any such cases, but it can't hurt to note the policy at least.
> 
> Otherwise, LGTM.  Should these be addressed as follow-ups rather than a
> re-spin?  Thanks,

I was planning to respin it but time keeps ticking away..

Jason

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 22/22] vfio: Remove the get_region_info op
  2025-11-03 10:52   ` Pranjal Shrivastava
@ 2025-11-07  0:43     ` Jason Gunthorpe
  0 siblings, 0 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-11-07  0:43 UTC (permalink / raw)
  To: Pranjal Shrivastava
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Longfang Liu, Matthew Rosato,
	Nikhil Agarwal, Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	qat-linux, Rodrigo Vivi, Simona Vetter, Shameer Kolothum,
	Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin, virtualization,
	Vineeth Vijayan, Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On Mon, Nov 03, 2025 at 10:52:07AM +0000, Pranjal Shrivastava wrote:
> > -	if (device->ops->get_region_info_caps) {
> > -		struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
> > +	ret = device->ops->get_region_info_caps(device, &info, &caps);
> > +	if (ret)
> > +		return ret;
> 
> Shall we kfree(caps.buf); before returning?

Yes, I changed it to use a goto unwind

Thanks,
Jason

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 20/22] vfio/platform: Convert to get_region_info_caps
  2025-11-03 14:20   ` Eric Auger
@ 2025-11-07  1:05     ` Jason Gunthorpe
  0 siblings, 0 replies; 66+ messages in thread
From: Jason Gunthorpe @ 2025-11-07  1:05 UTC (permalink / raw)
  To: Eric Auger
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Farman,
	Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens, intel-gfx,
	Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm, Kirti Wankhede,
	linux-s390, Longfang Liu, Matthew Rosato, Nikhil Agarwal,
	Nipun Gupta, Peter Oberparleiter, Halil Pasic,
	Pranjal Shrivastava, qat-linux, Rodrigo Vivi, Simona Vetter,
	Shameer Kolothum, Mostafa Saleh, Sven Schnelle, Tvrtko Ursulin,
	virtualization, Vineeth Vijayan, Yishai Hadas, Zhenyu Wang,
	Zhi Wang, patches

On Mon, Nov 03, 2025 at 03:20:52PM +0100, Eric Auger wrote:
> > @@ -115,7 +115,7 @@ static const struct vfio_device_ops vfio_amba_ops = {
> >  	.open_device	= vfio_platform_open_device,
> >  	.close_device	= vfio_platform_close_device,
> >  	.ioctl		= vfio_platform_ioctl,
> > -	.get_region_info = vfio_platform_ioctl_get_region_info,
> > +	.get_region_info_caps = vfio_platform_ioctl_get_region_info,
> This would be nicer if called vfio_platform_get_region_info_caps I think

Maybe, but I pretty consistently did not use the _caps name for any of
the function names.

Maybe we should rename .get_region_info_caps back to just
.get_region_info?

Jason

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH 02/22] vfio/hisi: Convert to the get_region_info op
  2025-11-03  6:06   ` Pranjal Shrivastava
  2025-11-03 13:31     ` Jason Gunthorpe
@ 2025-11-07  1:29     ` liulongfang
  1 sibling, 0 replies; 66+ messages in thread
From: liulongfang @ 2025-11-07  1:29 UTC (permalink / raw)
  To: Pranjal Shrivastava, Jason Gunthorpe
  Cc: Alexander Gordeev, David Airlie, Alex Williamson, Ankit Agrawal,
	Christian Borntraeger, Brett Creeley, dri-devel, Eric Auger,
	Eric Farman, Giovanni Cabiddu, Vasily Gorbik, Heiko Carstens,
	intel-gfx, Jani Nikula, Joonas Lahtinen, Kevin Tian, kvm,
	Kirti Wankhede, linux-s390, Matthew Rosato, Nikhil Agarwal,
	Nipun Gupta, Peter Oberparleiter, Halil Pasic, qat-linux,
	Rodrigo Vivi, Simona Vetter, Shameer Kolothum, Mostafa Saleh,
	Sven Schnelle, Tvrtko Ursulin, virtualization, Vineeth Vijayan,
	Yishai Hadas, Zhenyu Wang, Zhi Wang, patches

On 2025/11/3 14:06, Pranjal Shrivastava wrote:
> On Thu, Oct 23, 2025 at 08:09:16PM -0300, Jason Gunthorpe wrote:
>> Change the function signature of hisi_acc_vfio_pci_ioctl()
>> and re-indent it.
>>
>> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
>> ---
>>  .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c    | 57 +++++++++----------
>>  1 file changed, 27 insertions(+), 30 deletions(-)
>>
>> diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
>> index fde33f54e99ec5..f06dcfcf09599f 100644
>> --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
>> +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c
>> @@ -1324,43 +1324,39 @@ static ssize_t hisi_acc_vfio_pci_read(struct vfio_device *core_vdev,
>>  	return vfio_pci_core_read(core_vdev, buf, new_count, ppos);
>>  }
>>  
>> -static long hisi_acc_vfio_pci_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
>> -				    unsigned long arg)
>> +static int hisi_acc_vfio_get_region(struct vfio_device *core_vdev,
>> +				    struct vfio_region_info __user *arg)
>>  {
>> -	if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
>> -		struct vfio_pci_core_device *vdev =
>> -			container_of(core_vdev, struct vfio_pci_core_device, vdev);
>> -		struct pci_dev *pdev = vdev->pdev;
>> -		struct vfio_region_info info;
>> -		unsigned long minsz;
>> +	struct vfio_pci_core_device *vdev =
>> +		container_of(core_vdev, struct vfio_pci_core_device, vdev);
>> +	struct pci_dev *pdev = vdev->pdev;
>> +	struct vfio_region_info info;
>> +	unsigned long minsz;
>>  
>> -		minsz = offsetofend(struct vfio_region_info, offset);
>> +	minsz = offsetofend(struct vfio_region_info, offset);
>>  
>> -		if (copy_from_user(&info, (void __user *)arg, minsz))
>> -			return -EFAULT;
>> +	if (copy_from_user(&info, arg, minsz))
>> +		return -EFAULT;
>>  
>> -		if (info.argsz < minsz)
>> -			return -EINVAL;
>> +	if (info.argsz < minsz)
>> +		return -EINVAL;
>>  
>> -		if (info.index == VFIO_PCI_BAR2_REGION_INDEX) {
>> -			info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
>> +	if (info.index != VFIO_PCI_BAR2_REGION_INDEX)
>> +		return vfio_pci_ioctl_get_region_info(core_vdev, arg);
>>  
> 
> I'm curious to learn the reason for flipping polarity here? (apart from
> readability).
>

Here, since the function's behavior has been reversed, the internal processing
is also inverted accordingly.

Thanks.
Longfang.

>> -			/*
>> -			 * ACC VF dev BAR2 region consists of both functional
>> -			 * register space and migration control register space.
>> -			 * Report only the functional region to Guest.
>> -			 */
>> -			info.size = pci_resource_len(pdev, info.index) / 2;
>> +	info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
>>  
>> -			info.flags = VFIO_REGION_INFO_FLAG_READ |
>> -					VFIO_REGION_INFO_FLAG_WRITE |
>> -					VFIO_REGION_INFO_FLAG_MMAP;
>> +	/*
>> +	 * ACC VF dev BAR2 region consists of both functional
>> +	 * register space and migration control register space.
>> +	 * Report only the functional region to Guest.
>> +	 */
>> +	info.size = pci_resource_len(pdev, info.index) / 2;
>>  
>> -			return copy_to_user((void __user *)arg, &info, minsz) ?
>> -					    -EFAULT : 0;
>> -		}
>> -	}
>> -	return vfio_pci_core_ioctl(core_vdev, cmd, arg);
>> +	info.flags = VFIO_REGION_INFO_FLAG_READ | VFIO_REGION_INFO_FLAG_WRITE |
>> +		     VFIO_REGION_INFO_FLAG_MMAP;
>> +
>> +	return copy_to_user(arg, &info, minsz) ? -EFAULT : 0;
>>  }
>>  
>>  static int hisi_acc_vf_debug_check(struct seq_file *seq, struct vfio_device *vdev)
>> @@ -1557,7 +1553,8 @@ static const struct vfio_device_ops hisi_acc_vfio_pci_migrn_ops = {
>>  	.release = vfio_pci_core_release_dev,
>>  	.open_device = hisi_acc_vfio_pci_open_device,
>>  	.close_device = hisi_acc_vfio_pci_close_device,
>> -	.ioctl = hisi_acc_vfio_pci_ioctl,
>> +	.ioctl = vfio_pci_core_ioctl,
>> +	.get_region_info = hisi_acc_vfio_get_region,
>>  	.device_feature = vfio_pci_core_ioctl_feature,
>>  	.read = hisi_acc_vfio_pci_read,
>>  	.write = hisi_acc_vfio_pci_write,
> 
> The change seems to maintain original functionality and LGTM.
> Acked-by: Pranjal Shrivastava <praan@google.com>
> 
> Thanks,
> Praan
> .
> 

^ permalink raw reply	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2025-11-10 13:41 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-23 23:09 [PATCH 00/22] vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 01/22] vfio: Provide a get_region_info op Jason Gunthorpe
2025-11-03  5:57   ` Pranjal Shrivastava
2025-11-03 14:17   ` Eric Auger
2025-10-23 23:09 ` [PATCH 02/22] vfio/hisi: Convert to the " Jason Gunthorpe
2025-10-28  1:55   ` liulongfang
2025-10-28  7:07     ` Tian, Kevin
2025-11-03  6:06   ` Pranjal Shrivastava
2025-11-03 13:31     ` Jason Gunthorpe
2025-11-07  1:29     ` liulongfang
2025-10-23 23:09 ` [PATCH 03/22] vfio/virtio: " Jason Gunthorpe
2025-11-03  6:21   ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 04/22] vfio/nvgrace: " Jason Gunthorpe
2025-11-03  6:41   ` Pranjal Shrivastava
2025-11-03 13:35     ` Ankit Agrawal
2025-10-23 23:09 ` [PATCH 05/22] vfio/pci: Fill in the missing get_region_info ops Jason Gunthorpe
2025-11-03  6:43   ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 06/22] vfio/mtty: Provide a get_region_info op Jason Gunthorpe
2025-11-03  7:17   ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 07/22] vfio/mdpy: " Jason Gunthorpe
2025-11-03  7:18   ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 08/22] vfio/mbochs: " Jason Gunthorpe
2025-11-03  7:19   ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 09/22] vfio/platform: " Jason Gunthorpe
2025-11-03  7:14   ` Pranjal Shrivastava
2025-11-03  9:53   ` Mostafa Saleh
2025-11-03 13:59   ` Eric Auger
2025-11-03 14:27     ` Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 10/22] vfio/fsl: " Jason Gunthorpe
2025-11-03  7:30   ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 11/22] vfio/cdx: " Jason Gunthorpe
2025-11-03  7:31   ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 12/22] vfio/ccw: " Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 13/22] vfio/gvt: " Jason Gunthorpe
2025-10-24 10:12   ` Jani Nikula
2025-10-23 23:09 ` [PATCH 14/22] vfio: Require drivers to implement get_region_info Jason Gunthorpe
2025-11-03  7:39   ` Pranjal Shrivastava
2025-11-05 20:48     ` Alex Williamson
2025-11-05 20:56       ` Jason Gunthorpe
2025-11-05 21:19         ` Pranjal Shrivastava
2025-11-03  9:55   ` Mostafa Saleh
2025-10-23 23:09 ` [PATCH 15/22] vfio: Add get_region_info_caps op Jason Gunthorpe
2025-11-03 10:16   ` Pranjal Shrivastava
2025-11-03 11:03     ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 16/22] vfio/mbochs: Convert mbochs to use vfio_info_add_capability() Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 17/22] vfio/gvt: Convert to get_region_info_caps Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 18/22] vfio/ccw: " Jason Gunthorpe
2025-10-28  7:09   ` Tian, Kevin
2025-10-23 23:09 ` [PATCH 19/22] vfio/pci: Convert all PCI drivers " Jason Gunthorpe
2025-10-28 17:08   ` Brett Creeley
2025-11-03 10:25   ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 20/22] vfio/platform: Convert " Jason Gunthorpe
2025-11-03  9:57   ` Mostafa Saleh
2025-11-03 10:21   ` Pranjal Shrivastava
2025-11-03 14:20   ` Eric Auger
2025-11-07  1:05     ` Jason Gunthorpe
2025-10-23 23:09 ` [PATCH 21/22] vfio: Move the remaining drivers " Jason Gunthorpe
2025-11-03 10:29   ` Pranjal Shrivastava
2025-10-23 23:09 ` [PATCH 22/22] vfio: Remove the get_region_info op Jason Gunthorpe
2025-11-03 10:52   ` Pranjal Shrivastava
2025-11-07  0:43     ` Jason Gunthorpe
2025-10-24  0:11 ` ✗ Fi.CI.BUILD: failure for vfio: Give VFIO_DEVICE_GET_REGION_INFO its own op Patchwork
2025-10-28  7:10 ` [PATCH 00/22] " Tian, Kevin
2025-11-03  9:53 ` Mostafa Saleh
2025-11-05 20:58   ` Alex Williamson
2025-11-06 20:37     ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).