Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

shmem: fix tmpfs reconfiguration (remount) when noswap is set

In systemd we're trying to switch the internal credentials setup logic
to new mount API [1], and I noticed fsconfig(FSCONFIG_CMD_RECONFIGURE)
consistently fails on tmpfs with noswap option. This can be trivially
reproduced with the following:

```
int fs_fd = fsopen("tmpfs", 0);
fsconfig(fs_fd, FSCONFIG_SET_FLAG, "noswap", NULL, 0);
fsconfig(fs_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
fsmount(fs_fd, 0, 0);
fsconfig(fs_fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0); <------ EINVAL
```

After some digging the culprit is shmem_reconfigure() rejecting
!(ctx->seen & SHMEM_SEEN_NOSWAP) && sbinfo->noswap, which is bogus
as ctx->seen serves as a mask for whether certain options are touched
at all. On top of that, noswap option doesn't use fsparam_flag_no,
hence it's not really possible to "reenable" swap to begin with.
Drop the check and redundant SHMEM_SEEN_NOSWAP flag.

[1] https://github.com/systemd/systemd/pull/39637

Fixes: 2c6efe9cf2d7 ("shmem: add support to ignore swap")
Signed-off-by: Mike Yuan <me@yhndnzj.com>
Link: https://patch.msgid.link/20251108190930.440685-1-me@yhndnzj.com
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Mike Yuan and committed by
Christian Brauner
3cd1548a 78f0e33c

+7 -8
+7 -8
mm/shmem.c
··· 131 131 #define SHMEM_SEEN_INODES 2 132 132 #define SHMEM_SEEN_HUGE 4 133 133 #define SHMEM_SEEN_INUMS 8 134 - #define SHMEM_SEEN_NOSWAP 16 135 - #define SHMEM_SEEN_QUOTA 32 134 + #define SHMEM_SEEN_QUOTA 16 136 135 }; 137 136 138 137 #ifdef CONFIG_TRANSPARENT_HUGEPAGE ··· 4676 4677 "Turning off swap in unprivileged tmpfs mounts unsupported"); 4677 4678 } 4678 4679 ctx->noswap = true; 4679 - ctx->seen |= SHMEM_SEEN_NOSWAP; 4680 4680 break; 4681 4681 case Opt_quota: 4682 4682 if (fc->user_ns != &init_user_ns) ··· 4825 4827 err = "Current inum too high to switch to 32-bit inums"; 4826 4828 goto out; 4827 4829 } 4828 - if ((ctx->seen & SHMEM_SEEN_NOSWAP) && ctx->noswap && !sbinfo->noswap) { 4830 + 4831 + /* 4832 + * "noswap" doesn't use fsparam_flag_no, i.e. there's no "swap" 4833 + * counterpart for (re-)enabling swap. 4834 + */ 4835 + if (ctx->noswap && !sbinfo->noswap) { 4829 4836 err = "Cannot disable swap on remount"; 4830 - goto out; 4831 - } 4832 - if (!(ctx->seen & SHMEM_SEEN_NOSWAP) && !ctx->noswap && sbinfo->noswap) { 4833 - err = "Cannot enable swap on remount if it was disabled on first mount"; 4834 4837 goto out; 4835 4838 } 4836 4839