Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2236582rdg; Sun, 15 Oct 2023 18:47:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKpYjWDyUAOtjmyblXuJ2hTClDEDLNvOzH+mymLTnGYPUylTJnAYsH+zAuQCqZj1L7WZ2U X-Received: by 2002:a05:6a00:885:b0:68f:e810:e86f with SMTP id q5-20020a056a00088500b0068fe810e86fmr33896863pfj.28.1697420862608; Sun, 15 Oct 2023 18:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697420862; cv=none; d=google.com; s=arc-20160816; b=eXqmxzMQJS+6nSywO/vlST3HOYKvGbt3PI/w2vQacqeY8j7GFPXTp21SeSxbcRpDBN S6i9g3nzX18Skm8OfJ+u8/lJW58LTpxnQCbfTciNn559k4bIIYZU7iVLaW07wVLDcNeT YzDgl08OlNQpejfd+mPLCwLtPDExFMHfMpuui7oIs+wwoaqckNIWuBz7JqfxcyxYqu4/ EBc8kemlQLJ/GnYGb9mkTsrqnqOK/JRxc8rDPffCUWoa+vQuRdRfk450YHxbSph8XE/n TrCBlH2+ULjnHD9EeSoeQjO+nhtDWDWRdpd4+AA5rYgOVqPKkEzQH5b2g+pGYsKwdCp4 GVdQ== 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 :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=JPfBgBpHOuZUu0pawumzsVPAJATD+axNH7Rp5EqK3NU=; fh=btsc+LF4XLlIKTJLbWyw7Mhu/e9iXUipUNM+oGVzfjE=; b=Fno636CzNgJgtcKf23I+qXoeXNhfhbTOi6oO7DKCui70hfOYtj/Qk6fjmHrj75KHSH 5Eg4vCe7Yxsjj1IHpHJxPGeREU7LR/udM4vudHyWv+ZCxlTPRxy4iZaYQPJ1DWLSJJoq 0omi82PCefXvZ0sS8KQ5EYWAJTL54jb86Pem4Cmben1RPHCovxbqVsuXzu7GeXC67vd1 GEH/ofKAGdzzOLP6SvKszTOUk2WiHgtJM9Q4Y6AVIhRTQLFFHHRRt/EGLXtNCvF34aM2 54+Z8MUMx3gIb9fe5McQfrsbgZ1pfF3oDLgKsHVBZbpqYluAknTQeUZT6OGkAja0Wasg MXyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id g62-20020a636b41000000b0055e607f1e99si9585717pgc.882.2023.10.15.18.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 18:47:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id C83E88058B58; Sun, 15 Oct 2023 18:47:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230523AbjJPBrI (ORCPT + 99 others); Sun, 15 Oct 2023 21:47:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjJPBrH (ORCPT ); Sun, 15 Oct 2023 21:47:07 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94601A9; Sun, 15 Oct 2023 18:47:05 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4S80Mz6W1Gz4f3kp1; Mon, 16 Oct 2023 09:46:55 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP4 (Coremail) with SMTP id gCh0CgD3jd0TlixlP1JPDA--.33169S3; Mon, 16 Oct 2023 09:47:01 +0800 (CST) Subject: Re: [PATCH] blk-throttle: Calculate allowed value only when the throttle is enabled To: Khazhy Kumykov , Oleg Nesterov Cc: Yu Kuai , Li Nan , tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com, "yukuai (C)" References: <20230928015858.1809934-1-linan666@huaweicloud.com> <4ace01e8-6815-29d0-70ce-4632818ca701@huaweicloud.com> <20231005162417.GA32420@redhat.com> <0a8f34aa-ced9-e613-3e5f-b5e53a3ef3d9@huaweicloud.com> <20231007151607.GA24726@redhat.com> <21843836-7265-f903-a7d5-e77b07dd5a71@huaweicloud.com> <20231008113602.GB24726@redhat.com> From: Yu Kuai Message-ID: Date: Mon, 16 Oct 2023 09:46:59 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgD3jd0TlixlP1JPDA--.33169S3 X-Coremail-Antispam: 1UD129KBjvJXoW7Wr4xAFWkWr1DZF17tF48Xrb_yoW8JrWxpF WIgw12vrs0qas7JF1Iyw1jvF1UZFZrGFy5J3yDC34qvas5G3s7GF17CrZ0yr47X348Wa1r JwnIyF9rArnFqaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9F14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcVAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kI c2xKxwCYjI0SjxkI62AI1cAE67vIY487MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4 AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE 17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMI IF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Wr1j6rW3 Jr1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcS sGvfC2KfnxnUUI43ZEXa7VUbXdbUUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 15 Oct 2023 18:47:37 -0700 (PDT) Hi, 在 2023/10/14 5:51, Khazhy Kumykov 写道: > Looking at the generic mul_u64_u64_div_u64 impl, it doesn't handle > overflow of the final result either, as far as I can tell. So while on > x86 we get a DE, on non-x86 we just get the wrong result. > > (Aside: after 8d6bbaada2e0 ("blk-throttle: prevent overflow while > calculating wait time"), setting a very-high bps_limit would probably > also cause this crash, no?) > > Would it be possible to have a "check_mul_u64_u64_div_u64_overflow()", > where if the result doesn't fit in u64, we indicate (and let the > caller choose what to do? Here we should just return U64_MAX)? > > Absent that, maybe we can take inspiration from the generic > mul_u64_u64_div_u64? (Forgive the paste) > > static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed) > { > + /* Final result probably won't fit in u64 */ > + if (ilog2(bps_limit) + ilog2(jiffy_elapsed) - ilog2(HZ) > 62) I'm not sure, but this condition looks necessary, but doesn't look sufficient, for example, jiffy_elapsed cound be greater than HZ, while ilog2(jiffy_elapsed) is equal to ilog2(HZ). Thanks, Kuai > + return U64_MAX; > return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ); > } > > . >