From: Daeho Jeong <daeho43@gmail.com>
To: linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com
Cc: Daeho Jeong <daehojeong@google.com>, kernel test robot <lkp@intel.com>
Subject: [f2fs-dev] [PATCH v2 1/2] f2fs: use BIT_ULL for mount option bitmasks
Date: Fri, 11 Sep 2026 07:35:48 -0700 [thread overview]
Message-ID: <20260911143549.909867-1-daeho43@gmail.com> (raw)
From: Daeho Jeong <daehojeong@google.com>
Although f2fs_mount_info.opt and f2fs_fs_context.opt_mask are declared as
unsigned long long (64 bits), the option bit manipulation macros
(clear_opt, set_opt, test_opt) and context helpers (ctx_set_opt,
ctx_clear_opt, ctx_test_opt) use BIT(), which expands to (UL(1) << nr).
On 32-bit architectures, sizeof(unsigned long) is 32 bits, causing shift
count overflow warnings and functional truncation if mount option indices
reach or exceed 32.
Replace BIT() with BIT_ULL() for mount option bitmasks and helpers.
Additionally, introduce ctx_clear_opt_mask() and ctx_test_opt_mask()
helpers to avoid open-coded bitwise manipulations on ctx->opt_mask.
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202609111633.uyRbsEUB-lkp@intel.com/
Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
v2:
- Newly added in v2 to fix 32-bit shift count overflow reported by
the kernel test robot, and introduce ctx_{test,clear}_opt_mask() helpers.
---
fs/f2fs/f2fs.h | 6 +++---
fs/f2fs/super.c | 40 ++++++++++++++++++++++++++--------------
2 files changed, 29 insertions(+), 17 deletions(-)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 62efc25cd107..4aaf29de3f6f 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -149,11 +149,11 @@ enum f2fs_mount_opt {
#define F2FS_OPTION(sbi) ((sbi)->mount_opt)
#define clear_opt(sbi, option) \
- (F2FS_OPTION(sbi).opt &= ~BIT(F2FS_MOUNT_##option))
+ (F2FS_OPTION(sbi).opt &= ~BIT_ULL(F2FS_MOUNT_##option))
#define set_opt(sbi, option) \
- (F2FS_OPTION(sbi).opt |= BIT(F2FS_MOUNT_##option))
+ (F2FS_OPTION(sbi).opt |= BIT_ULL(F2FS_MOUNT_##option))
#define test_opt(sbi, option) \
- (F2FS_OPTION(sbi).opt & BIT(F2FS_MOUNT_##option))
+ (F2FS_OPTION(sbi).opt & BIT_ULL(F2FS_MOUNT_##option))
#define ver_after(a, b) (typecheck(unsigned long long, a) && \
typecheck(unsigned long long, b) && \
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index f96abecb3c55..a5e109bdcebc 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -420,21 +420,33 @@ struct f2fs_fs_context {
static inline void ctx_set_opt(struct f2fs_fs_context *ctx,
enum f2fs_mount_opt flag)
{
- ctx->info.opt |= BIT(flag);
- ctx->opt_mask |= BIT(flag);
+ ctx->info.opt |= BIT_ULL(flag);
+ ctx->opt_mask |= BIT_ULL(flag);
}
static inline void ctx_clear_opt(struct f2fs_fs_context *ctx,
enum f2fs_mount_opt flag)
{
- ctx->info.opt &= ~BIT(flag);
- ctx->opt_mask |= BIT(flag);
+ ctx->info.opt &= ~BIT_ULL(flag);
+ ctx->opt_mask |= BIT_ULL(flag);
}
static inline bool ctx_test_opt(struct f2fs_fs_context *ctx,
enum f2fs_mount_opt flag)
{
- return ctx->info.opt & BIT(flag);
+ return ctx->info.opt & BIT_ULL(flag);
+}
+
+static inline void ctx_clear_opt_mask(struct f2fs_fs_context *ctx,
+ enum f2fs_mount_opt flag)
+{
+ ctx->opt_mask &= ~BIT_ULL(flag);
+}
+
+static inline bool ctx_test_opt_mask(struct f2fs_fs_context *ctx,
+ enum f2fs_mount_opt flag)
+{
+ return ctx->opt_mask & BIT_ULL(flag);
}
void f2fs_printk(struct f2fs_sb_info *sbi, bool limit_rate,
@@ -1443,7 +1455,7 @@ static int f2fs_check_compression(struct fs_context *fc,
ctx_test_opt(ctx, F2FS_MOUNT_COMPRESS_CACHE))
f2fs_info(sbi, "Image doesn't support compression");
clear_compression_spec(ctx);
- ctx->opt_mask &= ~BIT(F2FS_MOUNT_COMPRESS_CACHE);
+ ctx_clear_opt_mask(ctx, F2FS_MOUNT_COMPRESS_CACHE);
return 0;
}
if (ctx->spec_mask & F2FS_SPEC_compress_extension) {
@@ -1511,43 +1523,43 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,
return -EINVAL;
if (f2fs_hw_should_discard(sbi) &&
- (ctx->opt_mask & BIT(F2FS_MOUNT_DISCARD)) &&
+ ctx_test_opt_mask(ctx, F2FS_MOUNT_DISCARD) &&
!ctx_test_opt(ctx, F2FS_MOUNT_DISCARD)) {
f2fs_warn(sbi, "discard is required for zoned block devices");
return -EINVAL;
}
if (!f2fs_hw_support_discard(sbi) &&
- (ctx->opt_mask & BIT(F2FS_MOUNT_DISCARD)) &&
+ ctx_test_opt_mask(ctx, F2FS_MOUNT_DISCARD) &&
ctx_test_opt(ctx, F2FS_MOUNT_DISCARD)) {
f2fs_warn(sbi, "device does not support discard");
ctx_clear_opt(ctx, F2FS_MOUNT_DISCARD);
- ctx->opt_mask &= ~BIT(F2FS_MOUNT_DISCARD);
+ ctx_clear_opt_mask(ctx, F2FS_MOUNT_DISCARD);
}
if (f2fs_sb_has_device_alias(sbi) &&
- (ctx->opt_mask & BIT(F2FS_MOUNT_READ_EXTENT_CACHE)) &&
+ ctx_test_opt_mask(ctx, F2FS_MOUNT_READ_EXTENT_CACHE) &&
!ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
f2fs_err(sbi, "device aliasing requires extent cache");
return -EINVAL;
}
if (test_opt(sbi, RESERVE_ROOT) &&
- (ctx->opt_mask & BIT(F2FS_MOUNT_RESERVE_ROOT)) &&
+ ctx_test_opt_mask(ctx, F2FS_MOUNT_RESERVE_ROOT) &&
ctx_test_opt(ctx, F2FS_MOUNT_RESERVE_ROOT)) {
f2fs_info(sbi, "Preserve previous reserve_root=%u",
F2FS_OPTION(sbi).root_reserved_blocks);
ctx_clear_opt(ctx, F2FS_MOUNT_RESERVE_ROOT);
- ctx->opt_mask &= ~BIT(F2FS_MOUNT_RESERVE_ROOT);
+ ctx_clear_opt_mask(ctx, F2FS_MOUNT_RESERVE_ROOT);
ctx->spec_mask &= ~F2FS_SPEC_reserve_root;
}
if (test_opt(sbi, RESERVE_NODE) &&
- (ctx->opt_mask & BIT(F2FS_MOUNT_RESERVE_NODE)) &&
+ ctx_test_opt_mask(ctx, F2FS_MOUNT_RESERVE_NODE) &&
ctx_test_opt(ctx, F2FS_MOUNT_RESERVE_NODE)) {
f2fs_info(sbi, "Preserve previous reserve_node=%u",
F2FS_OPTION(sbi).root_reserved_nodes);
ctx_clear_opt(ctx, F2FS_MOUNT_RESERVE_NODE);
- ctx->opt_mask &= ~BIT(F2FS_MOUNT_RESERVE_NODE);
+ ctx_clear_opt_mask(ctx, F2FS_MOUNT_RESERVE_NODE);
ctx->spec_mask &= ~F2FS_SPEC_reserve_node;
}
--
2.55.0.1007.g17ff1f9808-goog
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next reply other threads:[~2026-09-11 14:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 14:35 Daeho Jeong [this message]
2026-09-11 14:35 ` [f2fs-dev] [PATCH v2 2/2] f2fs: introduce reserve_shrink mount option for filesystem shrinkage Daeho Jeong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260911143549.909867-1-daeho43@gmail.com \
--to=daeho43@gmail.com \
--cc=daehojeong@google.com \
--cc=kernel-team@android.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.