public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Caleb Sander Mateos <csander@purestorage.com>,
	Joanne Koong <joannelkoong@gmail.com>
Cc: io-uring@vger.kernel.org
Subject: Re: [PATCH v1] io_uring/kbuf: use WRITE_ONCE() for userspace-shared buffer ring fields
Date: Fri, 5 Dec 2025 09:56:42 -0700	[thread overview]
Message-ID: <423d79a4-a825-4e5e-b695-099ec7e6c883@kernel.dk> (raw)
In-Reply-To: <CADUfDZrbZj+fqqzHddWVjHvhwS2GmUzKTWgknhDLdRt2_ufr=A@mail.gmail.com>

On 12/5/25 9:55 AM, Caleb Sander Mateos wrote:
> On Thu, Dec 4, 2025 at 3:55?PM Joanne Koong <joannelkoong@gmail.com> wrote:
>>
>> buf->addr and buf->len reside in memory shared with userspace. They
>> should be written with WRITE_ONCE() to guarantee atomic stores and
>> prevent tearing or other unsafe compiler optimizations.
> 
> I considered this too, but I'm not sure it's necessary. A correctly
> written userspace program won't access these fields concurrently with
> the kernel, right? I'm not too familiar with the buffer ring UAPI, but
> I would assume userspace is notified somehow (via a posted CQE?) that
> the io_uring_buf slots have been consumed and are available to reuse.
> In that case, a torn store here would only be observable to a buggy
> userspace program, so I don't think we need to add WRITE_ONCE().

I agree, see my reply from a few minutes ago. But I do think it serves a
documentation purpose ("shared memory is always read/write once"), which
is why I applied it.

-- 
Jens Axboe

      reply	other threads:[~2025-12-05 16:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-04 23:54 [PATCH v1] io_uring/kbuf: use WRITE_ONCE() for userspace-shared buffer ring fields Joanne Koong
2025-12-05 16:51 ` Jens Axboe
2025-12-05 16:52 ` Jens Axboe
2025-12-05 16:55 ` Caleb Sander Mateos
2025-12-05 16:56   ` Jens Axboe [this message]

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=423d79a4-a825-4e5e-b695-099ec7e6c883@kernel.dk \
    --to=axboe@kernel.dk \
    --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