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 10:24:34 -0700	[thread overview]
Message-ID: <CAJnrk1Z1n2xTem3xoP9oGDsJ3o9wPO_CfQ1GQy+d3ggLXP-9yg@mail.gmail.com> (raw)
In-Reply-To: <78925323-89b4-4def-aa5a-6138b4aa5d1c@kernel.dk>

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).

[1] https://lore.kernel.org/linux-fsdevel/000f7db7-5546-4680-bef2-84ce740ad8fd@gmail.com/

>
> I'd probably also prefer wrapping this in some kind of return struct, so
> that you just return that rather than having one part returned directly
> and one stuffed in a pointer to an unsigned for number of pages.

Sounds good, I will make this change.

Thanks,
Joanne
>
> --
> Jens Axboe

  reply	other threads:[~2026-03-25 17:24 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 [this message]
2026-03-25 17:27       ` Jens Axboe
2026-03-25 19:56         ` Joanne Koong
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=CAJnrk1Z1n2xTem3xoP9oGDsJ3o9wPO_CfQ1GQy+d3ggLXP-9yg@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