Re: [PATCH 1/2] pipe: change pipe_write() to never add a zero-sized buffer
From: Oleg Nesterov
Date: Mon Feb 10 2025 - 13:37:16 EST
On 02/10, Linus Torvalds wrote:
>
> On Mon, 10 Feb 2025 at 09:22, Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> >
> > + int avail = PAGE_SIZE - offset;
> >
> > - if ((buf->flags & PIPE_BUF_FLAG_CAN_MERGE) &&
> > - offset + chars <= PAGE_SIZE) {
> > + if (avail && (buf->flags & PIPE_BUF_FLAG_CAN_MERGE)) {
> > ret = pipe_buf_confirm(pipe, buf);
> > if (ret)
> > goto out;
> >
> > + chars = min_t(ssize_t, chars, avail);
>
> If I read this correctly, this patch is horribly broken.
>
> You can't do partial writes. Pipes have one very core atomicity
> guarantee: from the man-pages:
>
> PIPE_BUF
> POSIX.1 says that writes of less than PIPE_BUF bytes must be
> atomic:
Ah, I didn't know!
Thanks for your explanation and the quick NACK!
> Maybe we should add a comment somewhere about this.
Agreed. It would certainly help the ignorant readers like me ;)
So I guess that the "goto again" logic in sender/receiver in
tools/perf/bench/sched-messaging.c is currently pointless,
DATASIZE == 100 < PIPE_BUF.
Thanks.
Oleg.