Skip to contentSkip to conversation

cpufreq/amd-pstate: Do not fail init when auto_sel cannot be written

PATCH In review Wentao Guan 2 participants 9 messages Sep 18 – Oct 16

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

PATCH 1/1 cpufreq/amd-pstate: Do not fail init when auto_sel cannot be written

Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.

On platforms implementing CPPC v2 and below, _CPC reports Autonomous Selection Enable as a plain integer rather than as a register descriptor. Such a field is a read-only capability flag: cppc_get_reg_val() reads it back successfully (the firmware reports it as enabled), while cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.

shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:

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

Failing to write auto_sel is not fatal: the register is either already enabled, as reported by the cppc_get_auto_sel() call right above, or not writable at all, and active mode worked in both cases before the offending commit. Downgrade the failure to a warning and let initialization continue, matching how the cppc_get_auto_sel() failure is handled.

Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")
---
 drivers/cpufreq/amd-pstate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/amd-pstate.c +1 -1
index 80d99ba1902c9..3657c5cccd4d8 100644
@@ -538,5 +538,5 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
 	if (ret)
 		pr_warn("failed to set auto_sel, ret: %d\n", ret);
 
-	return ret;
+	return 0;
 }
#1 lore raw

Hello Wentao,

Quoted 10 lines · Wentao Guan

Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.

On platforms implementing CPPC v2 and below, _CPC reports Autonomous Selection Enable as a plain integer rather than as a register descriptor. Such a field is a read-only capability flag: cppc_get_reg_val() reads it back successfully (the firmware reports it as enabled), while cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.

Ah! So it is one of those platforms that fall into:

Platforms that exclusively support Autonomous Selection must populate this field as an Integer with a value of 1.

as per the ACPI spec.

Quoted 10 lines

shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:

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

Quoted 5 lines

Failing to write auto_sel is not fatal: the register is either already enabled, as reported by the cppc_get_auto_sel() call right above, or not writable at all, and active mode worked in both cases before the offending commit. Downgrade the failure to a warning and let initialization continue, matching how the cppc_get_auto_sel() failure is handled.

Can't we just skip cppc_set_auto_sel() if the auto_sel is already at the desired value? Something like:

(Completely untested)

drivers/cpufreq/amd-pstate.c +3 -0
index d4ff8b228f86..ed540da818ef 100644
@@ -524,6 +524,9 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
 		return 0;
 	}
 
+	if ((cppc_state != AMD_PSTATE_PASSIVE) == auto_sel)
+		return 0;
+
 	ret = cppc_set_auto_sel(cpudata->cpu,
 			(cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);
 

---

That way we fail for passive mode switch which will operate under incorrectly assumptions since these platform only supports autonomous modes.

Thoughts?

Quoted 20 lines
Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")
---
 drivers/cpufreq/amd-pstate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/amd-pstate.c +1 -1
index 80d99ba1902c9..3657c5cccd4d8 100644
@@ -538,5 +538,5 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
        if (ret)
                pr_warn("failed to set auto_sel, ret: %d\n", ret);
 
-       return ret;
+       return 0;
 }
Signature · 2 lines
Thanks and Regards,
Prateek
#2 lore raw

Hi,

Quoted 56 lines · Wentao Guan
Quoted 10 lines

Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.

On platforms implementing CPPC v2 and below, _CPC reports Autonomous Selection Enable as a plain integer rather than as a register descriptor. Such a field is a read-only capability flag: cppc_get_reg_val() reads it back successfully (the firmware reports it as enabled), while cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.

Ah! So it is one of those platforms that fall into:

Platforms that exclusively support Autonomous Selection must populate this field as an Integer with a value of 1.

as per the ACPI spec.

Quoted 10 lines

shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:

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

Quoted 5 lines

Failing to write auto_sel is not fatal: the register is either already enabled, as reported by the cppc_get_auto_sel() call right above, or not writable at all, and active mode worked in both cases before the offending commit. Downgrade the failure to a warning and let initialization continue, matching how the cppc_get_auto_sel() failure is handled.

Can't we just skip cppc_set_auto_sel() if the auto_sel is already at the desired value? Something like:

(Completely untested)

drivers/cpufreq/amd-pstate.c +3 -1
index d4ff8b228f86..ed540da818ef 100644
@@ -524,6 +524,9 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
 		return 0;
 	}
 
+	if ((cppc_state != AMD_PSTATE_PASSIVE) == auto_sel)
+		return 0;
+
 	ret = cppc_set_auto_sel(cpudata->cpu,
 			(cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);
 
---
Quoted 5 lines

That way we fail for passive mode switch which will operate under incorrectly assumptions since these platform only supports autonomous modes.

Thoughts?

Thanks for your review, full agree with your suggested patch. I will send v2 after be tested later.

BRs
Wentao Guan

#3 lore raw

PATCH v2 1/1 cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode

In reply to K Prateek Nayak

Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.

Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor. cppc_get_reg_val() reads such a field back successfully, but cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.

shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:

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

Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report auto_sel as 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.

Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")

---
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
---

---
 drivers/cpufreq/amd-pstate.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/cpufreq/amd-pstate.c +3 -0
index 3a6b4b224a66d..91ec44f9fbb96 100644
@@ -535,6 +535,9 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
 		return 0;
 	}
 
+	if ((cppc_state != AMD_PSTATE_PASSIVE) == auto_sel)
+		return 0;
+
 	ret = cppc_set_auto_sel(cpudata->cpu,
 			(cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);
 
Signature · 1 line
2.30.2
reviewer Reviewed-by Tested-by on v2 1/1
#4 lore raw

Re: [PATCH v2] cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode

Hello Wentao,

Quoted 25 lines · Wentao Guan

Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.

Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor. cppc_get_reg_val() reads such a field back successfully, but cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.

shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:

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

Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report auto_sel as 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.

Quoted 4 lines
Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")

You can flip that to:

You did all the hard work to find, debug, and test it!

Quoted 16 lines

---
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
---

---
 drivers/cpufreq/amd-pstate.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/cpufreq/amd-pstate.c +0 -0
index 3a6b4b224a66d..91ec44f9fbb96 100644

drivers/cpufreq/amd-pstate.c static int shmem_init_perf(struct amd_cpudata *cpudata) · line 542

Quoted 8 lines
drivers/cpufreq/amd-pstate.c +3 -0
@@ -535,6 +535,9 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
 		return 0;
 	}
 
+	if ((cppc_state != AMD_PSTATE_PASSIVE) == auto_sel)
+		return 0;
+
 	ret = cppc_set_auto_sel(cpudata->cpu,
 			(cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);

nit. Now that we arrive here only to flip the autosel value, you can just do:

    cppc_set_auto_sel(cpudata->cpu, !auto_sel)

... and remove that ternary op.

Signature · 2 lines
Thanks and Regards,
Prateek
#5 lore raw

PATCH v3 1/1 cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode

Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.

Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor. cppc_get_reg_val() reads such a field back successfully, but cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.

shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:

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

Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report auto_sel as 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.

Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")

---
changelog v3:
Include the K Prateek Nayak reviews to remove that ternary op base on current condition now have.

v2 link:
https://lore.kernel.org/stable/[email protected]/#R
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
---

---
 drivers/cpufreq/amd-pstate.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/cpufreq/amd-pstate.c +4 -2
index 80d99ba1902c9..2d1f5292d1738 100644
@@ -532,8 +532,10 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
 		return 0;
 	}
 
-	ret = cppc_set_auto_sel(cpudata->cpu,
-			(cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);
+	if ((cppc_state != AMD_PSTATE_PASSIVE) == auto_sel)
+		return 0;
+
+	ret = cppc_set_auto_sel(cpudata->cpu, !auto_sel);
 
 	if (ret)
 		pr_warn("failed to set auto_sel, ret: %d\n", ret);
Signature · 1 line
2.30.2
#6 lore raw

Re: [PATCH v3] cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode

Hi,

Quoted 65 lines

Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.

Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor. cppc_get_reg_val() reads such a field back successfully, but cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.

shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:

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

Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report auto_sel as 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.

Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")

---
changelog v3:
Include the K Prateek Nayak reviews to remove that ternary op base on current condition now have.

v2 link:
https://lore.kernel.org/stable/[email protected]/#R
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
---
---
drivers/cpufreq/amd-pstate.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
drivers/cpufreq/amd-pstate.c +4 -3
index 80d99ba1902c9..2d1f5292d1738 100644
@@ -532,8 +532,10 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
 		return 0;
 	}
 
-	ret = cppc_set_auto_sel(cpudata->cpu,
-			(cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);
+	if ((cppc_state != AMD_PSTATE_PASSIVE) == auto_sel)
+		return 0;
+
+	ret = cppc_set_auto_sel(cpudata->cpu, !auto_sel);
 
 	if (ret)
 		pr_warn("failed to set auto_sel, ret: %d\n", ret);
--
Quoted 1 line

2.30.2

Ping? Nearly a month passed, anything update?

BRs
Wentao Guan

#7 lore raw

Re: [PATCH v3] cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode

Hello Wentao,

Quoted 64 lines · Wentao Guan

Hi,

Quoted 62 lines

Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.

Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor. cppc_get_reg_val() reads such a field back successfully, but cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.

shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:

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

Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report auto_sel as 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.

Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")

---
changelog v3:
Include the K Prateek Nayak reviews to remove that ternary op base on current condition now have.

v2 link:
https://lore.kernel.org/stable/[email protected]/#R
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
---
---
drivers/cpufreq/amd-pstate.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
drivers/cpufreq/amd-pstate.c +4 -2
index 80d99ba1902c9..2d1f5292d1738 100644
@@ -532,8 +532,10 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
 		return 0;
 	}
 
-	ret = cppc_set_auto_sel(cpudata->cpu,
-			(cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);
+	if ((cppc_state != AMD_PSTATE_PASSIVE) == auto_sel)
+		return 0;
+
+	ret = cppc_set_auto_sel(cpudata->cpu, !auto_sel);
 
Quoted 6 lines
Quoted 4 lines
drivers/cpufreq/amd-pstate.c +0 -1
 	if (ret)
 		pr_warn("failed to set auto_sel, ret: %d\n", ret);
--

2.30.2

Ping? Nearly a month passed, anything update?

On a similar issue here
https://lore.kernel.org/all/[email protected]/
Mario had recently pointed out that this might be a BIOS issue on systems that may have MSR interface but running an old BIOS that does not advertise the CPUID bit.

Could you please share your system details here and check if you are running the latest BIOS from your vendor?

Signature · 2 lines
Thanks and Regards,
Prateek
#8 lore raw

Re: [PATCH v3] cpufreq/amd-pstate: Skip auto_sel write when it already matches the mode

Hi,

Quoted 72 lines · Wentao Guan
Quoted 64 lines

Hi,

Quoted 62 lines

Since commit 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems"), shmem_init_perf() programs AUTONOMOUS_SELECTION_ENABLE unconditionally, including in active mode.

Platforms that exclusively support autonomous selection report this field as an Integer of 1, as required by the ACPI specification, instead of as a register descriptor. cppc_get_reg_val() reads such a field back successfully, but cppc_set_reg_val() rejects the write with -EOPNOTSUPP because the entry is not an ACPI_TYPE_BUFFER.

shmem_init_perf() propagates that error, so every amd_pstate_epp_cpu_init() fails, cpufreq_register_driver() ends up with an empty policy list and returns -ENODEV, and amd-pstate refuses to load at all:

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

Skip the write when the register already holds the value the requested mode needs. Active and guided mode are fixed on these platforms, which report auto_sel as 1, while passive mode still fails to load on a platform that cannot disable autonomous selection, exactly as it did before the offending commit.

Fixes 9dfd13f80c85 ("cpufreq/amd-pstate: Toggle auto_sel in active mode on shared memory systems")

---
changelog v3:
Include the K Prateek Nayak reviews to remove that ternary op base on current condition now have.

v2 link:
https://lore.kernel.org/stable/[email protected]/#R
changelog v2:
Accecpt and tested the K Prateek Nayak reviews.
v1 link:
https://lore.kernel.org/stable/[email protected]/#R
---
---
drivers/cpufreq/amd-pstate.c | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
drivers/cpufreq/amd-pstate.c +4 -2
index 80d99ba1902c9..2d1f5292d1738 100644
@@ -532,8 +532,10 @@ static int shmem_init_perf(struct amd_cpudata *cpudata)
 		return 0;
 	}
 
-	ret = cppc_set_auto_sel(cpudata->cpu,
-			(cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);
+	if ((cppc_state != AMD_PSTATE_PASSIVE) == auto_sel)
+		return 0;
+
+	ret = cppc_set_auto_sel(cpudata->cpu, !auto_sel);
 
Quoted 6 lines
Quoted 4 lines
drivers/cpufreq/amd-pstate.c +0 -1
 	if (ret)
 		pr_warn("failed to set auto_sel, ret: %d\n", ret);
--

2.30.2

Ping? Nearly a month passed, anything update?

Quoted 5 lines

On a similar issue here
https://lore.kernel.org/all/[email protected]/
Mario had recently pointed out that this might be a BIOS issue on systems that may have MSR interface but running an old BIOS that does not advertise the CPUID bit.

Seem same issue.

Quoted 3 lines

Could you please share your system details here and check if you are running the latest BIOS from your vendor?

Emmm, the user report that dmesg showed running on this laptop:
DMI: METAPHYUNI MetamechBook01/MetamechBook01, BIOS AHP958_V00.01_T015A5ME1 02/22/2024 which vendor not ship new BIOS,
but it is verified in AMD Advantage: https://www.amd.com/en/gaming/laptops/advantage-premium.html ...

He also helped me to test the kernel patch.

BRs
Wentao Guan