From: Li Jinlin <lijinlin3@huawei.com>
To: Yu Kuai <yukuai1@huaweicloud.com>, Tejun Heo <tj@kernel.org>
Cc: <josef@toxicpanda.com>, <axboe@kernel.dk>,
<cgroups@vger.kernel.org>, <linux-block@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <liuzhiqiang26@huawei.com>,
"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH v2] blk-iocost: fix shift-out-of-bounds in iocg_hick_delay()
Date: Tue, 29 Nov 2022 12:52:40 +0800 [thread overview]
Message-ID: <7b447dcb-6009-31e1-8bf6-05b1cdb28b01@huawei.com> (raw)
In-Reply-To: <5489e3c5-30ad-d7af-c329-40c93d9a1b62@huaweicloud.com>
On 2022/11/29 10:59, Yu Kuai wrote:
> Hi,
>
> 在 2022/11/29 10:49, Li Jinlin 写道:
>>
>>
>> On 2022/11/29 9:14, Yu Kuai wrote:
>>> Hi,
>>>
>>> 在 2022/11/29 3:58, Tejun Heo 写道:
>>>> On Mon, Nov 28, 2022 at 11:04:13AM +0800, Li Jinlin wrote:
>>>>> /* calculate the current delay in effect - 1/2 every second */
>>>>> tdelta = now->now - iocg->delay_at;
>>>>> if (iocg->delay)
>>>>> - delay = iocg->delay >> div64_u64(tdelta, USEC_PER_SEC);
>>>>> + delay = iocg->delay >>
>>>>> + min_t(u64, div64_u64(tdelta, USEC_PER_SEC), 63);
>>>>
>>>> I replied earlier but the right thing to do here is setting delay to 0 if
>>>> the shift is >= 64.
>>>
>>> Perhaps following change will make more sense?
>>>
>>> @@ -1322,18 +1323,19 @@ static bool iocg_kick_delay(struct ioc_gq *iocg, struct ioc_now *now)
>>> {
>>> struct ioc *ioc = iocg->ioc;
>>> struct blkcg_gq *blkg = iocg_to_blkg(iocg);
>>> - u64 tdelta, delay, new_delay;
>>> + u64 delay = 0;
>>> + u64 new_delay;
>>> s64 vover, vover_pct;
>>> u32 hwa;
>>>
>>> lockdep_assert_held(&iocg->waitq.lock);
>>>
>>> /* calculate the current delay in effect - 1/2 every second */
>>> - tdelta = now->now - iocg->delay_at;
>>> - if (iocg->delay)
>>> + if (iocg->delay && now->now > iocg->delay_at) {
>>> + u64 tdelta = now->now - iocg->delay_at;
>>> +
>>> delay = iocg->delay >> div64_u64(tdelta, USEC_PER_SEC);
>>> - else
>>> - delay = 0;
>>> + }
>>>
>> I think "now->now > iocg->delay_at" is unnecessary, it is almost inevitable.
>
> From what I see, following can only happen if now->now < iocg->delay_at:
>
> "shift exponent 18446744073709"
>
You are right.
But I didn't see any ubsan reported at now->now - iocg->delay_at.
Need to confirm this.
Jinlin
Thanks.
> Or something else triggers it?
>
> Thanks,
> Kuai
>
prev parent reply other threads:[~2022-11-29 4:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-28 3:04 [PATCH v2] blk-iocost: fix shift-out-of-bounds in iocg_hick_delay() Li Jinlin
2022-11-28 19:58 ` Tejun Heo
2022-11-29 1:14 ` Yu Kuai
2022-11-29 2:49 ` Li Jinlin
2022-11-29 2:59 ` Yu Kuai
2022-11-29 4:52 ` Li Jinlin [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=7b447dcb-6009-31e1-8bf6-05b1cdb28b01@huawei.com \
--to=lijinlin3@huawei.com \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuzhiqiang26@huawei.com \
--cc=tj@kernel.org \
--cc=yukuai1@huaweicloud.com \
--cc=yukuai3@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox