Re: [PATCH] ext4: fix wrong unit of ratelimit_interval_ms sysfs attributes

From: Jan Kara

Date: Wed Nov 18 2026 - 06:31:04 EST


On Tue 17-11-26 01:17:00, Sang-Heon Jeon wrote:
> 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@xxxxxxxxx>
> ---
> fs/ext4/sysfs.c | 23 ++++++++++++++++++++---
> 1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
> index 923b375e017f..7cc3a2e663f0 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,11 @@ 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)
>
> +#define EXT4_RATELIMIT_INTERVAL_MAX_MS (INT_MAX / DIV_ROUND_UP(HZ, MSEC_PER_SEC))

I was staring at this for a while before I understood what's going on here.
Please add here a comment like:
/* Limit value so that we fit into int after a conversion to jiffies */


Otherwise the patch looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@xxxxxxx>

Honza
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR