Re: [RFC PATCH v6 11/11] PCI/TSM: Add reference-counted contexts for vdevice providers

From: Jason Gunthorpe

Date: Mon Sep 28 2026 - 19:08:51 EST


On Tue, Sep 29, 2026 at 12:17:30AM +0530, Sonang Patel wrote:
> On Thu, 17 Sep 2026 19:31:59 +0530, Aneesh Kumar K.V (Arm) wrote:
> > + if (is_pci_tsm_pf0(pdev)) {
> > + if (pci_tsm_disconnect(pdev))
> > + pci_warn(pdev, "TSM connection is still in use\n");
> > + } else {
> > + tsm_remove(pdev->tsm);
> > + }
>
> What happens if the PCI device is removed (e.g. sysfs remove, surprise
> hot-unplug) while the vDEVICE/TDI still exists?
> Since removal cannot be refused, should the remove path still force
> the unbind/unlock?

vfio prevents that. It currently will block the sysfs remove until
vfio is closed.

If we ever decide to fix that then vfio would have to tear down the
iommufd vdevice before allowing itself to be destroyed.

We don't need any lifetime nonsense once we are inside an iommufd
context, its existing locking scheme is very strong already. tsm
should not be allowed to change while a driver is bound, and basically
I shouldn't see any refcounting or locking in any of these paths
stemming from a bound driver context in iommufd.

Jason