Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4386886pxb; Tue, 26 Jan 2021 21:55:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJyiTsbdmeS8csdwXSgtXKya3WFL5acpJNjnJ4Ur3iiz+BNXJA7CBzH9vCAoixcFDPCESyMf X-Received: by 2002:aa7:c7d8:: with SMTP id o24mr7633334eds.328.1611726902149; Tue, 26 Jan 2021 21:55:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611726902; cv=none; d=google.com; s=arc-20160816; b=hYwlvkcO19oCs/HGYQMGnlODt6TZuR1qeE8QlsYy3KdzMDsheweb8AMF0BBcYWZJwU d7Cb/nGoVGj+cuNsJi0MW9W9rn8C2yhAQcryFSUJAUyGuJB8Vj/P5yxV579HKM+kOBIo k6Aw9D9fnHhc2Hitd9CW/1IUzNffw2H2WKOJbtWaaYOezbVYMRQDqte/vg33sX/h7Q+D Y8T3q+OWitpRD3QoBGTlvYBskqWw+jUvJkP8IVIWehBlacJQPG9a6df+eDTWEaK5P7HB QSVq5zgCSQ/QrnFyEalvo9946FB0sLUVqnuo4VJOTDVQGTKne8IJIFhkiLFlL7f/XG/Z VYBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=XWlLvQ74F5wl7Vo5nSQ+maUxmxCdNW0KwOFw9XvQhqI=; b=TWFaFytOAM+eWmYvwo4QMP9PmIu/q8Cgiah/1AagX3si44hOVJvqqDrvhATEqXwEQ6 vD3KAXfK1UwFdtJE+VgnHep+OF4bLKb6rnDFAuTVdgCq21rHR2dXTmSBxkZrbtu4e9nX Ry92MR3KETu6LQe65/8LUPgP57bg4Wn7g+6jt0sMehLBmTRWkdboC6ZheIyYM2/VzlBz PbmUjQm8TI+FmRmJZnsMa80usKDXvLw+5cpo/OEiIaVLvlgltX/ruNTY4IIVb9bjNM6g pbzFYpxu/UyHGUQ3iMhtDElW28gOOfAEWujKq13mDhyqgtZVxXkH3HQKwrHZqQETv5HT 3v7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o17si497370edf.247.2021.01.26.21.54.38; Tue, 26 Jan 2021 21:55:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389691AbhAZRPu (ORCPT + 99 others); Tue, 26 Jan 2021 12:15:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730229AbhAZGK2 (ORCPT ); Tue, 26 Jan 2021 01:10:28 -0500 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BE18C06178A for ; Mon, 25 Jan 2021 22:08:22 -0800 (PST) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1l4HWR-0068BS-7z; Tue, 26 Jan 2021 06:08:15 +0000 Date: Tue, 26 Jan 2021 06:08:15 +0000 From: Al Viro To: Linus Torvalds Cc: Johannes Berg , Christoph Hellwig , Oliver Giles , Linux Kernel Mailing List , Greg Kroah-Hartman Subject: [PATCH 1/3] do_splice_to(): move the logics for limiting the read length in Message-ID: <20210126060815.GA1461355@zeniv-ca.linux.org.uk> References: <20210118085311.GA2735@lst.de> <20210118194545.GB736435@zeniv-ca> <20210126060720.GJ740243@zeniv-ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210126060720.GJ740243@zeniv-ca> Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Both callers have the identical logics limiting the amount of data we try to read into pipe - no more than would fit into that pipe. Move that into do_splice_to() itself. Signed-off-by: Al Viro --- fs/splice.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 866d5c2367b2..c1ca2cc63b43 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -771,11 +771,16 @@ static long do_splice_to(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags) { + unsigned int p_space; int ret; if (unlikely(!(in->f_mode & FMODE_READ))) return -EBADF; + /* Don't try to read more the pipe has space for. */ + p_space = pipe->max_usage - pipe_occupancy(pipe->head, pipe->tail); + len = min_t(size_t, len, p_space << PAGE_SHIFT); + ret = rw_verify_area(READ, in, ppos, len); if (unlikely(ret < 0)) return ret; @@ -856,15 +861,10 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd, WARN_ON_ONCE(!pipe_empty(pipe->head, pipe->tail)); while (len) { - unsigned int p_space; size_t read_len; loff_t pos = sd->pos, prev_pos = pos; - /* Don't try to read more the pipe has space for. */ - p_space = pipe->max_usage - - pipe_occupancy(pipe->head, pipe->tail); - read_len = min_t(size_t, len, p_space << PAGE_SHIFT); - ret = do_splice_to(in, &pos, pipe, read_len, flags); + ret = do_splice_to(in, &pos, pipe, len, flags); if (unlikely(ret <= 0)) goto out_release; @@ -1083,15 +1083,8 @@ long do_splice(struct file *in, loff_t *off_in, struct file *out, pipe_lock(opipe); ret = wait_for_space(opipe, flags); - if (!ret) { - unsigned int p_space; - - /* Don't try to read more the pipe has space for. */ - p_space = opipe->max_usage - pipe_occupancy(opipe->head, opipe->tail); - len = min_t(size_t, len, p_space << PAGE_SHIFT); - + if (!ret) ret = do_splice_to(in, &offset, opipe, len, flags); - } pipe_unlock(opipe); if (ret > 0) wakeup_pipe_readers(opipe); -- 2.11.0