public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* fix swapon for recently unshared blocks v2
@ 2025-02-06  6:14 Christoph Hellwig
  2025-02-06  6:15 ` [PATCH 1/2] xfs: flush inodegc before swapon Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Christoph Hellwig @ 2025-02-06  6:14 UTC (permalink / raw)
  To: Carlos Maiolino; +Cc: Darrick J. Wong, Dave Chinner, Zorro Lang, linux-xfs

Hi all,

the first patch fixes the recently added generic/370, and the
second one does a bit of naming cleanup in the area.

Changes since v1:
 - expand the comment based on text from Dave Chinner
 - add a Fixes tag

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] xfs: flush inodegc before swapon
  2025-02-06  6:14 fix swapon for recently unshared blocks v2 Christoph Hellwig
@ 2025-02-06  6:15 ` Christoph Hellwig
  2025-02-11  8:44   ` Carlos Maiolino
  2025-02-06  6:15 ` [PATCH 2/2] xfs: rename xfs_iomap_swapfile_activate to xfs_vm_swap_activate Christoph Hellwig
  2025-02-06  7:03 ` fix swapon for recently unshared blocks v2 Dave Chinner
  2 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2025-02-06  6:15 UTC (permalink / raw)
  To: Carlos Maiolino; +Cc: Darrick J. Wong, Dave Chinner, Zorro Lang, linux-xfs

Fix the brand new xfstest that tries to swapon on a recently unshared
file and use the chance to document the other bit of magic in this
function.

The big comment is taken from a mailinglist post by Dave Chinner.

Fixes: 5e672cd69f0a53 ("xfs: introduce xfs_inodegc_push()")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/xfs/xfs_aops.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 69b8c2d1937d..9ff1a0b07303 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -21,6 +21,7 @@
 #include "xfs_error.h"
 #include "xfs_zone_alloc.h"
 #include "xfs_rtgroup.h"
+#include "xfs_icache.h"
 
 struct xfs_writepage_ctx {
 	struct iomap_writepage_ctx ctx;
@@ -685,7 +686,39 @@ xfs_iomap_swapfile_activate(
 	struct file			*swap_file,
 	sector_t			*span)
 {
-	sis->bdev = xfs_inode_buftarg(XFS_I(file_inode(swap_file)))->bt_bdev;
+	struct xfs_inode		*ip = XFS_I(file_inode(swap_file));
+
+	/*
+	 * Swap file activation can race against concurrent shared extent
+	 * removal in files that have been cloned.  If this happens,
+	 * iomap_swapfile_iter() can fail because it encountered a shared
+	 * extent even though an operation is in progress to remove those
+	 * shared extents.
+	 *
+	 * This race becomes problematic when we defer extent removal
+	 * operations beyond the end of a syscall (i.e. use async background
+	 * processing algorithms).  Users think the extents are no longer
+	 * shared, but iomap_swapfile_iter() still sees them as shared
+	 * because the refcountbt entries for the extents being removed have
+	 * not yet been updated.  Hence the swapon call fails unexpectedly.
+	 *
+	 * The race condition is currently most obvious from the unlink()
+	 * operation as extent removal is deferred until after the last
+	 * reference to the inode goes away.  We then process the extent
+	 * removal asynchronously, hence triggers the "syscall completed but
+	 * work not done" condition mentioned above.  To close this race
+	 * window, we need to flush any pending inodegc operations to ensure
+	 * they have updated the refcountbt records before we try to map the
+	 * swapfile.
+	 */
+	xfs_inodegc_flush(ip->i_mount);
+
+	/*
+	 * Direct the swap code to the correct block device when this file
+	 * sits on the RT device.
+	 */
+	sis->bdev = xfs_inode_buftarg(ip)->bt_bdev;
+
 	return iomap_swapfile_activate(sis, swap_file, span,
 			&xfs_read_iomap_ops);
 }
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] xfs: rename xfs_iomap_swapfile_activate to xfs_vm_swap_activate
  2025-02-06  6:14 fix swapon for recently unshared blocks v2 Christoph Hellwig
  2025-02-06  6:15 ` [PATCH 1/2] xfs: flush inodegc before swapon Christoph Hellwig
@ 2025-02-06  6:15 ` Christoph Hellwig
  2025-02-06  7:03 ` fix swapon for recently unshared blocks v2 Dave Chinner
  2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2025-02-06  6:15 UTC (permalink / raw)
  To: Carlos Maiolino; +Cc: Darrick J. Wong, Dave Chinner, Zorro Lang, linux-xfs

Match the method name and the naming convention or address_space
operations.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
---
 fs/xfs/xfs_aops.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 9ff1a0b07303..fb99b663138c 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -681,7 +681,7 @@ xfs_vm_readahead(
 }
 
 static int
-xfs_iomap_swapfile_activate(
+xfs_vm_swap_activate(
 	struct swap_info_struct		*sis,
 	struct file			*swap_file,
 	sector_t			*span)
@@ -734,11 +734,11 @@ const struct address_space_operations xfs_address_space_operations = {
 	.migrate_folio		= filemap_migrate_folio,
 	.is_partially_uptodate  = iomap_is_partially_uptodate,
 	.error_remove_folio	= generic_error_remove_folio,
-	.swap_activate		= xfs_iomap_swapfile_activate,
+	.swap_activate		= xfs_vm_swap_activate,
 };
 
 const struct address_space_operations xfs_dax_aops = {
 	.writepages		= xfs_dax_writepages,
 	.dirty_folio		= noop_dirty_folio,
-	.swap_activate		= xfs_iomap_swapfile_activate,
+	.swap_activate		= xfs_vm_swap_activate,
 };
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: fix swapon for recently unshared blocks v2
  2025-02-06  6:14 fix swapon for recently unshared blocks v2 Christoph Hellwig
  2025-02-06  6:15 ` [PATCH 1/2] xfs: flush inodegc before swapon Christoph Hellwig
  2025-02-06  6:15 ` [PATCH 2/2] xfs: rename xfs_iomap_swapfile_activate to xfs_vm_swap_activate Christoph Hellwig
@ 2025-02-06  7:03 ` Dave Chinner
  2 siblings, 0 replies; 5+ messages in thread
From: Dave Chinner @ 2025-02-06  7:03 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Carlos Maiolino, Darrick J. Wong, Zorro Lang, linux-xfs

On Thu, Feb 06, 2025 at 07:14:59AM +0100, Christoph Hellwig wrote:
> Hi all,
> 
> the first patch fixes the recently added generic/370, and the
> second one does a bit of naming cleanup in the area.
> 
> Changes since v1:
>  - expand the comment based on text from Dave Chinner
>  - add a Fixes tag

With the added comment:

Reviewed-by: Dave Chinner <dchinner@redhat.com>

-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] xfs: flush inodegc before swapon
  2025-02-06  6:15 ` [PATCH 1/2] xfs: flush inodegc before swapon Christoph Hellwig
@ 2025-02-11  8:44   ` Carlos Maiolino
  0 siblings, 0 replies; 5+ messages in thread
From: Carlos Maiolino @ 2025-02-11  8:44 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Darrick J. Wong, Dave Chinner, Zorro Lang, linux-xfs

On Thu, 06 Feb 2025 07:15:00 +0100, Christoph Hellwig wrote:
> Fix the brand new xfstest that tries to swapon on a recently unshared
> file and use the chance to document the other bit of magic in this
> function.
> 
> The big comment is taken from a mailinglist post by Dave Chinner.
> 
> 
> [...]

Applied to for-next, thanks!

[1/2] xfs: flush inodegc before swapon
      commit: 35010cc72acc468c98962f1056480a0a363eb1c3
[2/2] xfs: rename xfs_iomap_swapfile_activate to xfs_vm_swap_activate
      commit: 6f7ce473cca4952e4ac673f0fdf6dad2fac40324

Best regards,
-- 
Carlos Maiolino <cem@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-02-11  8:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-06  6:14 fix swapon for recently unshared blocks v2 Christoph Hellwig
2025-02-06  6:15 ` [PATCH 1/2] xfs: flush inodegc before swapon Christoph Hellwig
2025-02-11  8:44   ` Carlos Maiolino
2025-02-06  6:15 ` [PATCH 2/2] xfs: rename xfs_iomap_swapfile_activate to xfs_vm_swap_activate Christoph Hellwig
2025-02-06  7:03 ` fix swapon for recently unshared blocks v2 Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox