]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
swapfile: disable swapon for bs > ps devices
authorLuis Chamberlain <mcgrof@kernel.org>
Mon, 5 May 2025 19:35:19 +0000 (12:35 -0700)
committerChristian Brauner <brauner@kernel.org>
Tue, 6 May 2025 08:46:19 +0000 (10:46 +0200)
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.

With this we at least now put a stop gap of its use, until the
swap subsystem completes its major overhaul:

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 failed: Invalid argument

Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/aBkS926thy9zvdZb@bombadil.infradead.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
mm/swapfile.c

index 2eff8b51a9455f7bbced7206a14143b4e17bbbae..74a6c580b00dd8129f203d2534dd67fc92652e0e 100644 (file)
@@ -3322,6 +3322,15 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
                goto bad_swap_unlock_inode;
        }
 
+       /*
+        * The swap subsystem needs a major overhaul to support this.
+        * It doesn't work yet so just disable it for now.
+        */
+       if (mapping_min_folio_order(mapping) > 0) {
+               error = -EINVAL;
+               goto bad_swap_unlock_inode;
+       }
+
        /*
         * Read the swap header.
         */