Skip to content

Commit 3cd1548

Browse files
YHNdnzjbrauner
authored andcommitted
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] systemd/systemd#39637 Fixes: 2c6efe9 ("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>
1 parent 78f0e33 commit 3cd1548

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

mm/shmem.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ struct shmem_options {
131131
#define SHMEM_SEEN_INODES 2
132132
#define SHMEM_SEEN_HUGE 4
133133
#define SHMEM_SEEN_INUMS 8
134-
#define SHMEM_SEEN_NOSWAP 16
135-
#define SHMEM_SEEN_QUOTA 32
134+
#define SHMEM_SEEN_QUOTA 16
136135
};
137136

138137
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
@@ -4677,7 +4676,6 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param)
46774676
"Turning off swap in unprivileged tmpfs mounts unsupported");
46784677
}
46794678
ctx->noswap = true;
4680-
ctx->seen |= SHMEM_SEEN_NOSWAP;
46814679
break;
46824680
case Opt_quota:
46834681
if (fc->user_ns != &init_user_ns)
@@ -4827,14 +4825,15 @@ static int shmem_reconfigure(struct fs_context *fc)
48274825
err = "Current inum too high to switch to 32-bit inums";
48284826
goto out;
48294827
}
4830-
if ((ctx->seen & SHMEM_SEEN_NOSWAP) && ctx->noswap && !sbinfo->noswap) {
4828+
4829+
/*
4830+
* "noswap" doesn't use fsparam_flag_no, i.e. there's no "swap"
4831+
* counterpart for (re-)enabling swap.
4832+
*/
4833+
if (ctx->noswap && !sbinfo->noswap) {
48314834
err = "Cannot disable swap on remount";
48324835
goto out;
48334836
}
4834-
if (!(ctx->seen & SHMEM_SEEN_NOSWAP) && !ctx->noswap && sbinfo->noswap) {
4835-
err = "Cannot enable swap on remount if it was disabled on first mount";
4836-
goto out;
4837-
}
48384837

48394838
if (ctx->seen & SHMEM_SEEN_QUOTA &&
48404839
!sb_any_quota_loaded(fc->root->d_sb)) {

0 commit comments

Comments
 (0)