Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp227611imj; Wed, 13 Feb 2019 07:22:42 -0800 (PST) X-Google-Smtp-Source: AHgI3IZNJRocHY/nP8fP9/yqnyz02k2BKrs5C1ziHYO2RsDCpm7JvAeu6BMEZ/dfgeNrswCazEBq X-Received: by 2002:a62:e082:: with SMTP id d2mr1048015pfm.240.1550071362039; Wed, 13 Feb 2019 07:22:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550071362; cv=none; d=google.com; s=arc-20160816; b=wCIXNtmdLErqXim83u964bVFRX8UgvTvFlhWsu0d2uag7XHbW/RL9uaxwdQckWP481 Eo/+mvrK/vFccchdN5onx37vpcbi0M3DKXc+JL9iEo9iQTIS6Qzu8OcEMs0SngbkbzBa dJBxeXAJ1ha1xCtz4E/93b1d8m+qL/2uSr9ZFfvJ4bcw8STBxVd1vf5+4oOK3ZiRnBYV Gin6ZDTQ1hkkeW39gBNq6y9MtapWqWiCo0UOl6QFWbmr7p4YVlIBUF66jpEVZkTK89cM ArSUUCi8XQhEJ7WP+/j09qUSsb+jd+A/sWMYhop8ACO0B/ZQjmIDcISKMVhmWGr+zYCx yMsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=AQA+Jl2FHxIFnS57+VXjiZFPXGQ1XUWkT1LzSSgiM8E=; b=gQP3Csxi/W8+ExldpnEMY5wNxIiglSrarqx193Bd7eoESuJe0Tr7tHmhvy7JGJuCng UaiCQ+gwCj0ErbLHxVwscQU50st5E7a0eJjFAgKN3XnAhonWoXwmvi4cklSzSkYikp0r qqLnxpcifegyr8cIEtK6mwNajEjKVKudSGZrNDECvdiJECpyC3L/lkSzjDTbCejurhtx rQSzvgwSApoq4kqYfbyEtpDOe88KH096p+Udq+NRmnjwZ9Dnpv9milloCsPHlIdSyJzo 8/ZZhaC4+0Z1n29x3xIfdMVGCZ8tq3DcSsyJo0C0avezOKhTGYq4bu9UQZi8B1BQ6FMh Nj7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p65si6481445pfp.140.2019.02.13.07.22.24; Wed, 13 Feb 2019 07:22:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390743AbfBMOos (ORCPT + 99 others); Wed, 13 Feb 2019 09:44:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:59154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728867AbfBMOos (ORCPT ); Wed, 13 Feb 2019 09:44:48 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EF09F2075D; Wed, 13 Feb 2019 14:44:46 +0000 (UTC) Date: Wed, 13 Feb 2019 09:44:45 -0500 From: Steven Rostedt To: Slavomir Kaslev Cc: Alexander Viro , Jens Axboe , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] fs: Make splice() and tee() take into account O_NONBLOCK flag on pipes Message-ID: <20190213094445.1774f959@gandalf.local.home> In-Reply-To: <20190207154519.8635-1-kaslevs@vmware.com> References: <20190207154519.8635-1-kaslevs@vmware.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 7 Feb 2019 17:45:19 +0200 Slavomir Kaslev wrote: > The current implementation of splice() and tee() ignores O_NONBLOCK set on pipe > file descriptors and checks only the SPLICE_F_NONBLOCK flag for blocking on pipe > arguments. This is inconsistent since splice()-ing from/to non-pipe file > descriptors does take O_NONBLOCK into consideration. > > Fix this by promoting O_NONBLOCK, when set on a pipe, to SPLICE_F_NONBLOCK. > > Some context for how the current implementation of splice() leads to > inconsistent behavior. In the ongoing work[1] to add VM tracing capability to > trace-cmd we stream tracing data over named FIFOs or vsockets from guests back > to the host. > > When we receive SIGINT from user to stop tracing, we set O_NONBLOCK on the input > file descriptor and set SPLICE_F_NONBLOCK for the next call to splice(). If > splice() was blocked waiting on data from the input FIFO, after SIGINT splice() > restarts with the same arguments (no SPLICE_F_NONBLOCK) and blocks again instead > of returning -EAGAIN when no data is available. > > This differs from the splice() behavior when reading from a vsocket or when > we're doing a traditional read()/write() loop (trace-cmd's --nosplice argument). > > With this patch applied we get the same behavior in all situations after setting > O_NONBLOCK which also matches the behavior of doing a read()/write() loop > instead of splice(). > > This change does have potential of breaking users who don't expect EAGAIN from > splice() when SPLICE_F_NONBLOCK is not set. OTOH programs that set O_NONBLOCK > and don't anticipate EAGAIN are arguably buggy[2]. Reviewed-by: Steven Rostedt (VMware) Does anyone have any issues or comments about this patch? Thanks! -- Steve > > [1] https://github.com/skaslev/trace-cmd/tree/vsock > [2] https://github.com/torvalds/linux/blob/d47e3da1759230e394096fd742aad423c291ba48/fs/read_write.c#L1425 > > Signed-off-by: Slavomir Kaslev > --- > fs/splice.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/fs/splice.c b/fs/splice.c > index de2ede048473..6a1761b74f8d 100644 > --- a/fs/splice.c > +++ b/fs/splice.c > @@ -1123,6 +1123,9 @@ static long do_splice(struct file *in, loff_t __user *off_in, > if (ipipe == opipe) > return -EINVAL; > > + if ((in->f_flags | out->f_flags) & O_NONBLOCK) > + flags |= SPLICE_F_NONBLOCK; > + > return splice_pipe_to_pipe(ipipe, opipe, len, flags); > } > > @@ -1148,6 +1151,9 @@ static long do_splice(struct file *in, loff_t __user *off_in, > if (unlikely(ret < 0)) > return ret; > > + if (in->f_flags & O_NONBLOCK) > + flags |= SPLICE_F_NONBLOCK; > + > file_start_write(out); > ret = do_splice_from(ipipe, out, &offset, len, flags); > file_end_write(out); > @@ -1172,6 +1178,9 @@ static long do_splice(struct file *in, loff_t __user *off_in, > offset = in->f_pos; > } > > + if (out->f_flags & O_NONBLOCK) > + flags |= SPLICE_F_NONBLOCK; > + > pipe_lock(opipe); > ret = wait_for_space(opipe, flags); > if (!ret) > @@ -1717,6 +1726,9 @@ static long do_tee(struct file *in, struct file *out, size_t len, > * copying the data. > */ > if (ipipe && opipe && ipipe != opipe) { > + if ((in->f_flags | out->f_flags) & O_NONBLOCK) > + flags |= SPLICE_F_NONBLOCK; > + > /* > * Keep going, unless we encounter an error. The ipipe/opipe > * ordering doesn't really matter.