[PATCH] swapfile: disable swapon for bs > ps devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Devices which have a requirement for bs > ps cannot be supported for
swap as swap still needs work. Now that the block device cache sets the
min order for block devices we need this stop gap otherwise all
swap operations are rejected.

Without this you'll end up with errors on these devices as the swap
code still needs much love to support min order.

# cat /sys/block/nvme3n1/queue/logical_block_size  16384
# mkswap /dev/nvme3n1
mkswap: /dev/nvme3n1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 100 GiB (107374178304 bytes)
no label, UUID=6af76b5c-7e7b-4902-b7f7-4c24dde6fa36
# swapon /dev/nvme3n1
swapon: /dev/nvme3n1: swapon failed: Invalid argument

Signed-off-by: Luis Chamberlain <mcgrof@xxxxxxxxxx>
---

I had posted an RFC about a heads up about us needing this less than a year
ago [0] and well, we now need it for v6.15 since swap code is just not ready.

Christian, this should probably go through your tree.

I tested it on a LBS device where the logical block size is 16 KiB on
x86_64 and confirm that while mkswap would swapon would be rejected.

[0] https://lore.kernel.org/all/20240627000924.2074949-1-mcgrof@xxxxxxxxxx/T/#u

 mm/swapfile.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 2eff8b51a945..c24ec16dfc7a 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3322,6 +3322,11 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
 		goto bad_swap_unlock_inode;
 	}
 
+	if (mapping_min_folio_order(mapping) > 0) {
+		error = -EINVAL;
+		goto bad_swap_unlock_inode;
+	}
+
 	/*
 	 * Read the swap header.
 	 */
-- 
2.47.2





[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux