From: <gregkh@linuxfoundation.org>
To: bfoster@redhat.com,catherine.hoang@oracle.com,cem@kernel.org,djwong@kernel.org,gregkh@linuxfoundation.org,xfs-stable@lists.linux.dev
Cc: <stable-commits@vger.kernel.org>
Subject: Patch "xfs: don't free cowblocks from under dirty pagecache on unshare" has been added to the 6.6-stable tree
Date: Fri, 21 Feb 2025 16:23:27 +0100 [thread overview]
Message-ID: <2025022127-wisplike-quartet-1f98@gregkh> (raw)
In-Reply-To: <20250205214025.72516-7-catherine.hoang@oracle.com>
This is a note to let you know that I've just added the patch titled
xfs: don't free cowblocks from under dirty pagecache on unshare
to the 6.6-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:
xfs-don-t-free-cowblocks-from-under-dirty-pagecache-on-unshare.patch
and it can be found in the queue-6.6 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.
From stable+bounces-113972-greg=kroah.com@vger.kernel.org Wed Feb 5 22:40:54 2025
From: Catherine Hoang <catherine.hoang@oracle.com>
Date: Wed, 5 Feb 2025 13:40:07 -0800
Subject: xfs: don't free cowblocks from under dirty pagecache on unshare
To: stable@vger.kernel.org
Cc: xfs-stable@lists.linux.dev
Message-ID: <20250205214025.72516-7-catherine.hoang@oracle.com>
From: Brian Foster <bfoster@redhat.com>
commit 4390f019ad7866c3791c3d768d2ff185d89e8ebe upstream.
fallocate unshare mode explicitly breaks extent sharing. When a
command completes, it checks the data fork for any remaining shared
extents to determine whether the reflink inode flag and COW fork
preallocation can be removed. This logic doesn't consider in-core
pagecache and I/O state, however, which means we can unsafely remove
COW fork blocks that are still needed under certain conditions.
For example, consider the following command sequence:
xfs_io -fc "pwrite 0 1k" -c "reflink <file> 0 256k 1k" \
-c "pwrite 0 32k" -c "funshare 0 1k" <file>
This allocates a data block at offset 0, shares it, and then
overwrites it with a larger buffered write. The overwrite triggers
COW fork preallocation, 32 blocks by default, which maps the entire
32k write to delalloc in the COW fork. All but the shared block at
offset 0 remains hole mapped in the data fork. The unshare command
redirties and flushes the folio at offset 0, removing the only
shared extent from the inode. Since the inode no longer maps shared
extents, unshare purges the COW fork before the remaining 28k may
have written back.
This leaves dirty pagecache backed by holes, which writeback quietly
skips, thus leaving clean, non-zeroed pagecache over holes in the
file. To verify, fiemap shows holes in the first 32k of the file and
reads return different data across a remount:
$ xfs_io -c "fiemap -v" <file>
<file>:
EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS
...
1: [8..511]: hole 504
...
$ xfs_io -c "pread -v 4k 8" <file>
00001000: cd cd cd cd cd cd cd cd ........
$ umount <mnt>; mount <dev> <mnt>
$ xfs_io -c "pread -v 4k 8" <file>
00001000: 00 00 00 00 00 00 00 00 ........
To avoid this problem, make unshare follow the same rules used for
background cowblock scanning and never purge the COW fork for inodes
with dirty pagecache or in-flight I/O.
Fixes: 46afb0628b86347 ("xfs: only flush the unshared range in xfs_reflink_unshare")
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/xfs/xfs_icache.c | 8 +-------
fs/xfs/xfs_reflink.c | 3 +++
fs/xfs/xfs_reflink.h | 19 +++++++++++++++++++
3 files changed, 23 insertions(+), 7 deletions(-)
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -1271,13 +1271,7 @@ xfs_prep_free_cowblocks(
*/
if (!sync && inode_is_open_for_write(VFS_I(ip)))
return false;
- if ((VFS_I(ip)->i_state & I_DIRTY_PAGES) ||
- mapping_tagged(VFS_I(ip)->i_mapping, PAGECACHE_TAG_DIRTY) ||
- mapping_tagged(VFS_I(ip)->i_mapping, PAGECACHE_TAG_WRITEBACK) ||
- atomic_read(&VFS_I(ip)->i_dio_count))
- return false;
-
- return true;
+ return xfs_can_free_cowblocks(ip);
}
/*
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -1600,6 +1600,9 @@ xfs_reflink_clear_inode_flag(
ASSERT(xfs_is_reflink_inode(ip));
+ if (!xfs_can_free_cowblocks(ip))
+ return 0;
+
error = xfs_reflink_inode_has_shared_extents(*tpp, ip, &needs_flag);
if (error || needs_flag)
return error;
--- a/fs/xfs/xfs_reflink.h
+++ b/fs/xfs/xfs_reflink.h
@@ -16,6 +16,25 @@ static inline bool xfs_is_cow_inode(stru
return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
}
+/*
+ * Check whether it is safe to free COW fork blocks from an inode. It is unsafe
+ * to do so when an inode has dirty cache or I/O in-flight, even if no shared
+ * extents exist in the data fork, because outstanding I/O may target blocks
+ * that were speculatively allocated to the COW fork.
+ */
+static inline bool
+xfs_can_free_cowblocks(struct xfs_inode *ip)
+{
+ struct inode *inode = VFS_I(ip);
+
+ if ((inode->i_state & I_DIRTY_PAGES) ||
+ mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ||
+ mapping_tagged(inode->i_mapping, PAGECACHE_TAG_WRITEBACK) ||
+ atomic_read(&inode->i_dio_count))
+ return false;
+ return true;
+}
+
extern int xfs_reflink_trim_around_shared(struct xfs_inode *ip,
struct xfs_bmbt_irec *irec, bool *shared);
int xfs_bmap_trim_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,
Patches currently in stable-queue which might be from catherine.hoang@oracle.com are
queue-6.6/xfs-return-bool-from-xfs_attr3_leaf_add.patch
queue-6.6/xfs-fix-a-sloppy-memory-handling-bug-in-xfs_iroot_realloc.patch
queue-6.6/xfs-streamline-xfs_filestream_pick_ag.patch
queue-6.6/xfs-merge-xfs_attr_leaf_try_add-into-xfs_attr_leaf_addname.patch
queue-6.6/xfs-don-t-free-cowblocks-from-under-dirty-pagecache-on-unshare.patch
queue-6.6/xfs-pass-the-exact-range-to-initialize-to-xfs_initialize_perag.patch
queue-6.6/xfs-assert-a-valid-limit-in-xfs_rtfind_forw.patch
queue-6.6/xfs-don-t-use-__gfp_retry_mayfail-in-xfs_initialize_perag.patch
queue-6.6/xfs-use-try_cmpxchg-in-xlog_cil_insert_pcp_aggregate.patch
queue-6.6/xfs-don-t-ifdef-around-the-exact-minlen-allocations.patch
queue-6.6/xfs-reduce-unnecessary-searches-when-searching-for-the-best-extents.patch
queue-6.6/xfs-validate-inumber-in-xfs_iget.patch
queue-6.6/xfs-support-lowmode-allocations-in-xfs_bmap_exact_minlen_extent_alloc.patch
queue-6.6/xfs-skip-background-cowblock-trims-on-inodes-open-for-write.patch
queue-6.6/xfs-remove-empty-declartion-in-header-file.patch
queue-6.6/xfs-fold-xfs_bmap_alloc_userdata-into-xfs_bmapi_allocate.patch
queue-6.6/xfs-update-the-file-system-geometry-after-recoverying-superblock-buffers.patch
queue-6.6/xfs-call-xfs_bmap_exact_minlen_extent_alloc-from-xfs_bmap_btalloc.patch
queue-6.6/xfs-distinguish-extra-split-from-real-enospc-from-xfs_attr_node_try_addname.patch
queue-6.6/xfs-error-out-when-a-superblock-buffer-update-reduces-the-agcount.patch
queue-6.6/xfs-update-the-pag-for-the-last-ag-at-recovery-time.patch
queue-6.6/xfs-check-for-delayed-allocations-before-setting-extsize.patch
queue-6.6/xfs-fix-a-typo.patch
queue-6.6/xfs-distinguish-extra-split-from-real-enospc-from-xfs_attr3_leaf_split.patch
next prev parent reply other threads:[~2025-02-21 15:23 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 21:40 [PATCH 6.6 00/24] xfs backports for 6.6.y (from 6.12) Catherine Hoang
2025-02-05 21:40 ` [PATCH 6.6 01/24] xfs: assert a valid limit in xfs_rtfind_forw Catherine Hoang
2025-02-07 22:51 ` Sasha Levin
2025-02-21 15:23 ` Patch "xfs: assert a valid limit in xfs_rtfind_forw" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 02/24] xfs: validate inumber in xfs_iget Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: validate inumber in xfs_iget" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 03/24] xfs: fix a sloppy memory handling bug in xfs_iroot_realloc Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: fix a sloppy memory handling bug in xfs_iroot_realloc" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 04/24] xfs: fix a typo Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: fix a typo" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 05/24] xfs: skip background cowblock trims on inodes open for write Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: skip background cowblock trims on inodes open for write" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 06/24] xfs: don't free cowblocks from under dirty pagecache on unshare Catherine Hoang
2025-02-21 15:23 ` gregkh [this message]
2025-02-05 21:40 ` [PATCH 6.6 07/24] xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: merge xfs_attr_leaf_try_add into xfs_attr_leaf_addname" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 08/24] xfs: return bool from xfs_attr3_leaf_add Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: return bool from xfs_attr3_leaf_add" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 09/24] xfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: distinguish extra split from real ENOSPC from xfs_attr3_leaf_split" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 10/24] xfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: distinguish extra split from real ENOSPC from xfs_attr_node_try_addname" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 11/24] xfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: fold xfs_bmap_alloc_userdata into xfs_bmapi_allocate" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 12/24] xfs: don't ifdef around the exact minlen allocations Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: don't ifdef around the exact minlen allocations" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 13/24] xfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: call xfs_bmap_exact_minlen_extent_alloc from xfs_bmap_btalloc" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 14/24] xfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: support lowmode allocations in xfs_bmap_exact_minlen_extent_alloc" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 15/24] xfs: Use try_cmpxchg() in xlog_cil_insert_pcp_aggregate() Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: Use try_cmpxchg() in xlog_cil_insert_pcp_aggregate()" has been added to the 6.6-stable tree gregkh
2025-02-21 15:33 ` Uros Bizjak
2025-02-21 15:57 ` Greg KH
2025-02-05 21:40 ` [PATCH 6.6 16/24] xfs: Remove empty declartion in header file Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: Remove empty declartion in header file" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 17/24] xfs: pass the exact range to initialize to xfs_initialize_perag Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: pass the exact range to initialize to xfs_initialize_perag" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 18/24] xfs: update the file system geometry after recoverying superblock buffers Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: update the file system geometry after recoverying superblock buffers" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 19/24] xfs: error out when a superblock buffer update reduces the agcount Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: error out when a superblock buffer update reduces the agcount" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 20/24] xfs: don't use __GFP_RETRY_MAYFAIL in xfs_initialize_perag Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: don't use __GFP_RETRY_MAYFAIL in xfs_initialize_perag" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 21/24] xfs: update the pag for the last AG at recovery time Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: update the pag for the last AG at recovery time" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 22/24] xfs: Reduce unnecessary searches when searching for the best extents Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: Reduce unnecessary searches when searching for the best extents" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 23/24] xfs: streamline xfs_filestream_pick_ag Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: streamline xfs_filestream_pick_ag" has been added to the 6.6-stable tree gregkh
2025-02-05 21:40 ` [PATCH 6.6 24/24] xfs: Check for delayed allocations before setting extsize Catherine Hoang
2025-02-21 15:23 ` Patch "xfs: Check for delayed allocations before setting extsize" has been added to the 6.6-stable tree gregkh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2025022127-wisplike-quartet-1f98@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=bfoster@redhat.com \
--cc=catherine.hoang@oracle.com \
--cc=cem@kernel.org \
--cc=djwong@kernel.org \
--cc=stable-commits@vger.kernel.org \
--cc=xfs-stable@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.