> -----Original Message----- > From: Jason Gunthorpe [mailto:jgg@xxxxxxxxxx] > Sent: 03 May 2022 00:42 > To: Alex Williamson <alex.williamson@xxxxxxxxxx>; Cornelia Huck > <cohuck@xxxxxxxxxx>; kvm@xxxxxxxxxxxxxxx; liulongfang > <liulongfang@xxxxxxxxxx>; Shameerali Kolothum Thodi > <shameerali.kolothum.thodi@xxxxxxxxxx>; Yishai Hadas > <yishaih@xxxxxxxxxx> > Cc: Kevin Tian <kevin.tian@xxxxxxxxx> > Subject: [PATCH v2] vfio/pci: Remove vfio_device_get_from_dev() > > The last user of this function is in PCI callbacks that want to convert > their struct pci_dev to a vfio_device. Instead of searching use the > vfio_device available trivially through the drvdata. > > When a callback in the device_driver is called, the caller must hold the > device_lock() on dev. The purpose of the device_lock is to prevent > remove() from being called (see __device_release_driver), and allow the > driver to safely interact with its drvdata without races. > > The PCI core correctly follows this and holds the device_lock() when > calling error_detected (see report_error_detected) and > sriov_configure (see sriov_numvfs_store). > > Further, since the drvdata holds a positive refcount on the vfio_device > any access of the drvdata, under the driver_lock, from a driver callback device_lock() ? (v1 discussion says it's a typo). > needs no further protection or refcounting. > > Thus the remark in the vfio_device_get_from_dev() comment does not apply > here, VFIO PCI drivers all call vfio_unregister_group_dev() from their > remove callbacks under the driver lock and cannot race with the remaining > callers. May be we can also mention the removal of vfio_group_get_from_dev() as well in the commit. > Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx> > Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx> Reviewed-by: Shameer Kolothum <shameerali.kolothum.thodi@xxxxxxxxxx> Thanks, Shameer