public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jiri Pirko <jiri@resnulli.us>,
	linux-rdma@vger.kernel.org, mrgolin@amazon.com,
	gal.pressman@linux.dev, sleybo@amazon.com, parav@nvidia.com,
	mbloch@nvidia.com, yanjun.zhu@linux.dev, wangliang74@huawei.com,
	marco.crivellari@suse.com, roman.gushchin@linux.dev,
	phaddad@nvidia.com, lirongqing@baidu.com, ynachum@amazon.com,
	huangjunxian6@hisilicon.com, kalesh-anakkur.purayil@broadcom.com,
	ohartoov@nvidia.com, michaelgur@nvidia.com, shayd@nvidia.com,
	edwards@nvidia.com, sriharsha.basavapatna@broadcom.com,
	andrew.gospodarek@broadcom.com, selvin.xavier@broadcom.com
Subject: Re: [PATCH rdma-next 01/10] RDMA/umem: Add reference counting to ib_umem
Date: Tue, 3 Feb 2026 18:56:00 +0200	[thread overview]
Message-ID: <20260203165600.GW34749@unreal> (raw)
In-Reply-To: <20260203145138.GQ2328995@ziepe.ca>

On Tue, Feb 03, 2026 at 10:51:38AM -0400, Jason Gunthorpe wrote:
> On Tue, Feb 03, 2026 at 09:49:53AM +0100, Jiri Pirko wrote:
> > From: Jiri Pirko <jiri@nvidia.com>
> > 
> > Introduce reference counting for ib_umem objects to simplify memory
> > lifecycle management when umem buffers are shared between the core
> > layer and device drivers.
> 
> I admit I have reservations about this too.. The flow should not be so
> convoluted that a refcount is necessary. The lifecycle of a umem is
> not uncertain at all.
> 
> I imagine'd it would be like:
> 
> core code:
>   if (ops->create_cq_umem) {
>      umem = umem_get
>      rc = ops->create_cq_umem(umem)
>      if (rc)
>       umem_free(umem)
>   } else {
>      rc = ops->create_cq()
>   }
> 
> Driver:
>   create_cq():
>     copy_from_user(drvdata)
>     umem = umem_get()
>     rc = driver_create_cq_umem(umem, &drvdata))
>     if (rc)
>       umem_free(umem)
> 
>    create_cq_umem()
>      copy_from_user(drvdata)
>      return driver_create_cq_umem(umem, &drvdata)
> 
>    destroy_cq()
>      destry_hw
>      umem_free()
> 
> This basically moves all the working code in the driver to the
> driver_create_cq_umem() which *always* gets a umem as a parameter.
> 
> If the user uses the drvdata path to specify the umem then the driver
> helper create_cq() creates the umem from the drvdata parameters,
> otherwise the core creates it from the common UATTRs.
> 
> We can keep things so the umem is always freed by the driver on
> success, which doesn't require any driver changes.
> 
> It should never be "shared", this is just a very simple unwind on
> error kind of pattern.
> 
> I think the challenge here is to unwind the drivers into the above
> three functions so they don't have a mess of convoluted error handling
> around the umem.

I opted for an even simpler approach: embed the umem directly in ib_cq, set  
cq->umem in ib_core’s create_cq, and clean it up in ib_core’s destroy_cq.

The beginning of the series is available here:  
https://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git/log/?h=refactor-umem-v1

Thanks

> 
> Jason

  parent reply	other threads:[~2026-02-03 16:56 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-03  8:49 [PATCH rdma-next 00/10] RDMA: Extend uverbs umem support for QP buffers and doorbell records Jiri Pirko
2026-02-03  8:49 ` [PATCH rdma-next 01/10] RDMA/umem: Add reference counting to ib_umem Jiri Pirko
2026-02-03 10:03   ` Leon Romanovsky
2026-02-03 10:11     ` Jiri Pirko
2026-02-03 12:26       ` Leon Romanovsky
2026-02-03 12:46         ` Jiri Pirko
2026-02-03 13:03           ` Leon Romanovsky
2026-02-03 13:20             ` Jiri Pirko
2026-02-03 13:32               ` Leon Romanovsky
2026-02-03 14:31                 ` Jiri Pirko
2026-02-03 13:49               ` Sriharsha Basavapatna
2026-02-03 14:29                 ` Jiri Pirko
2026-02-03 14:49                   ` Sriharsha Basavapatna
2026-02-03 14:51   ` Jason Gunthorpe
2026-02-03 15:39     ` Jiri Pirko
2026-02-03 16:59       ` Jason Gunthorpe
2026-02-04  7:01         ` Jiri Pirko
2026-02-04 15:38         ` Jiri Pirko
2026-02-04 17:46           ` Jason Gunthorpe
2026-02-04 17:54             ` Leon Romanovsky
2026-02-04 17:56               ` Jiri Pirko
2026-02-03 16:56     ` Leon Romanovsky [this message]
2026-02-03 17:01       ` Jason Gunthorpe
2026-02-03  8:49 ` [PATCH rdma-next 02/10] RDMA/uverbs: Use umem refcounting for CQ creation with external buffer Jiri Pirko
2026-02-03  8:49 ` [PATCH rdma-next 03/10] RDMA/mlx5: Add support for CQ creation with external umem buffer Jiri Pirko
2026-02-03  8:49 ` [PATCH rdma-next 04/10] RDMA/uverbs: Factor out common buffer umem parsing into helper Jiri Pirko
2026-02-03  8:49 ` [PATCH rdma-next 05/10] RDMA/core: Add support for QP buffer umem in QP creation Jiri Pirko
2026-02-03  8:49 ` [PATCH rdma-next 06/10] RDMA/mlx5: Add support for QP creation with external umem buffers Jiri Pirko
2026-02-03  8:49 ` [PATCH rdma-next 07/10] RDMA/uverbs: Add doorbell record umem support to CQ creation Jiri Pirko
2026-02-03  8:50 ` [PATCH rdma-next 08/10] RDMA/mlx5: Add external doorbell record umem support for CQ Jiri Pirko
2026-02-03  8:50 ` [PATCH rdma-next 09/10] RDMA/uverbs: Add doorbell record umem support to QP creation Jiri Pirko
2026-02-03  8:50 ` [PATCH rdma-next 10/10] RDMA/mlx5: Add external doorbell record umem support for QP Jiri Pirko
2026-02-03  9:59 ` [PATCH rdma-next 00/10] RDMA: Extend uverbs umem support for QP buffers and doorbell records Leon Romanovsky
2026-02-03 10:13   ` Jiri Pirko

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=20260203165600.GW34749@unreal \
    --to=leon@kernel.org \
    --cc=andrew.gospodarek@broadcom.com \
    --cc=edwards@nvidia.com \
    --cc=gal.pressman@linux.dev \
    --cc=huangjunxian6@hisilicon.com \
    --cc=jgg@ziepe.ca \
    --cc=jiri@resnulli.us \
    --cc=kalesh-anakkur.purayil@broadcom.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=marco.crivellari@suse.com \
    --cc=mbloch@nvidia.com \
    --cc=michaelgur@nvidia.com \
    --cc=mrgolin@amazon.com \
    --cc=ohartoov@nvidia.com \
    --cc=parav@nvidia.com \
    --cc=phaddad@nvidia.com \
    --cc=roman.gushchin@linux.dev \
    --cc=selvin.xavier@broadcom.com \
    --cc=shayd@nvidia.com \
    --cc=sleybo@amazon.com \
    --cc=sriharsha.basavapatna@broadcom.com \
    --cc=wangliang74@huawei.com \
    --cc=yanjun.zhu@linux.dev \
    --cc=ynachum@amazon.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