Skip to contentSkip to conversation

cpufreq/amd-pstate: Don't fail active mode init on read-only auto_sel

PATCH In review Akram Boulahia 2 participants 4 messages Oct 8 – Oct 12

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq/amd-pstate: Don't fail active mode init on read-only auto_sel

Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() no longer returns early in active mode and always calls cppc_set_auto_sel(), which was needed for shared memory systems. However, on firmware where the Autonomous Selection Enable entry of _CPC is a constant integer rather than a register, that write fails with -EOPNOTSUPP. The error is returned, every CPU fails to initialize, cpufreq_register_driver() finds no policy and returns -ENODEV, and the kernel falls back to acpi-cpufreq:

amd_pstate: failed to set auto_sel, ret: -95
amd_pstate: Failed to initialize CPU 0: -95
...
amd_pstate: failed to register with return -19

This was seen on an ASUS ROG Zephyrus G14 (GA403UV, Ryzen 9 8945HS, BIOS 308). Its _CPC tables are revision 3 with the entry fixed at 1, and cppc_get_auto_sel() reads back 1 on all CPUs.

If the write returns -EOPNOTSUPP while active mode is requested and auto_sel already reads as enabled, which is what active mode needs, the refused write is harmless and initialization can continue. Any other failure, including a refusal where the current value does not match the requested mode, is still returned as before.

With this change, amd-pstate-epp loads on all 16 CPUs of that machine without warnings. amd_pstate=passive behaves as before: it still falls back to acpi-cpufreq with the same -95 errors, because auto_sel stays at 1 and cannot be changed.

Tested on Linux 7.3.0-rc6-00037-g7b63ef2d55f2.

Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")
Cc Marco Scardovi <[email protected]>
---
 drivers/cpufreq/amd-pstate.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/cpufreq/amd-pstate.c +12 -2
index 8bfd46d60843..05b496946d13 100644
@@ -500,6 +500,7 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
 	union perf_cached perf = READ_ONCE(cpudata->perf);
 	u64 numerator;
 	bool auto_sel;
+	bool want;
 
 	int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
 	if (ret)
@@ -518,14 +519,23 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
 	WRITE_ONCE(cpudata->perf, perf);
 	WRITE_ONCE(cpudata->prefcore_ranking, cppc_perf.highest_perf);
 
+	want = (cppc_state != AMD_PSTATE_PASSIVE);
+
 	ret = cppc_get_auto_sel(cpudata->cpu, &auto_sel);
 	if (ret) {
 		pr_warn("failed to get auto_sel, ret: %d\n", ret);
 		return 0;
 	}
 
-	ret = cppc_set_auto_sel(cpudata->cpu,
-			(cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);
+	ret = cppc_set_auto_sel(cpudata->cpu, want);
+
+	/*
+	 * Firmware may expose Autonomous Selection Enable as a read-only
+	 * constant. If it already matches what active mode needs, the
+	 * failed write is harmless.
+	 */
+	if (ret == -EOPNOTSUPP && want && auto_sel)
+		return 0;
 
 	if (ret)
 		pr_warn("failed to set auto_sel, ret: %d\n", ret);
Signature · 1 line
2.56.0
#1 lore raw
Quoted 30 lines · Akram Boulahia

Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() no longer returns early in active mode and always calls cppc_set_auto_sel(), which was needed for shared memory systems. However, on firmware where the Autonomous Selection Enable entry of _CPC is a constant integer rather than a register, that write fails with -EOPNOTSUPP. The error is returned, every CPU fails to initialize, cpufreq_register_driver() finds no policy and returns -ENODEV, and the kernel falls back to acpi-cpufreq:

amd_pstate: failed to set auto_sel, ret: -95
amd_pstate: Failed to initialize CPU 0: -95
...
amd_pstate: failed to register with return -19

This was seen on an ASUS ROG Zephyrus G14 (GA403UV, Ryzen 9 8945HS, BIOS 308). Its _CPC tables are revision 3 with the entry fixed at 1, and cppc_get_auto_sel() reads back 1 on all CPUs.

If the write returns -EOPNOTSUPP while active mode is requested and auto_sel already reads as enabled, which is what active mode needs, the refused write is harmless and initialization can continue. Any other failure, including a refusal where the current value does not match the requested mode, is still returned as before.

With this change, amd-pstate-epp loads on all 16 CPUs of that machine without warnings. amd_pstate=passive behaves as before: it still falls back to acpi-cpufreq with the same -95 errors, because auto_sel stays at 1 and cannot be changed.

Quoted 7 lines

Tested on Linux 7.3.0-rc6-00037-g7b63ef2d55f2.

Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")
Cc Marco Scardovi <[email protected]>

---

You're in a really weird path if you have an 8945HS that is using shared memory. That system has MSR access.

IE this sounds like a severe BIOS bug. Let's see what happens after you update BIOS. If it's still failing please share an acpidump somewhere (like a kernel bugzilla).

Need to make sure we understand why your system is behaving this way before making code changes.

Quoted 41 lines
  drivers/cpufreq/amd-pstate.c | 14 ++++++++++++--
  1 file changed, 12 insertions(+), 2 deletions(-)
drivers/cpufreq/amd-pstate.c +12 -2
index 8bfd46d60843..05b496946d13 100644
@@ -500,6 +500,7 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
  	union perf_cached perf = READ_ONCE(cpudata->perf);
  	u64 numerator;
  	bool auto_sel;
+	bool want;
 
  	int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf);
  	if (ret)
@@ -518,14 +519,23 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
  	WRITE_ONCE(cpudata->perf, perf);
  	WRITE_ONCE(cpudata->prefcore_ranking, cppc_perf.highest_perf);
 
+	want = (cppc_state != AMD_PSTATE_PASSIVE);
+
  	ret = cppc_get_auto_sel(cpudata->cpu, &auto_sel);
  	if (ret) {
  		pr_warn("failed to get auto_sel, ret: %d\n", ret);
  		return 0;
  	}
 
-	ret = cppc_set_auto_sel(cpudata->cpu,
-			(cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);
+	ret = cppc_set_auto_sel(cpudata->cpu, want);
+
+	/*
+	 * Firmware may expose Autonomous Selection Enable as a read-only
+	 * constant. If it already matches what active mode needs, the
+	 * failed write is harmless.
+	 */
+	if (ret == -EOPNOTSUPP && want && auto_sel)
+		return 0;
 
  	if (ret)
  		pr_warn("failed to set auto_sel, ret: %d\n", ret);
#2 lore raw
Quoted 9 lines · Mario Limonciello

You're in a really weird path if you have an 8945HS that is using shared memory. That system has MSR access.

IE this sounds like a severe BIOS bug. Let's see what happens after you update BIOS. If it's still failing please share an acpidump somewhere (like a kernel bugzilla).

Need to make sure we understand why your system is behaving this way before making code changes.

Thanks, you were right. After updating the BIOS from 308 to 311, amd-pstate works on this GA403UV with an unpatched 7.2.8 kernel. Active mode loads as amd-pstate-epp, amd_pstate=passive loads as amd-pstate, and the "CPPC feature is supported but currently disabled by the BIOS" line is gone.

So the BIOS update was the real fix, and this patch only worked around the old BIOS state. It also doesn't handle passive mode properly. Please drop it.

#3 lore raw
Quoted 17 lines · Akram Boulahia
Quoted 9 lines · Mario Limonciello

You're in a really weird path if you have an 8945HS that is using shared memory. That system has MSR access.

IE this sounds like a severe BIOS bug. Let's see what happens after you update BIOS. If it's still failing please share an acpidump somewhere (like a kernel bugzilla).

Need to make sure we understand why your system is behaving this way before making code changes.

Thanks, you were right. After updating the BIOS from 308 to 311, amd-pstate works on this GA403UV with an unpatched 7.2.8 kernel. Active mode loads as amd-pstate-epp, amd_pstate=passive loads as amd-pstate, and the "CPPC feature is supported but currently disabled by the BIOS" line is gone.

Quoted 3 lines

So the BIOS update was the real fix, and this patch only worked around the old BIOS state. It also doesn't handle passive mode properly. Please drop it.

Thanks, less quirks or unintended codepaths is the best outcome.