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

Configure Feed

Select the types of activity you want to include in your feed.

vfio/platform: Provide a get_region_info op

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

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Pranjal Shrivastava <praan@google.com>
Reviewed-by: Mostafa Saleh <smostafa@google.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/9-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
d4635df2 8339fccd

+32 -22
+1
drivers/vfio/platform/vfio_amba.c
··· 115 115 .open_device = vfio_platform_open_device, 116 116 .close_device = vfio_platform_close_device, 117 117 .ioctl = vfio_platform_ioctl, 118 + .get_region_info = vfio_platform_ioctl_get_region_info, 118 119 .read = vfio_platform_read, 119 120 .write = vfio_platform_write, 120 121 .mmap = vfio_platform_mmap,
+1
drivers/vfio/platform/vfio_platform.c
··· 101 101 .open_device = vfio_platform_open_device, 102 102 .close_device = vfio_platform_close_device, 103 103 .ioctl = vfio_platform_ioctl, 104 + .get_region_info = vfio_platform_ioctl_get_region_info, 104 105 .read = vfio_platform_read, 105 106 .write = vfio_platform_write, 106 107 .mmap = vfio_platform_mmap,
+28 -22
drivers/vfio/platform/vfio_platform_common.c
··· 272 272 } 273 273 EXPORT_SYMBOL_GPL(vfio_platform_open_device); 274 274 275 + int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev, 276 + struct vfio_region_info __user *arg) 277 + { 278 + struct vfio_platform_device *vdev = 279 + container_of(core_vdev, struct vfio_platform_device, vdev); 280 + struct vfio_region_info info; 281 + unsigned long minsz; 282 + 283 + minsz = offsetofend(struct vfio_region_info, offset); 284 + 285 + if (copy_from_user(&info, arg, minsz)) 286 + return -EFAULT; 287 + 288 + if (info.argsz < minsz) 289 + return -EINVAL; 290 + 291 + if (info.index >= vdev->num_regions) 292 + return -EINVAL; 293 + 294 + /* map offset to the physical address */ 295 + info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index); 296 + info.size = vdev->regions[info.index].size; 297 + info.flags = vdev->regions[info.index].flags; 298 + 299 + return copy_to_user(arg, &info, minsz) ? -EFAULT : 0; 300 + } 301 + EXPORT_SYMBOL_GPL(vfio_platform_ioctl_get_region_info); 302 + 275 303 long vfio_platform_ioctl(struct vfio_device *core_vdev, 276 304 unsigned int cmd, unsigned long arg) 277 305 { ··· 324 296 info.flags = vdev->flags; 325 297 info.num_regions = vdev->num_regions; 326 298 info.num_irqs = vdev->num_irqs; 327 - 328 - return copy_to_user((void __user *)arg, &info, minsz) ? 329 - -EFAULT : 0; 330 - 331 - } else if (cmd == VFIO_DEVICE_GET_REGION_INFO) { 332 - struct vfio_region_info info; 333 - 334 - minsz = offsetofend(struct vfio_region_info, offset); 335 - 336 - if (copy_from_user(&info, (void __user *)arg, minsz)) 337 - return -EFAULT; 338 - 339 - if (info.argsz < minsz) 340 - return -EINVAL; 341 - 342 - if (info.index >= vdev->num_regions) 343 - return -EINVAL; 344 - 345 - /* map offset to the physical address */ 346 - info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index); 347 - info.size = vdev->regions[info.index].size; 348 - info.flags = vdev->regions[info.index].flags; 349 299 350 300 return copy_to_user((void __user *)arg, &info, minsz) ? 351 301 -EFAULT : 0;
+2
drivers/vfio/platform/vfio_platform_private.h
··· 85 85 void vfio_platform_close_device(struct vfio_device *core_vdev); 86 86 long vfio_platform_ioctl(struct vfio_device *core_vdev, 87 87 unsigned int cmd, unsigned long arg); 88 + int vfio_platform_ioctl_get_region_info(struct vfio_device *core_vdev, 89 + struct vfio_region_info __user *arg); 88 90 ssize_t vfio_platform_read(struct vfio_device *core_vdev, 89 91 char __user *buf, size_t count, 90 92 loff_t *ppos);