All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: "Christian König" <christian.koenig@amd.com>
Cc: "Sumit Semwal" <sumit.semwal@linaro.org>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
	"Gurchetan Singh" <gurchetansingh@chromium.org>,
	"Chia-I Wu" <olvaffe@gmail.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Lucas De Marchi" <lucas.demarchi@intel.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"Kevin Tian" <kevin.tian@intel.com>,
	"Joerg Roedel" <joro@8bytes.org>, "Will Deacon" <will@kernel.org>,
	"Robin Murphy" <robin.murphy@arm.com>,
	"Alex Williamson" <alex@shazbot.org>,
	linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org,
	amd-gfx@lists.freedesktop.org, virtualization@lists.linux.dev,
	intel-xe@lists.freedesktop.org, linux-rdma@vger.kernel.org,
	iommu@lists.linux.dev, kvm@vger.kernel.org
Subject: Re: [PATCH v2 4/4] vfio: Add pinned interface to perform revoke semantics
Date: Mon, 19 Jan 2026 15:02:44 +0200	[thread overview]
Message-ID: <20260119130244.GN13201@unreal> (raw)
In-Reply-To: <bd37adf0-afd0-49c4-b608-7f9aa5994f7b@amd.com>

On Mon, Jan 19, 2026 at 01:12:45PM +0100, Christian König wrote:
> On 1/18/26 13:08, Leon Romanovsky wrote:
> > From: Leon Romanovsky <leonro@nvidia.com>
> > 
> > DMABUF ->pin() interface is called when the DMABUF importer perform
> > its DMA mapping, so let's use this opportunity to check if DMABUF
> > exporter revoked its buffer or not.
> > 
> > Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> > ---
> >  drivers/vfio/pci/vfio_pci_dmabuf.c | 16 ++++++++++++++++
> >  1 file changed, 16 insertions(+)
> > 
> > diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c
> > index d4d0f7d08c53..af9c315ddf71 100644
> > --- a/drivers/vfio/pci/vfio_pci_dmabuf.c
> > +++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
> > @@ -20,6 +20,20 @@ struct vfio_pci_dma_buf {
> >  	u8 revoked : 1;
> >  };
> >  
> > +static int vfio_pci_dma_buf_pin(struct dma_buf_attachment *attachment)
> > +{
> > +	struct vfio_pci_dma_buf *priv = attachment->dmabuf->priv;
> > +
> > +	dma_resv_assert_held(priv->dmabuf->resv);
> > +
> > +	return dma_buf_attachment_is_revoke(attachment) ? 0 : -EOPNOTSUPP;
> 
> It's probably better to do that check in vfio_pci_dma_buf_attach.

I assume you are proposing to add this check in both
vfio_pci_dma_buf_attach() and vfio_pci_dma_buf_pin(). Otherwise,
importers that lack .invalidate_mapping() will invoke dma_buf_pin()
and will not fail.

> 
> And BTW the function vfio_pci_dma_buf_move() seems to be broken:
> 
> void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev, bool revoked)
> {
>         struct vfio_pci_dma_buf *priv;
>         struct vfio_pci_dma_buf *tmp;
> 
>         lockdep_assert_held_write(&vdev->memory_lock);
> 
>         list_for_each_entry_safe(priv, tmp, &vdev->dmabufs, dmabufs_elm) {
>                 if (!get_file_active(&priv->dmabuf->file))
>                         continue;
> 
>                 if (priv->revoked != revoked) {
>                         dma_resv_lock(priv->dmabuf->resv, NULL);
>                         priv->revoked = revoked;
>                         dma_buf_move_notify(priv->dmabuf);
> 
> A dma_buf_move_notify() just triggers asynchronous invalidation of the mapping!
> 
> You need to use dma_resv_wait() to wait for that to finish.

We (VFIO and IOMMUFD) followed the same pattern used in  
amdgpu_bo_move_notify(), which also does not wait.

I'll add wait here.

Thanks

> 
>                         dma_resv_unlock(priv->dmabuf->resv);
>                 }
>                 fput(priv->dmabuf->file);
>         }
> }
> 
> Regards,
> Christian.
> 
> 
> > +}
> > +
> > +static void vfio_pci_dma_buf_unpin(struct dma_buf_attachment *attachment)
> > +{
> > +	/* Do nothing */
> > +}
> > +
> >  static int vfio_pci_dma_buf_attach(struct dma_buf *dmabuf,
> >  				   struct dma_buf_attachment *attachment)
> >  {
> > @@ -76,6 +90,8 @@ static void vfio_pci_dma_buf_release(struct dma_buf *dmabuf)
> >  }
> >  
> >  static const struct dma_buf_ops vfio_pci_dmabuf_ops = {
> > +	.pin = vfio_pci_dma_buf_pin,
> > +	.unpin = vfio_pci_dma_buf_unpin,
> >  	.attach = vfio_pci_dma_buf_attach,
> >  	.map_dma_buf = vfio_pci_dma_buf_map,
> >  	.unmap_dma_buf = vfio_pci_dma_buf_unmap,
> > 
> 

  reply	other threads:[~2026-01-19 13:02 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-18 12:08 [PATCH v2 0/4] dma-buf: document revoke mechanism to invalidate shared buffers Leon Romanovsky
2026-01-18 12:08 ` [PATCH v2 1/4] dma-buf: Rename .move_notify() callback to a clearer identifier Leon Romanovsky
2026-01-19 10:22   ` Christian König
2026-01-19 11:38     ` Leon Romanovsky
2026-01-19 12:00       ` Christian König
2026-01-19 12:39         ` Leon Romanovsky
2026-01-18 12:08 ` [PATCH v2 2/4] dma-buf: Document revoke semantics Leon Romanovsky
2026-01-18 14:29   ` Thomas Hellström
2026-01-19  9:04     ` Leon Romanovsky
2026-01-19 16:46     ` Jason Gunthorpe
2026-01-18 21:40   ` John Hubbard
2026-01-19  7:25     ` Leon Romanovsky
2026-01-19  7:32       ` John Hubbard
2026-01-19  8:04         ` Leon Romanovsky
2026-01-19 10:56   ` Christian König
2026-01-19 11:39     ` Leon Romanovsky
2026-01-19 16:44   ` Jason Gunthorpe
2026-01-20  9:45     ` Leon Romanovsky
2026-01-18 12:08 ` [PATCH v2 3/4] iommufd: Require DMABUF " Leon Romanovsky
2026-01-19 16:59   ` Jason Gunthorpe
2026-01-19 18:23     ` Leon Romanovsky
2026-01-19 19:54       ` Jason Gunthorpe
2026-01-20 13:10         ` Leon Romanovsky
2026-01-20 13:15           ` Jason Gunthorpe
2026-01-20 13:33             ` Leon Romanovsky
2026-01-18 12:08 ` [PATCH v2 4/4] vfio: Add pinned interface to perform " Leon Romanovsky
2026-01-19 12:12   ` Christian König
2026-01-19 13:02     ` Leon Romanovsky [this message]
2026-01-19 14:21       ` Christian König
2026-01-19 17:03       ` Jason Gunthorpe
2026-01-18 12:21 ` ✗ CI.checkpatch: warning for dma-buf: document revoke mechanism to invalidate shared buffers Patchwork
2026-01-18 12:23 ` ✓ CI.KUnit: success " Patchwork
2026-01-18 12:38 ` ✗ CI.checksparse: warning " Patchwork
2026-01-18 12:57 ` ✓ Xe.CI.BAT: success " Patchwork
2026-01-18 14:06 ` ✗ Xe.CI.Full: failure " Patchwork
2026-01-18 14:16 ` [PATCH v2 0/4] " Thomas Hellström
2026-01-19  7:52   ` Leon Romanovsky
2026-01-19  9:27     ` Thomas Hellström
2026-01-19 10:20       ` Leon Romanovsky
2026-01-19 10:20       ` Christian König
2026-01-19 10:53         ` Leon Romanovsky
2026-01-19 12:05           ` Christian König
2026-01-19 16:24       ` Jason Gunthorpe
2026-01-19 17:24         ` Thomas Hellström
2026-01-19 16:20   ` Jason Gunthorpe
2026-01-19 16:58 ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260119130244.GN13201@unreal \
    --to=leon@kernel.org \
    --cc=airlied@gmail.com \
    --cc=alex@shazbot.org \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dmitry.osipenko@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gurchetansingh@chromium.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=olvaffe@gmail.com \
    --cc=robin.murphy@arm.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=sumit.semwal@linaro.org \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tzimmermann@suse.de \
    --cc=virtualization@lists.linux.dev \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.