The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Haris Iqbal <haris.iqbal@linux.dev>
To: Tao Cui <cui.tao@linux.dev>,
	axboe@kernel.dk, tj@kernel.org, josef@toxicpanda.com
Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, Tao Cui <cuitao@kylinos.cn>
Subject: Re: [PATCH] blk-throttle: fix divide-by-zero on legacy iops limit of 0
Date: Wed, 15 Jul 2026 18:13:06 +0200	[thread overview]
Message-ID: <d7d251c8-c0a7-493d-ab7a-386d441b93cb@linux.dev> (raw)
In-Reply-To: <20260714103552.1335658-1-cui.tao@linux.dev>



On 7/14/26 12:35, Tao Cui wrote:
> From: Tao Cui <cuitao@kylinos.cn>
> 
> Writing a multiple of 2^32 (e.g. 4294967296) to a legacy cgroup v1
> throttle iops file (blkio.throttle.{read,write}_iops_device) silently
> truncates to 0: tg_set_conf() stores the sscanf-parsed u64 value into
> an unsigned int field with no clamping. The cgroup v2 path,
> tg_set_limit(), already clamps the same kind of value with
> min_t(u64, val, UINT_MAX), but the legacy path never did. Note that
> the "!v -> U64_MAX" mapping only catches an explicit zero and does not
> catch a value that truncates to zero.
> 
> With iops stored as 0, tg_update_has_rules() sets has_rules_iops[] and
> the next IO reaches tg_within_iops_limit(), which computes
> 
>      jiffy_wait = max(jiffy_wait, HZ / iops_limit + 1);
> 
> triggering a divide-by-zero oops.
> 
> Fix it in two places:
> 
>    * tg_set_conf(): clamp the value to UINT_MAX, consistent with
>      tg_set_limit(). This closes the truncation root cause (and the
>      general silent truncation for any value above UINT_MAX).
> 
>    * tg_dispatch_iops_time(): treat iops_limit == 0 as unlimited so the
>      divide in tg_within_iops_limit() is never reached, defending
>      against any future path that could produce a zero limit.
> 

Does this need a "Fixes:" tag.

> Signed-off-by: Tao Cui <cuitao@kylinos.cn>
> ---
>   block/blk-throttle.c | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/block/blk-throttle.c b/block/blk-throttle.c
> index ffc3b70065d4..3f3c1374f4b2 100644
> --- a/block/blk-throttle.c
> +++ b/block/blk-throttle.c
> @@ -883,7 +883,12 @@ static unsigned long tg_dispatch_iops_time(struct throtl_grp *tg, struct bio *bi
>   	u32 iops_limit = tg_iops_limit(tg, rw);
>   	unsigned long iops_wait;
>   
> -	if (iops_limit == UINT_MAX || tg->flags & THROTL_TG_CANCELING)
> +	/*
> +	 * iops_limit == 0 is not a valid limit. Treat it as unlimited so we
> +	 * never reach the HZ / iops_limit divide in tg_within_iops_limit().
> +	 */
> +	if (iops_limit == UINT_MAX || iops_limit == 0 ||
> +	    tg->flags & THROTL_TG_CANCELING)
>   		return 0;
>   
>   	tg_update_slice(tg, rw);
> @@ -1386,7 +1391,8 @@ static ssize_t tg_set_conf(struct kernfs_open_file *of,
>   	if (is_u64)
>   		*(u64 *)((void *)tg + of_cft(of)->private) = v;
>   	else
> -		*(unsigned int *)((void *)tg + of_cft(of)->private) = v;
> +		*(unsigned int *)((void *)tg + of_cft(of)->private) =
> +			min_t(u64, v, UINT_MAX);
>   
>   	tg_conf_updated(tg, false);
>   	ret = 0;


      parent reply	other threads:[~2026-07-15 16:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 10:35 [PATCH] blk-throttle: fix divide-by-zero on legacy iops limit of 0 Tao Cui
2026-07-14 11:37 ` David Laight
2026-07-15 12:44   ` Tao Cui
2026-07-15 15:01     ` David Laight
2026-07-15 16:13 ` Haris Iqbal [this message]

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=d7d251c8-c0a7-493d-ab7a-386d441b93cb@linux.dev \
    --to=haris.iqbal@linux.dev \
    --cc=axboe@kernel.dk \
    --cc=cgroups@vger.kernel.org \
    --cc=cui.tao@linux.dev \
    --cc=cuitao@kylinos.cn \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox