linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* When to lock pipe->rd_wait.lock?
@ 2023-09-20 12:34 Max Kellermann
  2023-09-20 13:30 ` Christian Brauner
  0 siblings, 1 reply; 9+ messages in thread
From: Max Kellermann @ 2023-09-20 12:34 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, linux-fsdevel

Hi,

I'm trying to understand the code that allocates a new buffer from a
pipe's buffer ring. I'd like to write a patch that eliminates some
duplicate code, to make it less error prone.

In fs/pipe.c, pipe_write() locks pipe->rd_wait.lock while the pipe's
head gets evaluated and incremented (all while pipe->mutex is locked).
My limited understand is that holding this spinlock is important
because it protects the head/tail accesses in pipe_readable() which is
gets called by wait_event while the spinlock is held, but without
pipe->mutex.

However in fs/splice.c, splice_pipe_to_pipe() contains very similar
code; a new buffer gets allocated, head gets incremented - but without
caring for pipe->rd_wait.lock.
Please help me understand the point of locking pipe->rd_wait.lock, and
why it's necessary in pipe_write() but not in splice_pipe_to_pipe().
Is that a bug or am I missing something?

Max

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-09-21 20:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-20 12:34 When to lock pipe->rd_wait.lock? Max Kellermann
2023-09-20 13:30 ` Christian Brauner
2023-09-20 15:21   ` Max Kellermann
2023-09-20 15:50     ` Christian Brauner
2023-09-20 16:14       ` Max Kellermann
2023-09-21  7:28   ` Max Kellermann
2023-09-21  8:05     ` Max Kellermann
2023-09-21  9:17       ` Christian Brauner
2023-09-21  9:38         ` Max Kellermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).