Commit 2ecf3b58 authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Alex Williamson

vfio-pci: Break up vfio_pci_core_ioctl() into one function per ioctl

500 lines is a bit long for a single function, move the bodies of each
ioctl into separate functions and leave behind a switch statement to
dispatch them. This patch just adds the function declarations and does not
fix the indenting. The next patch will restore the indenting.
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/2-v2-0f9e632d54fb+d6-vfio_ioctl_split_jgg@nvidia.comSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent 16f4cbd9
...@@ -689,21 +689,15 @@ int vfio_pci_core_register_dev_region(struct vfio_pci_core_device *vdev, ...@@ -689,21 +689,15 @@ int vfio_pci_core_register_dev_region(struct vfio_pci_core_device *vdev,
} }
EXPORT_SYMBOL_GPL(vfio_pci_core_register_dev_region); EXPORT_SYMBOL_GPL(vfio_pci_core_register_dev_region);
long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev,
unsigned long arg) void __user *arg)
{ {
struct vfio_pci_core_device *vdev = unsigned long minsz = offsetofend(struct vfio_device_info, num_irqs);
container_of(core_vdev, struct vfio_pci_core_device, vdev);
unsigned long minsz;
if (cmd == VFIO_DEVICE_GET_INFO) {
struct vfio_device_info info; struct vfio_device_info info;
struct vfio_info_cap caps = { .buf = NULL, .size = 0 }; struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
unsigned long capsz; unsigned long capsz;
int ret; int ret;
minsz = offsetofend(struct vfio_device_info, num_irqs);
/* For backward compatibility, cannot require this */ /* For backward compatibility, cannot require this */
capsz = offsetofend(struct vfio_iommu_type1_info, cap_offset); capsz = offsetofend(struct vfio_iommu_type1_info, cap_offset);
...@@ -752,15 +746,17 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, ...@@ -752,15 +746,17 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
return copy_to_user((void __user *)arg, &info, minsz) ? return copy_to_user((void __user *)arg, &info, minsz) ?
-EFAULT : 0; -EFAULT : 0;
}
} else if (cmd == VFIO_DEVICE_GET_REGION_INFO) { static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
void __user *arg)
{
unsigned long minsz = offsetofend(struct vfio_region_info, offset);
struct pci_dev *pdev = vdev->pdev; struct pci_dev *pdev = vdev->pdev;
struct vfio_region_info info; struct vfio_region_info info;
struct vfio_info_cap caps = { .buf = NULL, .size = 0 }; struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
int i, ret; int i, ret;
minsz = offsetofend(struct vfio_region_info, offset);
if (copy_from_user(&info, (void __user *)arg, minsz)) if (copy_from_user(&info, (void __user *)arg, minsz))
return -EFAULT; return -EFAULT;
...@@ -897,12 +893,14 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, ...@@ -897,12 +893,14 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
return copy_to_user((void __user *)arg, &info, minsz) ? return copy_to_user((void __user *)arg, &info, minsz) ?
-EFAULT : 0; -EFAULT : 0;
}
} else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) { static int vfio_pci_ioctl_get_irq_info(struct vfio_pci_core_device *vdev,
void __user *arg)
{
unsigned long minsz = offsetofend(struct vfio_irq_info, count);
struct vfio_irq_info info; struct vfio_irq_info info;
minsz = offsetofend(struct vfio_irq_info, count);
if (copy_from_user(&info, (void __user *)arg, minsz)) if (copy_from_user(&info, (void __user *)arg, minsz))
return -EFAULT; return -EFAULT;
...@@ -933,15 +931,17 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, ...@@ -933,15 +931,17 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
return copy_to_user((void __user *)arg, &info, minsz) ? return copy_to_user((void __user *)arg, &info, minsz) ?
-EFAULT : 0; -EFAULT : 0;
}
} else if (cmd == VFIO_DEVICE_SET_IRQS) { static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev,
void __user *arg)
{
unsigned long minsz = offsetofend(struct vfio_irq_set, count);
struct vfio_irq_set hdr; struct vfio_irq_set hdr;
u8 *data = NULL; u8 *data = NULL;
int max, ret = 0; int max, ret = 0;
size_t data_size = 0; size_t data_size = 0;
minsz = offsetofend(struct vfio_irq_set, count);
if (copy_from_user(&hdr, (void __user *)arg, minsz)) if (copy_from_user(&hdr, (void __user *)arg, minsz))
return -EFAULT; return -EFAULT;
...@@ -968,8 +968,11 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, ...@@ -968,8 +968,11 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
kfree(data); kfree(data);
return ret; return ret;
}
} else if (cmd == VFIO_DEVICE_RESET) { static int vfio_pci_ioctl_reset(struct vfio_pci_core_device *vdev,
void __user *arg)
{
int ret; int ret;
if (!vdev->reset_works) if (!vdev->reset_works)
...@@ -993,16 +996,20 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, ...@@ -993,16 +996,20 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
up_write(&vdev->memory_lock); up_write(&vdev->memory_lock);
return ret; return ret;
}
} else if (cmd == VFIO_DEVICE_GET_PCI_HOT_RESET_INFO) { static int
vfio_pci_ioctl_get_pci_hot_reset_info(struct vfio_pci_core_device *vdev,
void __user *arg)
{
unsigned long minsz =
offsetofend(struct vfio_pci_hot_reset_info, count);
struct vfio_pci_hot_reset_info hdr; struct vfio_pci_hot_reset_info hdr;
struct vfio_pci_fill_info fill = { 0 }; struct vfio_pci_fill_info fill = { 0 };
struct vfio_pci_dependent_device *devices = NULL; struct vfio_pci_dependent_device *devices = NULL;
bool slot = false; bool slot = false;
int ret = 0; int ret = 0;
minsz = offsetofend(struct vfio_pci_hot_reset_info, count);
if (copy_from_user(&hdr, (void __user *)arg, minsz)) if (copy_from_user(&hdr, (void __user *)arg, minsz))
return -EFAULT; return -EFAULT;
...@@ -1066,8 +1073,12 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, ...@@ -1066,8 +1073,12 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
kfree(devices); kfree(devices);
return ret; return ret;
}
} else if (cmd == VFIO_DEVICE_PCI_HOT_RESET) { static int vfio_pci_ioctl_pci_hot_reset(struct vfio_pci_core_device *vdev,
void __user *arg)
{
unsigned long minsz = offsetofend(struct vfio_pci_hot_reset, count);
struct vfio_pci_hot_reset hdr; struct vfio_pci_hot_reset hdr;
int32_t *group_fds; int32_t *group_fds;
struct file **files; struct file **files;
...@@ -1075,8 +1086,6 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, ...@@ -1075,8 +1086,6 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
bool slot = false; bool slot = false;
int file_idx, count = 0, ret = 0; int file_idx, count = 0, ret = 0;
minsz = offsetofend(struct vfio_pci_hot_reset, count);
if (copy_from_user(&hdr, (void __user *)arg, minsz)) if (copy_from_user(&hdr, (void __user *)arg, minsz))
return -EFAULT; return -EFAULT;
...@@ -1160,12 +1169,15 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, ...@@ -1160,12 +1169,15 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
kfree(files); kfree(files);
return ret; return ret;
} else if (cmd == VFIO_DEVICE_IOEVENTFD) { }
static int vfio_pci_ioctl_ioeventfd(struct vfio_pci_core_device *vdev,
void __user *arg)
{
unsigned long minsz = offsetofend(struct vfio_device_ioeventfd, fd);
struct vfio_device_ioeventfd ioeventfd; struct vfio_device_ioeventfd ioeventfd;
int count; int count;
minsz = offsetofend(struct vfio_device_ioeventfd, fd);
if (copy_from_user(&ioeventfd, (void __user *)arg, minsz)) if (copy_from_user(&ioeventfd, (void __user *)arg, minsz))
return -EFAULT; return -EFAULT;
...@@ -1182,8 +1194,35 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, ...@@ -1182,8 +1194,35 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
return vfio_pci_ioeventfd(vdev, ioeventfd.offset, return vfio_pci_ioeventfd(vdev, ioeventfd.offset,
ioeventfd.data, count, ioeventfd.fd); ioeventfd.data, count, ioeventfd.fd);
} }
long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
unsigned long arg)
{
struct vfio_pci_core_device *vdev =
container_of(core_vdev, struct vfio_pci_core_device, vdev);
void __user *uarg = (void __user *)arg;
switch (cmd) {
case VFIO_DEVICE_GET_INFO:
return vfio_pci_ioctl_get_info(vdev, uarg);
case VFIO_DEVICE_GET_IRQ_INFO:
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(vdev, uarg);
case VFIO_DEVICE_IOEVENTFD:
return vfio_pci_ioctl_ioeventfd(vdev, uarg);
case VFIO_DEVICE_PCI_HOT_RESET:
return vfio_pci_ioctl_pci_hot_reset(vdev, uarg);
case VFIO_DEVICE_RESET:
return vfio_pci_ioctl_reset(vdev, uarg);
case VFIO_DEVICE_SET_IRQS:
return vfio_pci_ioctl_set_irqs(vdev, uarg);
default:
return -ENOTTY; return -ENOTTY;
}
} }
EXPORT_SYMBOL_GPL(vfio_pci_core_ioctl); EXPORT_SYMBOL_GPL(vfio_pci_core_ioctl);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment