From patchwork Thu Aug 29 16:11:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11121841 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA89616B1 for ; Thu, 29 Aug 2019 16:12:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B89FD2339E for ; Thu, 29 Aug 2019 16:12:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="XMzk/Uf1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727257AbfH2QMB (ORCPT ); Thu, 29 Aug 2019 12:12:01 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:56762 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbfH2QMB (ORCPT ); Thu, 29 Aug 2019 12:12:01 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7TG9RiF040206; Thu, 29 Aug 2019 16:11:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=3CUI0Cvu1f5KuI3WE0OqIW3h5zxF9JVj5PFCxOZppVY=; b=XMzk/Uf17L1l/EpAfiFTE5YDENBuYakRCs9ajqfMv4FRq3KvoHM6S4ToPdeHcgGVrnwT sUJhCapYOgC+QcBi+vW0MhxpI5W6TWnRlRD4WCBhg4gXaxK/VDO08UVMltt30POhlBx+ 9CdP4UvXeAjouhooJvTAeoSA2JNGecF0FwfXPqAwtQsuCior4OgCxHIxXzs3dfae0NP8 zGFI4ZInJhokmMGkhemOl+AE2yQWgDdrKWVLtURWUI2KV0AbCsneO6Dn42us9OcE13Ts DbtBymAhrnLsVcAfNYJNb3NnrjE7YwvoIO5Yw7SP9s6EQtgavNDmzMm+G4+2c3CWeB/w vA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2uphyc00x8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 29 Aug 2019 16:11:58 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x7TG8NgW020090; Thu, 29 Aug 2019 16:11:57 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3020.oracle.com with ESMTP id 2upc8uvmae-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 29 Aug 2019 16:11:57 +0000 Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x7TGBuZM013206; Thu, 29 Aug 2019 16:11:56 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 29 Aug 2019 09:11:56 -0700 Date: Thu, 29 Aug 2019 09:11:55 -0700 From: "Darrick J. Wong" To: viro@zeniv.linux.org.uk, andreas.gruenbacher@gmail.com Cc: xfs , linux-fsdevel Subject: [PATCH] splice: only read in as much information as there is pipe buffer space Message-ID: <20190829161155.GA5360@magnolia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9364 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908290170 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9364 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908290170 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Darrick J. Wong Andreas Grünbacher reports that on the two filesystems that support iomap directio, it's possible for splice() to return -EAGAIN (instead of a short splice) if the pipe being written to has less space available in its pipe buffers than the length supplied by the calling process. Months ago we fixed splice_direct_to_actor to clamp the length of the read request to the size of the splice pipe. Do the same to do_splice. Fixes: 17614445576b6 ("splice: don't read more than available pipe space") Reported-by: Andreas Grünbacher Signed-off-by: Darrick J. Wong --- fs/splice.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/splice.c b/fs/splice.c index 98412721f056..7865a3bb6d88 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -1101,6 +1101,7 @@ static long do_splice(struct file *in, loff_t __user *off_in, struct pipe_inode_info *ipipe; struct pipe_inode_info *opipe; loff_t offset; + unsigned int pipe_pages; long ret; ipipe = get_pipe_info(in); @@ -1123,6 +1124,10 @@ static long do_splice(struct file *in, loff_t __user *off_in, if ((in->f_flags | out->f_flags) & O_NONBLOCK) flags |= SPLICE_F_NONBLOCK; + /* Don't try to read more the pipe has space for. */ + pipe_pages = opipe->buffers - opipe->nrbufs; + len = min(len, (size_t)pipe_pages << PAGE_SHIFT); + return splice_pipe_to_pipe(ipipe, opipe, len, flags); } @@ -1180,8 +1185,13 @@ static long do_splice(struct file *in, loff_t __user *off_in, pipe_lock(opipe); ret = wait_for_space(opipe, flags); - if (!ret) + if (!ret) { + /* Don't try to read more the pipe has space for. */ + pipe_pages = opipe->buffers - opipe->nrbufs; + len = min(len, (size_t)pipe_pages << PAGE_SHIFT); + ret = do_splice_to(in, &offset, opipe, len, flags); + } pipe_unlock(opipe); if (ret > 0) wakeup_pipe_readers(opipe);