Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp968831imw; Wed, 13 Jul 2022 11:14:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s5oMqTn3VB9fW9JI5KS/WqbRglmrKSseuSIQo+O8t0Pr5rx3UO9e+ry42PxQEFRr3bCjWz X-Received: by 2002:a05:6a00:4211:b0:52a:c86e:aba3 with SMTP id cd17-20020a056a00421100b0052ac86eaba3mr4531506pfb.41.1657736096446; Wed, 13 Jul 2022 11:14:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657736096; cv=none; d=google.com; s=arc-20160816; b=FoyJ0OXqyXiqbxgKjn9bB7vvUm3CKXZlHcFHsggOGj9x66QmdzEkJaC/y8IUe6Dv7U 2GaG0h92yFJeSNikp+60WIapeP5ruZ/Z9Cu1gONkbhnMTZjO3gKlH68xIWBmZhFVsM9z W5BLYfM5QRhCfhkUdhArZnbNdiGuN34KcStF6xh6Pr25W+Pa4QyGgxj6a8Ind5qtyNSL +lgFZOifUbcce7WGNSBWPSSNSmgRAIZLF8v69AbGA2HccM3bsq/rv7fsC66tmIekmXGZ F67DwN2I0d394WI/B0Q2HL2XyrUmjzFDvn2Jzia3AnMvKkDd+DSfKuf2g86wLnx3AbbJ eStw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=O2ZB0zaBvuSigJ8wTixzYr0WCoqo0gk9Cx66gvFyjbU=; b=F5gJ8zY9mDgcaBG2MeOBuN7VzYU+uClRL4eOsV3c97vVj6P5cnc/z4HOh00lUmJM70 pSJ1GKRwCbdIpSeA2EUYzG6gw0bUXICmmgpMf0eizXEn6Bx9IjDax781w9I9v4J+G+Yb 7S0WWJ8xV6dd2ffIF8WGJBs3LXw+lEt+duWsWmlEMyc4UKjJK/HgmlEaRiDu7/eHvgAs JulLRECSCgfbzPqVGD10Vn3uJ8OsP2lZxarkaY0RmR9eMzCkfTTqrledufy2/pAgRQ/M jWTmGuc6XzBsTKldYaSkyoYKqA3cmSCSZStxJ+isSaDASiPrN8jfN3tiLSFIj3MMfrVl ozWw== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a4-20020a63cd44000000b00412ace8b0ffsi18526863pgj.160.2022.07.13.11.14.44; Wed, 13 Jul 2022 11:14:56 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236216AbiGMRu2 (ORCPT + 99 others); Wed, 13 Jul 2022 13:50:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230102AbiGMRu0 (ORCPT ); Wed, 13 Jul 2022 13:50:26 -0400 Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB3731183B; Wed, 13 Jul 2022 10:50:25 -0700 (PDT) Received: by mail-yb1-f182.google.com with SMTP id 75so19249330ybf.4; Wed, 13 Jul 2022 10:50:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=O2ZB0zaBvuSigJ8wTixzYr0WCoqo0gk9Cx66gvFyjbU=; b=Ip73G7DEceugIeRWXa5iePF8m8gmVdFo9Rl/Qc8gaIlH+Ju8WtNqC0FDdMn1R2SLaa 9scw3+semulEbWaUkGS1GZh07K1UW1itTL5pg9MBq/UOKpOYFLBqsAHgpzKnXSVxlyy3 hV+5t4yIBUIQqIudJA/lL8azQBTKC2ygelDzBhGL7KqNvFY4jF6/bDxGhmQZ7Cxa1km6 fyjPmRel/xfQqXWVAACC7B/ajznWslcvfqMBu2PiYPVOaebht9IkTfP8UdF08cgBxfsb pwQKiDQ232EgtKSbH4Xn1i12R0zhunib/bNcfRbPNGHuYlpt83+8gc16lh7vFf/2846p Ej/Q== X-Gm-Message-State: AJIora9WqU88sdlsRL/MjpLZL6A78CiMsgRN0KsjJ2gXyM9H2LEtxaaB pXnj3QTFc2eaoUf3EG/6/4DtqDDjzJdspgd0deU= X-Received: by 2002:a25:a2ca:0:b0:66e:719e:279 with SMTP id c10-20020a25a2ca000000b0066e719e0279mr4629988ybn.622.1657734625055; Wed, 13 Jul 2022 10:50:25 -0700 (PDT) MIME-Version: 1.0 References: <20220623064605.2538969-1-quic_kshivnan@quicinc.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Wed, 13 Jul 2022 19:50:14 +0200 Message-ID: Subject: Re: [PATCH] PM: QoS: Add check to make sure CPU freq is non-negative To: Shivnandan Kumar Cc: "Rafael J. Wysocki" , Len Brown , Pavel Machek , Linux PM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Wed, Jul 13, 2022 at 10:37 AM Shivnandan Kumar wrote: > > 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. OK