All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liam Dana <azurecrimson@azurecrimson.com>
To: linux-fsdevel@vger.kernel.org
Cc: viro@zeniv.linux.org.uk
Subject: [PATCH] splice: fix splice_pipe_to_pipe() busy wait
Date: Wed, 29 Jan 2020 23:58:23 +0000	[thread overview]
Message-ID: <20200129235823.GA32247@sekhmet> (raw)

Fixes: 8cefc107ca54 ("pipe: Use head and tail pointers for the ring, not
cursor and length")

Commit 8cefc107ca54 ("pipe: Use head and tail pointers for the ring, not
cursor and length") changed the way buffer occupancy is computed. During
the refactor an early-return check in opipe_prep() was inverted, and it
no longer waits for a reader to drain the full pipe buffer. When
splicing 2 pipes (via the splice() syscall, SPLICE_F_NONBLOCK unset, and
opipe full), this causes splice_pipe_to_pipe() to busy-wait.

This bug can be reproduced by running the following command:
$ yes | ./bug | pv -qL 1 >/dev/null
where "./bug" is the following C program:
int main() {
 while (splice(STDIN_FILENO, 0, STDOUT_FILENO, 0, 65536, 0));
 return 0;
}

The above program will spend the majority of its time in the splice()
syscall, and will not return with ERESTARTSYS in the event of a
pending_signal(). Meanwhile busy-waiting causes high power usage.

Signed-off-by: Liam Dana <azurecrimson@azurecrimson.com>
---
 fs/splice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/splice.c b/fs/splice.c
index 3009652a41c8..06a21449e030 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -1503,7 +1503,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
 	 * Check pipe occupancy without the inode lock first. This function
 	 * is speculative anyways, so missing one is ok.
 	 */
-	if (pipe_full(pipe->head, pipe->tail, pipe->max_usage))
+	if (!pipe_full(pipe->head, pipe->tail, pipe->max_usage))
 		return 0;
 
 	ret = 0;
-- 
2.24.1


                 reply	other threads:[~2020-01-30  0:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200129235823.GA32247@sekhmet \
    --to=azurecrimson@azurecrimson.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.