Re: [PATCH v7 16/16] PCI/TSM: wait for vdevice contexts before removing a DSM

From: Jason Gunthorpe

Date: Wed Oct 28 2026 - 15:33:57 EST


> A PF0 DSM can be removed while a sibling function still has a vdevice.
> The context pins both the pci dev, but those references do not keep the
> PF0 DOE mailbox alive. Ignoring -EBUSY from link disconnect lets PCI
> continue to pci_doe_destroy(), leaving the vdevice with a stale mailbox
> pointer.

Everytime PCI SIG puts something on PF0 that effects the entire MFD I
think it is a mistake. This time is not an exception...

>
> This follows the VFIO PCI removal model: vfio_unregister_group_dev()
> prevents new userspace opens and waits for existing users to release the
> device before teardown proceeds. Likewise, DSM removal rejects new
> contexts and waits for existing vdevice contexts to drain before
> destroying the DOE mailbox.

I probably wouldn't focus on the vdevice so much here, it is really
any user of the tsm framework in the kernel.

> Mark the DSM as removing so no new contexts or subfunctions can attach.
> Wait for the last context to be released before disconnecting the link,
>
> VFIO PCI also uses an eventfd to notify userspace that the device should
> be released. This patch does not add an equivalent notification for
> vdevice contexts; DSM removal waits for userspace to release them. Such
> a notification can be added later if required.

I ran out of time to read this closely, but the explanation make sense

Fix the sashiko things and lets see a v8 after the merge window opens
and the first patches are picked up..

--
Jason