public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Joanne Koong <joannelkoong@gmail.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: csander@purestorage.com, asml.silence@gmail.com,
	io-uring@vger.kernel.org
Subject: Re: [PATCH v3 5/5] io_uring/rsrc: add io_uring_registered_mem_region_get()
Date: Wed, 25 Mar 2026 12:56:11 -0700	[thread overview]
Message-ID: <CAJnrk1YWh=bVNZkHYgtG4QSePTC2LGi-x=-AuecS=HG5wCTpKw@mail.gmail.com> (raw)
In-Reply-To: <147aa05f-2e03-4d0d-a86e-b145913d8584@kernel.dk>

On Wed, Mar 25, 2026 at 10:27 AM Jens Axboe <axboe@kernel.dk> wrote:
>
> On 3/25/26 11:24 AM, Joanne Koong wrote:
> > On Wed, Mar 25, 2026 at 7:56?AM Jens Axboe <axboe@kernel.dk> wrote:
> >>
> >> On 3/24/26 4:14 PM, Joanne Koong wrote:
> >>> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
> >>> index cf5638406a0c..c706324fd66d 100644
> >>> --- a/io_uring/rsrc.c
> >>> +++ b/io_uring/rsrc.c
> >>> @@ -1182,6 +1182,24 @@ int io_import_reg_buf(struct io_kiocb *req, struct iov_iter *iter,
> >>>       return io_import_fixed(ddir, iter, node->buf, buf_addr, len);
> >>>  }
> >>>
> >>> +void *io_uring_registered_mem_region_get(struct io_uring_cmd *cmd,
> >>> +                                      unsigned *nr_pages,
> >>> +                                      unsigned issue_flags)
> >>> +{
> >>> +     struct io_ring_ctx *ctx = cmd_to_io_kiocb(cmd)->ctx;
> >>> +     void *ptr;
> >>> +
> >>> +     io_ring_submit_lock(ctx, issue_flags);
> >>> +
> >>> +     ptr = ctx->param_region.ptr;
> >>> +     *nr_pages = ctx->param_region.nr_pages;
> >>> +
> >>> +     io_ring_submit_unlock(ctx, issue_flags);
> >>> +
> >>> +     return ptr;
> >>> +}
> >>> +EXPORT_SYMBOL_GPL(io_uring_registered_mem_region_get);
> >>
> >> This looks suspicious, but I actually think it looks suspicious because
> >> you add the submit locking around it. For patterns like that, it makes
> >> the brain go "hmm, what protects this from going invalid the instant
> >> io_ring_submit_unlock() is called??". But this should be stable for the
> >> duration of the ring, hence the locking should not be needed at all?
> >
> > My understanding is that once a memory region is registered to the
> > ring, it's registered for the ring's lifetime. There's no uapi to
> > unregister a memory region and my interpretation of the last paragraph
> > in this thread [1] is that unregistration is not intended to be
> > added/supported. I think the submit locking is needed in case another
> > thread is currently registering it so we don't see partially
> > initialized state between ptr and nr_pages (eg if the caller calls
> > this from a task work callback).
>
> Yes good point - can you please add a comment to that effect? Both why
> it's safe to return this state outside the lock, and also why the lock
> is actually required to ensure we see a sane state (either region fully
> registered, or not there)?

Good idea, I will add a comment about this to make this more clear,
something like:
/*
 * The submit lock ensures we don't see partially initialized state
 * if another thread is currently registering the region. Once registered,
 * the region is stable for the ring's lifetime (no unregister API exists),
 * so it's safe to access the returned pointer outside the lock.
 */

I will wait a day or two to send out v4 in case additional comments come in.

Thanks,
Joanne
>
> --
> Jens Axboe

  reply	other threads:[~2026-03-25 19:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24 22:14 [PATCH v3 0/5] io_uring: extend bvec registration and add mem region lookup Joanne Koong
2026-03-24 22:14 ` [PATCH v3 1/5] io_uring/rsrc: rename io_buffer_register_bvec()/io_buffer_unregister_bvec() Joanne Koong
2026-03-24 22:14 ` [PATCH v3 2/5] io_uring/rsrc: split io_buffer_register_request() logic Joanne Koong
2026-03-24 22:14 ` [PATCH v3 3/5] io_uring/rsrc: add io_buffer_register_bvec() Joanne Koong
2026-03-24 22:14 ` [PATCH v3 4/5] io_uring/rsrc: rename and export IO_IMU_DEST / IO_IMU_SOURCE Joanne Koong
2026-03-24 22:14 ` [PATCH v3 5/5] io_uring/rsrc: add io_uring_registered_mem_region_get() Joanne Koong
2026-03-25 14:56   ` Jens Axboe
2026-03-25 17:24     ` Joanne Koong
2026-03-25 17:27       ` Jens Axboe
2026-03-25 19:56         ` Joanne Koong [this message]
2026-03-25 20:15           ` Jens Axboe
2026-03-24 22:51 ` [PATCH v3 0/5] io_uring: extend bvec registration and add mem region lookup Joanne Koong

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='CAJnrk1YWh=bVNZkHYgtG4QSePTC2LGi-x=-AuecS=HG5wCTpKw@mail.gmail.com' \
    --to=joannelkoong@gmail.com \
    --cc=asml.silence@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=io-uring@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox