Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4235801rdb; Mon, 11 Dec 2023 12:52:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IECs1rqntGr3pSPydbpP0E8Xp0DUEpiB4tn9bMYWnMSP7nYP6kMH18vSUxiG4cBborRjN/U X-Received: by 2002:a17:90a:c7cf:b0:286:b8a1:f1a2 with SMTP id gf15-20020a17090ac7cf00b00286b8a1f1a2mr2204112pjb.44.1702327976311; Mon, 11 Dec 2023 12:52:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702327976; cv=none; d=google.com; s=arc-20160816; b=WRZ45/cUyHHSIbuC7meBPZczcq5QFgMBWLkE69Jx/UgISugyCy2NXo7ODAwvwdNdBB b2PKtYuzU8pi3vpHB2sr6NzSCu88OMsk7o26AxebiIPsOl9zNen7p/NgrIsMhkDzX4D/ 8MQ6+YC5ukVNqMcxhq1Jp7NiNcM6hswLRV5bV7KAP/XHJy1Q+/ZgMAIp7iTbfjlzLGM8 qmtJcXdbRHPZgrsO4IBqa5ecL3P6lcblDyp9+6qHhfconhzNYhqTWALIG1T5KzcAYuvp bdSCjpN1KL6gwKXXSI7n/ksyCE2IKosvK2Ofx7epq+gcSwhZGfUNYeLKzHKHQIMd56i5 Df2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=3T6gz+b7eqbFin1uBp4mrM9tFYsFV16Iw7YKSEAQiII=; fh=k4ldCuP5vOi/wlDwfK6Kgt23+/RUskrk56SATLpjT88=; b=gpwHbkB9XIXbX9CeBGmglNwVEQ8E11SguTc9EpH/KvQkCcE3DJOdYydrbA9vbL4cAZ aEPnur6pEg8t80QHrz1ot8O0r/rpduAiQSQyVkl67YdHsLk32Ln9XNeJBIWqtOkcGl9e YJwVx4hrwDylVq+uATw6TzsDwri0kAS3jPHnrAVagIZEvJOnehaatxH0Su/YwboauqQ1 zOf/OOb5BNBjWwdFZxHTqluv+iz2EKmo56piTBXsTtGbmSIsbB/2uaiWE0hE4/5zYItP Ocn+t+52UyyW4NEGh6h4RIHEtDjzprRx0AuMV7KmdDgV0tzZoGd+e/35HMiOl9vcgmZE hsHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id e8-20020a17090a9a8800b00286a9514be8si8017221pjp.81.2023.12.11.12.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 12:52:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id EEE2F8058C7B; Mon, 11 Dec 2023 12:52:53 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344837AbjLKUwk convert rfc822-to-8bit (ORCPT + 99 others); Mon, 11 Dec 2023 15:52:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344831AbjLKUwj (ORCPT ); Mon, 11 Dec 2023 15:52:39 -0500 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E3CA6; Mon, 11 Dec 2023 12:52:43 -0800 (PST) Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-6d9dcb2cb45so684733a34.1; Mon, 11 Dec 2023 12:52:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702327963; x=1702932763; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CykTHh1hqBcv3lKDskZucqp2rC4spPVBJz+bCkyVI0Y=; b=OWeJ1uiDJH3gs+wCkd9zoTS0+DDTXZIip7H61WgZQ7OA7FXPw9V1GSJMFdBHv++D4d ROFDqdBtInWYKHat3oR+9YmItScY3hEHejS5aS7VXG1GXiX87rPQdaoMau4McAwTVnor ihg5rx1qMbolpmYMSjwjBZHecL69vseg/2LKSH+r/9IXJLG+TzL1CGnpqqxUK0TK2zlb BC1fXf9DGJNuPhmAnsNDkfs5BiRgC7pToLbVU+NF5wUdZ2gNJhEmgkbSOfKZFLwHsO19 A3Zbu2iEm5kgqW96z5iezpuWoZdxOoMTM6a/OFZLRZNqTXgOka6SHjHLcD6lQhMsETr/ O98g== X-Gm-Message-State: AOJu0Yy1ekGqqz3Fq7m4uNvShN9MIPKMNj+XpF22V40izWPBvH6PwVw+ yquPqImsjJMFfAV7v3539n71c59W1teNQQeCgw67wrEr X-Received: by 2002:a05:6871:208c:b0:1fb:19d6:8715 with SMTP id ry12-20020a056871208c00b001fb19d68715mr9409171oab.4.1702327963105; Mon, 11 Dec 2023 12:52:43 -0800 (PST) MIME-Version: 1.0 References: <20231116132619.69500-1-bo.ye@mediatek.com> In-Reply-To: <20231116132619.69500-1-bo.ye@mediatek.com> From: "Rafael J. Wysocki" Date: Mon, 11 Dec 2023 21:52:31 +0100 Message-ID: Subject: Re: [PATCH] cpuidle: idle exit_latency overflow To: Bo Ye Cc: "Rafael J. Wysocki" , Daniel Lezcano , Matthias Brugger , AngeloGioacchino Del Regno , yongdong.zhang@mediatek.com, mtk24676 , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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]); Mon, 11 Dec 2023 12:52:54 -0800 (PST) On Thu, Nov 16, 2023 at 2:26 PM Bo Ye wrote: > > From: mtk24676 > > In detail: > In kernel-6.1, in the __cpuidle_driver_init function in > driver/cpuidle/driver.c, there is a line of code that causes > an overflow. The line is s->exit_latency_ns = s->exit_latency > * NSEC_PER_USEC. The overflow occurs because the product of an > int type and a constant exceeds the range of the int type. In general, but does it actually occur in that code? IOW, is there any system for which the exit latency of an idle state is so large that it will trigger the overflow, for example? > In C language, when you perform a multiplication operation, if > both operands are of int type, the multiplication operation is > performed on the int type, and then the result is converted to > the target type. Right, that's how C works. > This means that if the product of int type > multiplication exceeds the range that int type can represent, > an overflow will occur even if you store the result in a > variable of int64_t type. True. However, does this really happen in the particular case at hand? If not, it would be better to say something like "For a multiplication of two int values, it is better to use mul_u32_u32() that prevents overflows from occurring." > Signed-off-by: mtk24676 > Signed-off-by: bo.ye > --- > > diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c > index d9cda7f..631ca16 100644 > --- a/drivers/cpuidle/driver.c > +++ b/drivers/cpuidle/driver.c > @@ -187,7 +187,7 @@ > s->target_residency = div_u64(s->target_residency_ns, NSEC_PER_USEC); > > if (s->exit_latency > 0) > - s->exit_latency_ns = s->exit_latency * NSEC_PER_USEC; > + s->exit_latency_ns = (u64)s->exit_latency * NSEC_PER_USEC; mul_u32_u32()/? > else if (s->exit_latency_ns < 0) > s->exit_latency_ns = 0; > else