Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp472321imw; Wed, 13 Jul 2022 01:54:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vs5gg9XXMke5oWrFZytBvdCE0Xh31T1rMUolClJsoMhvFRO5V+Adrkpdx0yheuBR39V2VM X-Received: by 2002:a17:907:2cc8:b0:72b:7c72:e6a4 with SMTP id hg8-20020a1709072cc800b0072b7c72e6a4mr2449099ejc.160.1657702458609; Wed, 13 Jul 2022 01:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657702458; cv=none; d=google.com; s=arc-20160816; b=dU3kFTlBqvGHdHuVea6M80p73LJZkOE9NfFyZh6pz3z5H67gjjjBK6UVptpkOOm7mk 32fQFcCsm+VDXfhXIyPbmqRd1v2KZtg8pkv/ddeqBroE//5x/ik3zP8+hB1Jf9tHRk4f qoVXfsss7uya2Siar6T1FPVu7DEjBJ6GMbAUcHJIwqNIy6UlREJ8bCR476Mrt6NPVl8+ hCHZ3rxYjZ25nwekT4cksFcADFrso788hwoz79T18SB/nfkdEbh8vo/NudbzNk/EZtNH JaZT9HfnUncYVAQBIjvg9+g2qeRKQ/aFalZ3KKZKg2SjFI5FbwayppEfEp7g1TXLPmkn Nnrg== 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:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=TwuPam4BS9UKOoy0JogxR8Q0k598YrPB4nNp1nN5o3I=; b=kiLLUJCmp6x36XlLpUb36WMSTOeqqhGzeqGlR9o6+HAzYQDAN9qVlcFpyd1YPSerU7 7I04WLBqwnj4Q4hxmIZX2TgoklIWBqpSy7kczI+ic/JLwbiIh9iU/OrZdbXL78ClgHcs OkxYV0aQt9WmM9FI3DKx8NMTcBWX8WmJeR4IFrSp1ObEpMSVyF55Hgp2V9Ukt671VMMy +nGPTs2fCZXs5QCDQNdKzOV8aEOaaYS10foURjEmr5NQ1165eIoJYRxMLRjjoT7TcoZt mawhQy4ETIg8j9sQT9JlKlgiOSbxtGS5uJSMzI87uyLBDQCWmvYV44FK4DYevHBDGimn e7nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=q7XWkzKA; 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=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v1-20020a056402348100b004372b5307cfsi19129932edc.247.2022.07.13.01.53.54; Wed, 13 Jul 2022 01:54:18 -0700 (PDT) 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; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=q7XWkzKA; 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=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235683AbiGMIhT (ORCPT + 99 others); Wed, 13 Jul 2022 04:37:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234858AbiGMIhS (ORCPT ); Wed, 13 Jul 2022 04:37:18 -0400 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92152C48C3; Wed, 13 Jul 2022 01:37:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1657701436; x=1689237436; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=TwuPam4BS9UKOoy0JogxR8Q0k598YrPB4nNp1nN5o3I=; b=q7XWkzKAjdbc6cSQUxhumh7lHQx62vkywmC1ossbZ8TvBH+EEOz9qfKl WhpbsMPL2eKwfoPuhmdcsj7VrtEhizCnF28ICPRndfrvczWZM+ThpV2/C xx9wwCanAYaNsGrMu6PgfsiXT1MqiMOZZ8VYNlwKG+vY68y1Ek+o7nv1T o=; Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-02.qualcomm.com with ESMTP; 13 Jul 2022 01:37:16 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg04-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2022 01:37:15 -0700 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 13 Jul 2022 01:37:15 -0700 Received: from [10.216.9.126] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Wed, 13 Jul 2022 01:37:12 -0700 Message-ID: Date: Wed, 13 Jul 2022 14:07:09 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.0 Subject: Re: [PATCH] PM: QoS: Add check to make sure CPU freq is non-negative Content-Language: en-US To: "Rafael J. Wysocki" CC: Len Brown , Pavel Machek , Linux PM , Linux Kernel Mailing List References: <20220623064605.2538969-1-quic_kshivnan@quicinc.com> From: Shivnandan Kumar In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Hi Rafael, Thanks for taking the time to review my patch and providing feedback. Please find answer inline. Thanks, Shivnandan On 7/13/2022 12:07 AM, Rafael J. Wysocki wrote: > On Thu, Jun 23, 2022 at 8:47 AM Shivnandan Kumar > wrote: >> CPU frequency should never be negative. > Do you mean "always be non-negative"? Yes,corrected subject now. > >> If some client driver calls freq_qos_update_request with some >> value greater than INT_MAX, then it will set max CPU freq at >> fmax but it will add plist node with some negative priority. >> plist node has priority from INT_MIN (highest) to INT_MAX >> (lowest). Once priority is set as negative, another client >> will not be able to reduce max CPU frequency. Adding check >> to make sure CPU freq is non-negative will fix this problem. >> Signed-off-by: Shivnandan Kumar >> >> --- >> kernel/power/qos.c | 6 ++++-- >> 1 file changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/kernel/power/qos.c b/kernel/power/qos.c >> index ec7e1e85923e..41e96fe34bfd 100644 >> --- a/kernel/power/qos.c >> +++ b/kernel/power/qos.c >> @@ -531,7 +531,8 @@ int freq_qos_add_request(struct freq_constraints *qos, >> { >> int ret; >> >> - if (IS_ERR_OR_NULL(qos) || !req) >> + if (IS_ERR_OR_NULL(qos) || !req || value < FREQ_QOS_MIN_DEFAULT_VALUE >> + || value > FREQ_QOS_MAX_DEFAULT_VALUE) > Why do you check against the defaults? Want to make sure to guard against negative value. > >> return -EINVAL; >> >> if (WARN(freq_qos_request_active(req), >> @@ -563,7 +564,8 @@ EXPORT_SYMBOL_GPL(freq_qos_add_request); >> */ >> int freq_qos_update_request(struct freq_qos_request *req, s32 new_value) >> { >> - if (!req) >> + if (!req || new_value < FREQ_QOS_MIN_DEFAULT_VALUE || >> + new_value > FREQ_QOS_MAX_DEFAULT_VALUE) >> return -EINVAL; >> >> if (WARN(!freq_qos_request_active(req), >> -- > I agree that it should guard against adding negative values, but I > don't see why s32 can be greater than INT_MAX. yes, checking against negative values will be sufficient. I will share patch v2 with only check against negative values. > > Also why don't you put the guard into freq_qos_apply() instead of > duplicating it in the callers of that function? Because function  freq_qos_remove_request calls freq_qos_apply with PM_QOS_DEFAULT_VALUE which is actually negative. So I do not want to break that.