From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B5E74418DC for ; Wed, 15 Jul 2026 12:44:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784119501; cv=none; b=jpyk6OTAuRU7IT7nT51P3pxjzXCGIjcMYYNEKBcU1xhUNopyu2jD5yknVfUspzIOL4tkMceyE8hK4MAHJs1T3HYW0C3MluajyqscT63PKkdeEKiQ/mFdRj9e2k3/wqyOI1ZmZSS/VFSHn4qD+3sopH8RwHGqpCQBpSQ48NvGUwM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784119501; c=relaxed/simple; bh=Z13mCUbakk2/eWKWVOW9JmH2y08kjCRmD4nBz4zwb/k=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=pTZ+SzZpJiq1qkXNZ+q3l80Toy8CyAGPE8ILnPBm6g0pH4TgdFFYjiUsO3vsxT2aeWqVtXMIkW++1e6VmrvjR1P9OAMcontIwQ+QpDUNvafNAC4eQq69PtKx+bPU/3NhH5j9nFmxBExmy5cMw2gP1BteQjkwUTcuyS1oV1shfJU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=fWO690wB; arc=none smtp.client-ip=95.215.58.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="fWO690wB" Message-ID: <882fbac2-bd42-44a7-8fba-b387b3f0fb2b@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784119481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W/AULJBPGThMdnA0tzmgbmYa+mAU/00kSN7xatYKRAg=; b=fWO690wBzePos0ZC41kuuDNM8sVZqLVxEMHoTKZKM+z5izjTgG0PTb8GKSIt+lJpqHRw05 lIIZ+C+q70zFfdYGqMrUsFCnLdwIcyaIRFRQg2Zgjq60IZ08Un5ol4ziofVIWiudMPimPN S8kQ+SBV6OGIbLSKrMYlHq7kGtKdWBk= Date: Wed, 15 Jul 2026 20:44:19 +0800 Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Cc: cui.tao@linux.dev, axboe@kernel.dk, tj@kernel.org, josef@toxicpanda.com, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Tao Cui Subject: Re: [PATCH] blk-throttle: fix divide-by-zero on legacy iops limit of 0 To: David Laight References: <20260714103552.1335658-1-cui.tao@linux.dev> <20260714123754.7a88a65b@pumpkin> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Tao Cui In-Reply-To: <20260714123754.7a88a65b@pumpkin> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 在 2026/7/14 19:37, David Laight 写道: > On Tue, 14 Jul 2026 18:35:52 +0800 > Tao Cui wrote: > >> From: Tao Cui >> >> 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. >> >> Signed-off-by: Tao Cui >> --- >> 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); > > The LHS casts look horrid - there has to be a nicer way to do that. > > And you don't need min_t() a plain min() will be fine. > Hi David, Both done in v2 — introduced a void *field local so the writes read *(u64 *)field / *(unsigned int *)field, and switched to min(v, (u64)UINT_MAX). Thanks, Tao > David > > > >> >> tg_conf_updated(tg, false); >> ret = 0; >