RE: [PATCH v6 10/10] vfio/pci: Allow passing zero-length fd array in VFIO_DEVICE_PCI_HOT_RESET

Liu, Yi L
2023-06-01T05:56:17Z

> From: Alex Williamson <alex.williamson@redhat.com>
> Sent: Thursday, June 1, 2023 1:22 AM

> > Now, I intend to disallow it. If compat mode user binds the devices
> > to different containers, it shall be able to do hot reset as it can use
> > group fd to prove ownership. But if using the zero-length array, it
> > would be failed. So we may add below logic and remove the
> > vfio_device_cdev_opened() in vfio_pci_ioctl_pci_hot_reset_groups().
> >
> > vfio_pci_ioctl_pci_hot_reset()
> > {
> > ...
> > if (!!hdr.count == !!vfio_device_cdev_opened(&vdev->vdev))
> > return -EINVAL;
> > if (hdr.count)
> > vfio_pci_ioctl_pci_hot_reset_groups(vdev, hdr.count, slot, arg);
> > return vfio_pci_dev_set_hot_reset(vdev->vdev.dev_set, NULL,
> > vfio_iommufd_device_ictx(&vdev->vdev));
> > }
> >
> > >
> > > I thought it would be that this function is called with groups == NULL
> > > and therefore the vfio_dev_in_groups() test below fails, but I don't
> > > think that's true for a compat opened device. Thanks,
> >
> > How about above logic?
>
> The double negating a function that already returns bool is a bit

Yes.

> excessive. I might also move the test closer to the other parameter
> checking with a comment noting the null array interface is only for
> cdev opened devices. Thanks,

Yes.

Regards,
Yi Liu