Skip to contentSkip to conversation

exfat: swapon(2) fails with EINVAL after iomap conversion

REGRESSION Applied Jan Polensky 2 participants 6 messages Jun 3 – Jun 9

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

we are seeing a regression on linux-next after commit

614f71ca1bdfaa2f25a6f147fe22f3ad031f8e2b
("exfat: add iomap buffered I/O support")

With this change, swapon(2) on an exfat swapfile fails with EINVAL.

Observed fallout in LTP:
swapoff01
swapoff02
swapon01
swapon02
swapon03

Example failure:

tst_test.c:1980: TINFO: === Testing on exfat ===
tst_test.c:1291: TINFO: Formatting /dev/loop0 with exfat opts='' extra opts='' tst_test.c:1303: TINFO: Mounting /dev/loop0 to /tmp/LTP_swaKmkGVo/mntpoint fstyp=exfat flags=0 tse_swap.c:196: TINFO: create a swapfile size of 1 megabytes (MB) tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
tse_swap.c:228: TFAIL: swapon() on exfat failed: EINVAL (22)

and from swapon02:

swapon02.c:56: TWARN: swapon(alreadyused) failed: EINVAL (22) swapon02.c:73: TFAIL: swapon(2) fail with File already used expected EBUSY: EINVAL (22)

The iomap conversion changes exfat_aops to iomap based callbacks, but does not add a .swap_activate handler. The VFS documentation says that ->swap_activate() should call add_swap_extent(), or the helper iomap_swapfile_activate().

So this looks like an exfat swap activation regression triggered by the iomap buffered I/O conversion.

#regzbot introduced: 614f71ca1bdfaa2f25a6f147fe22f3ad031f8e2b
#regzbot monitor: https://lore.kernel.org/all/PUZPR04MB63168E8C2FB92B80F9F6476581002@PUZPR04MB6316.apcprd04.prod.outlook.com/

Thanks
Jan

maintainer
#1 lore raw
Quoted 28 lines · Jan Polensky

Hi,

we are seeing a regression on linux-next after commit

614f71ca1bdfaa2f25a6f147fe22f3ad031f8e2b
("exfat: add iomap buffered I/O support")

With this change, swapon(2) on an exfat swapfile fails with EINVAL.

Observed fallout in LTP:
swapoff01
swapoff02
swapon01
swapon02
swapon03

Example failure:

tst_test.c:1980: TINFO: === Testing on exfat ===
tst_test.c:1291: TINFO: Formatting /dev/loop0 with exfat opts='' extra opts='' tst_test.c:1303: TINFO: Mounting /dev/loop0 to /tmp/LTP_swaKmkGVo/mntpoint fstyp=exfat flags=0 tse_swap.c:196: TINFO: create a swapfile size of 1 megabytes (MB) tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
tse_swap.c:228: TFAIL: swapon() on exfat failed: EINVAL (22)

and from swapon02:

Quoted 8 lines

swapon02.c:56: TWARN: swapon(alreadyused) failed: EINVAL (22) swapon02.c:73: TFAIL: swapon(2) fail with File already used expected EBUSY: EINVAL (22)

The iomap conversion changes exfat_aops to iomap based callbacks, but does not add a .swap_activate handler. The VFS documentation says that ->swap_activate() should call add_swap_extent(), or the helper iomap_swapfile_activate().

So this looks like an exfat swap activation regression triggered by the iomap buffered I/O conversion.

You have already suggested a solution. Could you please provide a patch for this ?
Thanks for the report.

#2 lore raw

PATCH 1/1 exfat: add swap_activate support

Commit 614f71ca1bdf ("exfat: add iomap buffered I/O support") converted exfat buffered I/O to iomap, but did not add a .swap_activate handler to the address_space_operations.

swapon(2) on an exfat swapfile then fails with EINVAL, which causes LTP swap tests to fail.

Add exfat_iomap_swap_activate() and hook it into exfat_aops so exfat uses iomap_swapfile_activate() for swapfile activation.

Fixes 614f71ca1bdf ("exfat: add iomap buffered I/O support")
---
 fs/exfat/inode.c | 1 +
 fs/exfat/iomap.c | 6 ++++++
 fs/exfat/iomap.h | 3 +++
 3 files changed, 10 insertions(+)
fs/exfat/inode.c +1 -0
index 96ea243c67db..3b3ac722cf07 100644
@@ -496,6 +496,7 @@ static const struct address_space_operations exfat_aops = {
 	.release_folio		= iomap_release_folio,
 	.invalidate_folio	= iomap_invalidate_folio,
 	.direct_IO		= exfat_direct_IO,
+	.swap_activate		= exfat_iomap_swap_activate,
 };
 
 static inline unsigned long exfat_hash(loff_t i_pos)
fs/exfat/iomap.c +6 -0
index 188df8cfac9a..54c724cea1d0 100644
@@ -213,3 +213,9 @@ const struct iomap_read_ops exfat_iomap_bio_read_ops = {
 	.read_folio_range	= iomap_bio_read_folio_range,
 	.submit_read		= exfat_iomap_bio_submit_read,
 };
+
+int exfat_iomap_swap_activate(struct swap_info_struct *sis,
+			       struct file *file, sector_t *span)
+{
+	return iomap_swapfile_activate(sis, file, span, &exfat_iomap_ops);
+}
fs/exfat/iomap.h +3 -0
index 7f8dcbe20a17..295e36312baf 100644
@@ -11,4 +11,7 @@ extern const struct iomap_ops exfat_write_iomap_ops;
 extern const struct iomap_writeback_ops exfat_writeback_ops;
 extern const struct iomap_read_ops exfat_iomap_bio_read_ops;
 
+int exfat_iomap_swap_activate(struct swap_info_struct *sis,
+			       struct file *file, sector_t *span);
+
 #endif /* _LINUX_EXFAT_IOMAP_H */

--
2.53.0

maintainer Applied
#3 lore raw

Re: [PATCH] exfat: add swap_activate support

Quoted 8 lines · Jan Polensky

Commit 614f71ca1bdf ("exfat: add iomap buffered I/O support") converted exfat buffered I/O to iomap, but did not add a .swap_activate handler to the address_space_operations.

swapon(2) on an exfat swapfile then fails with EINVAL, which causes LTP swap tests to fail.

Quoted 6 lines

Add exfat_iomap_swap_activate() and hook it into exfat_aops so exfat uses iomap_swapfile_activate() for swapfile activation.

Fixes 614f71ca1bdf ("exfat: add iomap buffered I/O support")

Applied it to #dev.
Thanks!

#4 lore raw

Re: [PATCH] exfat: add swap_activate support

Quoted 9 lines · Namjae Jeon
Quoted 8 lines · Jan Polensky

Commit 614f71ca1bdf ("exfat: add iomap buffered I/O support") converted exfat buffered I/O to iomap, but did not add a .swap_activate handler to the address_space_operations.

swapon(2) on an exfat swapfile then fails with EINVAL, which causes LTP swap tests to fail.

Quoted 8 lines
Quoted 6 lines

Add exfat_iomap_swap_activate() and hook it into exfat_aops so exfat uses iomap_swapfile_activate() for swapfile activation.

Fixes 614f71ca1bdf ("exfat: add iomap buffered I/O support")

Applied it to #dev.
Thanks!

Hi Namjae,

I think one line might have been missed when applying my patch:

.swap_activate = exfat_iomap_swap_activate,

I checked linux-next (master and next-20260604 / next-20260605), and the issue is still present there.

Link:
https://lore.kernel.org/all/[email protected]/

Could you please take a look?

Thanks,
Jan

maintainer
#5 lore raw

Re: [PATCH] exfat: add swap_activate support

Quoted 26 lines · Jan Polensky
Quoted 9 lines · Namjae Jeon
Quoted 8 lines · Jan Polensky

Commit 614f71ca1bdf ("exfat: add iomap buffered I/O support") converted exfat buffered I/O to iomap, but did not add a .swap_activate handler to the address_space_operations.

swapon(2) on an exfat swapfile then fails with EINVAL, which causes LTP swap tests to fail.

Quoted 8 lines
Quoted 6 lines

Add exfat_iomap_swap_activate() and hook it into exfat_aops so exfat uses iomap_swapfile_activate() for swapfile activation.

Fixes 614f71ca1bdf ("exfat: add iomap buffered I/O support")

Applied it to #dev.
Thanks!

Hi Namjae,

I think one line might have been missed when applying my patch:

.swap_activate = exfat_iomap_swap_activate,

Quoted 7 lines

I checked linux-next (master and next-20260604 / next-20260605), and the issue is still present there.

Link:
https://lore.kernel.org/all/[email protected]/

Could you please take a look?

Sorry about that, my bad. Your patch wasn't being applied properly, so I tried to update it manually and made a mistake. Anyway, I have just fixed it. Thank you very much for pointing it out!