mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Breno Leitao <leitao@debian.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	 Christian Brauner <brauner@kernel.org>,
	mjguzik@gmail.com, josh@joshtriplett.org,
	 Jan Kara <jack@suse.cz>,
	jlayton@kernel.org, axboe@kernel.dk, shakeel.butt@linux.dev,
	 linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com
Subject: Re: [PATCH v4] fs/pipe: unify the page pools into a single per-pipe pool
Date: Mon, 20 Jul 2026 03:05:03 -0700	[thread overview]
Message-ID: <al3w54SsdZEjKVj4@gmail.com> (raw)
In-Reply-To: <alpWISUKMvqrp5ET@redhat.com>

On Fri, Jul 17, 2026 at 06:19:45PM +0200, Oleg Nesterov wrote:
> I personally like this change. To me it really makes this logic more
> simple/clear.
> 
> Reviewed-by: Oleg Nesterov <oleg@redhat.com>

Thanks for the review.

> > +static void anon_pipe_prefill_and_lock(struct pipe_inode_info *pipe, size_t total_len)
> >  {
> > -	unsigned int want, i;
> > -	struct page *page;
> > -
> > -	prealloc->count = 0;
> > -	if (total_len <= PAGE_SIZE)
> > -		return;
> > +	struct page *pages[PIPE_PREALLOC_MAX];
> > +	unsigned int want, have, need, n = 0;
> >
> >  	want = min_t(unsigned int, DIV_ROUND_UP(total_len, PAGE_SIZE),
> >  		     PIPE_PREALLOC_MAX);
> > +	/* Unlocked read; the pool is refilled under the lock below. */
> > +	have = min_t(unsigned int, READ_ONCE(pipe->prealloc.count), want);
> 
> And READ_ONCE() is enough correctness wise.
> 
> But AFAIK it is not enough to make KCSAN happy. anon_pipe_prealloc_pop/push
> which modify ->count under pipe->mutex need WRITE_ONCE() to please KCSAN.
> 
> Or anon_pipe_prefill_and_lock() can use data_race(READ_ONCE()).

I am not sure that is correct. I got the impression if the reading side
has READ_ONCE or data_race(), that is enough to please KCSAN.

I've also run a test with this code, and KCSAN doesn't show any complain
here.

The only complain is coming from osq_lock(), but not from here. This is
the osq_lock complain:

 BUG: KCSAN: data-race in osq_lock / osq_unlock

 write (marked) to 0xff11000527a42f80 of 8 bytes by task 1366 on cpu 23:
  osq_lock+0xf4/0x270
  __mutex_lock+0x1ab/0xe70
  mutex_lock_nested+0x17/0x20
  anon_pipe_read+0x69/0x570
  vfs_read+0x3e3/0x4b0
  ksys_read+0x95/0x120
  __x64_sys_read+0x3c/0x50
  x64_sys_call+0x69a/0x8d0
  do_syscall_64+0xfd/0x4f0
  entry_SYSCALL_64_after_hwframe+0x4b/0x53

 read to 0xff11000527a42f80 of 8 bytes by task 1363 on cpu 20:
  osq_unlock+0x14c/0x1a0
  __mutex_lock+0x1dd/0xe70
  mutex_lock_nested+0x17/0x20
  anon_pipe_read+0x451/0x570
  vfs_read+0x3e3/0x4b0
  ksys_read+0x95/0x120
  __x64_sys_read+0x3c/0x50
  x64_sys_call+0x69a/0x8d0
  do_syscall_64+0xfd/0x4f0
  entry_SYSCALL_64_after_hwframe+0x4b/0x53

 value changed: 0x0000000000000000 -> 0xff11000527bc2f80

that said, I think it makes sense to mark count as racy, given it is
read without a lock.

I will respin with, an additional "__data_racy" attribute in `count`

  struct anon_pipe_prealloc {
    struct page *pages[PIPE_PREALLOC_MAX];
    unsigned int __data_racy count;
  };

Thanks for the review,
--breno

  reply	other threads:[~2026-07-20 10:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-10 10:31 Breno Leitao
2026-07-17 16:19 ` Oleg Nesterov
2026-07-20 10:05   ` Breno Leitao [this message]
2026-07-20 11:53     ` Oleg Nesterov

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=al3w54SsdZEjKVj4@gmail.com \
    --to=leitao@debian.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=jlayton@kernel.org \
    --cc=josh@joshtriplett.org \
    --cc=kernel-team@meta.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjguzik@gmail.com \
    --cc=oleg@redhat.com \
    --cc=shakeel.butt@linux.dev \
    --cc=viro@zeniv.linux.org.uk \
    /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

Powered by JetHome