Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp99437lqc; Thu, 29 Feb 2024 11:24:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV8ZwTxxmI6usohe2MMHoXe5ZpQFpeVRA36SsNnkHnnD82DNhoEZXHz8hnBmUkQcMg7K7+XXdtneekDHyzJR2sdd7WCV7E4IYY3Tx04nA== X-Google-Smtp-Source: AGHT+IFMEoO0gxCWdZntfyQNw3zAHYCy2x2L7GIvgM1isDmKuXTPz1fvESKTfPPgYpPsq/fsuiYB X-Received: by 2002:a05:6a20:4c22:b0:19e:cf31:6a04 with SMTP id fm34-20020a056a204c2200b0019ecf316a04mr2884656pzb.59.1709234644775; Thu, 29 Feb 2024 11:24:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709234644; cv=pass; d=google.com; s=arc-20160816; b=HohSAUW67Sso7F9LbccMKZbVU+zVlqqBPu+le4hZEa9tHaV/+r6cfoqeQlWq6lRCFH GEiYBf2VZX7hpFaWtlH2I9msSCzwOxLwZ5OnBnIo04mw0jhZn4oUN9X8I7+VRuBK0w/S 91PNVUEBPnwC1qNIN2M4W50QtAkf2Cuhgl6rNNSi2ijBlTv1/ZbbxWc9mvKE5V0HPY39 UyUMIsesY0aCHvOa09VpClxnP4EF8SHpdVqyE2PJI0ygeJ6Fzgd+s0cpwC3JUQrKMzpi YR5vVu8qGCI2JOBEDmXljJGyqL2GwSlIfAmMy1QV7kIC3p2aI4q0XggBlIBfsiyqIHlo hc/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=g6NaLatfJwhBBr41fUTowNr9UwPZsNeg9XIMkONoPug=; fh=Qla+h9hBwQGCuIgV1xFMaYGYpbhjf+zGPFu7Ak4aeeQ=; b=ITDDJZ/G/7cCv+Xhc+Jgc8b5KF/knZn+Zy9yTzsd90M+j1G26FpgHX6nVJaLgPoLUa 73IvPP0W+c789+cCvPDHDW7SeoalfxtzPdeErViw182RytpUF6y+LY20xJL7WGacm5DB jpEpzG0wGayl09ubAt+mOmm5ZxFTA2SlcsCZdIOQtYIQa5mdf85YF62fCgLeQLZcYFKk yzrhJ+xvdWL5ReBTQKpgmlsMTF8QieLaNP2o2AI/2jPFVlVQ3rUcPfnhrP5i23sJq+FT HCDhdzI6M/Puo2TP0pK8JmFQ5D//wTwakcxzHACePGTNZlb9TJVmjBjl4Y/Oj3fIs7NP 07Dg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-87339-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87339-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a13-20020a63cd4d000000b005df58c84bfesi1892848pgj.506.2024.02.29.11.24.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 11:24:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87339-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-87339-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87339-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 75321285C6E for ; Thu, 29 Feb 2024 19:24:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8734313C9E2; Thu, 29 Feb 2024 19:23:37 +0000 (UTC) Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 983FC2E3E1; Thu, 29 Feb 2024 19:23:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709234617; cv=none; b=i5kLBKAY5SX7cuhB3C2yXICaRj2n7Yk5aIU46m9aYKJh514eZ8CzOWtTx5smUrWwgRvaj39ACPGEthO++e93Vx/N8OUn0yTmFrASWGsjKQfOn0Ikfukl8V4D87BekvlaBg1H+YCAWU5JPEb9ihnVoXY96EUQgfLO0AJNCC7llv0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709234617; c=relaxed/simple; bh=NS5lvKFQMunOW+vtSdt7RNYSiDnH4Z9HphPa0V7EW9o=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Q6hNjgaxn3VeEByrP1mi+MZmYuHipRyBuGFJ5V/q0uU5aPhPEUCZK1tZ8+GXVur7VhYJXTu6lGJDIb5CI8ve25I0YiN5gycv5j0xETCc5aj7EPQWMDtvhSsIciLffldGANPp1SHxa159eVqZ2Pzbri35zvu/miklBbV6EiQeBrc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6e45f7c63f4so174351a34.1; Thu, 29 Feb 2024 11:23:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709234614; x=1709839414; 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=g6NaLatfJwhBBr41fUTowNr9UwPZsNeg9XIMkONoPug=; b=pew2mhRbBhq7UfxYz7QBo4nMg+Mxv6W7kqOx57ER4Sj3Ff/MJFlj3NVGM6yTvWLei+ uBYb9QhiWh+atUwVlnDiKBeqLMd/CkrS3oH2SxUZCWl+XW139N/lPg24tiZQQedvljsz ueVnA89PmzzDejMwXL0tPPZpyI3Dl3iQCM1WwZQ00hM/e2N5GuPNn68DsgS5QIbOaNyS BzMp/npQ6IPdfnvKAYdTGzOkmq1hZ0q0fQdnznP9rGXc71j3Cqffav5JOyGK/oMxWfcj IuoiIaL5nb0rllcJq0y7fubQ31Vxs61ZOKLsLYlK2LbCixPSB4H3AqR9DeTXDsJwCsSe JNgg== X-Forwarded-Encrypted: i=1; AJvYcCWrPFhCUzC7jZSUCCVMyh48kHNG8K5zLl36Avb35mEAGsreVZI97ddxbc7Y0pZ7UytMQC8ncnt1ElWMqFIQQyzn6lnQVP2Mf0AxO6hS7vlbODeKkE1agCInVTsX41/EIdJr0vZHUYsGhzBDm4Mi0PgkJ6T8u3fVST+uXc+ZEGU= X-Gm-Message-State: AOJu0YwKdjkpDIiLaemgt8HQJ1H2CTdcF/nCS7g1ggJZhxnKFG05hj47 U7Il9cg7STFxTD32l1GxGlo7bkaChJIHWPUcyXR3556vn8kkuRc7RkS6LG6ydtsbv6BczI8fIpS PrQPHSAuebO98SL1tm/E9CWzvL3Y= X-Received: by 2002:a4a:a543:0:b0:5a0:ec66:b56b with SMTP id s3-20020a4aa543000000b005a0ec66b56bmr2200040oom.0.1709234614722; Thu, 29 Feb 2024 11:23:34 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240227091351.1144757-1-quic_kshivnan@quicinc.com> In-Reply-To: <20240227091351.1144757-1-quic_kshivnan@quicinc.com> From: "Rafael J. Wysocki" Date: Thu, 29 Feb 2024 20:23:23 +0100 Message-ID: Subject: Re: [PATCH v2] cpufreq: Limit resolving a frequency to policy min/max To: Shivnandan Kumar Cc: rafael@kernel.org, Viresh Kumar , Vincent Donnefort , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, quic_pkondeti@quicinc.com, quic_namajain@quicinc.com, quic_rgottimu@quicinc.com, kernel , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 27, 2024 at 10:15=E2=80=AFAM Shivnandan Kumar wrote: > > Resolving a frequency to an efficient one should not transgress policy->m= ax > (which can be set for thermal reason) and policy->min. Currently there is > possibility where scaling_cur_freq can exceed scaling_max_freq when > scaling_max_freq is inefficient frequency. Add additional check to ensure > that resolving a frequency will respect policy->min/max. > > Cc: > Fixes: 1f39fa0dccff ("cpufreq: Introducing CPUFREQ_RELATION_E") > Signed-off-by: Shivnandan Kumar > -- > > Changes in v2: > -rename function name from cpufreq_table_index_is_in_limits to cpufreq_is= _in_limits > -remove redundant outer parenthesis in return statement > -Make comment single line > > -- > --- > include/linux/cpufreq.h | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h > index afda5f24d3dd..7741244dee6e 100644 > --- a/include/linux/cpufreq.h > +++ b/include/linux/cpufreq.h > @@ -1021,6 +1021,19 @@ static inline int cpufreq_table_find_index_c(struc= t cpufreq_policy *policy, > efficiencies); > } > > +static inline bool cpufreq_is_in_limits(struct cpufreq_policy *policy, > + int idx) > +{ > + unsigned int freq; > + > + if (idx < 0) > + return false; > + > + freq =3D policy->freq_table[idx].frequency; > + > + return freq =3D=3D clamp_val(freq, policy->min, policy->max); > +} > + > static inline int cpufreq_frequency_table_target(struct cpufreq_policy *= policy, > unsigned int target_freq= , > unsigned int relation) > @@ -1054,7 +1067,8 @@ static inline int cpufreq_frequency_table_target(st= ruct cpufreq_policy *policy, > return 0; > } > > - if (idx < 0 && efficiencies) { > + /* Limit frequency index to honor policy->min/max */ > + if (!cpufreq_is_in_limits(policy, idx) && efficiencies) { > efficiencies =3D false; > goto retry; > } > -- Applied (with a whitespace adjustment and changelog edits) as 6.9 material, thanks!