From patchwork Wed Aug 28 21:02:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13781953 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 D9DA4C71143 for ; Wed, 28 Aug 2024 21:03:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 766686B008C; Wed, 28 Aug 2024 17:03:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 716706B0092; Wed, 28 Aug 2024 17:03:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B70E6B0093; Wed, 28 Aug 2024 17:03:15 -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 3C5E86B008C for ; Wed, 28 Aug 2024 17:03:15 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id ED6911C4984 for ; Wed, 28 Aug 2024 21:03:14 +0000 (UTC) X-FDA: 82502879508.12.5852696 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 34BFD40025 for ; Wed, 28 Aug 2024 21:03:13 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ab+rDiIe; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724878921; a=rsa-sha256; cv=none; b=qgGqu+QW1E+IOqeozwhxjfcYftJV5OUc+O94Z9C3BYckvqkfrVbH96d7aYUmZQnaWOVBMo muwMRgbqdzaC/ILbJPwwfjMZjLIpdlbU2FXVTn7OJ2rqchdqn9mGNbMhm4NpTN8it3z8Is 5++DX9jxmje4UTsWnLu9ew5EiXWoImo= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ab+rDiIe; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724878921; 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=k+Ag0KIEXPXhIYeO4viaYtekKPR+wLWVBoG/fcAtp3c=; b=5Vbu2k/yElek1BhZ7e5ctTJh9LsKUW0+CRNggptotTGVtMw6L21C637piWl8QA2JURVWI9 0LU0+MfpNBJPdwKXVc7SryDH7It4fdE6w2xIApXRyykq49N9hfRXbKocp1VBKXQ5IXd83q arFTMUwplT06k6OXOON8UeKgaLHjDKY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724878992; 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=k+Ag0KIEXPXhIYeO4viaYtekKPR+wLWVBoG/fcAtp3c=; b=ab+rDiIeaDPKwWoznEQPBnM+9op9Agq4lCbrAAb+wYXQXdOGg9Zmqq5KNkfnS2i3UJkGxz 35otL0BURzeu7rB4y/YX03vh6uxnlPHsBVxe7zX+mmQJ8CTXVg/wQlDdnwF8tB8OdoWuPD vcIXcQAc5Umaw9zmYae2tYQtzkIcj4w= Received: from mx-prod-mc-02.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-686-txbxPPosMOmM4C5xzMQn5w-1; Wed, 28 Aug 2024 17:03:11 -0400 X-MC-Unique: txbxPPosMOmM4C5xzMQn5w-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6DAE71955D4D; Wed, 28 Aug 2024 21:03:07 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.30]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7442630001A1; Wed, 28 Aug 2024 21:03:01 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Paulo Alcantara , Tom Talpey , Dominique Martinet , 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 Subject: [PATCH 1/6] cifs: Fix lack of credit renegotiation on read retry Date: Wed, 28 Aug 2024 22:02:42 +0100 Message-ID: <20240828210249.1078637-2-dhowells@redhat.com> In-Reply-To: <20240828210249.1078637-1-dhowells@redhat.com> References: <20240828210249.1078637-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 34BFD40025 X-Stat-Signature: fwtk4m31nykeq9aq8gpukc9kb8dcz3ne X-Rspam-User: X-HE-Tag: 1724878993-102146 X-HE-Meta: U2FsdGVkX18gBWXYu8ALnPmFIdC9VpR9eHV/OrxoK9sbwnxGu+9JNfbptYDUZPhqzsdkMHOR4l1vY+PpsyNgGbxYMgNLIVhrWQgJVmTgFUtUatoZu5F5H2IrAnn4t30rZLQ+fEKuIxj8eiNQMJ+cO05Phep6qCKIlqWM/fJbUZ4blTtD9ng/vEsaZot+CDU4B00XV937Jjz7eMCvlLTHtNVVpWBy2futiBP/XyW/LLMVZTYmkvF62EARYTNIzpCaqRFXW2oiCks8biuoocv2HlnvtG2BjAk7h+Lfxf09WHmWds+rizvnBLfoMn4nJk/aE9K1IgTn30uZSura7c6X5C/b2DZV4ALqJeU8SH2WRdwaakOLnQWr/IY3ZMuMHFaHY46ortqnbCPIEPLPXppXEsUp2tmFK0pu2TbHKvv0JFfy3+5XegGpw24MnblzZzbLoK38MlWybwN06jelJIb0who8ZJNjn1nkYE6lodMWPVmjps5A36yPQYfgnoemErRAP/KTDxWWCnLyJqqtn9GvRcePc1s6bOKqha0g77RR7ibotoqLTDFfKSG7fZev4FR/Rwbe8ilzvdOMejUypSrZIJ1BGerK5HXMQdlGiN+kJdbns4EcZFmFPjLH8ek4kZGBOWL4nJZhgz3qgUB787Dh4+LQSwxF+xx2J4dqg1k/FOl+DxG2kxYdS0Lpm/Nutuaeyxq1hQnJNcgL8wSak+TxAexZAinNwUy7vtE3t+MY90nnCkT5wX8UZDCRAZmZdvcfsvPt0S/nU0ktXAj1w5vuMRN2aJbAW08z9y4uNziNlVyFcmo9eg5Mrjl4WmHDph1+qm5dmnfa42mJPkFa4k2evS7BaJGdJFxsVqBsEwNMb3CuRYeJ4vxk4TULg6jTkl2XSyWEgCDW9Fzi7wFdfsa5HY8e5o/z60e/fg49tzUXBg4KcCQlr4N624RX/hrMR8nhlpABs9oVglA+wenk+Kq bTVSvJfx CSXkwRj1UxizvArH7wEbempXkP43AdbcknOdjEltT+5lxcykVGlEvK0OeOdBcoiWrIkQDRdbu6MGd61sRXe8Kxg8Ks6WilkfSo2815ql4VMm0KpwJSQEi3nhGZJp0h/yh2SyRHLdHr6AB9GUCEY3S1ujG+yZPrW+x9RzW5/3q89NMVmJ29cW5qqpoEAxSKMiCi/diWX18knBBWQm7hM74W7zcFhBKu2EUEAaPpBQ4cdQMBQcOHpTw7tBxYN6omNn7L4f0UvOnhYuri29HSPv1CdzudUHq776S2x1MasvxWtIGGBz36IFKc22YcDGELUkySQyugf3QewGKfG3dfrXBGqcZUBmsXh+06xjLWwcqAQI2gm6prk4/e5zNwu3MtcIrxXEXVxH7jzbj4xdEGC22nq4zw1BTPXeq87ax8ciOgfRglMhZL1tLqRfZaMiCHlVfAbm3VNfRIln0JwmKN9SCYgrYPML4Q+x+rZTg7YHH+fkzfaFzhdKsc7bvcA+I/Yh/HyH+ 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: When netfslib asks cifs to issue a read operation, it prefaces this with a call to ->clamp_length() which cifs uses to negotiate credits, providing receive capacity on the server; however, in the event that a read op needs reissuing, netfslib doesn't call ->clamp_length() again as that could shorten the subrequest, leaving a gap. This causes the retried read to be done with zero credits which causes the server to reject it with STATUS_INVALID_PARAMETER. This is a problem for a DIO read that is requested that would go over the EOF. The short read will be retried, causing EINVAL to be returned to the user when it fails. Fix this by making cifs_req_issue_read() negotiate new credits if retrying (NETFS_SREQ_RETRYING now gets set in the read side as well as the write side in this instance). This isn't sufficient, however: the new credits might not be sufficient to complete the remainder of the read, so also add an additional field, rreq->actual_len, that holds the actual size of the op we want to perform without having to alter subreq->len. We then rely on repeated short reads being retried until we finish the read or reach the end of file and make a zero-length read. Also fix a couple of places where the subrequest start and length need to be altered by the amount so far transferred when being used. 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 | 2 ++ fs/smb/client/cifsglob.h | 1 + fs/smb/client/file.c | 37 +++++++++++++++++++++++++++++++++---- fs/smb/client/smb2ops.c | 2 +- fs/smb/client/smb2pdu.c | 28 +++++++++++++++++----------- fs/smb/client/trace.h | 1 + 6 files changed, 55 insertions(+), 16 deletions(-) diff --git a/fs/netfs/io.c b/fs/netfs/io.c index 4da0a494e860..3303b515b536 100644 --- a/fs/netfs/io.c +++ b/fs/netfs/io.c @@ -306,6 +306,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_io_request *rreq) break; subreq->source = NETFS_DOWNLOAD_FROM_SERVER; subreq->error = 0; + __set_bit(NETFS_SREQ_RETRYING, &subreq->flags); netfs_stat(&netfs_n_rh_download_instead); trace_netfs_sreq(subreq, netfs_sreq_trace_download_instead); netfs_get_subrequest(subreq, netfs_sreq_trace_get_resubmit); @@ -313,6 +314,7 @@ static bool netfs_rreq_perform_resubmissions(struct netfs_io_request *rreq) netfs_reset_subreq_iter(rreq, subreq); netfs_read_from_server(rreq, subreq); } else if (test_bit(NETFS_SREQ_SHORT_IO, &subreq->flags)) { + __set_bit(NETFS_SREQ_RETRYING, &subreq->flags); netfs_reset_subreq_iter(rreq, subreq); netfs_rreq_short_read(rreq, subreq); } diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index f379b9dc93ba..9eae8649f90c 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -1485,6 +1485,7 @@ struct cifs_io_subrequest { struct cifs_io_request *req; }; ssize_t got_bytes; + size_t actual_len; unsigned int xid; int result; bool have_xid; diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c index f9b302cb8233..2d387485f05b 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -111,6 +111,7 @@ static void cifs_issue_write(struct netfs_io_subrequest *subreq) goto fail; } + wdata->actual_len = wdata->subreq.len; rc = adjust_credits(wdata->server, wdata, cifs_trace_rw_credits_issue_write_adjust); if (rc) goto fail; @@ -153,7 +154,7 @@ static bool cifs_clamp_length(struct netfs_io_subrequest *subreq) struct cifs_io_request *req = container_of(subreq->rreq, struct cifs_io_request, rreq); struct TCP_Server_Info *server = req->server; struct cifs_sb_info *cifs_sb = CIFS_SB(rreq->inode->i_sb); - size_t rsize = 0; + size_t rsize; int rc; rdata->xid = get_xid(); @@ -166,8 +167,8 @@ static bool cifs_clamp_length(struct netfs_io_subrequest *subreq) cifs_sb->ctx); - rc = server->ops->wait_mtu_credits(server, cifs_sb->ctx->rsize, &rsize, - &rdata->credits); + rc = server->ops->wait_mtu_credits(server, cifs_sb->ctx->rsize, + &rsize, &rdata->credits); if (rc) { subreq->error = rc; return false; @@ -183,7 +184,8 @@ static bool cifs_clamp_length(struct netfs_io_subrequest *subreq) server->credits, server->in_flight, 0, cifs_trace_rw_credits_read_submit); - subreq->len = min_t(size_t, subreq->len, rsize); + subreq->len = umin(subreq->len, rsize); + rdata->actual_len = subreq->len; #ifdef CONFIG_CIFS_SMB_DIRECT if (server->smbd_conn) @@ -203,12 +205,39 @@ static void cifs_req_issue_read(struct netfs_io_subrequest *subreq) struct netfs_io_request *rreq = subreq->rreq; struct cifs_io_subrequest *rdata = container_of(subreq, struct cifs_io_subrequest, subreq); struct cifs_io_request *req = container_of(subreq->rreq, struct cifs_io_request, rreq); + struct TCP_Server_Info *server = req->server; + struct cifs_sb_info *cifs_sb = CIFS_SB(rreq->inode->i_sb); int rc = 0; cifs_dbg(FYI, "%s: op=%08x[%x] mapping=%p len=%zu/%zu\n", __func__, rreq->debug_id, subreq->debug_index, rreq->mapping, subreq->transferred, subreq->len); + if (test_bit(NETFS_SREQ_RETRYING, &subreq->flags)) { + /* + * As we're issuing a retry, we need to negotiate some new + * credits otherwise the server may reject the op with + * INVALID_PARAMETER. Note, however, we may get back less + * credit than we need to complete the op, in which case, we + * shorten the op and rely on additional rounds of retry. + */ + size_t rsize = umin(subreq->len - subreq->transferred, + cifs_sb->ctx->rsize); + + rc = server->ops->wait_mtu_credits(server, rsize, &rdata->actual_len, + &rdata->credits); + if (rc) + goto out; + + rdata->credits.in_flight_check = 1; + + trace_smb3_rw_credits(rdata->rreq->debug_id, + rdata->subreq.debug_index, + rdata->credits.value, + server->credits, server->in_flight, 0, + cifs_trace_rw_credits_read_resubmit); + } + if (req->cfile->invalidHandle) { do { rc = cifs_reopen_file(req->cfile, true); diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 0b9cb1a60d4a..a6f00b157275 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -301,7 +301,7 @@ smb2_adjust_credits(struct TCP_Server_Info *server, unsigned int /*enum smb3_rw_credits_trace*/ trace) { struct cifs_credits *credits = &subreq->credits; - int new_val = DIV_ROUND_UP(subreq->subreq.len, SMB2_MAX_BUFFER_SIZE); + int new_val = DIV_ROUND_UP(subreq->actual_len, SMB2_MAX_BUFFER_SIZE); int scredits, in_flight; if (!credits->value || credits->value == new_val) diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 2d7e6c42cf18..be7a1a9c691d 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -4529,9 +4529,9 @@ smb2_readv_callback(struct mid_q_entry *mid) "rdata server %p != mid server %p", rdata->server, mid->server); - cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%zu\n", + cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%zu/%zu\n", __func__, mid->mid, mid->mid_state, rdata->result, - rdata->subreq.len); + rdata->actual_len, rdata->subreq.len - rdata->subreq.transferred); switch (mid->mid_state) { case MID_RESPONSE_RECEIVED: @@ -4585,15 +4585,18 @@ smb2_readv_callback(struct mid_q_entry *mid) rdata->subreq.debug_index, rdata->xid, rdata->req->cfile->fid.persistent_fid, - tcon->tid, tcon->ses->Suid, rdata->subreq.start, - rdata->subreq.len, rdata->result); + tcon->tid, tcon->ses->Suid, + rdata->subreq.start + rdata->subreq.transferred, + rdata->actual_len, + rdata->result); } else trace_smb3_read_done(rdata->rreq->debug_id, rdata->subreq.debug_index, rdata->xid, rdata->req->cfile->fid.persistent_fid, tcon->tid, tcon->ses->Suid, - rdata->subreq.start, rdata->got_bytes); + rdata->subreq.start + rdata->subreq.transferred, + rdata->got_bytes); if (rdata->result == -ENODATA) { /* We may have got an EOF error because fallocate @@ -4621,6 +4624,7 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) { int rc, flags = 0; char *buf; + struct netfs_io_subrequest *subreq = &rdata->subreq; struct smb2_hdr *shdr; struct cifs_io_parms io_parms; struct smb_rqst rqst = { .rq_iov = rdata->iov, @@ -4631,15 +4635,15 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) int credit_request; cifs_dbg(FYI, "%s: offset=%llu bytes=%zu\n", - __func__, rdata->subreq.start, rdata->subreq.len); + __func__, subreq->start, subreq->len); if (!rdata->server) rdata->server = cifs_pick_channel(tcon->ses); io_parms.tcon = tlink_tcon(rdata->req->cfile->tlink); io_parms.server = server = rdata->server; - io_parms.offset = rdata->subreq.start; - io_parms.length = rdata->subreq.len; + io_parms.offset = subreq->start + subreq->transferred; + io_parms.length = rdata->actual_len; io_parms.persistent_fid = rdata->req->cfile->fid.persistent_fid; io_parms.volatile_fid = rdata->req->cfile->fid.volatile_fid; io_parms.pid = rdata->req->pid; @@ -4654,11 +4658,13 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) rdata->iov[0].iov_base = buf; rdata->iov[0].iov_len = total_len; + rdata->got_bytes = 0; + rdata->result = 0; shdr = (struct smb2_hdr *)buf; if (rdata->credits.value > 0) { - shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->subreq.len, + shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->actual_len, SMB2_MAX_BUFFER_SIZE)); credit_request = le16_to_cpu(shdr->CreditCharge) + 8; if (server->credits >= server->max_credits) @@ -4682,11 +4688,11 @@ smb2_async_readv(struct cifs_io_subrequest *rdata) if (rc) { cifs_stats_fail_inc(io_parms.tcon, SMB2_READ_HE); trace_smb3_read_err(rdata->rreq->debug_id, - rdata->subreq.debug_index, + subreq->debug_index, rdata->xid, io_parms.persistent_fid, io_parms.tcon->tid, io_parms.tcon->ses->Suid, - io_parms.offset, io_parms.length, rc); + io_parms.offset, rdata->actual_len, rc); } async_readv_out: diff --git a/fs/smb/client/trace.h b/fs/smb/client/trace.h index 0f0c10c7ada7..8e9964001e2a 100644 --- a/fs/smb/client/trace.h +++ b/fs/smb/client/trace.h @@ -30,6 +30,7 @@ EM(cifs_trace_rw_credits_old_session, "old-session") \ EM(cifs_trace_rw_credits_read_response_add, "rd-resp-add") \ EM(cifs_trace_rw_credits_read_response_clear, "rd-resp-clr") \ + EM(cifs_trace_rw_credits_read_resubmit, "rd-resubmit") \ EM(cifs_trace_rw_credits_read_submit, "rd-submit ") \ EM(cifs_trace_rw_credits_write_prepare, "wr-prepare ") \ EM(cifs_trace_rw_credits_write_response_add, "wr-resp-add") \ From patchwork Wed Aug 28 21:02:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13781954 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 6B987C7113C for ; Wed, 28 Aug 2024 21:03:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6BAF6B0093; Wed, 28 Aug 2024 17:03:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E1B866B0095; Wed, 28 Aug 2024 17:03:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE30C6B0096; Wed, 28 Aug 2024 17:03:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B2A906B0093 for ; Wed, 28 Aug 2024 17:03:29 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6FAF01C4CF3 for ; Wed, 28 Aug 2024 21:03:29 +0000 (UTC) X-FDA: 82502880138.01.BB582DE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 98C68100014 for ; Wed, 28 Aug 2024 21:03:27 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eonLIneL; spf=pass (imf14.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1724878919; 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=SffgkMs/hp1KXQEZaoQRSa21BzPv6+eMsTbdq3Ogtdc=; b=ilbRn6PKC9LwFno/eWFj1hesFF+uHfm4/MTVWTKVFzCkj+cNJPe9Msp0L6TpXd7mXOmZPZ jRbTxB6Qk+8Gk4xeI8ts9PLem2YMIL5pjA2dmL/27ejyNMWxkHytXMZXqffarNS11kAGJU LCjzOpxIITJPlFcXiVpbHJBRxoUcqOg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724878919; a=rsa-sha256; cv=none; b=OnIUYTXzOM2DKcP+BXznuA4N4tBS2lbIEQCRqFQh1bspq0Thv9xfZGGuG1g88EhURYQngk Z4WtwHllnwjJmcsvChpXKKzX1RHBAul2QeL860oggGS5+LM09yyIDZFeZ4hLJ9FzgSWtSC l+08BohS3a+zInlx5Uwhya/mTAynhOE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eonLIneL; spf=pass (imf14.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724879006; 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=SffgkMs/hp1KXQEZaoQRSa21BzPv6+eMsTbdq3Ogtdc=; b=eonLIneLgV34pw2NDgKbqtobNIGvn2ShZP18i4iDmDR+r4nft8zAjWwu6yXN0eLvaCn1eX xGrnKd5TajF2LGuKkyGu7Tu5qnz0fQV6qymi0oYSOdY+4JwoI3aKYEmKa43HkUTcHUXNxL 2VlDFVft4KPJLSb1n8BybbbzyYTRsd0= Received: from mx-prod-mc-02.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-408-vTkglQjNNRCmXpRkS29Zvg-1; Wed, 28 Aug 2024 17:03:18 -0400 X-MC-Unique: vTkglQjNNRCmXpRkS29Zvg-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5A8181955D4E; Wed, 28 Aug 2024 21:03:14 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.30]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 115191955BF2; Wed, 28 Aug 2024 21:03:08 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Paulo Alcantara , Tom Talpey , Dominique Martinet , 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 Subject: [PATCH 2/6] netfs, cifs: Fix handling of short DIO read Date: Wed, 28 Aug 2024 22:02:43 +0100 Message-ID: <20240828210249.1078637-3-dhowells@redhat.com> In-Reply-To: <20240828210249.1078637-1-dhowells@redhat.com> References: <20240828210249.1078637-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Stat-Signature: qniwycbpotwjrnzm6c1ffekhi9dc1dby X-Rspamd-Queue-Id: 98C68100014 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724879007-661943 X-HE-Meta: U2FsdGVkX18+laldmH0BZow+5BtZttvSdFlamhfiRo2DjuP5iz5ns3lLU9D4dCkKPED+E0QmsI1J7mQm2F4AhqYmI3/2iI+XX3cjkInCJTG+L3h01s8i2v3+kWRi+TKjNHsiCjGsCNAcUBVDihDu+wE9S59EaeRxvigDWkTm0ZwmWY4Wv6RW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CLC282rxWTV21zzxlSZfeUtJpYkw2vUNBye2TMN6Vwm9X6o4va+gdZY6yFX7mZquU1EsMr+WlUTgJ6qTaJmsCuMlKW6pSV4zTZyMy0vs5kM1hYEFE/b2ZW5MsW85LYEDCxh5cbNpxHmwp3gCrg1vl5vch/68xEpF66SevFNAu2EIGSObdQ7QW1wAIRpiAj/49eRTO3XRWC09L95GF8MizIc/zH9wcJUW0baqgbzYCOs1Yu 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. (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 | 13 +++++++++---- include/linux/netfs.h | 1 + 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/fs/netfs/io.c b/fs/netfs/io.c index 3303b515b536..943128507af5 100644 --- a/fs/netfs/io.c +++ b/fs/netfs/io.c @@ -368,7 +368,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; } @@ -503,7 +504,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: @@ -782,10 +784,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 be7a1a9c691d..88dc49d67037 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 = @@ -4599,11 +4600,15 @@ smb2_readv_callback(struct mid_q_entry *mid) rdata->got_bytes); if (rdata->result == -ENODATA) { - /* We may have got an EOF error because fallocate - * failed to enlarge the file. - */ - if (rdata->subreq.start < rdata->subreq.rreq->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 { From patchwork Wed Aug 28 21:02:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13781955 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 598DEC71147 for ; Wed, 28 Aug 2024 21:03:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A28766B0095; Wed, 28 Aug 2024 17:03:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C6646B0096; Wed, 28 Aug 2024 17:03:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F02F6B0098; Wed, 28 Aug 2024 17:03:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 52B056B0095 for ; Wed, 28 Aug 2024 17:03:30 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 01B3EC07AF for ; Wed, 28 Aug 2024 21:03:29 +0000 (UTC) X-FDA: 82502880180.17.D3E57E2 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 4AAE6140013 for ; Wed, 28 Aug 2024 21:03:28 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UQP4RqFT; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1724878963; a=rsa-sha256; cv=none; b=w7X8U5152FQQzAfdKYEqWy9/iU4VHSATBdXbsax2WZL6kAybQ2f6O/2Ye7GHy3VtWGLIOS QT5Gey4vrLvkVjsvmCJX24R2BxqvMMaR+3aHuSccX5T1UFPMg/XlAGDTKtVRcaagJy158e IsZstGTqbFvbUj5gGwaPn8GByka3Sig= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UQP4RqFT; spf=pass (imf23.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1724878963; 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=29rNMGcbzhhOXDnkGZZqENHeVIOwTy/JkQWfMjJEQZk=; b=cO/PvhmJ8IvbEcxsP/NmYMMF7CuMy+7K5QB78c+OVDKCQriJLv6ZF9SM/84IL6SgeC1J3S 2pWDv2tfy7kXihDAXT+t6d3VG9WWyyqyZ2ucXxiPaca67KaFAxJbRSAA+0oJ1EbWjIadVj UipRYBO/Ydfg0kQppCqPfW0LXVjvCHA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724879007; 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=29rNMGcbzhhOXDnkGZZqENHeVIOwTy/JkQWfMjJEQZk=; b=UQP4RqFTR76c/OHdYgdQnAcRt7gxPvetQSF0PaUH7SDvdbREzQTrM2nISSPfXD+CvIot7M iMqha0zuLikwtcASkJ40S6U071aG5um+CImIv/b3/EGhsXRfwoxtfI4V+opV2BkRSGjcgJ E9cyz6i0+Xc43wjk/kxZ7zsFBbLfZ1U= Received: from mx-prod-mc-04.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-62-Gp7aQV_ZPh6R-b_4tg_Akg-1; Wed, 28 Aug 2024 17:03:24 -0400 X-MC-Unique: Gp7aQV_ZPh6R-b_4tg_Akg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 30BFC19560B7; Wed, 28 Aug 2024 21:03:21 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.30]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B57471955F1B; Wed, 28 Aug 2024 21:03:15 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Paulo Alcantara , Tom Talpey , Dominique Martinet , 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 , Shyam Prasad N , Rohith Surabattula Subject: [PATCH 3/6] cifs: Fix copy offload to flush destination region Date: Wed, 28 Aug 2024 22:02:44 +0100 Message-ID: <20240828210249.1078637-4-dhowells@redhat.com> In-Reply-To: <20240828210249.1078637-1-dhowells@redhat.com> References: <20240828210249.1078637-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Stat-Signature: 1purhbig8o1p8rxhbyrp65aqhk76y5b9 X-Rspamd-Queue-Id: 4AAE6140013 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724879008-949426 X-HE-Meta: U2FsdGVkX1+lp7ZaM09kqE78yohYQDKMllDPyouD+Q13xZiWqcY1a30d8n0uwWXAhhLnxkhw8XkqzMh1sBc3c+5fwZTYBxOCSQz/Vg9ajX6ChcSGb8aKFBy8qOI5hcp1UzPQGzbn7iTbTsDylYM3TTizvSiYByYWqpzzmcI37feCMBC+UKadT+oQa0LsjQaMsLyQIPYugOHVjvR9RlKRFP8xArJKpklTAjKea84hAe01ekaD21GnI1uYWo39ejEi4IdGTz+seiLo8+bXBsrYkWkxv856NOI43opPjT8rvOri+A7owvM1mgNCGYyDptBBbNFS+t9Wlo0kbTeDk5ynrTHpnOnUxXRIWOv1bCvnIeYltozosJXcCJlZ9DGOq4ZIIyeTl9eXT9emPsqtosUqUImRsimElghBkGDT4EbFBewhBwt1gWJsYcE37+4fBSNBUKUFx+53mIqEXjsWej/eCbOgiPFTVsdczHhO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Ac3oWaKf21UvL+XhPpzzg8FeFszXPPE3CgEQlgpLjcFMydR0Y8axDYf7XGbaz/QkSpafIUeT8uPMC1bwxUv5sukBRdP9vuKoTRn6YOXFJFrHdJck/2w= 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: Fix cifs_file_copychunk_range() to flush the destination region before invalidating it to avoid potential loss of data should the copy fail, in whole or in part, in some way. Fixes: 7b2404a886f8 ("cifs: Fix flushing, invalidation and file size with copy_file_range()") Signed-off-by: David Howells cc: Steve French cc: Paulo Alcantara cc: Shyam Prasad N cc: Rohith Surabattula cc: Matthew Wilcox cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- fs/smb/client/cifsfs.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c index d89485235425..2a2523c93944 100644 --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -1341,7 +1341,6 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, struct cifsFileInfo *smb_file_target; struct cifs_tcon *src_tcon; struct cifs_tcon *target_tcon; - unsigned long long destend, fstart, fend; ssize_t rc; cifs_dbg(FYI, "copychunk range\n"); @@ -1391,25 +1390,13 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, goto unlock; } - destend = destoff + len - 1; - - /* Flush the folios at either end of the destination range to prevent - * accidental loss of dirty data outside of the range. + /* Flush and invalidate all the folios in the destination region. If + * the copy was successful, then some of the flush is extra overhead, + * but we need to allow for the copy failing in some way (eg. ENOSPC). */ - fstart = destoff; - fend = destend; - - rc = cifs_flush_folio(target_inode, destoff, &fstart, &fend, true); + rc = filemap_invalidate_inode(target_inode, true, destoff, destoff + len - 1); if (rc) goto unlock; - rc = cifs_flush_folio(target_inode, destend, &fstart, &fend, false); - if (rc) - goto unlock; - if (fend > target_cifsi->netfs.zero_point) - target_cifsi->netfs.zero_point = fend + 1; - - /* Discard all the folios that overlap the destination region. */ - truncate_inode_pages_range(&target_inode->i_data, fstart, fend); fscache_invalidate(cifs_inode_cookie(target_inode), NULL, i_size_read(target_inode), 0); From patchwork Wed Aug 28 21:02:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13781956 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 52CC2C7113C for ; Wed, 28 Aug 2024 21:03:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1E156B0099; Wed, 28 Aug 2024 17:03:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF4BA6B009A; Wed, 28 Aug 2024 17:03:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C95BC6B009B; Wed, 28 Aug 2024 17:03:40 -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 A94C06B0099 for ; Wed, 28 Aug 2024 17:03:40 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6B424A9CB0 for ; Wed, 28 Aug 2024 21:03:40 +0000 (UTC) X-FDA: 82502880600.15.18DD68E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id A642940017 for ; Wed, 28 Aug 2024 21:03:38 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DtD67Plb; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724878947; a=rsa-sha256; cv=none; b=gflCbnSxFIyCBnDblxv5DUuVe9dV6JULBebYgUkOWFqCog5wYdomicMgyFyBP4eARYom0l tfPjkg3KiV9mOxxMCTSqJtVvWOmZaZuqoDxDtuyxy1PkTJogdE7JZtircghTmAKY+1JytQ DXHv0OqI1XdDVcQN/BAw2zDgDWgVzE4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DtD67Plb; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724878947; 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=gafgwUBwZzk/cup16/E12xqM5SQfOL2Vg1E23SCR1HY=; b=loGu2BA7TOiBagH8OpgGqeEBnX8fC1J6EgZNby197daxmmvE9K7Gw7n9hOKm4zIv3Xu/Vm 3FKWpPXyetfyN7ybXshNaNEf2CHEFOsPhc03ifBgwATle58joR/f42iL6zS7O38w2v6R/H E8MakD7hSICgG0wzzM2cMTtAK3PgC5o= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724879017; 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=gafgwUBwZzk/cup16/E12xqM5SQfOL2Vg1E23SCR1HY=; b=DtD67PlbQo9ebJ6xIlK8ueZ+YmfBDtyTv6bHjHEYBwpcPGDLjW4BtjkJOy1sqdRYhB78UP zwhbSTHGP/8JW+oxGYwL6RDKcku0MusGNuLbCoXPvlqRkgYHsDcZeXKG6UQ5+iBsbCq6aY yAiuHz+2iyrMVlsb1L9P3EINtyptTPk= Received: from mx-prod-mc-03.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-556-nlBAerB_MSuc8tJsU0uD8A-1; Wed, 28 Aug 2024 17:03:34 -0400 X-MC-Unique: nlBAerB_MSuc8tJsU0uD8A-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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 060FE1955BEE; Wed, 28 Aug 2024 21:03:30 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.30]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 74A7019560A3; Wed, 28 Aug 2024 21:03:21 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Paulo Alcantara , Tom Talpey , Dominique Martinet , 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, Miklos Szeredi , Trond Myklebust , Christoph Hellwig , Andrew Morton , Alexander Viro , Christian Brauner , devel@lists.orangefs.org Subject: [PATCH 4/6] mm: Fix filemap_invalidate_inode() to use invalidate_inode_pages2_range() Date: Wed, 28 Aug 2024 22:02:45 +0100 Message-ID: <20240828210249.1078637-5-dhowells@redhat.com> In-Reply-To: <20240828210249.1078637-1-dhowells@redhat.com> References: <20240828210249.1078637-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A642940017 X-Stat-Signature: 4kzo5nisnzihgo6gwb4emusaqiwqd6hb X-Rspam-User: X-HE-Tag: 1724879018-304602 X-HE-Meta: U2FsdGVkX19Mr+WVegBZQn6GChzDMFS7f8cyRbjqSiLC9nOepcuizFvac+ExbzThpfwUF93V788PRGhLnCFoCAQU9wo/lHhMA1BAHTWnOCEeQmj/FMWMef3IWOIht/gglk9U0X/8GZ33Mr0yY6JcaTAit+dGI6kxAQLn4lPLbP/WbeU6PYwIKP4YO+TB8CcZwTHBK8nQfEAIhz5/ADTBKkn7f7suooJm9VLIrda99VTQsi3WaBrxpQhgMxB8yA3mzFZj/nrYJTj4FxdIia/aCeB7EW6rioX5kcCZMOogJdZV+3lTfrePibMw250evfVjmKYtpDta1dulctCNeyLTp1s5jjSwoupbS6+e6WK6PdcXG5vJzuy3HJKwFmj/5Eqj7yXCy6TPvgoCTd09xfpGz6OPxEm4oCr1k0unkhJVF/z9nQ5MgjwhKsuArNQUrWs82nYK1K/Xllgkpq8tRJwij3sqxPPVzTlUvXbTkBCNb+4GfWcXYE9oS97uuxGHJNMNbZVpuYYS3nwMPHsk7UUPLaKiE2nwvJ7cUzpdR4CXr95vjpbtDWRbNoT2UeV++H5Ni6meRltBnAl0T9Wd8wmPZVb6x+7KkOXDdZdfNHj5VkgeJUPUqJ189kimLB0B81TaDhVRmKYV3+c2kCNEgLDAc0M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ykt9x6EOn0hya7W7poqodXzNdGGfhdTX0CsK2VM6mlfosw 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: Fix filemap_invalidate_inode() to use invalidate_inode_pages2_range() rather than truncate_inode_pages_range(). The latter clears the invalidated bit of a partial pages rather than discarding it entirely. This causes copy_file_range() to fail on cifs because the partial pages at either end of the destination range aren't evicted and reread, but rather just partly cleared. This causes generic/075 and generic/112 xfstests to fail. Fixes: 74e797d79cf1 ("mm: Provide a means of invalidation without using launder_folio") Signed-off-by: David Howells cc: Matthew Wilcox cc: Miklos Szeredi cc: Trond Myklebust cc: Christoph Hellwig cc: Andrew Morton cc: Alexander Viro cc: Christian Brauner cc: Jeff Layton cc: linux-mm@kvack.org cc: linux-fsdevel@vger.kernel.org cc: netfs@lists.linux.dev cc: v9fs@lists.linux.dev cc: linux-afs@lists.infradead.org cc: ceph-devel@vger.kernel.org cc: linux-cifs@vger.kernel.org cc: linux-nfs@vger.kernel.org cc: devel@lists.orangefs.org --- mm/filemap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/filemap.c b/mm/filemap.c index d62150418b91..0ca9c1377b68 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -4231,7 +4231,7 @@ int filemap_invalidate_inode(struct inode *inode, bool flush, } /* Wait for writeback to complete on all folios and discard. */ - truncate_inode_pages_range(mapping, start, end); + invalidate_inode_pages2_range(mapping, start / PAGE_SIZE, end / PAGE_SIZE); unlock: filemap_invalidate_unlock(mapping); From patchwork Wed Aug 28 21:02:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13781957 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 ED4C2C71147 for ; Wed, 28 Aug 2024 21:03:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8043A6B009B; Wed, 28 Aug 2024 17:03:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78C8A6B009C; Wed, 28 Aug 2024 17:03:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 653BB6B009D; Wed, 28 Aug 2024 17:03:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4444F6B009B for ; Wed, 28 Aug 2024 17:03:46 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 020121C3E96 for ; Wed, 28 Aug 2024 21:03:45 +0000 (UTC) X-FDA: 82502880852.19.DACEC96 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 41DA580010 for ; Wed, 28 Aug 2024 21:03:44 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aUCl8CDd; spf=pass (imf30.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=1724879003; 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=cZLOwDsDBBJUFs2hQlOukyGuDHu131MWSIeu0yUM/RI=; b=D94iCKpyNgpLJPQ86DxQSGRLFwYLF12ybrg1jkQnQV4giXqPw+v/jr9O5sTo37jhrkuqee R533J9+dWu2pP6YUqxmWHylv2F259HyIsNzCchpflcM/BOxlGup+nPix2nX4eysYniGJNA 7x/xHEyfn04zHTEGt3jVDj9MEIfacXg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aUCl8CDd; spf=pass (imf30.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=1724879003; a=rsa-sha256; cv=none; b=2ZF21Vo5SlLEh3Kx4OrH6S/JDOONsgYscCsGfQPcFK6AMqJqrbyJhGrv/Kf4ULuDL7S9us S5FQbzgz+d5sivPj9H1pMtSq70dnJPVg8xB3502Stj4k5YfwUsHw6svPgNsPPYr2PZEHwV ItSrPxYUum7veQ32/mMNWYyvb+bjhLo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724879023; 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=cZLOwDsDBBJUFs2hQlOukyGuDHu131MWSIeu0yUM/RI=; b=aUCl8CDdxJQ9A5HaTLTS+e3wXVxPEM4LVuRUwEoC0KkG9kmQMm4PW+h5r9ge++K5n8d6g9 3uKGuAZ5IJap4sjd+EyePoDi5f5tZlaoF1XtOCgKfZpVi2hfrx2IlSiZHIspJ4Wc1x+ezu hCL5+VNwIrdVgabNAVqyeS8r755bRfI= Received: from mx-prod-mc-01.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-465-vc_IMyGmMNa-yhlY57doPw-1; Wed, 28 Aug 2024 17:03:40 -0400 X-MC-Unique: vc_IMyGmMNa-yhlY57doPw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 06D7A1955D48; Wed, 28 Aug 2024 21:03:37 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.30]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4C66B30001A1; Wed, 28 Aug 2024 21:03:30 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Paulo Alcantara , Tom Talpey , Dominique Martinet , 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 , Zhang Xiaoxu , Pavel Shilovsky , Shyam Prasad N , Rohith Surabattula Subject: [PATCH 5/6] cifs: Fix FALLOC_FL_ZERO_RANGE to preflush buffered part of target region Date: Wed, 28 Aug 2024 22:02:46 +0100 Message-ID: <20240828210249.1078637-6-dhowells@redhat.com> In-Reply-To: <20240828210249.1078637-1-dhowells@redhat.com> References: <20240828210249.1078637-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspam-User: X-Stat-Signature: 3cmu7kwdcobcz65q6rxz96is5pfdcy9g X-Rspamd-Queue-Id: 41DA580010 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RYVhathOQS/4l/oj5Xs1LTbECmj5UvXHHnqpRCEIcT8++lTYtHi0+YbHzk7h4MDmerEmJ2AeTri0+c3qKfWfBBH+E4lR9cBOBlQ6IKnxqN6/mvfmIK+Woc6WVCy78YzcuKmGlXQxW/gat4F3vbl6ElFGO8FLtx629B2aFC6K8c5/7VwrBPiT2vwrvo+ItDK4UqI+7ykYsYFOWDUzIBLiyf/uOF6HzMsuq5hoCxCt1wwJ4AYM6v35shlE8iQcxhsQw3ei8LQ+xnBLFRIgc3B5IxMWjeWTH356RwkI+8d3n0OdqO3HyblSzQcuunpUeBYpOUoOTkBtpTI2MDs3Cxwsa5YrKwhd04g8+4qOUy3UFK6L9HcQYZ6XVLpF0IEsXyekKXzD7fyyPNOiVwdhpaB7ymBPO92yimW0WFvzz/FgHWTPUK3zQJsvfxAC0Tpgro05H5kDzbwYeh3WNC2fSzzTrjQO7gSIrzlHiHzihtxdt2jfI+dX+yYyO0zG0GdZYTpyqy4UVkctmVhZN4WtwC2SRy+FFlEO3QmdHHT0oAXrnv4WPR9hY0HxpKrmLlS/lwqp2msXpONG10ccQvrcMHL0j9H2wkniwtDaY 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: Under certain conditions, the range to be cleared by FALLOC_FL_ZERO_RANGE may only be buffered locally and not yet have been flushed to the server. For example: xfs_io -f -t -c "pwrite -S 0x41 0 4k" \ -c "pwrite -S 0x42 4k 4k" \ -c "fzero 0 4k" \ -c "pread -v 0 8k" /xfstest.test/foo will write two 4KiB blocks of data, which get buffered in the pagecache, and then fallocate() is used to clear the first 4KiB block on the server - but we don't flush the data first, which means the EOF position on the server is wrong, and so the FSCTL_SET_ZERO_DATA RPC fails (and xfs_io ignores the error), but then when we try to read it, we see the old data. Fix this by preflushing any part of the target region that above the server's idea of the EOF position to force the server to update its EOF position. Note, however, that we don't want to simply expand the file by moving the EOF before doing the FSCTL_SET_ZERO_DATA[*] because someone else might see the zeroed region or if the RPC fails we then have to try to clean it up or risk getting corruption. [*] And we have to move the EOF first otherwise FSCTL_SET_ZERO_DATA won't do what we want. This fixes the generic/008 xfstest. [!] Note: A better way to do this might be to split the operation into two parts: we only do FSCTL_SET_ZERO_DATA for the part of the range below the server's EOF and then, if that worked, invalidate the buffered pages for the part above the range. Fixes: 6b69040247e1 ("cifs/smb3: Fix data inconsistent when zero file range") Signed-off-by: David Howells cc: Steve French cc: Zhang Xiaoxu cc: Pavel Shilovsky cc: Paulo Alcantara cc: Shyam Prasad N cc: Rohith Surabattula cc: Jeff Layton cc: linux-cifs@vger.kernel.org cc: linux-mm@kvack.org --- fs/smb/client/smb2ops.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index a6f00b157275..4df84ebe8dbe 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3237,13 +3237,15 @@ static long smb3_zero_data(struct file *file, struct cifs_tcon *tcon, } static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, - loff_t offset, loff_t len, bool keep_size) + unsigned long long offset, unsigned long long len, + bool keep_size) { struct cifs_ses *ses = tcon->ses; struct inode *inode = file_inode(file); struct cifsInodeInfo *cifsi = CIFS_I(inode); struct cifsFileInfo *cfile = file->private_data; - unsigned long long new_size; + struct netfs_inode *ictx = netfs_inode(inode); + unsigned long long i_size, new_size, remote_size; long rc; unsigned int xid; @@ -3255,6 +3257,16 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, inode_lock(inode); filemap_invalidate_lock(inode->i_mapping); + i_size = i_size_read(inode); + remote_size = ictx->remote_i_size; + if (offset + len >= remote_size && offset < i_size) { + unsigned long long top = umin(offset + len, i_size); + + rc = filemap_write_and_wait_range(inode->i_mapping, offset, top - 1); + if (rc < 0) + goto zero_range_exit; + } + /* * We zero the range through ioctl, so we need remove the page caches * first, otherwise the data may be inconsistent with the server. From patchwork Wed Aug 28 21:02:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13781958 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 BEF6EC71143 for ; Wed, 28 Aug 2024 21:03:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 481F36B009D; Wed, 28 Aug 2024 17:03:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 430E06B009E; Wed, 28 Aug 2024 17:03:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D1CE6B009F; Wed, 28 Aug 2024 17:03:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0CC156B009D for ; Wed, 28 Aug 2024 17:03:52 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8108212083D for ; Wed, 28 Aug 2024 21:03:51 +0000 (UTC) X-FDA: 82502881062.20.6ED202D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 9697E20019 for ; Wed, 28 Aug 2024 21:03:49 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=H84WH5+U; spf=pass (imf13.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1724878941; 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=HnRbucMY226i4IUYHJiuv+7kBNxjZEs05bItUy7sjXs=; b=jTYlUKHAo5o9NQohlKAFrNrhbiQA8WOMlCHw4fNWviz6mwUeLYVPZEUbKkZhEoilhZP9Wj DST5YMBtgRSNUW12U4zzsVV0ePeybVNDRilhhxS61EKKDXKV85eh3Pf5WPTUCukhUoJ/7s rgnNLPKiy0PcsClpWOVD9obXWNHLuug= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724878941; a=rsa-sha256; cv=none; b=o49BsJCJ/T+frStjooAsku7RGNDL3m8gQMwmDR/H6iFix51Z6NKBOcUg1guS/o1gooEy3v 2EQdKDBN1Pq+xVp4uG+JvU9FpAuCE9spAhH7HnooY0bMmvd66zrG/GKEFxZfj/GR7xi0YM mIP24/uyYN6Alpe60tLWwEe+0C4zCd0= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=H84WH5+U; spf=pass (imf13.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724879028; 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=HnRbucMY226i4IUYHJiuv+7kBNxjZEs05bItUy7sjXs=; b=H84WH5+UL8UxRRVnpf9p0V5mVablrgZRKX406GqAboL5SOin45CuNKCcuFozUU0bEwRyec qjP2uVZ1VVWKany/0WmjH6KWnSDFP0Vlh/VP0Qsa8NxmknjEhinTRBRoZts5gj88ABxVzg 8NGDYgEtsEK62SYEr0xLuu+d+w+flSo= Received: from mx-prod-mc-01.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-122-iAIpNcUkPheyG0CeJjFQ_w-1; Wed, 28 Aug 2024 17:03:45 -0400 X-MC-Unique: iAIpNcUkPheyG0CeJjFQ_w-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 010F11955BF1; Wed, 28 Aug 2024 21:03:43 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.30]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5B35C1955BF2; Wed, 28 Aug 2024 21:03:38 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French Cc: David Howells , Paulo Alcantara , Tom Talpey , Dominique Martinet , 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 Subject: [PATCH 6/6] netfs, cifs: Improve some debugging bits Date: Wed, 28 Aug 2024 22:02:47 +0100 Message-ID: <20240828210249.1078637-7-dhowells@redhat.com> In-Reply-To: <20240828210249.1078637-1-dhowells@redhat.com> References: <20240828210249.1078637-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Stat-Signature: wkmpcz37zwb545iznbsatikpc9bk7mcn X-Rspamd-Queue-Id: 9697E20019 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724879029-577605 X-HE-Meta: U2FsdGVkX1/fBqg0920zmX6b+7VhmYmpioyPBQif/d4PMHN15eAGfZwaWCtKjnPCOaXtNbVFh0K4cmWhQSY+U7FAiOR+DxCbRSSwWHl3EYUia48iXBruFKMv6jmeT7wbPwuz7Qv50+GMXwkELya457WjE1q8fHfUJCfBQtFiMqVOzTCbJKnoPHdXzRma3i/k/HVAOU8WglfO7KWA5RmbzB+ZWD66kL5XdnhVnMFA3L/wk7Ggc24Oe0Mc+lEdLqe6fzLz66HX9rkJZo+zsAXY/8XDK6HRE25D+wszz/73oIE63cnSN1lNqIJN2I/As3l5Ho11H2VaakVSo92Bb7PExOkt/pkBvVSvGdVjeGS+KtpoSQsn3x26ATL6R3oH/l1GebT3kmiKqgQ1x7pZ6HIru0GkQAN7ImNqBWcPhPEbosrVyfMcejWqZ3sOpafzFv2IMRz/JmTz++w8Gu54Oj6Jqy8SJb3Dtaw/+gu0cY+lYfubT6z2KxJOCSx7U5NsTHtJpddcUv42t/ykdVqr6o4dDh6yT3BqT/TpdzUurfgQqknVaWUVJBvtUkyXmnC/+NszbhWgQ7rgU1Tc6KaZvx5yzKZdapLLOn66yHdHJNebQ+2VXIr1Q/Es4dZOoAEPZvXsu56Ow4ejAlfsBp0pVDVQcmr40SttpJ9bf4ryQBSVDAILXd+Z7rp5vCU2ZZ74N7k4isTMAUvfuKuuEz2svFv3NuEeb31ySJGd4qey6+Zs8zD+67Bz4gxCYVHeYlcYeqq3+CT2gekBroUipI9tasN3gEd5UvumQfhtRAvOVT/OcBQcqUChENmHXKVDwXCKGc6VkWVopqB6/3ag9xxhWl3Cr5cVHfu8kU7JwptRjk2jg5X0hYVg0DcOV3N1PRcyxkX6aPZ3Vohtae7p6Nek7e0vTcWriUJBoe2nl0NsxqZvZKJwzhUtYyRp8UPNsevuB4qixJ2wdmzT3HJ7OD+abb4 9IaRTSmt dG3Dvh4jNi/nSxsl4EVbrZJ1/HEq0iNo5gc7Lkw9I0CrWtXM1dyFjz5FeKLGpGz9z9dRPmxlGODwT99DeQOZ4go/CqnRjFFuP00tJQrdahAo8n0I4zna8LomTWi6axhjEYMmDKKFawJI8hsde6xdk0V8fk3jkuPNlxcldSoLp5mp1mSe7GRHucdIS7v3YrUvIIu8rEenFidTPzUGXMvXONYDMOPnRw4WP32sO7ZHaakPOzieLpv/CbS5S54ye7fD2BKtRmLFzVRSTWv+ArANBOXbJn9V89bLCl5k7AvD6PVCnrDqpVY8KPk1dVSDMc0ttFiqcFIhxT/NJt0ieizabh0g2uhNwj0Bh1l5WeThlz0//chgRcnr3PrT+/wnqXLje3KDSq8LAFJuIda0bj3xgWUUV/YVuHIjUKZwIwsfnn36cmrusAA6a4SJcg2oSTMdQRuWuZksob4oyaGfEDBHidIGUWnFGn3Y3vYb42lu6PTsLGgt+8cGT+R0V7ki2OJNDKQ50 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: Improve some debugging bits: (1) The netfslib _debug() macro doesn't need a newline in its format string. (2) Display the request debug ID and subrequest index in messages emitted in smb2_adjust_credits() to make it easier to reference in traces. 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 | 2 +- fs/smb/client/smb2ops.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/netfs/io.c b/fs/netfs/io.c index 943128507af5..d6ada4eba744 100644 --- a/fs/netfs/io.c +++ b/fs/netfs/io.c @@ -270,7 +270,7 @@ static void netfs_reset_subreq_iter(struct netfs_io_request *rreq, if (count == remaining) return; - _debug("R=%08x[%u] ITER RESUB-MISMATCH %zx != %zx-%zx-%llx %x\n", + _debug("R=%08x[%u] ITER RESUB-MISMATCH %zx != %zx-%zx-%llx %x", rreq->debug_id, subreq->debug_index, iov_iter_count(&subreq->io_iter), subreq->transferred, subreq->len, rreq->i_size, diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 4df84ebe8dbe..e6540072ffb0 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -316,7 +316,8 @@ smb2_adjust_credits(struct TCP_Server_Info *server, cifs_trace_rw_credits_no_adjust_up); trace_smb3_too_many_credits(server->CurrentMid, server->conn_id, server->hostname, 0, credits->value - new_val, 0); - cifs_server_dbg(VFS, "request has less credits (%d) than required (%d)", + cifs_server_dbg(VFS, "R=%x[%x] request has less credits (%d) than required (%d)", + subreq->rreq->debug_id, subreq->subreq.debug_index, credits->value, new_val); return -EOPNOTSUPP; @@ -338,8 +339,9 @@ smb2_adjust_credits(struct TCP_Server_Info *server, trace_smb3_reconnect_detected(server->CurrentMid, server->conn_id, server->hostname, scredits, credits->value - new_val, in_flight); - cifs_server_dbg(VFS, "trying to return %d credits to old session\n", - credits->value - new_val); + cifs_server_dbg(VFS, "R=%x[%x] trying to return %d credits to old session\n", + subreq->rreq->debug_id, subreq->subreq.debug_index, + credits->value - new_val); return -EAGAIN; }