public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Joanne Koong <joannelkoong@gmail.com>
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 11:27:04 -0600	[thread overview]
Message-ID: <147aa05f-2e03-4d0d-a86e-b145913d8584@kernel.dk> (raw)
In-Reply-To: <CAJnrk1Z1n2xTem3xoP9oGDsJ3o9wPO_CfQ1GQy+d3ggLXP-9yg@mail.gmail.com>

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

-- 
Jens Axboe

  reply	other threads:[~2026-03-25 17:27 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 [this message]
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=147aa05f-2e03-4d0d-a86e-b145913d8584@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=asml.silence@gmail.com \
    --cc=csander@purestorage.com \
    --cc=io-uring@vger.kernel.org \
    --cc=joannelkoong@gmail.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