[PATCH v2 1/2] f2fs: use BIT_ULL for mount option bitmasks

From: Daeho Jeong

Date: Fri Sep 11 2026 - 10:45:04 EST


From: Daeho Jeong <daehojeong@xxxxxxxxxx>

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@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202609111633.uyRbsEUB-lkp@xxxxxxxxx/
Signed-off-by: Daeho Jeong <daehojeong@xxxxxxxxxx>
---
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