Re: [PATCH] pipe_read: don't wake up the writer if the pipe is still full
From: Linus Torvalds
Date: Tue Mar 04 2025 - 23:52:59 EST
On Tue, 4 Mar 2025 at 18:41, K Prateek Nayak <kprateek.nayak@xxxxxxx> wrote:
>
> > spin_lock_irq(&pipe->rd_wait.lock);
> > ...
> > pipe->tail = ++tail;
> > ...
> > spin_unlock_irq(&pipe->rd_wait.lock);
>
> From my understanding, this is still done with "pipe->mutex" held. Both
> anon_pipe_read() and pipe_resize_ring() will lock "pipe->mutex" first
> and then take the "pipe->rd_wait.lock" when updating "pipe->tail".
> "pipe->head" is always updated with "pipe->mutex" held.
No, see the actual watch_queue code: post_one_notification() in
fs/watch_queue.c.
It's isn't the exact sequence I posted, it looks like
smp_store_release(&pipe->head, head + 1); /* vs pipe_read() */
instead, and it's pipe->head there vs pipe->tail in pipe_read().
And I do think we end up having exclusion thanks to pipe_update_tail()
taking that spinlock if the pipe is actually a watchqueue thing, so it
might all be ok on alpha too.
So *maybe* we can just make it all be two 16-bit words in a 32-bit
thing, but somebody needs to walk through it all to make sure.
Linus