public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Jacob Moroni <jmoroni@google.com>
Cc: tatyana.e.nikolova@intel.com, krzysztof.czurylo@intel.com,
	leon@kernel.org, linux-rdma@vger.kernel.org
Subject: Re: [RFC] RDMA/irdma: Add support for revocable dmabuf import
Date: Tue, 17 Feb 2026 14:45:59 -0400	[thread overview]
Message-ID: <20260217184559.GP750753@ziepe.ca> (raw)
In-Reply-To: <20260217182116.1726438-1-jmoroni@google.com>

On Tue, Feb 17, 2026 at 06:21:15PM +0000, Jacob Moroni wrote:
> +static void irdma_dmabuf_invalidate_cb(struct dma_buf_attachment *attach)
> +{
> +	struct ib_umem_dmabuf *umem_dmabuf = attach->importer_priv;
> +	struct irdma_mr *iwmr = umem_dmabuf->private;
> +	int err;
> +
> +	dma_resv_assert_held(umem_dmabuf->attach->dmabuf->resv);
> +
> +	if (!iwmr)
> +		return;
> +
> +	/* Invalidate the region in hardware, but do not release the key yet.
> +	 * This will either invalidate the region or issue a reset. Either way,
> +	 * the HW will no longer touch the region after. If successful, the
> +	 * region is marked as invalidated so that the real dereg MR later ends
> +	 * up skipping the HW request.
> +	 */
> +	err = irdma_hwdereg_mr(&iwmr->ibmr);

Er this command issues:

cqp_info->cqp_cmd = IRDMA_OP_DEALLOC_STAG;

Really need to explain this better, I forget how iwarp works - but you
can't release the rkey/stag in a way that something else can get it
reallocated.

Generally the way to do this is with the IBA defined reregister MR
verb and change some property of it to do revoke, eg change the PD or
make it 0 length or something like that.

> @@ -3599,7 +3639,7 @@ static struct ib_mr *irdma_reg_user_mr_dmabuf(struct ib_pd *pd, u64 start,
>  	struct irdma_device *iwdev = to_iwdev(pd->device);
>  	struct ib_umem_dmabuf *umem_dmabuf;
>  	struct irdma_mr *iwmr;
> -	int err;
> +	int err = -1;
>  
>  	if (dmah)
>  		return ERR_PTR(-EOPNOTSUPP);
> @@ -3607,31 +3647,43 @@ static struct ib_mr *irdma_reg_user_mr_dmabuf(struct ib_pd *pd, u64 start,
>  	if (len > iwdev->rf->sc_dev.hw_attrs.max_mr_size)
>  		return ERR_PTR(-EINVAL);
>  
> -	umem_dmabuf = ib_umem_dmabuf_get_pinned(pd->device, start, len, fd, access);
> +	umem_dmabuf = ib_umem_dmabuf_get(pd->device, start, len, fd, access,
> +					 &irdma_dmabuf_attach_ops);
>  	if (IS_ERR(umem_dmabuf)) {
>  		ibdev_dbg(&iwdev->ibdev, "Failed to get dmabuf umem[%pe]\n",
>  			  umem_dmabuf);
>  		return ERR_CAST(umem_dmabuf);
>  	}
>  
> +	dma_resv_lock(umem_dmabuf->attach->dmabuf->resv, NULL);
> +
> +	err = ib_umem_dmabuf_map_pages(umem_dmabuf);
> +	if (err)
> +		goto err_map;
> +
>  	iwmr = irdma_alloc_iwmr(&umem_dmabuf->umem, pd, virt, IRDMA_MEMREG_TYPE_MEM);
>  	if (IS_ERR(iwmr)) {
>  		err = PTR_ERR(iwmr);
> -		goto err_release;
> +		goto err_alloc;
>  	}

You also need to be careful of races here because it could have been
revoked already. Also notice if this ahppens private is NULL and it
will crash.

Finally, we don't actually support revocable mappings at the core code
level. We either have fully pinned or fully movable, so this is not
right to just change to ib_umem_dmabuf_get(), that assumes the HW is
fault capable.

Probably what you want to do is add a revoke callback to the pinned
importer?

Jason

  reply	other threads:[~2026-02-17 18:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-17 18:21 [RFC] RDMA/irdma: Add support for revocable dmabuf import Jacob Moroni
2026-02-17 18:45 ` Jason Gunthorpe [this message]
2026-02-17 23:08   ` Jacob Moroni
2026-02-17 23:21     ` Jason Gunthorpe
2026-02-18  9:05       ` Leon Romanovsky
2026-02-18 15:24         ` Jacob Moroni

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=20260217184559.GP750753@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=jmoroni@google.com \
    --cc=krzysztof.czurylo@intel.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=tatyana.e.nikolova@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox