Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3444424pxk; Mon, 28 Sep 2020 18:42:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCAtODSau6T4Kj9PI7ZBr4HlXKoxFKIsmS1O8U5LhxR3E73yM2F5pF8PGFHkgk1GYdPFyL X-Received: by 2002:a17:907:3301:: with SMTP id ym1mr1577507ejb.367.1601343740074; Mon, 28 Sep 2020 18:42:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601343740; cv=none; d=google.com; s=arc-20160816; b=gGP8Ftg46RxYoEyGx7ERqb0vUqFXHC/+9M6GgR3ch0PxZFKioMvlJ5VlfqloDV43vQ tHSYOPx3vS5KXO8JSITXWXJEOvT/7o64NjM8mOftn5CHcNAMkkEYSZrhJVzxu2sjuCSv 5cholQbfFcwB0hvHNjn0lJ1O7by3nczptsg5/0R89o2kwvtSAnPXeXBGvMrjqOqaF+AV SX/8tybFnh68P2gBTWMUtZkICnnkp/xYgvfzMBUR8WuZsDqcsk1+gq2akUcjnYUlNkA+ mMqNCuAPX3t6H7nicbT0z8NEO/skuBR+Et5cqiPbsXNgN4F8o9xYFbBjtDnbwkDpFWFC TPNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a/7xUdPIweh9OgCYmVAWiEKmZD+tPFlorzxsPyAH7Zc=; b=tatw5YORs/Sz+CPNkIesikxagDZHT57h6/aa0qDcwvzaPbY+XHl0nq6b9Pg7Z+Q2C0 23iQEdyBp5/d3FvzR4Kuy56azB4VKEMbLcwk955GYnWLv5NSU8QxlnJgO/ExALCowflR ICjzq31iYEX/jdShLMUwS4raRsLFCGn6S69VrIjsQ0M1BMOFqI0sqsQabtTRvZcbXz+h J77mZ2vs14dc9Q31ltbZYaxLAIIO/RLXTr8lASoxcR0PzZMMd76+kEJUfTcCxuBarFBt L6FSVNvNd9V219RsFQYlq+hm/xa+L1o5WxslG8NMIVDH/QQ5YyhDN4jqi4UwENQMcRtn pNtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zl9b9IaO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w23si1917075edl.335.2020.09.28.18.41.48; Mon, 28 Sep 2020 18:42:20 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=zl9b9IaO; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727804AbgI2BgX (ORCPT + 99 others); Mon, 28 Sep 2020 21:36:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:39926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727218AbgI2Baw (ORCPT ); Mon, 28 Sep 2020 21:30:52 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EAA8721D43; Tue, 29 Sep 2020 01:30:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601343047; bh=mQw6OM3u2KV7FtkFQ65Z0Bp1vJ5Xuw66f17h80F5flE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zl9b9IaOHL+Hp1rBbP6ES7g3/DD+BAiyIQeSvKU3I68i+TDr3iua0ewZ9NQ9v6MQA B/xs7MRiW/J1yX5QLdlPTVeofMdlXYYPh48wQ6okhR6Pcc11B4TFW+Oogssl2hgqYw 4aGpWrGhg3J4q9s10A/SNQRQwhUS/EpnI7RvmaYI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Al Viro , Qian Cai , Sasha Levin , linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 5.8 15/29] fuse: fix the ->direct_IO() treatment of iov_iter Date: Mon, 28 Sep 2020 21:30:12 -0400 Message-Id: <20200929013027.2406344-15-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200929013027.2406344-1-sashal@kernel.org> References: <20200929013027.2406344-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro [ Upstream commit 933a3752babcf6513117d5773d2b70782d6ad149 ] the callers rely upon having any iov_iter_truncate() done inside ->direct_IO() countered by iov_iter_reexpand(). Reported-by: Qian Cai Tested-by: Qian Cai Signed-off-by: Al Viro Signed-off-by: Sasha Levin --- fs/fuse/file.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 83d917f7e5425..98e170cc0b932 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -3091,11 +3091,10 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ssize_t ret = 0; struct file *file = iocb->ki_filp; struct fuse_file *ff = file->private_data; - bool async_dio = ff->fc->async_dio; loff_t pos = 0; struct inode *inode; loff_t i_size; - size_t count = iov_iter_count(iter); + size_t count = iov_iter_count(iter), shortened = 0; loff_t offset = iocb->ki_pos; struct fuse_io_priv *io; @@ -3103,17 +3102,9 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) inode = file->f_mapping->host; i_size = i_size_read(inode); - if ((iov_iter_rw(iter) == READ) && (offset > i_size)) + if ((iov_iter_rw(iter) == READ) && (offset >= i_size)) return 0; - /* optimization for short read */ - if (async_dio && iov_iter_rw(iter) != WRITE && offset + count > i_size) { - if (offset >= i_size) - return 0; - iov_iter_truncate(iter, fuse_round_up(ff->fc, i_size - offset)); - count = iov_iter_count(iter); - } - io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL); if (!io) return -ENOMEM; @@ -3129,15 +3120,22 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) * By default, we want to optimize all I/Os with async request * submission to the client filesystem if supported. */ - io->async = async_dio; + io->async = ff->fc->async_dio; io->iocb = iocb; io->blocking = is_sync_kiocb(iocb); + /* optimization for short read */ + if (io->async && !io->write && offset + count > i_size) { + iov_iter_truncate(iter, fuse_round_up(ff->fc, i_size - offset)); + shortened = count - iov_iter_count(iter); + count -= shortened; + } + /* * We cannot asynchronously extend the size of a file. * In such case the aio will behave exactly like sync io. */ - if ((offset + count > i_size) && iov_iter_rw(iter) == WRITE) + if ((offset + count > i_size) && io->write) io->blocking = true; if (io->async && io->blocking) { @@ -3155,6 +3153,7 @@ fuse_direct_IO(struct kiocb *iocb, struct iov_iter *iter) } else { ret = __fuse_direct_read(io, iter, &pos); } + iov_iter_reexpand(iter, iov_iter_count(iter) + shortened); if (io->async) { bool blocking = io->blocking; -- 2.25.1