On Wed, Jan 21, 2026 at 12:44:51PM +0200, Leon Romanovsky wrote:
> On Wed, Jan 21, 2026 at 11:41:48AM +0100, Christian König wrote:
> > On 1/20/26 21:44, Matthew Brost wrote:
> > > On Tue, Jan 20, 2026 at 04:07:06PM +0200, Leon Romanovsky wrote:
> > >> From: Leon Romanovsky <[email protected]>
> > >>
> > >> dma-buf invalidation is performed asynchronously by hardware, so VFIO 
> > >> must
> > >> wait until all affected objects have been fully invalidated.
> > >>
> > >> Fixes: 5d74781ebc86 ("vfio/pci: Add dma-buf export support for MMIO 
> > >> regions")
> > >> Signed-off-by: Leon Romanovsky <[email protected]>
> > >> ---
> > >>  drivers/vfio/pci/vfio_pci_dmabuf.c | 5 +++++
> > >>  1 file changed, 5 insertions(+)
> > >>
> > >> diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c 
> > >> b/drivers/vfio/pci/vfio_pci_dmabuf.c
> > >> index d4d0f7d08c53..33bc6a1909dd 100644
> > >> --- a/drivers/vfio/pci/vfio_pci_dmabuf.c
> > >> +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
> > >> @@ -321,6 +321,9 @@ void vfio_pci_dma_buf_move(struct 
> > >> vfio_pci_core_device *vdev, bool revoked)
> > >>                          dma_resv_lock(priv->dmabuf->resv, NULL);
> > >>                          priv->revoked = revoked;
> > >>                          dma_buf_move_notify(priv->dmabuf);
> > >> +                        dma_resv_wait_timeout(priv->dmabuf->resv,
> > >> +                                              DMA_RESV_USAGE_KERNEL, 
> > >> false,
> > >> +                                              MAX_SCHEDULE_TIMEOUT);
> > > 
> > > Should we explicitly call out in the dma_buf_move_notify() /
> > > invalidate_mappings kernel-doc that KERNEL slots are the mechanism
> > > for communicating asynchronous dma_buf_move_notify /
> > > invalidate_mappings events via fences?
> > 
> > Oh, I missed that! And no that is not correct.
> > 

+1 on DMA_RESV_USAGE_BOOKKEEP, I reasoned we have to wait for all fences
after I typed the original response. For example preempt fences GPU
drivers are in BOOKKEEP which you'd certainly have to wait on for move
notify to called complete. Likewise a user issued unbind or TLB
invalidation fence would typically be in BOOKKEEP as well, which again
would need to be waited on.

Matt

> > This should be DMA_RESV_USAGE_BOOKKEEP so that we wait for everything.
> 
> Will change.
> 
> > 
> > Regards,
> > Christian.
> > 
> > > 
> > > Yes, this is probably implied, but it wouldn’t hurt to state this
> > > explicitly as part of the cross-driver contract.
> > > 
> > > Here is what we have now:
> > > 
> > >    * - Dynamic importers should set fences for any access that they can't
> > >    *   disable immediately from their 
> > > &dma_buf_attach_ops.invalidate_mappings
> > >    *   callback.
> > > 
> > > Matt
> > > 
> > >>                          dma_resv_unlock(priv->dmabuf->resv);
> > >>                  }
> > >>                  fput(priv->dmabuf->file);
> > >> @@ -342,6 +345,8 @@ void vfio_pci_dma_buf_cleanup(struct 
> > >> vfio_pci_core_device *vdev)
> > >>                  priv->vdev = NULL;
> > >>                  priv->revoked = true;
> > >>                  dma_buf_move_notify(priv->dmabuf);
> > >> +                dma_resv_wait_timeout(priv->dmabuf->resv, 
> > >> DMA_RESV_USAGE_KERNEL,
> > >> +                                      false, MAX_SCHEDULE_TIMEOUT);
> > >>                  dma_resv_unlock(priv->dmabuf->resv);
> > >>                  vfio_device_put_registration(&vdev->vdev);
> > >>                  fput(priv->dmabuf->file);
> > >>
> > >> -- 
> > >> 2.52.0
> > >>
> > 
> > 

Reply via email to