Commit ea3fc04d authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Alex Williamson

vfio-pci: Re-indent what was vfio_pci_core_ioctl()

Done mechanically with:

 $ git clang-format-14 -i --lines 675:1210 drivers/vfio/pci/vfio_pci_core.c

And manually reflow the multi-line comments clang-format doesn't fix.
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/3-v2-0f9e632d54fb+d6-vfio_ioctl_split_jgg@nvidia.comSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent 2ecf3b58
...@@ -722,7 +722,8 @@ static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev, ...@@ -722,7 +722,8 @@ static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev,
ret = vfio_pci_info_zdev_add_caps(vdev, &caps); ret = vfio_pci_info_zdev_add_caps(vdev, &caps);
if (ret && ret != -ENODEV) { if (ret && ret != -ENODEV) {
pci_warn(vdev->pdev, "Failed to setup zPCI info capabilities\n"); pci_warn(vdev->pdev,
"Failed to setup zPCI info capabilities\n");
return ret; return ret;
} }
...@@ -732,9 +733,8 @@ static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev, ...@@ -732,9 +733,8 @@ static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev,
info.argsz = sizeof(info) + caps.size; info.argsz = sizeof(info) + caps.size;
} else { } else {
vfio_info_cap_shift(&caps, sizeof(info)); vfio_info_cap_shift(&caps, sizeof(info));
if (copy_to_user((void __user *)arg + if (copy_to_user((void __user *)arg + sizeof(info),
sizeof(info), caps.buf, caps.buf, caps.size)) {
caps.size)) {
kfree(caps.buf); kfree(caps.buf);
return -EFAULT; return -EFAULT;
} }
...@@ -744,8 +744,7 @@ static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev, ...@@ -744,8 +744,7 @@ static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev,
kfree(caps.buf); kfree(caps.buf);
} }
return copy_to_user((void __user *)arg, &info, minsz) ? return copy_to_user((void __user *)arg, &info, minsz) ? -EFAULT : 0;
-EFAULT : 0;
} }
static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev, static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
...@@ -790,8 +789,7 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev, ...@@ -790,8 +789,7 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
} }
break; break;
case VFIO_PCI_ROM_REGION_INDEX: case VFIO_PCI_ROM_REGION_INDEX: {
{
void __iomem *io; void __iomem *io;
size_t size; size_t size;
u16 cmd; u16 cmd;
...@@ -811,8 +809,8 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev, ...@@ -811,8 +809,8 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
} }
/* /*
* Is it really there? Enable memory decode for * Is it really there? Enable memory decode for implicit access
* implicit access in pci_map_rom(). * in pci_map_rom().
*/ */
cmd = vfio_pci_memory_lock_and_enable(vdev); cmd = vfio_pci_memory_lock_and_enable(vdev);
io = pci_map_rom(pdev, &size); io = pci_map_rom(pdev, &size);
...@@ -836,18 +834,16 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev, ...@@ -836,18 +834,16 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
VFIO_REGION_INFO_FLAG_WRITE; VFIO_REGION_INFO_FLAG_WRITE;
break; break;
default: default: {
{
struct vfio_region_info_cap_type cap_type = { struct vfio_region_info_cap_type cap_type = {
.header.id = VFIO_REGION_INFO_CAP_TYPE, .header.id = VFIO_REGION_INFO_CAP_TYPE,
.header.version = 1 }; .header.version = 1
};
if (info.index >= if (info.index >= VFIO_PCI_NUM_REGIONS + vdev->num_regions)
VFIO_PCI_NUM_REGIONS + vdev->num_regions)
return -EINVAL; return -EINVAL;
info.index = array_index_nospec(info.index, info.index = array_index_nospec(
VFIO_PCI_NUM_REGIONS + info.index, VFIO_PCI_NUM_REGIONS + vdev->num_regions);
vdev->num_regions);
i = info.index - VFIO_PCI_NUM_REGIONS; i = info.index - VFIO_PCI_NUM_REGIONS;
...@@ -864,8 +860,8 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev, ...@@ -864,8 +860,8 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
return ret; return ret;
if (vdev->region[i].ops->add_capability) { if (vdev->region[i].ops->add_capability) {
ret = vdev->region[i].ops->add_capability(vdev, ret = vdev->region[i].ops->add_capability(
&vdev->region[i], &caps); vdev, &vdev->region[i], &caps);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -879,9 +875,8 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev, ...@@ -879,9 +875,8 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
info.cap_offset = 0; info.cap_offset = 0;
} else { } else {
vfio_info_cap_shift(&caps, sizeof(info)); vfio_info_cap_shift(&caps, sizeof(info));
if (copy_to_user((void __user *)arg + if (copy_to_user((void __user *)arg + sizeof(info),
sizeof(info), caps.buf, caps.buf, caps.size)) {
caps.size)) {
kfree(caps.buf); kfree(caps.buf);
return -EFAULT; return -EFAULT;
} }
...@@ -891,8 +886,7 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev, ...@@ -891,8 +886,7 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
kfree(caps.buf); kfree(caps.buf);
} }
return copy_to_user((void __user *)arg, &info, minsz) ? return copy_to_user((void __user *)arg, &info, minsz) ? -EFAULT : 0;
-EFAULT : 0;
} }
static int vfio_pci_ioctl_get_irq_info(struct vfio_pci_core_device *vdev, static int vfio_pci_ioctl_get_irq_info(struct vfio_pci_core_device *vdev,
...@@ -924,13 +918,12 @@ static int vfio_pci_ioctl_get_irq_info(struct vfio_pci_core_device *vdev, ...@@ -924,13 +918,12 @@ static int vfio_pci_ioctl_get_irq_info(struct vfio_pci_core_device *vdev,
info.count = vfio_pci_get_irq_count(vdev, info.index); info.count = vfio_pci_get_irq_count(vdev, info.index);
if (info.index == VFIO_PCI_INTX_IRQ_INDEX) if (info.index == VFIO_PCI_INTX_IRQ_INDEX)
info.flags |= (VFIO_IRQ_INFO_MASKABLE | info.flags |=
VFIO_IRQ_INFO_AUTOMASKED); (VFIO_IRQ_INFO_MASKABLE | VFIO_IRQ_INFO_AUTOMASKED);
else else
info.flags |= VFIO_IRQ_INFO_NORESIZE; info.flags |= VFIO_IRQ_INFO_NORESIZE;
return copy_to_user((void __user *)arg, &info, minsz) ? return copy_to_user((void __user *)arg, &info, minsz) ? -EFAULT : 0;
-EFAULT : 0;
} }
static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev, static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev,
...@@ -947,22 +940,21 @@ static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev, ...@@ -947,22 +940,21 @@ static int vfio_pci_ioctl_set_irqs(struct vfio_pci_core_device *vdev,
max = vfio_pci_get_irq_count(vdev, hdr.index); max = vfio_pci_get_irq_count(vdev, hdr.index);
ret = vfio_set_irqs_validate_and_prepare(&hdr, max, ret = vfio_set_irqs_validate_and_prepare(&hdr, max, VFIO_PCI_NUM_IRQS,
VFIO_PCI_NUM_IRQS, &data_size); &data_size);
if (ret) if (ret)
return ret; return ret;
if (data_size) { if (data_size) {
data = memdup_user((void __user *)(arg + minsz), data = memdup_user((void __user *)(arg + minsz), data_size);
data_size);
if (IS_ERR(data)) if (IS_ERR(data))
return PTR_ERR(data); return PTR_ERR(data);
} }
mutex_lock(&vdev->igate); mutex_lock(&vdev->igate);
ret = vfio_pci_set_irqs_ioctl(vdev, hdr.flags, hdr.index, ret = vfio_pci_set_irqs_ioctl(vdev, hdr.flags, hdr.index, hdr.start,
hdr.start, hdr.count, data); hdr.count, data);
mutex_unlock(&vdev->igate); mutex_unlock(&vdev->igate);
kfree(data); kfree(data);
...@@ -981,13 +973,12 @@ static int vfio_pci_ioctl_reset(struct vfio_pci_core_device *vdev, ...@@ -981,13 +973,12 @@ static int vfio_pci_ioctl_reset(struct vfio_pci_core_device *vdev,
vfio_pci_zap_and_down_write_memory_lock(vdev); vfio_pci_zap_and_down_write_memory_lock(vdev);
/* /*
* This function can be invoked while the power state is non-D0. * This function can be invoked while the power state is non-D0. If
* If pci_try_reset_function() has been called while the power * pci_try_reset_function() has been called while the power state is
* state is non-D0, then pci_try_reset_function() will * non-D0, then pci_try_reset_function() will internally set the power
* internally set the power state to D0 without vfio driver * state to D0 without vfio driver involvement. For the devices which
* involvement. For the devices which have NoSoftRst-, the * have NoSoftRst-, the reset function can cause the PCI config space
* reset function can cause the PCI config space reset without * reset without restoring the original state (saved locally in
* restoring the original state (saved locally in
* 'vdev->pm_save'). * 'vdev->pm_save').
*/ */
vfio_pci_set_power_state(vdev, PCI_D0); vfio_pci_set_power_state(vdev, PCI_D0);
...@@ -1025,8 +1016,7 @@ vfio_pci_ioctl_get_pci_hot_reset_info(struct vfio_pci_core_device *vdev, ...@@ -1025,8 +1016,7 @@ vfio_pci_ioctl_get_pci_hot_reset_info(struct vfio_pci_core_device *vdev,
return -ENODEV; return -ENODEV;
/* How many devices are affected? */ /* How many devices are affected? */
ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_count_devs,
vfio_pci_count_devs,
&fill.max, slot); &fill.max, slot);
if (ret) if (ret)
return ret; return ret;
...@@ -1034,8 +1024,8 @@ vfio_pci_ioctl_get_pci_hot_reset_info(struct vfio_pci_core_device *vdev, ...@@ -1034,8 +1024,8 @@ vfio_pci_ioctl_get_pci_hot_reset_info(struct vfio_pci_core_device *vdev,
WARN_ON(!fill.max); /* Should always be at least one */ WARN_ON(!fill.max); /* Should always be at least one */
/* /*
* If there's enough space, fill it now, otherwise return * If there's enough space, fill it now, otherwise return -ENOSPC and
* -ENOSPC and the number of devices affected. * the number of devices affected.
*/ */
if (hdr.argsz < sizeof(hdr) + (fill.max * sizeof(*devices))) { if (hdr.argsz < sizeof(hdr) + (fill.max * sizeof(*devices))) {
ret = -ENOSPC; ret = -ENOSPC;
...@@ -1049,14 +1039,13 @@ vfio_pci_ioctl_get_pci_hot_reset_info(struct vfio_pci_core_device *vdev, ...@@ -1049,14 +1039,13 @@ vfio_pci_ioctl_get_pci_hot_reset_info(struct vfio_pci_core_device *vdev,
fill.devices = devices; fill.devices = devices;
ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_fill_devs,
vfio_pci_fill_devs,
&fill, slot); &fill, slot);
/* /*
* If a device was removed between counting and filling, * If a device was removed between counting and filling, we may come up
* we may come up short of fill.max. If a device was * short of fill.max. If a device was added, we'll have a return of
* added, we'll have a return of -EAGAIN above. * -EAGAIN above.
*/ */
if (!ret) if (!ret)
hdr.count = fill.cur; hdr.count = fill.cur;
...@@ -1099,13 +1088,11 @@ static int vfio_pci_ioctl_pci_hot_reset(struct vfio_pci_core_device *vdev, ...@@ -1099,13 +1088,11 @@ static int vfio_pci_ioctl_pci_hot_reset(struct vfio_pci_core_device *vdev,
return -ENODEV; return -ENODEV;
/* /*
* We can't let userspace give us an arbitrarily large * We can't let userspace give us an arbitrarily large buffer to copy,
* buffer to copy, so verify how many we think there * so verify how many we think there could be. Note groups can have
* could be. Note groups can have multiple devices so * multiple devices so one group per device is the max.
* one group per device is the max.
*/ */
ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_count_devs,
vfio_pci_count_devs,
&count, slot); &count, slot);
if (ret) if (ret)
return ret; return ret;
...@@ -1130,9 +1117,9 @@ static int vfio_pci_ioctl_pci_hot_reset(struct vfio_pci_core_device *vdev, ...@@ -1130,9 +1117,9 @@ static int vfio_pci_ioctl_pci_hot_reset(struct vfio_pci_core_device *vdev,
} }
/* /*
* For each group_fd, get the group through the vfio external * For each group_fd, get the group through the vfio external user
* user interface and store the group and iommu ID. This * interface and store the group and iommu ID. This ensures the group
* ensures the group is held across the reset. * is held across the reset.
*/ */
for (file_idx = 0; file_idx < hdr.count; file_idx++) { for (file_idx = 0; file_idx < hdr.count; file_idx++) {
struct file *file = fget(group_fds[file_idx]); struct file *file = fget(group_fds[file_idx]);
...@@ -1192,8 +1179,8 @@ static int vfio_pci_ioctl_ioeventfd(struct vfio_pci_core_device *vdev, ...@@ -1192,8 +1179,8 @@ static int vfio_pci_ioctl_ioeventfd(struct vfio_pci_core_device *vdev,
if (hweight8(count) != 1 || ioeventfd.fd < -1) if (hweight8(count) != 1 || ioeventfd.fd < -1)
return -EINVAL; return -EINVAL;
return vfio_pci_ioeventfd(vdev, ioeventfd.offset, return vfio_pci_ioeventfd(vdev, ioeventfd.offset, ioeventfd.data, count,
ioeventfd.data, count, ioeventfd.fd); ioeventfd.fd);
} }
long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,
......
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