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

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.com


Signed-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent 2ecf3b58
Loading
Loading
Loading
Loading
+349 −362
Original line number Diff line number Diff line
@@ -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);
	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;
	}

@@ -732,9 +733,8 @@ static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev,
			info.argsz = sizeof(info) + caps.size;
		} else {
			vfio_info_cap_shift(&caps, sizeof(info));
				if (copy_to_user((void __user *)arg +
						  sizeof(info), caps.buf,
						  caps.size)) {
			if (copy_to_user((void __user *)arg + sizeof(info),
					 caps.buf, caps.size)) {
				kfree(caps.buf);
				return -EFAULT;
			}
@@ -744,8 +744,7 @@ static int vfio_pci_ioctl_get_info(struct vfio_pci_core_device *vdev,
		kfree(caps.buf);
	}

		return copy_to_user((void __user *)arg, &info, minsz) ?
			-EFAULT : 0;
	return copy_to_user((void __user *)arg, &info, minsz) ? -EFAULT : 0;
}

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;
		case VFIO_PCI_ROM_REGION_INDEX:
		{
	case VFIO_PCI_ROM_REGION_INDEX: {
		void __iomem *io;
		size_t size;
		u16 cmd;
@@ -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
			 * implicit access in pci_map_rom().
		 * Is it really there?  Enable memory decode for implicit access
		 * in pci_map_rom().
		 */
		cmd = vfio_pci_memory_lock_and_enable(vdev);
		io = pci_map_rom(pdev, &size);
@@ -836,18 +834,16 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
			     VFIO_REGION_INFO_FLAG_WRITE;

		break;
		default:
		{
	default: {
		struct vfio_region_info_cap_type cap_type = {
			.header.id = VFIO_REGION_INFO_CAP_TYPE,
					.header.version = 1 };
			.header.version = 1
		};

			if (info.index >=
			    VFIO_PCI_NUM_REGIONS + vdev->num_regions)
		if (info.index >= VFIO_PCI_NUM_REGIONS + vdev->num_regions)
			return -EINVAL;
			info.index = array_index_nospec(info.index,
							VFIO_PCI_NUM_REGIONS +
							vdev->num_regions);
		info.index = array_index_nospec(
			info.index, VFIO_PCI_NUM_REGIONS + vdev->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,
			return ret;

		if (vdev->region[i].ops->add_capability) {
				ret = vdev->region[i].ops->add_capability(vdev,
						&vdev->region[i], &caps);
			ret = vdev->region[i].ops->add_capability(
				vdev, &vdev->region[i], &caps);
			if (ret)
				return ret;
		}
@@ -879,9 +875,8 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
			info.cap_offset = 0;
		} else {
			vfio_info_cap_shift(&caps, sizeof(info));
				if (copy_to_user((void __user *)arg +
						  sizeof(info), caps.buf,
						  caps.size)) {
			if (copy_to_user((void __user *)arg + sizeof(info),
					 caps.buf, caps.size)) {
				kfree(caps.buf);
				return -EFAULT;
			}
@@ -891,8 +886,7 @@ static int vfio_pci_ioctl_get_region_info(struct vfio_pci_core_device *vdev,
		kfree(caps.buf);
	}

		return copy_to_user((void __user *)arg, &info, minsz) ?
			-EFAULT : 0;
	return copy_to_user((void __user *)arg, &info, minsz) ? -EFAULT : 0;
}

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);

	if (info.index == VFIO_PCI_INTX_IRQ_INDEX)
			info.flags |= (VFIO_IRQ_INFO_MASKABLE |
				       VFIO_IRQ_INFO_AUTOMASKED);
		info.flags |=
			(VFIO_IRQ_INFO_MASKABLE | VFIO_IRQ_INFO_AUTOMASKED);
	else
		info.flags |= VFIO_IRQ_INFO_NORESIZE;

		return copy_to_user((void __user *)arg, &info, minsz) ?
			-EFAULT : 0;
	return copy_to_user((void __user *)arg, &info, minsz) ? -EFAULT : 0;
}

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);

		ret = vfio_set_irqs_validate_and_prepare(&hdr, max,
						 VFIO_PCI_NUM_IRQS, &data_size);
	ret = vfio_set_irqs_validate_and_prepare(&hdr, max, VFIO_PCI_NUM_IRQS,
						 &data_size);
	if (ret)
		return ret;

	if (data_size) {
			data = memdup_user((void __user *)(arg + minsz),
					    data_size);
		data = memdup_user((void __user *)(arg + minsz), data_size);
		if (IS_ERR(data))
			return PTR_ERR(data);
	}

	mutex_lock(&vdev->igate);

		ret = vfio_pci_set_irqs_ioctl(vdev, hdr.flags, hdr.index,
					      hdr.start, hdr.count, data);
	ret = vfio_pci_set_irqs_ioctl(vdev, hdr.flags, hdr.index, hdr.start,
				      hdr.count, data);

	mutex_unlock(&vdev->igate);
	kfree(data);
@@ -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);

	/*
		 * This function can be invoked while the power state is non-D0.
		 * If pci_try_reset_function() has been called while the power
		 * state is non-D0, then pci_try_reset_function() will
		 * internally set the power state to D0 without vfio driver
		 * involvement. For the devices which have NoSoftRst-, the
		 * reset function can cause the PCI config space reset without
		 * restoring the original state (saved locally in
	 * This function can be invoked while the power state is non-D0. If
	 * pci_try_reset_function() has been called while the power state is
	 * non-D0, then pci_try_reset_function() will internally set the power
	 * state to D0 without vfio driver involvement. For the devices which
	 * have NoSoftRst-, the reset function can cause the PCI config space
	 * reset without restoring the original state (saved locally in
	 * 'vdev->pm_save').
	 */
	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,
		return -ENODEV;

	/* How many devices are affected? */
		ret = vfio_pci_for_each_slot_or_bus(vdev->pdev,
						    vfio_pci_count_devs,
	ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_count_devs,
					    &fill.max, slot);
	if (ret)
		return ret;
@@ -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 */

	/*
		 * If there's enough space, fill it now, otherwise return
		 * -ENOSPC and the number of devices affected.
	 * If there's enough space, fill it now, otherwise return -ENOSPC and
	 * the number of devices affected.
	 */
	if (hdr.argsz < sizeof(hdr) + (fill.max * sizeof(*devices))) {
		ret = -ENOSPC;
@@ -1049,14 +1039,13 @@ vfio_pci_ioctl_get_pci_hot_reset_info(struct vfio_pci_core_device *vdev,

	fill.devices = devices;

		ret = vfio_pci_for_each_slot_or_bus(vdev->pdev,
						    vfio_pci_fill_devs,
	ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_fill_devs,
					    &fill, slot);

	/*
		 * If a device was removed between counting and filling,
		 * we may come up short of fill.max.  If a device was
		 * added, we'll have a return of -EAGAIN above.
	 * If a device was removed between counting and filling, we may come up
	 * short of fill.max.  If a device was added, we'll have a return of
	 * -EAGAIN above.
	 */
	if (!ret)
		hdr.count = fill.cur;
@@ -1099,13 +1088,11 @@ static int vfio_pci_ioctl_pci_hot_reset(struct vfio_pci_core_device *vdev,
		return -ENODEV;

	/*
		 * We can't let userspace give us an arbitrarily large
		 * buffer to copy, so verify how many we think there
		 * could be.  Note groups can have multiple devices so
		 * one group per device is the max.
	 * We can't let userspace give us an arbitrarily large buffer to copy,
	 * so verify how many we think there could be.  Note groups can have
	 * multiple devices so one group per device is the max.
	 */
		ret = vfio_pci_for_each_slot_or_bus(vdev->pdev,
						    vfio_pci_count_devs,
	ret = vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_count_devs,
					    &count, slot);
	if (ret)
		return ret;
@@ -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
		 * user interface and store the group and iommu ID.  This
		 * ensures the group is held across the reset.
	 * For each group_fd, get the group through the vfio external user
	 * interface and store the group and iommu ID.  This ensures the group
	 * is held across the reset.
	 */
	for (file_idx = 0; file_idx < hdr.count; 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,
	if (hweight8(count) != 1 || ioeventfd.fd < -1)
		return -EINVAL;

		return vfio_pci_ioeventfd(vdev, ioeventfd.offset,
					  ioeventfd.data, count, ioeventfd.fd);
	return vfio_pci_ioeventfd(vdev, ioeventfd.offset, ioeventfd.data, count,
				  ioeventfd.fd);
}

long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd,