From nobody Fri Dec 19 21:52:20 2025 Received: from mail-10624.protonmail.ch (mail-10624.protonmail.ch [79.135.106.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EB561E32D3 for ; Sat, 8 Nov 2025 19:10:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.24 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762629003; cv=none; b=uZiJ/9xIPaD48Kg8HymrDkJmtJOjqgqs5RwXtL/HRD4UP18qRWatvdLwHdAMcgKGHoJcN+YtKW7xMBzk9qLH67zIo2y6Q2xK75lmPyySBMx/alVcnirKUaCflh/++xvsDrxkS5vcJ2BJfIlA0/Mzq+keEWxijxyErAAJLpLwcx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762629003; c=relaxed/simple; bh=9e3E1g4hxN+rejc8kzum2wJk3KiPtUh8/abMAG27iG8=; h=Date:To:From:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=AsXgTBwSws/oFHE9bMC/viTE5c8YHOsAZvSHlQ5EEG54Xw4NhxPKOPec6D11lmByQ9kfkRnyWo8QkYhbhyD/wBnrrV696jV3X+2n5sBCEAdqk3TRg+xL6LNKwNli4y2LsxFG+Wrp3SftFZRWIcHuwBtgznv0CcBkspMMx59vV+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=yhndnzj.com; spf=pass smtp.mailfrom=yhndnzj.com; dkim=pass (2048-bit key) header.d=yhndnzj.com header.i=@yhndnzj.com header.b=fEfR45/B; arc=none smtp.client-ip=79.135.106.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=yhndnzj.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yhndnzj.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yhndnzj.com header.i=@yhndnzj.com header.b="fEfR45/B" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yhndnzj.com; s=protonmail; t=1762628992; x=1762888192; bh=WfmfezCASpoeRxzyP97/Bg6TuZeskJUKe+Q4rAekhjg=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=fEfR45/BGmwWjUPZt6R1yF9uOirxoDV5bmKbJHcdmYTVN6KC1lLXBcFooWKTSwOa9 EvBA3LO5ooz9thOjCxycCoPWu7v7B4iN0NMZ5RJR+xqfPiQT9A+bflUjd8jKs5vutw o8WpXvXUEpgUiQzmG1tsgj+BWtJGrbSKTJN0Z8N3f62gfnVu0INV3RaSOA1XG4ZrVJ ipi2kFQQZkEomm03BbX3b++TPECxdbtcQm2y7BNFPnOCPktyGZIlGIleeRnW+vqzZo 1V/UZT605WmGMutL6ZSZpGrRMS+G1bxZiN+wPuGJ+p/VQfm5U6jiU6lxb/ogidYUvn dLse2aUSQu/5Q== Date: Sat, 08 Nov 2025 19:09:47 +0000 To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org From: Mike Yuan Cc: Mike Yuan , linux-kernel@vger.kernel.org, Luis Chamberlain , Christian Brauner , Hugh Dickins , stable@vger.kernel.org Subject: [PATCH] shmem: fix tmpfs reconfiguration (remount) when noswap is set Message-ID: <20251108190930.440685-1-me@yhndnzj.com> Feedback-ID: 102487535:user:proton X-Pm-Message-ID: 149e0ed8edb97c432bef16be68b2175ea0fe5f86 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D 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 Cc: Luis Chamberlain Cc: Christian Brauner Cc: Hugh Dickins Cc: Reviewed-by: Christian Brauner Reviewed-by: David Hildenbrand (Red Hat) --- mm/shmem.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index b9081b817d28..1b976414d6fa 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -131,8 +131,7 @@ struct shmem_options { #define SHMEM_SEEN_INODES 2 #define SHMEM_SEEN_HUGE 4 #define SHMEM_SEEN_INUMS 8 -#define SHMEM_SEEN_NOSWAP 16 -#define SHMEM_SEEN_QUOTA 32 +#define SHMEM_SEEN_QUOTA 16 }; =20 #ifdef CONFIG_TRANSPARENT_HUGEPAGE @@ -4677,7 +4676,6 @@ static int shmem_parse_one(struct fs_context *fc, str= uct fs_parameter *param) "Turning off swap in unprivileged tmpfs mounts unsupported"); } ctx->noswap =3D true; - ctx->seen |=3D SHMEM_SEEN_NOSWAP; break; case Opt_quota: if (fc->user_ns !=3D &init_user_ns) @@ -4827,14 +4825,15 @@ static int shmem_reconfigure(struct fs_context *fc) err =3D "Current inum too high to switch to 32-bit inums"; goto out; } - if ((ctx->seen & SHMEM_SEEN_NOSWAP) && ctx->noswap && !sbinfo->noswap) { + + /* + * "noswap" doesn't use fsparam_flag_no, i.e. there's no "swap" + * counterpart for (re-)enabling swap. + */ + if (ctx->noswap && !sbinfo->noswap) { err =3D "Cannot disable swap on remount"; goto out; } - if (!(ctx->seen & SHMEM_SEEN_NOSWAP) && !ctx->noswap && sbinfo->noswap) { - err =3D "Cannot enable swap on remount if it was disabled on first mount= "; - goto out; - } =20 if (ctx->seen & SHMEM_SEEN_QUOTA && !sb_any_quota_loaded(fc->root->d_sb)) { base-commit: 0d7bee10beeb59b1133bf5a4749b17a4ef3bbb01 --=20 2.51.1