From mboxrd@z Thu Jan 1 00:00:00 1970 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 CC92BC4167B for ; Mon, 11 Dec 2023 12:58:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 556D86B00D9; Mon, 11 Dec 2023 07:58:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 506AB6B00DA; Mon, 11 Dec 2023 07:58:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CF5B6B00DB; Mon, 11 Dec 2023 07:58:40 -0500 (EST) 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 289CA6B00D9 for ; Mon, 11 Dec 2023 07:58:40 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 00B371A0781 for ; Mon, 11 Dec 2023 12:58:39 +0000 (UTC) X-FDA: 81554541600.10.ACCB6DC Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf24.hostedemail.com (Postfix) with ESMTP id 12F15180020 for ; Mon, 11 Dec 2023 12:58:36 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=S5mEwDS0; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf24.hostedemail.com: domain of gregkh@linuxfoundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702299517; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=v751ilRGbrFfXcQ91YsjhVwHywiPRWZX/XF0Y7V9yEQ=; b=a4M1DIl+px2LuMclVWnNsLyOHvn8TB7/bgPiN0/3mf/rPoVOpsVZPM8g/VL/+6ZUJoXyzG OpdQeOvna+9wWLHlQAEKs1Nl/Cwp8MyHjqjJpDPuxJ6EY05g4UaNkAEs9dimzncCpuG5Q1 rwWPq7vuFKE/piXva/yfeekhXdMLvRQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=S5mEwDS0; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf24.hostedemail.com: domain of gregkh@linuxfoundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702299517; a=rsa-sha256; cv=none; b=1wXqq5qo/fN6w1VschZGdsdT1lkRt3yKS933GTHXuRcy9cJrLnJpLDBSSotW5NdqBBxEhI B/H7Zg42mPi5kK9CQMvkbxOwfmOLNNoLQPlpTr2JfNAGXsgkVnsPZGCtWhKqJkWFPrHVZe Q/hWvKNT+PteYHQlFKzwHPUEChvqNLo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 7B74EB80E38; Mon, 11 Dec 2023 12:58:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83AD2C433C8; Mon, 11 Dec 2023 12:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1702299512; bh=GNXCCa0ekKoPtAtCNQSIFTafRzcZqjD7uIdQu/27WTc=; h=Subject:To:Cc:From:Date:From; b=S5mEwDS04BMiBKRVC457uNeUVb7JZ6BE5xTA3UCedsTOywAbt046OJUnHNBKbaEOI O+dbE6GofhUZ0hfzHbPsl4enJ4Sj7BPMx8I0tpnv9bLINheD9YFqE/Hh3M7Jxcxosb lAP+L9ptvLAC3x2AGRU8miMJ8y8Nv5ZimHQ133n8= Subject: Patch "cifs: Fix flushing, invalidation and file size with FICLONE" has been added to the 6.1-stable tree To: dhowells@redhat.com,gregkh@linuxfoundation.org,hch@lst.de,jlayton@kernel.org,linux-mm@kvack.org,nspmangalore@gmail.com,pc@manguebit.com,rohiths.msft@gmail.com,stfrench@microsoft.com,willy@infradead.org Cc: From: Date: Mon, 11 Dec 2023 13:57:24 +0100 Message-ID: <2023121124-left-tapeless-3929@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit X-stable: commit X-Patchwork-Hint: ignore X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 12F15180020 X-Stat-Signature: s3omsyrdr4z4non89npj7gocfr5i3pph X-HE-Tag: 1702299516-221287 X-HE-Meta: U2FsdGVkX1/2hlJ/hUaiFeTPVr8Z3DuoYaTUq9Ur3mEhNK9AYkbW1bSA7hAZ2/BdQvDTOx1q6BOU4MJciiu16OKiAR7QUs0+SL1b/reuASaja3dJEfPE9kNSniIOc5D7Y0hiF2eepMGobOTU8h6Ize7HzIEPa24do8LQJzPEyt0bQggfrso16MWyGneAkp5tVPOU6NY5x758W14af3/Qhzk79UFidxfwnMhTKPL1P+v/m+qcOZ9jCpmHgwIiIRbiPB0DoEu6oEgKUXodRA8M5BApBOrRLfnK3yd5bwK7YcelKOUyRC5XQ25zJT5GQM14o0YZYYqnvSGtexKP49YzDCWzejsWghI94sPoobloPwFKipvmx4KYj8T1+diM2m4ex1xhLm22gUMuSBq8RAcJRsNdymEcot02ovCzB/RKR+vYichBo0WR6G0v1dSqAs1qPAhSIB6iymF0gn4LBG9qRFJIQSrn1Q47EPCkCh9ax0Wt90xRChJJpaQARD0RqvVqh9IRAxAtaDW6QZLPD3+UEb/NufDyt0E2HWeVq9g3sgk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gSLubVRGVEMvPkb48VkUqWSJJQ= 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: This is a note to let you know that I've just added the patch titled cifs: Fix flushing, invalidation and file size with FICLONE to the 6.1-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: cifs-fix-flushing-invalidation-and-file-size-with-ficlone.patch and it can be found in the queue-6.1 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. >From c54fc3a4f375663f2361a9cbb2955fb4ef912879 Mon Sep 17 00:00:00 2001 From: David Howells Date: Fri, 1 Dec 2023 00:22:01 +0000 Subject: cifs: Fix flushing, invalidation and file size with FICLONE From: David Howells commit c54fc3a4f375663f2361a9cbb2955fb4ef912879 upstream. Fix a number of issues in the cifs filesystem implementation of the FICLONE ioctl in cifs_remap_file_range(). This is analogous to the previously fixed bug in cifs_file_copychunk_range() and can share the helper functions. Firstly, the invalidation of the destination range is handled incorrectly: We shouldn't just invalidate the whole file as dirty data in the file may get lost and we can't just call truncate_inode_pages_range() to invalidate the destination range as that will erase parts of a partial folio at each end whilst invalidating and discarding all the folios in the middle. We need to force all the folios covering the range to be reloaded, but we mustn't lose dirty data in them that's not in the destination range. Further, we shouldn't simply round out the range to PAGE_SIZE at each end as cifs should move to support multipage folios. Secondly, there's an issue whereby a write may have extended the file locally, but not have been written back yet. This can leaves the local idea of the EOF at a later point than the server's EOF. If a clone request is issued, this will fail on the server with STATUS_INVALID_VIEW_SIZE (which gets translated to -EIO locally) if the clone source extends past the server's EOF. Fix this by: (0) Flush the source region (already done). The flush does nothing and the EOF isn't moved if the source region has no dirty data. (1) Move the EOF to the end of the source region if it isn't already at least at this point. If we can't do this, for instance if the server doesn't support it, just flush the entire source file. (2) Find the folio (if present) at each end of the range, flushing it and increasing the region-to-be-invalidated to cover those in their entirety. (3) Fully discard all the folios covering the range as we want them to be reloaded. (4) Then perform the extent duplication. Thirdly, set i_size after doing the duplicate_extents operation as this value may be used by various things internally. stat() hides the issue because setting ->time to 0 causes cifs_getatr() to revalidate the attributes. These were causing the cifs/001 xfstest to fail. Fixes: 04b38d601239 ("vfs: pull btrfs clone API to vfs layer") Signed-off-by: David Howells Cc: stable@vger.kernel.org cc: Christoph Hellwig 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 Signed-off-by: David Howells Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/smb/client/cifsfs.c | 68 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 11 deletions(-) --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -1263,9 +1263,12 @@ static loff_t cifs_remap_file_range(stru { struct inode *src_inode = file_inode(src_file); struct inode *target_inode = file_inode(dst_file); + struct cifsInodeInfo *src_cifsi = CIFS_I(src_inode); + struct cifsInodeInfo *target_cifsi = CIFS_I(target_inode); struct cifsFileInfo *smb_file_src = src_file->private_data; - struct cifsFileInfo *smb_file_target; - struct cifs_tcon *target_tcon; + struct cifsFileInfo *smb_file_target = dst_file->private_data; + struct cifs_tcon *target_tcon, *src_tcon; + unsigned long long destend, fstart, fend, new_size; unsigned int xid; int rc; @@ -1278,13 +1281,13 @@ static loff_t cifs_remap_file_range(stru xid = get_xid(); - if (!src_file->private_data || !dst_file->private_data) { + if (!smb_file_src || !smb_file_target) { rc = -EBADF; cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n"); goto out; } - smb_file_target = dst_file->private_data; + src_tcon = tlink_tcon(smb_file_src->tlink); target_tcon = tlink_tcon(smb_file_target->tlink); /* @@ -1297,20 +1300,63 @@ static loff_t cifs_remap_file_range(stru if (len == 0) len = src_inode->i_size - off; - cifs_dbg(FYI, "about to flush pages\n"); - /* should we flush first and last page first */ - truncate_inode_pages_range(&target_inode->i_data, destoff, - PAGE_ALIGN(destoff + len)-1); + cifs_dbg(FYI, "clone range\n"); + + /* Flush the source buffer */ + rc = filemap_write_and_wait_range(src_inode->i_mapping, off, + off + len - 1); + if (rc) + goto unlock; + + /* The server-side copy will fail if the source crosses the EOF marker. + * Advance the EOF marker after the flush above to the end of the range + * if it's short of that. + */ + if (src_cifsi->netfs.remote_i_size < off + len) { + rc = cifs_precopy_set_eof(src_inode, src_cifsi, src_tcon, xid, off + len); + if (rc < 0) + goto unlock; + } + + new_size = destoff + len; + destend = destoff + len - 1; - if (target_tcon->ses->server->ops->duplicate_extents) + /* Flush the folios at either end of the destination range to prevent + * accidental loss of dirty data outside of the range. + */ + fstart = destoff; + fend = destend; + + rc = cifs_flush_folio(target_inode, destoff, &fstart, &fend, true); + if (rc) + goto unlock; + rc = cifs_flush_folio(target_inode, destend, &fstart, &fend, false); + if (rc) + goto unlock; + + /* Discard all the folios that overlap the destination region. */ + cifs_dbg(FYI, "about to discard pages %llx-%llx\n", fstart, fend); + truncate_inode_pages_range(&target_inode->i_data, fstart, fend); + + fscache_invalidate(cifs_inode_cookie(target_inode), NULL, + i_size_read(target_inode), 0); + + rc = -EOPNOTSUPP; + if (target_tcon->ses->server->ops->duplicate_extents) { rc = target_tcon->ses->server->ops->duplicate_extents(xid, smb_file_src, smb_file_target, off, len, destoff); - else - rc = -EOPNOTSUPP; + if (rc == 0 && new_size > i_size_read(target_inode)) { + truncate_setsize(target_inode, new_size); + netfs_resize_file(&target_cifsi->netfs, new_size); + fscache_resize_cookie(cifs_inode_cookie(target_inode), + new_size); + } + } /* force revalidate of size and timestamps of target file now that target is updated on the server */ CIFS_I(target_inode)->time = 0; +unlock: /* although unlocking in the reverse order from locking is not strictly necessary here it is a little cleaner to be consistent */ unlock_two_nondirectories(src_inode, target_inode); Patches currently in stable-queue which might be from dhowells@redhat.com are queue-6.1/cifs-fix-flushing-invalidation-and-file-size-with-copy_file_range.patch queue-6.1/cifs-fix-flushing-invalidation-and-file-size-with-ficlone.patch queue-6.1/cifs-fix-non-availability-of-dedup-breaking-generic-304.patch