Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp203448rwb; Mon, 28 Nov 2022 19:20:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf4UT71N16VNif208k2XCsYmigDXo9enGKbu/y70uO9Cw/mFKFbvusvgCvl20mhRX4PmxvOb X-Received: by 2002:a63:1025:0:b0:476:8f1c:d095 with SMTP id f37-20020a631025000000b004768f1cd095mr30537097pgl.412.1669692055721; Mon, 28 Nov 2022 19:20:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669692055; cv=none; d=google.com; s=arc-20160816; b=mj8LCInA1juE2pks59P7+RXIIFhtx/5fhsJDHKg3KbYzzZpJH88zE6zSfwFZHBtSJA WWyRIwYDi50qubrASbPgQqhv65VLmrKXGpfeUaEer+3MjWSa9oPs8oSfubWX1fGXYXef 83KQwcmyWQMMJ+gdeuJNpI+Cj5ek1zTC9+pn3NIlFut3BGeVMRRMefnXJawkmTsYZ/ph Eon2GVjEZY1wnxVw23PrN2vjN4xyUMY4H0qfkoVT3hHe+IuYrA4K/m+HQCSp/5WSrfOD 8GHKaeAjEvFYR1tCyiQjsMETdwlDTtzk3zvesjb0DClJYeYCs3naBHK3to96lSPDr7JY 16PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=MulJ6JIeA+a4T8GteplleD0GQBAmQ/VYTWA5FD/WWZs=; b=y8FZwqFnjAzOod7Yghf1dQOGpqc1lXY5LiEMP3zPFuFOQmJDMSmJ7Y7qDl/3cxMiWm MrwdLCsM2EfPEQyLdApcPoWco7Q6884ijwIJpf5obU8fx2tbcua4xYa5BUqAPl6RgLq+ iwGp4yBtBkDQeO99wI1zE+woApZA9wDp7rgUNFeSqxR/e0Ac6Zy/+lcuApUzoOcW1cNM LfvlzrHxZewNADV87ox6+M93HrFqInivXenKqOPboO+/bfuqb7dLxNAF7TzU1DiYbFcx gtxMwx/iUdiP4iWNLcTUoe+BoIbfaJg4gmTjfg3FHpeuyl4/2ho1RiYdQ6zwFUBbVtj8 wN1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c20-20020a6566d4000000b00478446557bdsi126721pgw.18.2022.11.28.19.20.45; Mon, 28 Nov 2022 19:20:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235102AbiK2CtO (ORCPT + 82 others); Mon, 28 Nov 2022 21:49:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234872AbiK2CtL (ORCPT ); Mon, 28 Nov 2022 21:49:11 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE9353F06E; Mon, 28 Nov 2022 18:49:10 -0800 (PST) Received: from canpemm500008.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NLmxB282nzmWGF; Tue, 29 Nov 2022 10:48:30 +0800 (CST) Received: from [10.174.179.2] (10.174.179.2) by canpemm500008.china.huawei.com (7.192.105.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 29 Nov 2022 10:49:08 +0800 Message-ID: <2830bd58-0f53-fa54-58e5-e87225b1fdf1@huawei.com> Date: Tue, 29 Nov 2022 10:49:08 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.1.1 Subject: Re: [PATCH v2] blk-iocost: fix shift-out-of-bounds in iocg_hick_delay() To: Yu Kuai , Tejun Heo CC: , , , , , , "yukuai (C)" References: <20221128030413.882998-1-lijinlin3@huawei.com> From: Li Jinlin In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500008.china.huawei.com (7.192.105.151) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. What about the following change for setting delay to 0 if the shift is >= 64. @@ -1329,11 +1329,9 @@ static bool iocg_kick_delay(struct ioc_gq *iocg, struct ioc_now *now) 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) - delay = iocg->delay >> div64_u64(tdelta, USEC_PER_SEC); - else - delay = 0; + tdelta = div64_u64(now->now - iocg->delay_at, USEC_PER_SEC); + delay = (iocg->delay && tdelta < 64) ? iocg->delay >> tdelta : 0; /* calculate the new delay from the debt amount */ current_hweight(iocg, &hwa, NULL); Jinlin Thanks. >> >> Thanks. >> >