lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250823200121.1320197-6-sumitg@nvidia.com>
Date: Sun, 24 Aug 2025 01:31:18 +0530
From: Sumit Gupta <sumitg@...dia.com>
To: <rafael@...nel.org>, <viresh.kumar@...aro.org>, <lenb@...nel.org>,
	<robert.moore@...el.com>, <corbet@....net>, <pierre.gondois@....com>,
	<zhenglifeng1@...wei.com>, <ray.huang@....com>, <gautham.shenoy@....com>,
	<mario.limonciello@....com>, <perry.yuan@....com>,
	<linux-pm@...r.kernel.org>, <linux-acpi@...r.kernel.org>,
	<linux-doc@...r.kernel.org>, <acpica-devel@...ts.linux.dev>,
	<linux-kernel@...r.kernel.org>
CC: <linux-tegra@...r.kernel.org>, <treding@...dia.com>,
	<jonathanh@...dia.com>, <vsethi@...dia.com>, <ksitaraman@...dia.com>,
	<sanjayc@...dia.com>, <bbasu@...dia.com>, <sumitg@...dia.com>
Subject: [PATCH v2 5/7] cpufreq: CPPC: update policy min/max when toggling auto_select

When CPPC autonomous selection (auto_select) is enabled or disabled,
the policy min/max frequency limits should be updated appropriately to
reflect the new operating mode.

Currently, toggling auto_select only changes the hardware register but
doesn't update the cpufreq policy constraints, which can lead to
inconsistent behavior between the hardware state and the policy limits
visible to userspace and other kernel components.

When auto_select is enabled, preserve the current min/max performance
values to maintain user-configured limits. When disabled, the hardware
operates in a default mode where the OS directly controls performance,
so update the policy limits accordingly.

Signed-off-by: Sumit Gupta <sumitg@...dia.com>
---
 drivers/cpufreq/cppc_cpufreq.c | 47 ++++++++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index d9aae1ec26e1..5e1bbb5f67b8 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -880,6 +880,10 @@ static ssize_t show_auto_select(struct cpufreq_policy *policy, char *buf)
 static ssize_t store_auto_select(struct cpufreq_policy *policy,
 				 const char *buf, size_t count)
 {
+	struct cppc_cpudata *cpu_data = policy->driver_data;
+	unsigned int cpu = policy->cpu;
+	bool update_reg = false;
+	u32 min_perf, max_perf;
 	bool val;
 	int ret;
 
@@ -887,9 +891,48 @@ static ssize_t store_auto_select(struct cpufreq_policy *policy,
 	if (ret)
 		return ret;
 
-	ret = cppc_set_auto_sel(policy->cpu, val);
-	if (ret)
+	mutex_lock(&cppc_cpufreq_update_autosel_config_lock);
+	if (val) {
+		/* Enabling auto_select: set current user-configured limits */
+		min_perf = cpu_data->perf_ctrls.min_perf;
+		max_perf = cpu_data->perf_ctrls.max_perf;
+		update_reg = true;
+	} else {
+		/*
+		 * Disabling auto_select: set defaults for OS control.
+		 * Use lowest_nonlinear_perf as minimum to avoid very low frequencies
+		 * and nominal_perf as maximum for balanced operation.
+		 */
+		min_perf = cpu_data->perf_caps.lowest_nonlinear_perf;
+		max_perf = cpu_data->perf_caps.nominal_perf;
+	}
+
+	ret = cppc_set_auto_sel(cpu, val);
+	if (ret) {
+		pr_warn("failed to set auto_sel for cpu:%d (%d)\n", cpu, ret);
+		mutex_unlock(&cppc_cpufreq_update_autosel_config_lock);
+		return ret;
+	}
+	cpu_data->perf_caps.auto_sel = val;
+	mutex_unlock(&cppc_cpufreq_update_autosel_config_lock);
+
+	/*
+	 * On enabling auto_select: set min/max_perf register and update policy.
+	 * On disabling auto_select: update only policy.
+	 */
+	ret = cppc_cpufreq_set_min_perf(policy, min_perf, update_reg, true);
+	if (ret) {
+		pr_warn("failed to %s update min policy for cpu:%d (%d)\n",
+			val > 0 ? "set min_perf and" : "", cpu, ret);
 		return ret;
+	}
+
+	ret = cppc_cpufreq_set_max_perf(policy, max_perf, update_reg, true);
+	if (ret) {
+		pr_warn("failed to %s update max policy for cpu:%d (%d)\n",
+			val > 0 ? "set max_perf and" : "", cpu, ret);
+		return ret;
+	}
 
 	return count;
 }
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ