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

From: K Prateek Nayak

Date: Fri Sep 18 2026 - 04:50:22 EST


Hello Wentao,

On 9/18/2026 12:38 PM, Wentao Guan wrote:
> 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")
> Cc: stable@xxxxxxxxxxxxxxx
> Tested-by: LFRon <ronforever@xxxxxxxxxxx>
> Signed-off-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>

You can flip that to:

Reviewed-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>
Tested-by: K Prateek Nayak <kprateek.nayak@xxxxxxx>

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

> Signed-off-by: Wentao Guan <guanwentao@xxxxxxxxxxxxx>
> ---
> changelog v2:
> Accecpt and tested the K Prateek Nayak reviews.
> v1 link:
> https://lore.kernel.org/stable/20260918054808.48999-1-guanwentao@xxxxxxxxxxxxx/#R
> ---
> ---
> drivers/cpufreq/amd-pstate.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 3a6b4b224a66d..91ec44f9fbb96 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -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.

--
Thanks and Regards,
Prateek