mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marco Scardovi <scardracs@disroot.org>
To: viresh.kumar@linaro.org, rafael@kernel.org, ray.huang@amd.com,
	mario.limonciello@amd.com
Cc: perry.yuan@amd.com, kprateek.nayak@amd.com, wyes.karny@amd.com,
	stuartmeckle@gmail.com, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] cpufreq/amd-pstate: Prevent active mode on systems without EPP support
Date: Wed,  3 Jun 2026 10:19:57 +0200	[thread overview]
Message-ID: <20260603082143.11215-2-scardracs@disroot.org> (raw)
In-Reply-To: <20260603082143.11215-1-scardracs@disroot.org>

Zen 2 and older AMD processors do not support Collaborative Processor
Performance Control (CPPC) Energy Performance Preference (EPP). Loading
the amd-pstate driver in EPP-reliant "active" mode on these systems
pins the CPU frequency to the lowest non-linear frequency (1.7GHz).

Unconditionally probe EPP support during driver initialization via a new
amd_pstate_epp_supported() helper, which queries cppc_get_epp_perf() on
the first online CPU. Lack of ENERGY_PERF support or any error from
cppc_get_epp_perf() causes EPP to be treated as unsupported, with
unexpected errors printing a warning.

Cache the capability in a static global `epp_supported` boolean to avoid
redundant register reads during runtime mode transitions.

If EPP is unsupported:
- Fall back to passive mode at boot to keep the system functional.
- Reject runtime switches to active mode with -ENODEV.

Fixes: ffa5096a7c33 ("cpufreq: amd-pstate: implement Pstate EPP support for the AMD processors")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=221473
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Marco Scardovi <scardracs@disroot.org>
---
 drivers/cpufreq/amd-pstate.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 8d55e2be825b..61b75e3999b5 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -27,6 +27,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/smp.h>
+#include <linux/cpumask.h>
 #include <linux/sched.h>
 #include <linux/cpufreq.h>
 #include <linux/compiler.h>
@@ -88,6 +89,8 @@ static struct cpufreq_driver amd_pstate_epp_driver;
 static int cppc_state = AMD_PSTATE_UNDEFINED;
 static bool amd_pstate_prefcore = true;
 static bool dynamic_epp;
+/* EPP support capability cached for driver mode switches. */
+static bool epp_supported;
 static struct quirk_entry *quirks;
 
 /*
@@ -1614,6 +1617,10 @@ static void amd_pstate_driver_cleanup(void)
 static int amd_pstate_set_driver(int mode_idx)
 {
 	if (mode_idx >= AMD_PSTATE_DISABLE && mode_idx < AMD_PSTATE_MAX) {
+		if (mode_idx == AMD_PSTATE_ACTIVE && !epp_supported) {
+			pr_debug("EPP is not supported by this processor\n");
+			return -ENODEV;
+		}
 		cppc_state = mode_idx;
 		if (cppc_state == AMD_PSTATE_DISABLE)
 			pr_info("driver is explicitly disabled\n");
@@ -2222,6 +2229,22 @@ static bool amd_cppc_supported(void)
 	return true;
 }
 
+static bool amd_pstate_epp_supported(void)
+{
+	unsigned int cpu = cpumask_first(cpu_online_mask);
+	u64 epp;
+	int ret;
+
+	ret = cppc_get_epp_perf(cpu, &epp);
+	if (!ret)
+		return true;
+
+	if (ret != -EOPNOTSUPP)
+		pr_warn("Unable to determine EPP capability: %d\n", ret);
+
+	return false;
+}
+
 static int __init amd_pstate_init(void)
 {
 	struct device *dev_root;
@@ -2274,6 +2297,12 @@ static int __init amd_pstate_init(void)
 		return -ENODEV;
 	}
 
+	epp_supported = amd_pstate_epp_supported();
+	if (cppc_state == AMD_PSTATE_ACTIVE && !epp_supported) {
+		pr_warn("EPP not supported, falling back to passive mode\n");
+		cppc_state = AMD_PSTATE_PASSIVE;
+	}
+
 	/* capability check */
 	if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
 		pr_debug("AMD CPPC MSR based functionality is supported\n");
-- 
2.54.0


  reply	other threads:[~2026-06-03  8:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03  8:19 [PATCH 0/1] " Marco Scardovi
2026-06-03  8:19 ` Marco Scardovi [this message]
2026-06-03  9:39 ` K Prateek Nayak
2026-06-03 11:56   ` [PATCH v2 0/2] cpufreq/amd-pstate: Fix EPP initialization and add capability check Marco Scardovi
2026-06-03 11:56     ` [PATCH v2 1/2] cpufreq/amd-pstate: Fix EPP initialization for shared memory systems Marco Scardovi
2026-06-03 18:53       ` Mario Limonciello
2026-06-04  3:56         ` K Prateek Nayak
2026-06-04  6:56           ` Marco Scardovi
2026-06-04 18:43             ` Mario Limonciello
2026-06-05  3:41               ` K Prateek Nayak
2026-06-03 11:56     ` [PATCH v2 2/2] cpufreq/amd-pstate: Prevent active mode on systems without EPP support Marco Scardovi
2026-06-03 18:08     ` [PATCH v2 0/2] cpufreq/amd-pstate: Fix EPP initialization and add capability check Mario Limonciello

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260603082143.11215-2-scardracs@disroot.org \
    --to=scardracs@disroot.org \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=perry.yuan@amd.com \
    --cc=rafael@kernel.org \
    --cc=ray.huang@amd.com \
    --cc=stuartmeckle@gmail.com \
    --cc=viresh.kumar@linaro.org \
    --cc=wyes.karny@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®