From patchwork Thu Aug 22 22:06:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13774268 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8399FC3DA4A for ; Thu, 22 Aug 2024 22:07:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 111E96B01B3; Thu, 22 Aug 2024 18:07:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 09C0F6B0202; Thu, 22 Aug 2024 18:07:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2F736B01FB; Thu, 22 Aug 2024 18:07:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B49C76B01A6 for ; Thu, 22 Aug 2024 18:07:20 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 698681A1A21 for ; Thu, 22 Aug 2024 22:07:20 +0000 (UTC) X-FDA: 82481268240.02.DFAD4B4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id A071EA0016 for ; Thu, 22 Aug 2024 22:07:18 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=W6VcskzZ; spf=pass (imf25.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724364421; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=K4cMR1cPV7JXYWx72h4PebZI2yNIfo6unToml+bPSHM=; b=edKqp8hBmVnC2E5wKV3nPvS4mj9xr/0a7IlGOtjxDJh1SNtGs2uFykHSFwwN5f7m9G4NdZ ZkUOdiqyknEotM/TFHGMA/6yv1pFTbRwRBzhvJXKMF6XGEgUIH2Gtb9C7s1FIvsxNwVay1 IJLwC9YZYntPPE98aNhUlpgjgdwYeKY= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=W6VcskzZ; spf=pass (imf25.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724364421; a=rsa-sha256; cv=none; b=MVsYE8sOrqj+dFA47h5Cpxnv0UcuxdeLQOdE3fooQ2eBFOyDHTIt2pzS22vQRnK9Dkeqfk 629Xne9Ho1bY3qy0XpPg1Y9sN/8gBrhYjICwvgiZL9vTMoAYqqh14JAYwaT7WL5ot9iBBh 3Z017v01Ttkf9JCO7coKeRsdYFGiP3k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724364437; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K4cMR1cPV7JXYWx72h4PebZI2yNIfo6unToml+bPSHM=; b=W6VcskzZywatLjfQVtnUtwtKo1JnlTpIVgZyUHEcx3UQXrQg+VHq0DH6w2CpDY3N7xFsKF V7EpTCMLK5Xz2rmMlE+TFaBnMUVA5V+IXX49YBY9aEX/fcfoUj3NCY7iRQ3dR9N1XyGZ6L 4EcmMyuzUVB9BK42AeK27H2xgwP/80s= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-bMIxmBy2PluYI0jC0-NnCQ-1; Thu, 22 Aug 2024 18:07:14 -0400 X-MC-Unique: bMIxmBy2PluYI0jC0-NnCQ-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C8AD61955F40; Thu, 22 Aug 2024 22:07:11 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F0C2F19560A3; Thu, 22 Aug 2024 22:07:06 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Pankaj Raghav , Jeff Layton , Matthew Wilcox , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Steve French , Paulo Alcantara Subject: [PATCH 2/2] netfs, cifs: Fix handling of short DIO read Date: Thu, 22 Aug 2024 23:06:49 +0100 Message-ID: <20240822220650.318774-3-dhowells@redhat.com> In-Reply-To: <20240822220650.318774-1-dhowells@redhat.com> References: <20240822220650.318774-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspam-User: X-Stat-Signature: zxicw6tm13dkg9zmp7y61n98f8wwdtei X-Rspamd-Queue-Id: A071EA0016 X-Rspamd-Server: rspam11 X-HE-Tag: 1724364438-413544 X-HE-Meta: U2FsdGVkX19tFrnbWjp+zFPEyU9iStYy1gs5WLSwUKg1q3yN77jhM3GZ8DzoWFior6LCwwE0x/h1oMXF3iy6kGEpWP4TNXKkCKB4QmS6hRYZbt4uYDpBOMV2uVcgdrm+P38DOSXPTjTDJEJty49/x5lZp8ILIJAWkzpN+mbLRJv+Naupn0bkOF+7xIFWbGwR5Rm5f4fwlh2N1pJO84GS4aYUe1DooInm42JKKBDVyn3ur4ppxxR1CNbuA3U+BUBJpYeVo5pC23z564FgSi37z7hl2veXUIFIcmjVsk941MfDF4zZsOOuI+Fd7WA+kbPi1lNABeTBmuRe/prjnRMNDL8cEdubSnCWV2LOdn2B+XHIewZWuVZI/bosMmNh+x4pgEFAQ2h87YtGl4FbcMPdzdjmcP1GbJEeIAM2hZasscY7HrAhoklXdzwImL5PPjr2Wc7NgTZITahq/64Zm3+DQS6BO1duefXzBx4eKZSJlEIg65G7S1AlG1h3mqh2eWnS/KGSVMZxCQ1HsE0saoukGpL9JMa+NxX0iY1foa+kao5t3GIZ3rC25/RU1We7eP4XqLg516y2MsugHolaaTuKTs0XQHXriMptMJH0QX5PV5gDXwP9pmebPOFA7bLM2UD+NcSC0Pqfa8c3cxkYhgrykQIqVBvdWLr4VncZzaaDU1is7wDho8xuj2huIw2ZRSNwrjqZdNWV+i9L4jxicXAF9+pE7elPwndkaWryuDv5sVpNUX7Dzvu5PZR4A0oVfgVZRz5OHnl3MnJVLsLRiEjN2aKodDPZu8JtzPzZU8mMBnmzqL2dS29oYCKZoXdmeIO0zEc82ofT79mf8NOtaJABJTbG+X9YXW5rw7AEYyYQpf2QuDBJuIpK9t55fuyghfJyJDc51goiTVdPwjhqXpZFaGEBEv/6neKgyoTlTKGCijC5bHkSEXWTTBggidGVRx2Pzff77GHLKTrJuR8VvxG gy6LCUbo iNPimwkS9ujoSBHRvIZt+xz5KbpVnXICioBeU+uRLa/V7psBm8SDhgSSNep82t4ZNP6aCAAk7o1xytjLI7xZaS8bZnbyH1bGmyhCNvUb/h86f82Q8sPaNywM/rdgsNwi1K51twvxRVGSwyvJ8+JHRgpb8cLX/Fdi+Bm3Z4cWv2t9vdVUlHhmoB7rhNpjLauowilzMGnJIrYF7T0QYFb9eNHIGI2Rbk9qKCOLebbxKkxDow06U2MAcqHanWQMWe1M2NO/18Fu/ousriXOzyU6AenBcx/V7YNnHoN6QWKknVW7zDnN3Phn5WVPN9/mKKUa4Zq9TSmzbsrCvWegeT6Vusa/UHSo/fRNK6kNbV0s/g83amUKtaWW34BYh5FHu0XgY3w6zcFvQ7u67jn4oKKDkNk43vEkGZe06RMX81rkwnzQSd5xVRhYCp4MTQc6ZzxotfXhgd2j14yoeE3opQZeimnpdOb8ajwtM63o2 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Short DIO reads, particularly in relation to cifs, are not being handled correctly by cifs and netfslib. This can be tested by doing a DIO read of a file where the size of read is larger than the size of the file. When it crosses the EOF, it gets a short read and this gets retried, and in the case of cifs, the retry read fails, with the failure being translated to ENODATA. Fix this by the following means: (1) Add a flag, NETFS_SREQ_HIT_EOF, for the filesystem to set when it detects that the read did hit the EOF. (2) Make the netfslib read assessment stop processing subrequests when it encounters one with that flag set. (3) Return rreq->transferred, the accumulated contiguous amount read to that point, to userspace for a DIO read. (4) Make cifs set the flag and clear the error if the read RPC returned ENODATA and the read-to file position is at or after the remote inode size. (5) Make cifs set the flag and clear the error if a short read occurred without error and the read-to file position is now at the remote inode size. Fixes: 69c3c023af25 ("cifs: Implement netfslib hooks") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev cc: linux-fsdevel@vger.kernel.org --- fs/netfs/io.c | 17 +++++++++++------ fs/smb/client/smb2pdu.c | 15 ++++++++++++++- include/linux/netfs.h | 1 + 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/fs/netfs/io.c b/fs/netfs/io.c index a72bc01b9609..d6510a9385dc 100644 --- a/fs/netfs/io.c +++ b/fs/netfs/io.c @@ -367,7 +367,8 @@ static void netfs_rreq_assess_dio(struct netfs_io_request *rreq) if (subreq->error || subreq->transferred == 0) break; transferred += subreq->transferred; - if (subreq->transferred < subreq->len) + if (subreq->transferred < subreq->len || + test_bit(NETFS_SREQ_HIT_EOF, &subreq->flags)) break; } @@ -502,7 +503,8 @@ void netfs_subreq_terminated(struct netfs_io_subrequest *subreq, subreq->error = 0; subreq->transferred += transferred_or_error; - if (subreq->transferred < subreq->len) + if (subreq->transferred < subreq->len && + !test_bit(NETFS_SREQ_HIT_EOF, &subreq->flags)) goto incomplete; complete: @@ -781,10 +783,13 @@ int netfs_begin_read(struct netfs_io_request *rreq, bool sync) TASK_UNINTERRUPTIBLE); ret = rreq->error; - if (ret == 0 && rreq->submitted < rreq->len && - rreq->origin != NETFS_DIO_READ) { - trace_netfs_failure(rreq, NULL, ret, netfs_fail_short_read); - ret = -EIO; + if (ret == 0) { + if (rreq->origin == NETFS_DIO_READ) { + ret = rreq->transferred; + } else if (rreq->submitted < rreq->len) { + trace_netfs_failure(rreq, NULL, ret, netfs_fail_short_read); + ret = -EIO; + } } } else { /* If we decrement nr_outstanding to 0, the ref belongs to us. */ diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index d80107d1ba9e..e182fdbec887 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -4507,6 +4507,7 @@ static void smb2_readv_callback(struct mid_q_entry *mid) { struct cifs_io_subrequest *rdata = mid->callback_data; + struct netfs_inode *ictx = netfs_inode(rdata->rreq->inode); struct cifs_tcon *tcon = tlink_tcon(rdata->req->cfile->tlink); struct TCP_Server_Info *server = rdata->server; struct smb2_hdr *shdr = @@ -4603,8 +4604,20 @@ smb2_readv_callback(struct mid_q_entry *mid) /* We may have got an EOF error because fallocate * failed to enlarge the file. */ - if (rdata->subreq.start < rdata->subreq.rreq->i_size) + if (rdata->subreq.start + rdata->subreq.transferred < rdata->subreq.rreq->i_size) rdata->result = 0; + if (rdata->subreq.start + rdata->subreq.transferred + rdata->got_bytes >= + ictx->remote_i_size) { + __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags); + rdata->result = 0; + } + } else { + if (rdata->got_bytes < rdata->actual_len && + rdata->subreq.start + rdata->subreq.transferred + rdata->got_bytes == + ictx->remote_i_size) { + __set_bit(NETFS_SREQ_HIT_EOF, &rdata->subreq.flags); + rdata->result = 0; + } } trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value, server->credits, server->in_flight, diff --git a/include/linux/netfs.h b/include/linux/netfs.h index 983816608f15..c47443e7a97e 100644 --- a/include/linux/netfs.h +++ b/include/linux/netfs.h @@ -198,6 +198,7 @@ struct netfs_io_subrequest { #define NETFS_SREQ_NEED_RETRY 9 /* Set if the filesystem requests a retry */ #define NETFS_SREQ_RETRYING 10 /* Set if we're retrying */ #define NETFS_SREQ_FAILED 11 /* Set if the subreq failed unretryably */ +#define NETFS_SREQ_HIT_EOF 12 /* Set if we hit the EOF */ }; enum netfs_io_origin {