mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] ACPI: CPPC: Fixes to limit actions to online CPUs
@ 2025-11-05 14:38 Gautham R. Shenoy
  2025-11-05 14:38 ` [PATCH 1/4] ACPI: CPPC: Detect preferred core availability on " Gautham R. Shenoy
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Gautham R. Shenoy @ 2025-11-05 14:38 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown, Mario Limonciello, Yunhui Cui,
	Jeremy Linton, Viresh Kumar, Ionela Voinescu
  Cc: linux-acpi, linux-kernel, Christopher Harris, linux-pm,
	Gautham R. Shenoy

Hello,

Christopher Harris reported a regression between v6.10 to v6.11 that
the amd-pstate driver failed to load even when the commandline had
"amd_pstate=passive"
(https://lore.kernel.org/lkml/CAM+eXpdDT7KjLV0AxEwOLkSJ2QtrsvGvjA2cCHvt1d0k2_C4Cw@mail.gmail.com/)

On debugging the issue it was observed that when the commandline
contains "nosmt=force", the CPPC code fails when performing certain
checks such as checking for the presence of preferred cores and
validity of the _CPC object since it iterates through all "present"
CPUs while the object state was populated only for "online" CPUs.

This patchset contains fixes to address this issue.

The first two patches in the series address the issue reported by
Chris.

Patches 3 and 4 harden the code in a couple of more functions which
iterated through the present CPUs when it is more apt to restrict the
operations to online CPUs



Gautham R. Shenoy (4):
  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

 arch/x86/kernel/acpi/cppc.c | 2 +-
 drivers/acpi/cppc_acpi.c    | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

-- 
2.34.1


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

* [PATCH 1/4] ACPI: CPPC: Detect preferred core availability on online CPUs
  2025-11-05 14:38 [PATCH 0/4] ACPI: CPPC: Fixes to limit actions to online CPUs Gautham R. Shenoy
@ 2025-11-05 14:38 ` Gautham R. Shenoy
  2025-11-05 14:38 ` [PATCH 2/4] ACPI: CPPC: Check _CPC validity for only the " Gautham R. Shenoy
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Gautham R. Shenoy @ 2025-11-05 14:38 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown, Mario Limonciello, Yunhui Cui,
	Jeremy Linton, Viresh Kumar, Ionela Voinescu
  Cc: linux-acpi, linux-kernel, Christopher Harris, linux-pm,
	Gautham R. Shenoy

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.

Fixes: 279f838a61f9 ("x86/amd: Detect preferred cores in amd_get_boost_ratio_numerator()")
Reported-by: Christopher Harris <chris.harris79@gmail.com>
Closes: https://lore.kernel.org/lkml/CAM+eXpdDT7KjLV0AxEwOLkSJ2QtrsvGvjA2cCHvt1d0k2_C4Cw@mail.gmail.com/
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
 arch/x86/kernel/acpi/cppc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c
index 7047124490f6..d7c8ef1e354d 100644
--- a/arch/x86/kernel/acpi/cppc.c
+++ b/arch/x86/kernel/acpi/cppc.c
@@ -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;
 
-- 
2.34.1


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

* [PATCH 2/4] ACPI: CPPC: Check _CPC validity for only the online CPUs
  2025-11-05 14:38 [PATCH 0/4] ACPI: CPPC: Fixes to limit actions to online CPUs Gautham R. Shenoy
  2025-11-05 14:38 ` [PATCH 1/4] ACPI: CPPC: Detect preferred core availability on " Gautham R. Shenoy
@ 2025-11-05 14:38 ` Gautham R. Shenoy
  2025-11-05 14:38 ` [PATCH 3/4] ACPI: CPPC: Perform fast check switch only for " Gautham R. Shenoy
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Gautham R. Shenoy @ 2025-11-05 14:38 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown, Mario Limonciello, Yunhui Cui,
	Jeremy Linton, Viresh Kumar, Ionela Voinescu
  Cc: linux-acpi, linux-kernel, Christopher Harris, linux-pm,
	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.

Fixes: 2aeca6bd0277 ("ACPI: CPPC: Check present CPUs for determining _CPC is valid")
Reported-by: Christopher Harris <chris.harris79@gmail.com>
Closes: https://lore.kernel.org/lkml/CAM+eXpdDT7KjLV0AxEwOLkSJ2QtrsvGvjA2cCHvt1d0k2_C4Cw@mail.gmail.com/
Suggested-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
 drivers/acpi/cppc_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index ab4651205e8a..50e6348b511f 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -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;
-- 
2.34.1


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

* [PATCH 3/4] ACPI: CPPC: Perform fast check switch only for online CPUs
  2025-11-05 14:38 [PATCH 0/4] ACPI: CPPC: Fixes to limit actions to online CPUs Gautham R. Shenoy
  2025-11-05 14:38 ` [PATCH 1/4] ACPI: CPPC: Detect preferred core availability on " Gautham R. Shenoy
  2025-11-05 14:38 ` [PATCH 2/4] ACPI: CPPC: Check _CPC validity for only the " Gautham R. Shenoy
@ 2025-11-05 14:38 ` Gautham R. Shenoy
  2025-11-05 14:38 ` [PATCH 4/4] ACPI: CPPC: Limit perf ctrs in PCC check only to " Gautham R. Shenoy
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Gautham R. Shenoy @ 2025-11-05 14:38 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown, Mario Limonciello, Yunhui Cui,
	Jeremy Linton, Viresh Kumar, Ionela Voinescu
  Cc: linux-acpi, linux-kernel, Christopher Harris, linux-pm,
	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")
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
 drivers/acpi/cppc_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 50e6348b511f..fb7696b27d82 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -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) &&
-- 
2.34.1


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

* [PATCH 4/4] ACPI: CPPC: Limit perf ctrs in PCC check only to online CPUs
  2025-11-05 14:38 [PATCH 0/4] ACPI: CPPC: Fixes to limit actions to online CPUs Gautham R. Shenoy
                   ` (2 preceding siblings ...)
  2025-11-05 14:38 ` [PATCH 3/4] ACPI: CPPC: Perform fast check switch only for " Gautham R. Shenoy
@ 2025-11-05 14:38 ` Gautham R. Shenoy
  2025-11-05 16:00 ` [PATCH 0/4] ACPI: CPPC: Fixes to limit actions " Mario Limonciello (AMD) (kernel.org)
  2025-11-05 21:13 ` Chris H
  5 siblings, 0 replies; 8+ messages in thread
From: Gautham R. Shenoy @ 2025-11-05 14:38 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown, Mario Limonciello, Yunhui Cui,
	Jeremy Linton, Viresh Kumar, Ionela Voinescu
  Cc: linux-acpi, linux-kernel, Christopher Harris, linux-pm,
	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")
Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
---
 drivers/acpi/cppc_acpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index fb7696b27d82..f49c72d3a78b 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -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;
 
-- 
2.34.1


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

* Re: [PATCH 0/4] ACPI: CPPC: Fixes to limit actions to online CPUs
  2025-11-05 14:38 [PATCH 0/4] ACPI: CPPC: Fixes to limit actions to online CPUs Gautham R. Shenoy
                   ` (3 preceding siblings ...)
  2025-11-05 14:38 ` [PATCH 4/4] ACPI: CPPC: Limit perf ctrs in PCC check only to " Gautham R. Shenoy
@ 2025-11-05 16:00 ` Mario Limonciello (AMD) (kernel.org)
  2025-11-07  4:42   ` Gautham R. Shenoy
  2025-11-05 21:13 ` Chris H
  5 siblings, 1 reply; 8+ messages in thread
From: Mario Limonciello (AMD) (kernel.org) @ 2025-11-05 16:00 UTC (permalink / raw)
  To: Gautham R. Shenoy, Rafael J . Wysocki, Len Brown, Yunhui Cui,
	Jeremy Linton, Viresh Kumar, Ionela Voinescu
  Cc: linux-acpi, linux-kernel, Christopher Harris, linux-pm



On 11/5/2025 8:38 AM, Gautham R. Shenoy wrote:
> Hello,
> 
> Christopher Harris reported a regression between v6.10 to v6.11 that
> the amd-pstate driver failed to load even when the commandline had
> "amd_pstate=passive"
> (https://lore.kernel.org/lkml/CAM+eXpdDT7KjLV0AxEwOLkSJ2QtrsvGvjA2cCHvt1d0k2_C4Cw@mail.gmail.com/)
> 
> On debugging the issue it was observed that when the commandline
> contains "nosmt=force", the CPPC code fails when performing certain
> checks such as checking for the presence of preferred cores and
> validity of the _CPC object since it iterates through all "present"
> CPUs while the object state was populated only for "online" CPUs.
> 
> This patchset contains fixes to address this issue.
> 
> The first two patches in the series address the issue reported by
> Chris.
> 
> Patches 3 and 4 harden the code in a couple of more functions which
> iterated through the present CPUs when it is more apt to restrict the
> operations to online CPUs
> 
> 
> 
> Gautham R. Shenoy (4):
>    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
> 
>   arch/x86/kernel/acpi/cppc.c | 2 +-
>   drivers/acpi/cppc_acpi.c    | 6 +++---
>   2 files changed, 4 insertions(+), 4 deletions(-)
> 

The series looks good to me.

Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>

But I would say I noticed we are also using for_each_present_cpu() in 
amd-pstate with amd_pstate_change_mode_without_dvr_change().

Should that also get a similar change?

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

* Re: [PATCH 0/4] ACPI: CPPC: Fixes to limit actions to online CPUs
  2025-11-05 14:38 [PATCH 0/4] ACPI: CPPC: Fixes to limit actions to online CPUs Gautham R. Shenoy
                   ` (4 preceding siblings ...)
  2025-11-05 16:00 ` [PATCH 0/4] ACPI: CPPC: Fixes to limit actions " Mario Limonciello (AMD) (kernel.org)
@ 2025-11-05 21:13 ` Chris H
  5 siblings, 0 replies; 8+ messages in thread
From: Chris H @ 2025-11-05 21:13 UTC (permalink / raw)
  To: Gautham R. Shenoy
  Cc: Rafael J . Wysocki, Len Brown, Mario Limonciello, Yunhui Cui,
	Jeremy Linton, Viresh Kumar, Ionela Voinescu, linux-acpi,
	linux-kernel, linux-pm

Confirming: I've tested the first two patches in the series on kernel
v6.17.  The patches successfully resolve the issue described, allowing
one to boot with amd-pstate + nosmt=force.  In other words: receive
the expected amd-pstate scaling driver when SMT logical cores are
disabled.

ACPI: CPPC: Detect preferred core availability on online CPUs
ACPI: CPPC: Check _CPC validity for only the online CPUs

Thank you Mario and Gautham for addressing this so quickly.

Chris Harris

On Wed, Nov 5, 2025 at 6:39 AM Gautham R. Shenoy <gautham.shenoy@amd.com> wrote:
>
> Hello,
>
> Christopher Harris reported a regression between v6.10 to v6.11 that
> the amd-pstate driver failed to load even when the commandline had
> "amd_pstate=passive"
> (https://lore.kernel.org/lkml/CAM+eXpdDT7KjLV0AxEwOLkSJ2QtrsvGvjA2cCHvt1d0k2_C4Cw@mail.gmail.com/)
>
> On debugging the issue it was observed that when the commandline
> contains "nosmt=force", the CPPC code fails when performing certain
> checks such as checking for the presence of preferred cores and
> validity of the _CPC object since it iterates through all "present"
> CPUs while the object state was populated only for "online" CPUs.
>
> This patchset contains fixes to address this issue.
>
> The first two patches in the series address the issue reported by
> Chris.
>
> Patches 3 and 4 harden the code in a couple of more functions which
> iterated through the present CPUs when it is more apt to restrict the
> operations to online CPUs
>
>
>
> Gautham R. Shenoy (4):
>   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
>
>  arch/x86/kernel/acpi/cppc.c | 2 +-
>  drivers/acpi/cppc_acpi.c    | 6 +++---
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> --
> 2.34.1
>

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

* Re: [PATCH 0/4] ACPI: CPPC: Fixes to limit actions to online CPUs
  2025-11-05 16:00 ` [PATCH 0/4] ACPI: CPPC: Fixes to limit actions " Mario Limonciello (AMD) (kernel.org)
@ 2025-11-07  4:42   ` Gautham R. Shenoy
  0 siblings, 0 replies; 8+ messages in thread
From: Gautham R. Shenoy @ 2025-11-07  4:42 UTC (permalink / raw)
  To: Mario Limonciello (AMD) (kernel.org)
  Cc: Rafael J . Wysocki, Len Brown, Yunhui Cui, Jeremy Linton,
	Viresh Kumar, Ionela Voinescu, linux-acpi, linux-kernel,
	Christopher Harris, linux-pm

On Wed, Nov 05, 2025 at 10:00:25AM -0600, Mario Limonciello (AMD) (kernel.org) wrote:
> 
> > 
> 
> The series looks good to me.
> 
> Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>

Thank you!

> 
> But I would say I noticed we are also using for_each_present_cpu() in
> amd-pstate with amd_pstate_change_mode_without_dvr_change().
> 
> Should that also get a similar change?

Good catch! Yes, that too needs to be fixed to for_each_online_cpu().

I will spin a v2 to include that patch and pick up your Reviewed-by
tag for the earlier ones, and also Chris's Tested-by tag for the first
two patches.

-- 
Thanks and Regards
gautham.



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

end of thread, other threads:[~2025-11-07  4:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-05 14:38 [PATCH 0/4] ACPI: CPPC: Fixes to limit actions to online CPUs Gautham R. Shenoy
2025-11-05 14:38 ` [PATCH 1/4] ACPI: CPPC: Detect preferred core availability on " Gautham R. Shenoy
2025-11-05 14:38 ` [PATCH 2/4] ACPI: CPPC: Check _CPC validity for only the " Gautham R. Shenoy
2025-11-05 14:38 ` [PATCH 3/4] ACPI: CPPC: Perform fast check switch only for " Gautham R. Shenoy
2025-11-05 14:38 ` [PATCH 4/4] ACPI: CPPC: Limit perf ctrs in PCC check only to " Gautham R. Shenoy
2025-11-05 16:00 ` [PATCH 0/4] ACPI: CPPC: Fixes to limit actions " Mario Limonciello (AMD) (kernel.org)
2025-11-07  4:42   ` Gautham R. Shenoy
2025-11-05 21:13 ` Chris H

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®