mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] cpufreq/amd-pstate: Do not cache bios_min_perf from populated CPPC_REQ
@ 2026-12-03 13:07 Farrukh Seyer Hasan
  2026-12-03 20:38 ` Mario Limonciello
  0 siblings, 1 reply; 4+ messages in thread
From: Farrukh Seyer Hasan @ 2026-12-03 13:07 UTC (permalink / raw)
  To: Mario Limonciello, Huang Rui, Rafael J . Wysocki, Viresh Kumar
  Cc: Perry Yuan, K Prateek Nayak, linux-pm, linux-kernel, Farrukh Seyer Hasan

Since commit 0e850278016e ("cpufreq/amd-pstate: Remove the defensive
check for bios_min_perf"), msr_init_perf() unconditionally reads
MIN_PERF from MSR_AMD_CPPC_REQ into perf.bios_min_perf.

That assumes MSR_AMD_CPPC_REQ only holds a BIOS-configured minimum on
boot, which breaks on warm reboots or crashes because amd-pstate does
not reset the MSR on reboot. On a Ryzen 7 4800H, warm rebooting after
running performance policy leaves MAX_PERF and MIN_PERF at nominal_perf
in MSR_AMD_CPPC_REQ, so msr_init_perf() treats the stale MIN_PERF as a
BIOS minimum and amd_pstate_verify() sets policy->min to nominal_freq
(2901000 kHz) instead of lowest_nonlinear_freq.

Only cache perf.bios_min_perf when MAX_PERF and DES_PERF are both zero
in MSR_AMD_CPPC_REQ. Checking only those fields instead of the whole
register rejects stale limits from previous boots while still accepting
firmware that sets a default EPP alongside the BIOS min option.

Fixes: 0e850278016e ("cpufreq/amd-pstate: Remove the defensive check for bios_min_perf")
Signed-off-by: Farrukh Seyer Hasan <farrukh13hasan31@gmail.com>
---
 drivers/cpufreq/amd-pstate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 4bedfbfc18b6..69bfeb923a53 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -533,7 +533,8 @@ static int msr_init_perf(struct amd_cpudata *cpudata)
 	perf.nominal_perf = FIELD_GET(AMD_CPPC_NOMINAL_PERF_MASK, cap1);
 	perf.lowest_nonlinear_perf = FIELD_GET(AMD_CPPC_LOWNONLIN_PERF_MASK, cap1);
 	perf.lowest_perf = FIELD_GET(AMD_CPPC_LOWEST_PERF_MASK, cap1);
-	perf.bios_min_perf = FIELD_GET(AMD_CPPC_MIN_PERF_MASK, cppc_req);
+	if (!(cppc_req & (AMD_CPPC_MAX_PERF_MASK | AMD_CPPC_DES_PERF_MASK)))
+		perf.bios_min_perf = FIELD_GET(AMD_CPPC_MIN_PERF_MASK, cppc_req);
 	WRITE_ONCE(cpudata->perf, perf);
 	WRITE_ONCE(cpudata->prefcore_ranking, FIELD_GET(AMD_CPPC_HIGHEST_PERF_MASK, cap1));
 	WRITE_ONCE(cpudata->floor_perf_cnt, FIELD_GET(AMD_CPPC_FLOOR_PERF_CNT_MASK, cap1));
-- 
2.56.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpufreq/amd-pstate: Do not cache bios_min_perf from populated CPPC_REQ
  2026-12-03 13:07 [PATCH] cpufreq/amd-pstate: Do not cache bios_min_perf from populated CPPC_REQ Farrukh Seyer Hasan
@ 2026-12-03 20:38 ` Mario Limonciello
  2026-12-04  7:15   ` Farrukh Seyer Hasan
  0 siblings, 1 reply; 4+ messages in thread
From: Mario Limonciello @ 2026-12-03 20:38 UTC (permalink / raw)
  To: Farrukh Seyer Hasan, Huang Rui, Rafael J . Wysocki, Viresh Kumar
  Cc: Perry Yuan, K Prateek Nayak, linux-pm, linux-kernel



On 12/3/26 07:07, Farrukh Seyer Hasan wrote:
> Since commit 0e850278016e ("cpufreq/amd-pstate: Remove the defensive
> check for bios_min_perf"), msr_init_perf() unconditionally reads
> MIN_PERF from MSR_AMD_CPPC_REQ into perf.bios_min_perf.
> 
> That assumes MSR_AMD_CPPC_REQ only holds a BIOS-configured minimum on
> boot, which breaks on warm reboots or crashes because amd-pstate does
> not reset the MSR on reboot. On a Ryzen 7 4800H, warm rebooting after
> running performance policy leaves MAX_PERF and MIN_PERF at nominal_perf
> in MSR_AMD_CPPC_REQ, so msr_init_perf() treats the stale MIN_PERF as a
> BIOS minimum and amd_pstate_verify() sets policy->min to nominal_freq
> (2901000 kHz) instead of lowest_nonlinear_freq.
> 
> Only cache perf.bios_min_perf when MAX_PERF and DES_PERF are both zero
> in MSR_AMD_CPPC_REQ. Checking only those fields instead of the whole
> register rejects stale limits from previous boots while still accepting
> firmware that sets a default EPP alongside the BIOS min option.
> 
> Fixes: 0e850278016e ("cpufreq/amd-pstate: Remove the defensive check for bios_min_perf")
> Signed-off-by: Farrukh Seyer Hasan <farrukh13hasan31@gmail.com>
> ---
>   drivers/cpufreq/amd-pstate.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
> index 4bedfbfc18b6..69bfeb923a53 100644
> --- a/drivers/cpufreq/amd-pstate.c
> +++ b/drivers/cpufreq/amd-pstate.c
> @@ -533,7 +533,8 @@ static int msr_init_perf(struct amd_cpudata *cpudata)
>   	perf.nominal_perf = FIELD_GET(AMD_CPPC_NOMINAL_PERF_MASK, cap1);
>   	perf.lowest_nonlinear_perf = FIELD_GET(AMD_CPPC_LOWNONLIN_PERF_MASK, cap1);
>   	perf.lowest_perf = FIELD_GET(AMD_CPPC_LOWEST_PERF_MASK, cap1);
> -	perf.bios_min_perf = FIELD_GET(AMD_CPPC_MIN_PERF_MASK, cppc_req);
> +	if (!(cppc_req & (AMD_CPPC_MAX_PERF_MASK | AMD_CPPC_DES_PERF_MASK)))
> +		perf.bios_min_perf = FIELD_GET(AMD_CPPC_MIN_PERF_MASK, cppc_req);
>   	WRITE_ONCE(cpudata->perf, perf);
>   	WRITE_ONCE(cpudata->prefcore_ranking, FIELD_GET(AMD_CPPC_HIGHEST_PERF_MASK, cap1));
>   	WRITE_ONCE(cpudata->floor_perf_cnt, FIELD_GET(AMD_CPPC_FLOOR_PERF_CNT_MASK, cap1));

Can you tell me more about the actual issue that reproduced this?  Did 
you really see a problem with warm reboots?  Or are you having a system 
crash?  Can you give me some reproduce steps?

My knee jerk reaction was this doesn't make sense for kexec and the 
shutdown sequence both are expecting this flow.  Sashiko seems to agree.

https://sashiko.dev/#/patchset/20261203130758.38506-1-farrukh13hasan31%40gmail.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpufreq/amd-pstate: Do not cache bios_min_perf from populated CPPC_REQ
  2026-12-03 20:38 ` Mario Limonciello
@ 2026-12-04  7:15   ` Farrukh Seyer Hasan
  2026-12-04 22:25     ` Mario Limonciello
  0 siblings, 1 reply; 4+ messages in thread
From: Farrukh Seyer Hasan @ 2026-12-04  7:15 UTC (permalink / raw)
  To: Mario Limonciello
  Cc: Huang Rui, Rafael J . Wysocki, Viresh Kumar, Perry Yuan,
	K Prateek Nayak, linux-pm, linux-kernel, Farrukh Seyer Hasan

(Resending in plain text so this reaches the mailing lists.)

On 12/3/26 20:38, Mario Limonciello wrote:
> Can you tell me more about the actual issue that reproduced this?  Did 
> you really see a problem with warm reboots?  Or are you having a system 
> crash?  Can you give me some reproduce steps?
> 
> My knee jerk reaction was this doesn't make sense for kexec and the 
> shutdown sequence both are expecting this flow.  Sashiko seems to agree.
> 
> https://sashiko.dev/#/patchset/20261203130758.38506-1-farrukh13hasan31%40gmail.com

Hi Mario,

Sorry, you and Sashiko are right about v1. It breaks kexec because
device_shutdown() -> cpufreq_suspend() -> amd_pstate_suspend() keeps
MAX_PERF and DES_PERF non-zero, and commit 0e850278016e dropped the
check for that reason. Please drop v1.

I had not tested a cold boot before. When I checked a clean cold boot
(poweroff -> power on) on stock 7.3.6-200.fc44.x86_64 with
dyndbg="file drivers/cpufreq/amd-pstate.c +p", the issue reproduced
directly on cold boot:

Hardware: ASUS TUF Gaming A17 FA706IC (BIOS FA706IC.302, Ryzen 7 4800H)
There is no "Requested CPU Min frequency" option in BIOS.

MSR_AMD_CPPC_CAP1 (0xC00102B0): 0xffac4218
  lowest=24 (404791 KHz), lownonlin=66 (1113175 KHz),
  nominal=172 (2901000 KHz), highest=255 (4300902 KHz)

On cold boot, dmesg logs on all 16 CPUs show:
  amd_pstate: Found Requested CPU Min Frequency of 4300902KHz on CPU0

Under balanced (powersave governor, balance_performance EPP):
  scaling_min_freq: 4300902
  scaling_max_freq: 4300902
  MSR_AMD_CPPC_REQ (0xC00102B3): 0x8000ffff (max=255 min=255 des=0 epp=0x80)

Under powersave (power EPP, max capped at nominal):
  scaling_min_freq: 2901000
  scaling_max_freq: 2901000
  MSR_AMD_CPPC_REQ (0xC00102B3): 0xff00acac (max=172 min=172 des=0 epp=0xff)

Earlier I observed the 2901000 KHz clamped state while powersave was
active, which made me suspect a leftover value across reboot/crash. On
cold boot this firmware leaves MSR_AMD_CPPC_REQ at 0xffff (min=max=255),
so after 0e850278016e, msr_init_perf() latches bios_min_perf = highest_perf.

For v2, which direction would you prefer so that I can prepare and test
the patch before sending it?
1. Reject min_perf >= perf.highest_perf in msr_init_perf()
   (seems least invasive to me as it avoids touching suspend/kexec for
   lower bios_min_perf values).
2. Restore the check on other CPPC_REQ fields in msr_init_perf() and
   clear MAX_PERF/DES_PERF in amd_pstate_suspend()/offline.
3. Add a DMI quirk for FA706IC.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] cpufreq/amd-pstate: Do not cache bios_min_perf from populated CPPC_REQ
  2026-12-04  7:15   ` Farrukh Seyer Hasan
@ 2026-12-04 22:25     ` Mario Limonciello
  0 siblings, 0 replies; 4+ messages in thread
From: Mario Limonciello @ 2026-12-04 22:25 UTC (permalink / raw)
  To: Farrukh Seyer Hasan
  Cc: Huang Rui, Rafael J . Wysocki, Viresh Kumar, Perry Yuan,
	K Prateek Nayak, linux-pm, linux-kernel



On 12/4/26 01:15, Farrukh Seyer Hasan wrote:
> (Resending in plain text so this reaches the mailing lists.)
> 
> On 12/3/26 20:38, Mario Limonciello wrote:
>> Can you tell me more about the actual issue that reproduced this?  Did
>> you really see a problem with warm reboots?  Or are you having a system
>> crash?  Can you give me some reproduce steps?
>>
>> My knee jerk reaction was this doesn't make sense for kexec and the
>> shutdown sequence both are expecting this flow.  Sashiko seems to agree.
>>
>> https://sashiko.dev/#/patchset/20261203130758.38506-1-farrukh13hasan31%40gmail.com
> 
> Hi Mario,
> 
> Sorry, you and Sashiko are right about v1. It breaks kexec because
> device_shutdown() -> cpufreq_suspend() -> amd_pstate_suspend() keeps
> MAX_PERF and DES_PERF non-zero, and commit 0e850278016e dropped the
> check for that reason. Please drop v1.
> 
> I had not tested a cold boot before. When I checked a clean cold boot
> (poweroff -> power on) on stock 7.3.6-200.fc44.x86_64 with
> dyndbg="file drivers/cpufreq/amd-pstate.c +p", the issue reproduced
> directly on cold boot:
> 
> Hardware: ASUS TUF Gaming A17 FA706IC (BIOS FA706IC.302, Ryzen 7 4800H)
> There is no "Requested CPU Min frequency" option in BIOS.
> 
> MSR_AMD_CPPC_CAP1 (0xC00102B0): 0xffac4218
>    lowest=24 (404791 KHz), lownonlin=66 (1113175 KHz),
>    nominal=172 (2901000 KHz), highest=255 (4300902 KHz)
> 
> On cold boot, dmesg logs on all 16 CPUs show:
>    amd_pstate: Found Requested CPU Min Frequency of 4300902KHz on CPU0
> 
> Under balanced (powersave governor, balance_performance EPP):
>    scaling_min_freq: 4300902
>    scaling_max_freq: 4300902
>    MSR_AMD_CPPC_REQ (0xC00102B3): 0x8000ffff (max=255 min=255 des=0 epp=0x80)
> 
> Under powersave (power EPP, max capped at nominal):
>    scaling_min_freq: 2901000
>    scaling_max_freq: 2901000
>    MSR_AMD_CPPC_REQ (0xC00102B3): 0xff00acac (max=172 min=172 des=0 epp=0xff)
> 
> Earlier I observed the 2901000 KHz clamped state while powersave was
> active, which made me suspect a leftover value across reboot/crash. On
> cold boot this firmware leaves MSR_AMD_CPPC_REQ at 0xffff (min=max=255),
> so after 0e850278016e, msr_init_perf() latches bios_min_perf = highest_perf.
> 
> For v2, which direction would you prefer so that I can prepare and test
> the patch before sending it?
> 1. Reject min_perf >= perf.highest_perf in msr_init_perf()
>     (seems least invasive to me as it avoids touching suspend/kexec for
>     lower bios_min_perf values).
> 2. Restore the check on other CPPC_REQ fields in msr_init_perf() and
>     clear MAX_PERF/DES_PERF in amd_pstate_suspend()/offline.
> 3. Add a DMI quirk for FA706IC.

Definitely not a DMI quirk.

I think rejecting min_perf >= highest perf is logical, but I do wonder 
if there is another bug on the table, it sounds like you're turning 
boost on and off?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-04 22:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 13:07 [PATCH] cpufreq/amd-pstate: Do not cache bios_min_perf from populated CPPC_REQ Farrukh Seyer Hasan
2026-12-03 20:38 ` Mario Limonciello
2026-12-04  7:15   ` Farrukh Seyer Hasan
2026-12-04 22:25     ` Mario Limonciello

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®