Skip to contentSkip to conversation

CPPC/amd-pstate: Fixes to limit actions to online CPUs

PATCH In review Gautham R. Shenoy 3 participants 8 messages Nov 7, 2025 – Nov 9, 2025

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

v2 cover CPPC/amd-pstate: Fixes to limit actions to online CPUs

Hello,

This is the v2 of the patchset to restrict certain actions to only online CPUs instead of present CPUs.

The v1 of this patchset can be found here:
https://lore.kernel.org/lkml/[email protected]/

Changes between v1 --> v2:

* Picked up the Reviewed-by tags from Mario for the first four patches

* Picked up the Tested-by tags from Chris for the first two patches

* Added a fifth patch to fix calling of cppc_set_auto_sel() for only online CPUs in the amd-pstate driver code (Mario)

Gautham R. Shenoy (5):
ACPI: CPPC: Detect preferred core availability on online CPUs
ACPI: CPPC: Check _CPC validity for only the online CPUs
ACPI: CPPC: Perform fast check switch only for online CPUs
ACPI: CPPC: Limit perf ctrs in PCC check only to online CPUs cpufreq/amd-pstate: Call cppc_set_auto_sel() only for online CPUs

 arch/x86/kernel/acpi/cppc.c  | 2 +-
 drivers/acpi/cppc_acpi.c     | 6 +++---
 drivers/cpufreq/amd-pstate.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/5 ACPI: CPPC: Detect preferred core availability on online CPUs

Commit 279f838a61f9 ("x86/amd: Detect preferred cores in amd_get_boost_ratio_numerator()") introduced the ability to detect the preferred core on AMD platforms by checking if there at least two distinct highest_perf values.

However, it uses for_each_present_cpu() to iterate through all the CPUs in the platform, which is problematic when the kernel is booted with "nosmt=force" commandline option.

Hence limit the search to only the online CPUs.

---
 arch/x86/kernel/acpi/cppc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/acpi/cppc.c +1 -1
index 7047124490f6..d7c8ef1e354d 100644
@@ -196,7 +196,7 @@ int amd_detect_prefcore(bool *detected)
 		break;
 	}
 
-	for_each_present_cpu(cpu) {
+	for_each_online_cpu(cpu) {
 		u32 tmp;
 		int ret;
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 2/5 ACPI: CPPC: Check _CPC validity for only the online CPUs

In reply to Gautham R. Shenoy

per_cpu(cpc_desc_ptr, cpu) object is initialized for only the online CPUs via acpi_soft_cpu_online() --> __acpi_processor_start() --> acpi_cppc_processor_probe().

However the function acpi_cpc_valid() checks for the validity of the _CPC object for all the present CPUs. This breaks when the kernel is booted with "nosmt=force".

Hence check the validity of the _CPC objects of only the online CPUs.

---
 drivers/acpi/cppc_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/cppc_acpi.c +1 -1
index ab4651205e8a..50e6348b511f 100644
@@ -460,7 +460,7 @@ bool acpi_cpc_valid(void)
 	if (acpi_disabled)
 		return false;
 
-	for_each_present_cpu(cpu) {
+	for_each_online_cpu(cpu) {
 		cpc_ptr = per_cpu(cpc_desc_ptr, cpu);
 		if (!cpc_ptr)
 			return false;
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 3/5 ACPI: CPPC: Perform fast check switch only for online CPUs

In reply to Gautham R. Shenoy

per_cpu(cpc_desc_ptr, cpu) object is initialized for only the online CPUs via acpi_soft_cpu_online() --> __acpi_processor_start() --> acpi_cppc_processor_probe().

However the function cppc_allow_fast_switch() checks for the validity of the _CPC object for all the present CPUs. This breaks when the kernel is booted with "nosmt=force".

Check fast_switch capability only on online CPUs

Fixes 15eece6c5b05 ("ACPI: CPPC: Fix NULL pointer dereference when nosmp is used")
---
 drivers/acpi/cppc_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/cppc_acpi.c +1 -1
index 50e6348b511f..fb7696b27d82 100644
@@ -476,7 +476,7 @@ bool cppc_allow_fast_switch(void)
 	struct cpc_desc *cpc_ptr;
 	int cpu;
 
-	for_each_present_cpu(cpu) {
+	for_each_online_cpu(cpu) {
 		cpc_ptr = per_cpu(cpc_desc_ptr, cpu);
 		desired_reg = &cpc_ptr->cpc_regs[DESIRED_PERF];
 		if (!CPC_IN_SYSTEM_MEMORY(desired_reg) &&
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 4/5 ACPI: CPPC: Limit perf ctrs in PCC check only to online CPUs

In reply to Gautham R. Shenoy

per_cpu(cpc_desc_ptr, cpu) object is initialized for only the online CPU via acpi_soft_cpu_online() --> __acpi_processor_start() --> acpi_cppc_processor_probe().

However the function cppc_perf_ctrs_in_pcc() checks if the CPPC perf-ctrs are in a PCC region for all the present CPUs, which breaks when the kernel is booted with "nosmt=force".

Hence, limit the check only to the online CPUs.

Fixes ae2df912d1a5 ("ACPI: CPPC: Disable FIE if registers in PCC regions")
---
 drivers/acpi/cppc_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/acpi/cppc_acpi.c +1 -1
index fb7696b27d82..f49c72d3a78b 100644
@@ -1435,7 +1435,7 @@ bool cppc_perf_ctrs_in_pcc(void)
 {
 	int cpu;
 
-	for_each_present_cpu(cpu) {
+	for_each_online_cpu(cpu) {
 		struct cpc_register_resource *ref_perf_reg;
 		struct cpc_desc *cpc_desc;
 
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 5/5 cpufreq/amd-pstate: Call cppc_set_auto_sel() only for online CPUs

In reply to Gautham R. Shenoy

amd_pstate_change_mode_without_dvr_change() calls cppc_set_auto_sel() for all the present CPUs.

However, this callpath eventually calls cppc_set_reg_val() which accesses the per-cpu cpc_desc_ptr object. This object is initialized only for online CPUs via acpi_soft_cpu_online() --> __acpi_processor_start() --> acpi_cppc_processor_probe().

Hence, restrict calling cppc_set_auto_sel() to only the online CPUs.

Fixes 3ca7bc818d8c ("cpufreq: amd-pstate: Add guided mode control support via sysfs")
---
 drivers/cpufreq/amd-pstate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/amd-pstate.c +1 -1
index b44f0f7a5ba1..602e4fa81d6c 100644
@@ -1282,7 +1282,7 @@ static int amd_pstate_change_mode_without_dvr_change(int mode)
 	if (cpu_feature_enabled(X86_FEATURE_CPPC) || cppc_state == AMD_PSTATE_ACTIVE)
 		return 0;
 
-	for_each_present_cpu(cpu) {
+	for_each_online_cpu(cpu) {
 		cppc_set_auto_sel(cpu, (cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);
 	}
 
Signature · 1 line
2.34.1
#6 lore raw
In reply to Gautham R. Shenoy

Hi,

Quoted 20 lines · Gautham R. Shenoy

Hello,

This is the v2 of the patchset to restrict certain actions to only online CPUs instead of present CPUs.

The v1 of this patchset can be found here:
https://lore.kernel.org/lkml/[email protected]/

Changes between v1 --> v2:

* Picked up the Reviewed-by tags from Mario for the first four patches

* Picked up the Tested-by tags from Chris for the first two patches

* Added a fifth patch to fix calling of cppc_set_auto_sel() for only online CPUs in the amd-pstate driver code (Mario)

Quoted 5 lines

Gautham R. Shenoy (5):
ACPI: CPPC: Detect preferred core availability on online CPUs
ACPI: CPPC: Check _CPC validity for only the online CPUs
ACPI: CPPC: Perform fast check switch only for online CPUs
ACPI: CPPC: Limit perf ctrs in PCC check only to online CPUs

The above 4 patches applied as 6.18-rc material.

Quoted 1 line

cpufreq/amd-pstate: Call cppc_set_auto_sel() only for online CPUs

And I'm leaving this one to Mario.

Thanks!

#7 lore raw

Hi, I've tested all five v2 patches and have observed no issues in the use case the bug report was based upon. I continue to successfully receive the desired amd-pstate scaling driver when 'nosmt=force' and 'amd_pstate=passive' are set. I've not tested other cases/scenarios for which the additional hardening/patches may have been intended.

Thank you again for the rapid efforts that went into this solution.

Chris Harris

Quoted 37 lines · Rafael J. Wysocki

Hi,

Quoted 20 lines · Gautham R. Shenoy

Hello,

This is the v2 of the patchset to restrict certain actions to only online CPUs instead of present CPUs.

The v1 of this patchset can be found here:
https://lore.kernel.org/lkml/[email protected]/

Changes between v1 --> v2:

* Picked up the Reviewed-by tags from Mario for the first four patches

* Picked up the Tested-by tags from Chris for the first two patches

* Added a fifth patch to fix calling of cppc_set_auto_sel() for only online CPUs in the amd-pstate driver code (Mario)

Quoted 5 lines

Gautham R. Shenoy (5):
ACPI: CPPC: Detect preferred core availability on online CPUs
ACPI: CPPC: Check _CPC validity for only the online CPUs
ACPI: CPPC: Perform fast check switch only for online CPUs
ACPI: CPPC: Limit perf ctrs in PCC check only to online CPUs

The above 4 patches applied as 6.18-rc material.

Quoted 1 line

cpufreq/amd-pstate: Call cppc_set_auto_sel() only for online CPUs

And I'm leaving this one to Mario.

Thanks!