Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfio: Move the remaining drivers to get_region_info_caps

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

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Acked-by: Pranjal Shrivastava <praan@google.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/21-v2-2a9e24d62f1b+e10a-vfio_get_region_info_op_jgg@nvidia.com
Signed-off-by: Alex Williamson <alex@shazbot.org>

authored by

Jason Gunthorpe and committed by
Alex Williamson
dc107346 182c6286

+29 -101
+8 -16
drivers/vfio/cdx/main.c
··· 130 130 } 131 131 132 132 static int vfio_cdx_ioctl_get_region_info(struct vfio_device *core_vdev, 133 - struct vfio_region_info __user *arg) 133 + struct vfio_region_info *info, 134 + struct vfio_info_cap *caps) 134 135 { 135 136 struct vfio_cdx_device *vdev = 136 137 container_of(core_vdev, struct vfio_cdx_device, vdev); 137 - unsigned long minsz = offsetofend(struct vfio_region_info, offset); 138 138 struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev); 139 - struct vfio_region_info info; 140 139 141 - if (copy_from_user(&info, arg, minsz)) 142 - return -EFAULT; 143 - 144 - if (info.argsz < minsz) 145 - return -EINVAL; 146 - 147 - if (info.index >= cdx_dev->res_count) 140 + if (info->index >= cdx_dev->res_count) 148 141 return -EINVAL; 149 142 150 143 /* map offset to the physical address */ 151 - info.offset = vfio_cdx_index_to_offset(info.index); 152 - info.size = vdev->regions[info.index].size; 153 - info.flags = vdev->regions[info.index].flags; 154 - 155 - return copy_to_user(arg, &info, minsz) ? -EFAULT : 0; 144 + info->offset = vfio_cdx_index_to_offset(info->index); 145 + info->size = vdev->regions[info->index].size; 146 + info->flags = vdev->regions[info->index].flags; 147 + return 0; 156 148 } 157 149 158 150 static int vfio_cdx_ioctl_get_irq_info(struct vfio_cdx_device *vdev, ··· 276 284 .open_device = vfio_cdx_open_device, 277 285 .close_device = vfio_cdx_close_device, 278 286 .ioctl = vfio_cdx_ioctl, 279 - .get_region_info = vfio_cdx_ioctl_get_region_info, 287 + .get_region_info_caps = vfio_cdx_ioctl_get_region_info, 280 288 .device_feature = vfio_cdx_ioctl_feature, 281 289 .mmap = vfio_cdx_mmap, 282 290 .bind_iommufd = vfio_iommufd_physical_bind,
+8 -21
drivers/vfio/fsl-mc/vfio_fsl_mc.c
··· 117 117 fsl_mc_cleanup_irq_pool(mc_cont); 118 118 } 119 119 120 - static int 121 - vfio_fsl_mc_ioctl_get_region_info(struct vfio_device *core_vdev, 122 - struct vfio_region_info __user *arg) 120 + static int vfio_fsl_mc_ioctl_get_region_info(struct vfio_device *core_vdev, 121 + struct vfio_region_info *info, 122 + struct vfio_info_cap *caps) 123 123 { 124 124 struct vfio_fsl_mc_device *vdev = 125 125 container_of(core_vdev, struct vfio_fsl_mc_device, vdev); 126 126 struct fsl_mc_device *mc_dev = vdev->mc_dev; 127 - struct vfio_region_info info; 128 - unsigned long minsz; 129 127 130 - minsz = offsetofend(struct vfio_region_info, offset); 131 - 132 - if (copy_from_user(&info, arg, minsz)) 133 - return -EFAULT; 134 - 135 - if (info.argsz < minsz) 136 - return -EINVAL; 137 - 138 - if (info.index >= mc_dev->obj_desc.region_count) 128 + if (info->index >= mc_dev->obj_desc.region_count) 139 129 return -EINVAL; 140 130 141 131 /* map offset to the physical address */ 142 - info.offset = VFIO_FSL_MC_INDEX_TO_OFFSET(info.index); 143 - info.size = vdev->regions[info.index].size; 144 - info.flags = vdev->regions[info.index].flags; 145 - 146 - if (copy_to_user(arg, &info, minsz)) 147 - return -EFAULT; 132 + info->offset = VFIO_FSL_MC_INDEX_TO_OFFSET(info->index); 133 + info->size = vdev->regions[info->index].size; 134 + info->flags = vdev->regions[info->index].flags; 148 135 return 0; 149 136 } 150 137 ··· 583 596 .open_device = vfio_fsl_mc_open_device, 584 597 .close_device = vfio_fsl_mc_close_device, 585 598 .ioctl = vfio_fsl_mc_ioctl, 586 - .get_region_info = vfio_fsl_mc_ioctl_get_region_info, 599 + .get_region_info_caps = vfio_fsl_mc_ioctl_get_region_info, 587 600 .read = vfio_fsl_mc_read, 588 601 .write = vfio_fsl_mc_write, 589 602 .mmap = vfio_fsl_mc_mmap,
+7 -32
samples/vfio-mdev/mdpy.c
··· 435 435 return remap_vmalloc_range(vma, mdev_state->memblk, 0); 436 436 } 437 437 438 - static int mdpy_get_region_info(struct mdev_state *mdev_state, 439 - struct vfio_region_info *region_info, 440 - u16 *cap_type_id, void **cap_type) 438 + static int mdpy_ioctl_get_region_info(struct vfio_device *vdev, 439 + struct vfio_region_info *region_info, 440 + struct vfio_info_cap *caps) 441 441 { 442 + struct mdev_state *mdev_state = 443 + container_of(vdev, struct mdev_state, vdev); 444 + 442 445 if (region_info->index >= VFIO_PCI_NUM_REGIONS && 443 446 region_info->index != MDPY_DISPLAY_REGION) 444 447 return -EINVAL; ··· 512 509 plane->x_hot = 0; 513 510 plane->y_hot = 0; 514 511 515 - return 0; 516 - } 517 - 518 - static int mdpy_ioctl_get_region_info(struct vfio_device *vdev, 519 - struct vfio_region_info __user *arg) 520 - { 521 - struct mdev_state *mdev_state = 522 - container_of(vdev, struct mdev_state, vdev); 523 - struct vfio_region_info info; 524 - void *cap_type = NULL; 525 - u16 cap_type_id = 0; 526 - unsigned long minsz; 527 - int ret; 528 - 529 - minsz = offsetofend(struct vfio_region_info, offset); 530 - 531 - if (copy_from_user(&info, arg, minsz)) 532 - return -EFAULT; 533 - 534 - if (info.argsz < minsz) 535 - return -EINVAL; 536 - 537 - ret = mdpy_get_region_info(mdev_state, &info, &cap_type_id, &cap_type); 538 - if (ret) 539 - return ret; 540 - 541 - if (copy_to_user(arg, &info, minsz)) 542 - return -EFAULT; 543 512 return 0; 544 513 } 545 514 ··· 644 669 .read = mdpy_read, 645 670 .write = mdpy_write, 646 671 .ioctl = mdpy_ioctl, 647 - .get_region_info = mdpy_ioctl_get_region_info, 672 + .get_region_info_caps = mdpy_ioctl_get_region_info, 648 673 .mmap = mdpy_mmap, 649 674 .bind_iommufd = vfio_iommufd_emulated_bind, 650 675 .unbind_iommufd = vfio_iommufd_emulated_unbind,
+6 -32
samples/vfio-mdev/mtty.c
··· 1717 1717 return ret; 1718 1718 } 1719 1719 1720 - static int mtty_get_region_info(struct mdev_state *mdev_state, 1721 - struct vfio_region_info *region_info, 1722 - u16 *cap_type_id, void **cap_type) 1720 + static int mtty_ioctl_get_region_info(struct vfio_device *vdev, 1721 + struct vfio_region_info *region_info, 1722 + struct vfio_info_cap *caps) 1723 1723 { 1724 + struct mdev_state *mdev_state = 1725 + container_of(vdev, struct mdev_state, vdev); 1724 1726 unsigned int size = 0; 1725 1727 u32 bar_index; 1726 1728 ··· 1784 1782 dev_info->num_regions = VFIO_PCI_NUM_REGIONS; 1785 1783 dev_info->num_irqs = VFIO_PCI_NUM_IRQS; 1786 1784 1787 - return 0; 1788 - } 1789 - 1790 - static int mtty_ioctl_get_region_info(struct vfio_device *vdev, 1791 - struct vfio_region_info __user *arg) 1792 - { 1793 - struct mdev_state *mdev_state = 1794 - container_of(vdev, struct mdev_state, vdev); 1795 - struct vfio_region_info info; 1796 - void *cap_type = NULL; 1797 - u16 cap_type_id = 0; 1798 - unsigned long minsz; 1799 - int ret; 1800 - 1801 - minsz = offsetofend(struct vfio_region_info, offset); 1802 - 1803 - if (copy_from_user(&info, arg, minsz)) 1804 - return -EFAULT; 1805 - 1806 - if (info.argsz < minsz) 1807 - return -EINVAL; 1808 - 1809 - ret = mtty_get_region_info(mdev_state, &info, &cap_type_id, &cap_type); 1810 - if (ret) 1811 - return ret; 1812 - 1813 - if (copy_to_user(arg, &info, minsz)) 1814 - return -EFAULT; 1815 1785 return 0; 1816 1786 } 1817 1787 ··· 1927 1953 .read = mtty_read, 1928 1954 .write = mtty_write, 1929 1955 .ioctl = mtty_ioctl, 1930 - .get_region_info = mtty_ioctl_get_region_info, 1956 + .get_region_info_caps = mtty_ioctl_get_region_info, 1931 1957 .bind_iommufd = vfio_iommufd_emulated_bind, 1932 1958 .unbind_iommufd = vfio_iommufd_emulated_unbind, 1933 1959 .attach_ioas = vfio_iommufd_emulated_attach_ioas,