From: Sang-Heon Jeon <ekffu200098@gmail.com>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>,
Baokun Li <libaokun@linux.alibaba.com>, Jan Kara <jack@suse.cz>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
Ojaswin Mujoo <ojaswin@linux.ibm.com>,
"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
Zhang Yi <yi.zhang@huawei.com>
Subject: [PATCH v2] ext4: fix wrong unit of ratelimit_interval_ms sysfs attributes
Date: Fri, 20 Nov 2026 23:59:22 +0900 [thread overview]
Message-ID: <20261120145923.1143594-1-ekffu200098@gmail.com> (raw)
The interval of ratelimit_state is in jiffies. But the
ratelimit_interval_ms sysfs attributes are read and written without
converting the interval, so the values are in milliseconds only if HZ
is 1000.
If HZ is 250, the default interval of 5 seconds is read as 1250, and
writing 5000 sets the interval to 20 seconds.
So use jiffies_to_msecs() and msecs_to_jiffies() when reading and
writing. Also reject values which are too large for the interval.
Fixes: efbed4dc5857 ("ext4: add ratelimiting to ext4 messages")
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
Changes from v1 [1]
- Add comment to EXT4_RATELIMIT_INTERVAL_MAX_MS suggested by Jan
- Add reviewed-by tag by Jan
[1] https://lore.kernel.org/all/20261116161701.3664310-1-ekffu200098@gmail.com/
---
fs/ext4/sysfs.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
index 923b375e017f..a005c6fea48c 100644
--- a/fs/ext4/sysfs.c
+++ b/fs/ext4/sysfs.c
@@ -33,6 +33,7 @@ typedef enum {
attr_mb_order,
attr_feature,
attr_pointer_pi,
+ attr_pointer_pi_msecs,
attr_pointer_ui,
attr_pointer_ul,
attr_pointer_u64,
@@ -215,6 +216,12 @@ static struct ext4_attr ext4_attr_##_name = { \
#define EXT4_RW_ATTR_SBI_PI(_name,_elname) \
EXT4_ATTR_OFFSET(_name, 0644, pointer_pi, ext4_sb_info, _elname)
+/* Limit value so that we fit into int after a conversion to jiffies */
+#define EXT4_RATELIMIT_INTERVAL_MAX_MS (INT_MAX / DIV_ROUND_UP(HZ, MSEC_PER_SEC))
+
+#define EXT4_RW_ATTR_SBI_PI_MSECS(_name, _elname) \
+ EXT4_ATTR_OFFSET(_name, 0644, pointer_pi_msecs, ext4_sb_info, _elname)
+
#define EXT4_RW_ATTR_SBI_UI(_name,_elname) \
EXT4_ATTR_OFFSET(_name, 0644, pointer_ui, ext4_sb_info, _elname)
@@ -258,11 +265,11 @@ EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
EXT4_RW_ATTR_SBI_UI(mb_max_linear_groups, s_mb_max_linear_groups);
EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb);
EXT4_ATTR(trigger_fs_error, 0200, trigger_test_error);
-EXT4_RW_ATTR_SBI_PI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval);
+EXT4_RW_ATTR_SBI_PI_MSECS(err_ratelimit_interval_ms, s_err_ratelimit_state.interval);
EXT4_RW_ATTR_SBI_PI(err_ratelimit_burst, s_err_ratelimit_state.burst);
-EXT4_RW_ATTR_SBI_PI(warning_ratelimit_interval_ms, s_warning_ratelimit_state.interval);
+EXT4_RW_ATTR_SBI_PI_MSECS(warning_ratelimit_interval_ms, s_warning_ratelimit_state.interval);
EXT4_RW_ATTR_SBI_PI(warning_ratelimit_burst, s_warning_ratelimit_state.burst);
-EXT4_RW_ATTR_SBI_PI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval);
+EXT4_RW_ATTR_SBI_PI_MSECS(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval);
EXT4_RW_ATTR_SBI_PI(msg_ratelimit_burst, s_msg_ratelimit_state.burst);
#ifdef CONFIG_EXT4_DEBUG
EXT4_RW_ATTR_SBI_UL(simulate_fail, s_simulate_fail);
@@ -434,6 +441,9 @@ static ssize_t ext4_generic_attr_show(struct ext4_attr *a,
if (a->attr_ptr == ptr_ext4_super_block_offset)
return sysfs_emit(buf, "%u\n", le32_to_cpup(ptr));
return sysfs_emit(buf, "%u\n", *((unsigned int *) ptr));
+ case attr_pointer_pi_msecs:
+ return sysfs_emit(buf, "%u\n",
+ jiffies_to_msecs(*((unsigned int *) ptr)));
case attr_pointer_ul:
case attr_err_report_sec:
return sysfs_emit(buf, "%lu\n", *((unsigned long *) ptr));
@@ -509,6 +519,14 @@ static ssize_t ext4_generic_attr_store(struct ext4_attr *a,
return -EINVAL;
*((unsigned int *) ptr) = t;
return len;
+ case attr_pointer_pi_msecs:
+ ret = kstrtouint(skip_spaces(buf), 0, &t);
+ if (ret)
+ return ret;
+ if (t > EXT4_RATELIMIT_INTERVAL_MAX_MS)
+ return -EINVAL;
+ *((unsigned int *) ptr) = msecs_to_jiffies(t);
+ return len;
case attr_pointer_ui:
ret = kstrtouint(skip_spaces(buf), 0, &t);
if (ret)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
--
2.53.0
next reply other threads:[~2026-11-20 14:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 14:59 Sang-Heon Jeon [this message]
2026-11-20 15:05 ` [PATCH v2] ext4: fix wrong unit of ratelimit_interval_ms sysfs attributes sashiko-bot
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=20261120145923.1143594-1-ekffu200098@gmail.com \
--to=ekffu200098@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
--cc=yi.zhang@huawei.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.