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

v2:
 - Rename
    hisi_acc_vfio_get_region -> hisi_acc_vfio_ioctl_get_region
    vfio_fsl_mc_get_region_info -> vfio_fsl_mc_ioctl_get_region_info
    intel_vgpu_get_region_info -> intel_vgpu_ioctl_get_region_info
    mbochs_get_region_info -> mbochs_ioctl_get_region_info
    intel_vgpu_get_region_info -> intel_vgpu_ioctl_get_region_info
    vfio_ccw_mdev_get_region_info -> vfio_ccw_mdev_ioctl_get_region_info
    hisi_acc_vfio_get_region -> hisi_acc_vfio_ioctl_get_region
    vfio_fsl_mc_get_region_info -> vfio_fsl_mc_ioctl_get_region_info
 - Consistently free caps.buf in vfio_get_region_info()
v1: 
https://patch.msgid.link/r/[email protected]

Signed-off-by: Jason Gunthorpe <[email protected]>

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               |  47 +--
 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                      |  49 ++++
 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, 368 insertions(+), 531 deletions(-)


base-commit: 211ddde0823f1442e4ad052a2f30f050145ccada
-- 
2.43.0

Reply via email to