mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches
@ 2025-12-23 10:09 Huisong Li
  2025-12-23 10:09 ` [PATCH v1 1/6] ACPI: processor: idle: Optimize ACPI idle driver registration Huisong Li
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Huisong Li @ 2025-12-23 10:09 UTC (permalink / raw)
  To: rafael, lenb, bp, AmandeepKaur.Longia
  Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
	zhenglifeng1, yubowen8, zhangpengjie2, wangzhi12, prime.zeng,
	lihuisong

This series of patches have been reverted due to the crash issue reported
by Borislav [1] and a missing cpuidle sysfs directory reported by Amandeep.

The root cause was commit 7a8c994cbb2d (ACPI: processor: idle: Optimize
ACPI idle driver registration).  Since the other patches in the series 
depended on this commit, they were also reverted.

I have analyzed these issues and implemented the following fixes:
Fix for the Crash:
The crash occurred because 'max_cstate' (which defaults to 8) was not
updated before the ACPI idle states were initialized.  As a result, the idle
driver believed multiple C-states were available, but only the state with
index 1 was actually initialized in the per-CPU acpi_cstate array.  When the
cpuidle governor tried to access a C-state index greater than 1, it hit a
NULL pointer.
Patch 1/6 fixes this by adding acpi_processor_cstate_first_run_checks() to
update 'max_cstate' before initialization.

Fix for missing /sys/devices/system/cpu/cpu*/cpuidle directory:
The previous optimization depended on an external patch [2].  In kernel versions
without that patch, acpi_processor_start() was being called before the ACPI idle
driver had finished registering.  This caused the cpuidle device registration
to fail, resulting in the missing directory.
Patch 1/6 fixes this by moving acpi_processor_register_idle_driver() ahead of 
the acpi_processor_driver registration.

Note:
In this series, only patch 1/6 has been modified to address these bugs, more
detail changes please see the commit.  Patches 2-6/6 remain identical to the
versions that were previously merged.

[1] https://lore.kernel.org/lkml/20251124200019.GIaSS5U9HhsWBotrQZ@fat_crate.local/
[2] https://lore.kernel.org/all/20240529133446.28446-2-Jonathan.Cameron@huawei.com/

Huisong Li (4):
  ACPI: processor: idle: Optimize ACPI idle driver registration
  ACPI: processor: Remove unused empty stubs of some functions
  ACPI: processor: idle: Rearrange declarations in header file
  ACPI: processor: Do not expose global variable acpi_idle_driver

Rafael J. Wysocki (2):
  ACPI: processor: Update cpuidle driver check in
    __acpi_processor_start()
  ACPI: processor: idle: Redefine two functions as void

 drivers/acpi/processor_driver.c |  13 +++-
 drivers/acpi/processor_idle.c   | 116 +++++++++++++++++++-------------
 include/acpi/processor.h        |  34 ++--------
 3 files changed, 86 insertions(+), 77 deletions(-)

-- 
2.33.0


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

* [PATCH v1 1/6] ACPI: processor: idle: Optimize ACPI idle driver registration
  2025-12-23 10:09 [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Huisong Li
@ 2025-12-23 10:09 ` Huisong Li
  2025-12-23 10:09 ` [PATCH v1 2/6] ACPI: processor: Remove unused empty stubs of some functions Huisong Li
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Huisong Li @ 2025-12-23 10:09 UTC (permalink / raw)
  To: rafael, lenb, bp, AmandeepKaur.Longia
  Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
	zhenglifeng1, yubowen8, zhangpengjie2, wangzhi12, prime.zeng,
	lihuisong

Currently, the ACPI idle driver is registered from within a CPU
hotplug callback. Although this didn't cause any functional issues,
this is questionable and confusing. And it is better to register
the cpuidle driver when all of the CPUs have been brought up.

So add a new function to initialize acpi_idle_driver based on the
power management information of an available CPU and register cpuidle
driver in acpi_processor_driver_init().

This commit has four changes under the commit 7a8c994cbb2d (ACPI:
processor: idle: Optimize ACPI idle driver registration):
1) move acpi_processor_register_idle_driver() ahead of the
   driver_register().
2) add acpi_processor_cstate_first_run_checks() before calling
   acpi_processor_get_power_info().
3) squash the commit 9d68320b2bca (ACPI: processor: idle: Fix
   function defined but not used warning) into this commit.
4) use for_each_possible_cpu(cpu) to scan all possible cpus.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Link: https://patch.msgid.link/20250728070612.1260859-3-lihuisong@huawei.com
[ rjw: Added missing inline modifiers ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/processor_driver.c | 10 ++++-
 drivers/acpi/processor_idle.c   | 66 +++++++++++++++++++++------------
 include/acpi/processor.h        |  2 +
 3 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 65e779be64ff..311863e00ffd 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -259,9 +259,11 @@ static int __init acpi_processor_driver_init(void)
 		acpi_processor_ignore_ppc_init();
 	}
 
+	acpi_processor_register_idle_driver();
+
 	result = driver_register(&acpi_processor_driver);
 	if (result < 0)
-		return result;
+		goto unregister_idle_drv;
 
 	result = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
 				   "acpi/cpu-drv:online",
@@ -283,8 +285,13 @@ static int __init acpi_processor_driver_init(void)
 	acpi_idle_rescan_dead_smt_siblings();
 
 	return 0;
+
 err:
 	driver_unregister(&acpi_processor_driver);
+
+unregister_idle_drv:
+	acpi_processor_unregister_idle_driver();
+
 	return result;
 }
 
@@ -302,6 +309,7 @@ static void __exit acpi_processor_driver_exit(void)
 	cpuhp_remove_state_nocalls(hp_online);
 	cpuhp_remove_state_nocalls(CPUHP_ACPI_CPUDRV_DEAD);
 	driver_unregister(&acpi_processor_driver);
+	acpi_processor_unregister_idle_driver();
 }
 
 module_init(acpi_processor_driver_init);
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 89f2f08b2554..ca7ae64def73 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -1347,7 +1347,49 @@ int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
 	return 0;
 }
 
-static int acpi_processor_registered;
+void acpi_processor_register_idle_driver(void)
+{
+	struct acpi_processor *pr;
+	int ret = -ENODEV;
+	int cpu;
+
+	/*
+	 * Acpi idle driver is used by all possible CPUs.
+	 * Install the idle handler by the processor power info of one in them.
+	 * Note that we use previously set idle handler will be used on
+	 * platforms that only support C1.
+	 */
+	for_each_possible_cpu(cpu) {
+		pr = per_cpu(processors, cpu);
+		if (!pr)
+			continue;
+
+		acpi_processor_cstate_first_run_checks();
+		ret = acpi_processor_get_power_info(pr);
+		if (!ret) {
+			pr->flags.power_setup_done = 1;
+			acpi_processor_setup_cpuidle_states(pr);
+			break;
+		}
+	}
+
+	if (ret) {
+		pr_debug("No ACPI power information from any CPUs.\n");
+		return;
+	}
+
+	ret = cpuidle_register_driver(&acpi_idle_driver);
+	if (ret) {
+		pr_debug("register %s failed.\n", acpi_idle_driver.name);
+		return;
+	}
+	pr_debug("%s registered with cpuidle.\n", acpi_idle_driver.name);
+}
+
+void acpi_processor_unregister_idle_driver(void)
+{
+	cpuidle_unregister_driver(&acpi_idle_driver);
+}
 
 int acpi_processor_power_init(struct acpi_processor *pr)
 {
@@ -1362,22 +1404,7 @@ int acpi_processor_power_init(struct acpi_processor *pr)
 	if (!acpi_processor_get_power_info(pr))
 		pr->flags.power_setup_done = 1;
 
-	/*
-	 * Install the idle handler if processor power management is supported.
-	 * Note that we use previously set idle handler will be used on
-	 * platforms that only support C1.
-	 */
 	if (pr->flags.power) {
-		/* Register acpi_idle_driver if not already registered */
-		if (!acpi_processor_registered) {
-			acpi_processor_setup_cpuidle_states(pr);
-			retval = cpuidle_register_driver(&acpi_idle_driver);
-			if (retval)
-				return retval;
-			pr_debug("%s registered with cpuidle\n",
-				 acpi_idle_driver.name);
-		}
-
 		dev = kzalloc(sizeof(*dev), GFP_KERNEL);
 		if (!dev)
 			return -ENOMEM;
@@ -1390,14 +1417,11 @@ int acpi_processor_power_init(struct acpi_processor *pr)
 		 */
 		retval = cpuidle_register_device(dev);
 		if (retval) {
-			if (acpi_processor_registered == 0)
-				cpuidle_unregister_driver(&acpi_idle_driver);
 
 			per_cpu(acpi_cpuidle_device, pr->id) = NULL;
 			kfree(dev);
 			return retval;
 		}
-		acpi_processor_registered++;
 	}
 	return 0;
 }
@@ -1411,10 +1435,6 @@ int acpi_processor_power_exit(struct acpi_processor *pr)
 
 	if (pr->flags.power) {
 		cpuidle_unregister_device(dev);
-		acpi_processor_registered--;
-		if (acpi_processor_registered == 0)
-			cpuidle_unregister_driver(&acpi_idle_driver);
-
 		kfree(dev);
 	}
 
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index d0eccbd920e5..ff864c1cee3a 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -423,6 +423,8 @@ int acpi_processor_power_init(struct acpi_processor *pr);
 int acpi_processor_power_exit(struct acpi_processor *pr);
 int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
 int acpi_processor_hotplug(struct acpi_processor *pr);
+void acpi_processor_register_idle_driver(void);
+void acpi_processor_unregister_idle_driver(void);
 #else
 static inline int acpi_processor_power_init(struct acpi_processor *pr)
 {
-- 
2.33.0


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

* [PATCH v1 2/6] ACPI: processor: Remove unused empty stubs of some functions
  2025-12-23 10:09 [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Huisong Li
  2025-12-23 10:09 ` [PATCH v1 1/6] ACPI: processor: idle: Optimize ACPI idle driver registration Huisong Li
@ 2025-12-23 10:09 ` Huisong Li
  2025-12-23 10:09 ` [PATCH v1 3/6] ACPI: processor: Update cpuidle driver check in __acpi_processor_start() Huisong Li
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Huisong Li @ 2025-12-23 10:09 UTC (permalink / raw)
  To: rafael, lenb, bp, AmandeepKaur.Longia
  Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
	zhenglifeng1, yubowen8, zhangpengjie2, wangzhi12, prime.zeng,
	lihuisong

Empty stubs are defined in processor.h for some functions provided by
the ACPI processor idle driver, but those functions are only used in
the main ACPI processor driver which requires the ACPI processor idle
driver to be present (selecting CONFIG_ACPI_PROCESSOR causes
CONFIG_ACPI_PROCESSOR_IDLE to be selected too automatically).

This means that the empty stubs in question are not really necessary and
if both CONFIG_ACPI_PROCESSOR and CONFIG_ACPI_PROCESSOR_IDLE are unset,
the compiler complains that they are defined, but not used.  Drop them
to get rid of the compiler warning.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Link: https://patch.msgid.link/20250911112408.1668431-2-lihuisong@huawei.com
[ rjw: Subject and changelog rewrite ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 include/acpi/processor.h | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index ff864c1cee3a..2976a6d0c54f 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -425,26 +425,6 @@ int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
 int acpi_processor_hotplug(struct acpi_processor *pr);
 void acpi_processor_register_idle_driver(void);
 void acpi_processor_unregister_idle_driver(void);
-#else
-static inline int acpi_processor_power_init(struct acpi_processor *pr)
-{
-	return -ENODEV;
-}
-
-static inline int acpi_processor_power_exit(struct acpi_processor *pr)
-{
-	return -ENODEV;
-}
-
-static inline int acpi_processor_power_state_has_changed(struct acpi_processor *pr)
-{
-	return -ENODEV;
-}
-
-static inline int acpi_processor_hotplug(struct acpi_processor *pr)
-{
-	return -ENODEV;
-}
 #endif /* CONFIG_ACPI_PROCESSOR_IDLE */
 
 /* in processor_thermal.c */
-- 
2.33.0


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

* [PATCH v1 3/6] ACPI: processor: Update cpuidle driver check in __acpi_processor_start()
  2025-12-23 10:09 [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Huisong Li
  2025-12-23 10:09 ` [PATCH v1 1/6] ACPI: processor: idle: Optimize ACPI idle driver registration Huisong Li
  2025-12-23 10:09 ` [PATCH v1 2/6] ACPI: processor: Remove unused empty stubs of some functions Huisong Li
@ 2025-12-23 10:09 ` Huisong Li
  2025-12-23 10:09 ` [PATCH v1 4/6] ACPI: processor: idle: Redefine two functions as void Huisong Li
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Huisong Li @ 2025-12-23 10:09 UTC (permalink / raw)
  To: rafael, lenb, bp, AmandeepKaur.Longia
  Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
	zhenglifeng1, yubowen8, zhangpengjie2, wangzhi12, prime.zeng,
	lihuisong

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

Commit 7a8c994cbb2d ("ACPI: processor: idle: Optimize ACPI idle
driver registration") moved the ACPI idle driver registration to
acpi_processor_driver_init() and acpi_processor_power_init() does
not register an idle driver any more.

Accordingly, the cpuidle driver check in __acpi_processor_start() needs
to be updated to avoid calling acpi_processor_power_init() without a
cpuidle driver, in which case the registration of the cpuidle device
in that function would lead to a NULL pointer dereference in
__cpuidle_register_device().

Fixes: 7a8c994cbb2d ("ACPI: processor: idle: Optimize ACPI idle driver registration")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
Link: https://patch.msgid.link/5044465.31r3eYUQgx@rafael.j.wysocki
[ rjw: Changelog update ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/processor_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 311863e00ffd..f5b4f6a29143 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -166,7 +166,7 @@ static int __acpi_processor_start(struct acpi_device *device)
 	if (result && !IS_ENABLED(CONFIG_ACPI_CPU_FREQ_PSS))
 		dev_dbg(&device->dev, "CPPC data invalid or not present\n");
 
-	if (!cpuidle_get_driver() || cpuidle_get_driver() == &acpi_idle_driver)
+	if (cpuidle_get_driver() == &acpi_idle_driver)
 		acpi_processor_power_init(pr);
 
 	acpi_pss_perf_init(pr);
-- 
2.33.0


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

* [PATCH v1 4/6] ACPI: processor: idle: Redefine two functions as void
  2025-12-23 10:09 [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Huisong Li
                   ` (2 preceding siblings ...)
  2025-12-23 10:09 ` [PATCH v1 3/6] ACPI: processor: Update cpuidle driver check in __acpi_processor_start() Huisong Li
@ 2025-12-23 10:09 ` Huisong Li
  2025-12-23 10:09 ` [PATCH v1 5/6] ACPI: processor: idle: Rearrange declarations in header file Huisong Li
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Huisong Li @ 2025-12-23 10:09 UTC (permalink / raw)
  To: rafael, lenb, bp, AmandeepKaur.Longia
  Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
	zhenglifeng1, yubowen8, zhangpengjie2, wangzhi12, prime.zeng,
	lihuisong

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

Notice that acpi_processor_power_init() and acpi_processor_power_exit()
don't need to return any values because their callers don't check them
anyway, so redefine those functions as void.

While at it, rearrange the code in acpi_processor_power_init() to
reduce the indentation level, get rid of a redundant local variable
in that function, and rephrase a code comment in it.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
 drivers/acpi/processor_idle.c | 41 ++++++++++++++++-------------------
 include/acpi/processor.h      |  4 ++--
 2 files changed, 21 insertions(+), 24 deletions(-)

diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index ca7ae64def73..05425d1b3ef7 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -1391,47 +1391,45 @@ void acpi_processor_unregister_idle_driver(void)
 	cpuidle_unregister_driver(&acpi_idle_driver);
 }
 
-int acpi_processor_power_init(struct acpi_processor *pr)
+void acpi_processor_power_init(struct acpi_processor *pr)
 {
-	int retval;
 	struct cpuidle_device *dev;
 
 	if (disabled_by_idle_boot_param())
-		return 0;
+		return;
 
 	acpi_processor_cstate_first_run_checks();
 
 	if (!acpi_processor_get_power_info(pr))
 		pr->flags.power_setup_done = 1;
 
-	if (pr->flags.power) {
-		dev = kzalloc(sizeof(*dev), GFP_KERNEL);
-		if (!dev)
-			return -ENOMEM;
-		per_cpu(acpi_cpuidle_device, pr->id) = dev;
+	if (!pr->flags.power)
+		return;
 
-		acpi_processor_setup_cpuidle_dev(pr, dev);
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return;
 
-		/* Register per-cpu cpuidle_device. Cpuidle driver
-		 * must already be registered before registering device
-		 */
-		retval = cpuidle_register_device(dev);
-		if (retval) {
+	per_cpu(acpi_cpuidle_device, pr->id) = dev;
 
-			per_cpu(acpi_cpuidle_device, pr->id) = NULL;
-			kfree(dev);
-			return retval;
-		}
+	acpi_processor_setup_cpuidle_dev(pr, dev);
+
+	/*
+	 * Register a cpuidle device for this CPU.  The cpuidle driver using
+	 * this device is expected to be registered.
+	 */
+	if (cpuidle_register_device(dev)) {
+		per_cpu(acpi_cpuidle_device, pr->id) = NULL;
+		kfree(dev);
 	}
-	return 0;
 }
 
-int acpi_processor_power_exit(struct acpi_processor *pr)
+void acpi_processor_power_exit(struct acpi_processor *pr)
 {
 	struct cpuidle_device *dev = per_cpu(acpi_cpuidle_device, pr->id);
 
 	if (disabled_by_idle_boot_param())
-		return 0;
+		return;
 
 	if (pr->flags.power) {
 		cpuidle_unregister_device(dev);
@@ -1439,7 +1437,6 @@ int acpi_processor_power_exit(struct acpi_processor *pr)
 	}
 
 	pr->flags.power_setup_done = 0;
-	return 0;
 }
 
 MODULE_IMPORT_NS("ACPI_PROCESSOR_IDLE");
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 2976a6d0c54f..0200aef6e754 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -419,8 +419,8 @@ static inline void acpi_processor_throttling_init(void) {}
 /* in processor_idle.c */
 extern struct cpuidle_driver acpi_idle_driver;
 #ifdef CONFIG_ACPI_PROCESSOR_IDLE
-int acpi_processor_power_init(struct acpi_processor *pr);
-int acpi_processor_power_exit(struct acpi_processor *pr);
+void acpi_processor_power_init(struct acpi_processor *pr);
+void acpi_processor_power_exit(struct acpi_processor *pr);
 int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
 int acpi_processor_hotplug(struct acpi_processor *pr);
 void acpi_processor_register_idle_driver(void);
-- 
2.33.0


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

* [PATCH v1 5/6] ACPI: processor: idle: Rearrange declarations in header file
  2025-12-23 10:09 [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Huisong Li
                   ` (3 preceding siblings ...)
  2025-12-23 10:09 ` [PATCH v1 4/6] ACPI: processor: idle: Redefine two functions as void Huisong Li
@ 2025-12-23 10:09 ` Huisong Li
  2025-12-23 10:09 ` [PATCH v1 6/6] ACPI: processor: Do not expose global variable acpi_idle_driver Huisong Li
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 12+ messages in thread
From: Huisong Li @ 2025-12-23 10:09 UTC (permalink / raw)
  To: rafael, lenb, bp, AmandeepKaur.Longia
  Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
	zhenglifeng1, yubowen8, zhangpengjie2, wangzhi12, prime.zeng,
	lihuisong

Group all of the declarations of functions that belong to the ACPI
processor idle driver together in one place in processor.h.

While at it, drop the unnecessary extern modifier from the declaraions
of two functions.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Link: https://patch.msgid.link/20250911112408.1668431-3-lihuisong@huawei.com
[ rjw: Subject and changelog rewrite ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 include/acpi/processor.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 0200aef6e754..24fdaa3c2899 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -425,6 +425,8 @@ int acpi_processor_power_state_has_changed(struct acpi_processor *pr);
 int acpi_processor_hotplug(struct acpi_processor *pr);
 void acpi_processor_register_idle_driver(void);
 void acpi_processor_unregister_idle_driver(void);
+int acpi_processor_ffh_lpi_probe(unsigned int cpu);
+int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi);
 #endif /* CONFIG_ACPI_PROCESSOR_IDLE */
 
 /* in processor_thermal.c */
@@ -447,11 +449,6 @@ static inline void acpi_thermal_cpufreq_exit(struct cpufreq_policy *policy)
 }
 #endif	/* CONFIG_CPU_FREQ */
 
-#ifdef CONFIG_ACPI_PROCESSOR_IDLE
-extern int acpi_processor_ffh_lpi_probe(unsigned int cpu);
-extern int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi);
-#endif
-
 void acpi_processor_init_invariance_cppc(void);
 
 #endif
-- 
2.33.0


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

* [PATCH v1 6/6] ACPI: processor: Do not expose global variable acpi_idle_driver
  2025-12-23 10:09 [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Huisong Li
                   ` (4 preceding siblings ...)
  2025-12-23 10:09 ` [PATCH v1 5/6] ACPI: processor: idle: Rearrange declarations in header file Huisong Li
@ 2025-12-23 10:09 ` Huisong Li
  2025-12-24  2:05 ` [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Borislav Petkov
  2026-01-07 10:21 ` lihuisong (C)
  7 siblings, 0 replies; 12+ messages in thread
From: Huisong Li @ 2025-12-23 10:09 UTC (permalink / raw)
  To: rafael, lenb, bp, AmandeepKaur.Longia
  Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
	zhenglifeng1, yubowen8, zhangpengjie2, wangzhi12, prime.zeng,
	lihuisong

Move the cpuidle driver check from __acpi_processor_start() to
acpi_processor_power_init() which allows variable acpi_idle_driver to
become static.

No intentional functional impact.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Link: https://patch.msgid.link/20250923032428.2656329-2-lihuisong@huawei.com
[ rjw: Subject tweak, new changelog, adjustment of a new comment ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/processor_driver.c | 3 +--
 drivers/acpi/processor_idle.c   | 9 ++++++++-
 include/acpi/processor.h        | 1 -
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index f5b4f6a29143..882709796b4f 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -166,8 +166,7 @@ static int __acpi_processor_start(struct acpi_device *device)
 	if (result && !IS_ENABLED(CONFIG_ACPI_CPU_FREQ_PSS))
 		dev_dbg(&device->dev, "CPPC data invalid or not present\n");
 
-	if (cpuidle_get_driver() == &acpi_idle_driver)
-		acpi_processor_power_init(pr);
+	acpi_processor_power_init(pr);
 
 	acpi_pss_perf_init(pr);
 
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 05425d1b3ef7..427423e7a0c7 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -51,7 +51,7 @@ module_param(latency_factor, uint, 0644);
 
 static DEFINE_PER_CPU(struct cpuidle_device *, acpi_cpuidle_device);
 
-struct cpuidle_driver acpi_idle_driver = {
+static struct cpuidle_driver acpi_idle_driver = {
 	.name =		"acpi_idle",
 	.owner =	THIS_MODULE,
 };
@@ -1395,6 +1395,13 @@ void acpi_processor_power_init(struct acpi_processor *pr)
 {
 	struct cpuidle_device *dev;
 
+	/*
+	 * The code below only works if the current cpuidle driver is the ACPI
+	 * idle driver.
+	 */
+	if (cpuidle_get_driver() != &acpi_idle_driver)
+		return;
+
 	if (disabled_by_idle_boot_param())
 		return;
 
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 24fdaa3c2899..7146a8e9e9c2 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -417,7 +417,6 @@ static inline void acpi_processor_throttling_init(void) {}
 #endif	/* CONFIG_ACPI_CPU_FREQ_PSS */
 
 /* in processor_idle.c */
-extern struct cpuidle_driver acpi_idle_driver;
 #ifdef CONFIG_ACPI_PROCESSOR_IDLE
 void acpi_processor_power_init(struct acpi_processor *pr);
 void acpi_processor_power_exit(struct acpi_processor *pr);
-- 
2.33.0


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

* Re: [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches
  2025-12-23 10:09 [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Huisong Li
                   ` (5 preceding siblings ...)
  2025-12-23 10:09 ` [PATCH v1 6/6] ACPI: processor: Do not expose global variable acpi_idle_driver Huisong Li
@ 2025-12-24  2:05 ` Borislav Petkov
  2026-01-02 10:18   ` Borislav Petkov
  2026-01-07 10:21 ` lihuisong (C)
  7 siblings, 1 reply; 12+ messages in thread
From: Borislav Petkov @ 2025-12-24  2:05 UTC (permalink / raw)
  To: Huisong Li
  Cc: rafael, lenb, AmandeepKaur.Longia, linux-acpi, linux-kernel,
	linuxarm, jonathan.cameron, zhanjie9, zhenglifeng1, yubowen8,
	zhangpengjie2, wangzhi12, prime.zeng

On Tue, Dec 23, 2025 at 06:09:08PM +0800, Huisong Li wrote:
> Huisong Li (4):
>   ACPI: processor: idle: Optimize ACPI idle driver registration
>   ACPI: processor: Remove unused empty stubs of some functions
>   ACPI: processor: idle: Rearrange declarations in header file
>   ACPI: processor: Do not expose global variable acpi_idle_driver
> 
> Rafael J. Wysocki (2):
>   ACPI: processor: Update cpuidle driver check in
>     __acpi_processor_start()
>   ACPI: processor: idle: Redefine two functions as void
> 
>  drivers/acpi/processor_driver.c |  13 +++-
>  drivers/acpi/processor_idle.c   | 116 +++++++++++++++++++-------------
>  include/acpi/processor.h        |  34 ++--------
>  3 files changed, 86 insertions(+), 77 deletions(-)

I'll run them on the affected machine once I get to it.

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

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

* Re: [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches
  2025-12-24  2:05 ` [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Borislav Petkov
@ 2026-01-02 10:18   ` Borislav Petkov
  2026-01-04  9:57     ` lihuisong (C)
  2026-01-09 21:40     ` Rafael J. Wysocki
  0 siblings, 2 replies; 12+ messages in thread
From: Borislav Petkov @ 2026-01-02 10:18 UTC (permalink / raw)
  To: Huisong Li
  Cc: rafael, lenb, AmandeepKaur.Longia, linux-acpi, linux-kernel,
	linuxarm, jonathan.cameron, zhanjie9, zhenglifeng1, yubowen8,
	zhangpengjie2, wangzhi12, prime.zeng

On Wed, Dec 24, 2025 at 03:05:32AM +0100, Borislav Petkov wrote:
> On Tue, Dec 23, 2025 at 06:09:08PM +0800, Huisong Li wrote:
> > Huisong Li (4):
> >   ACPI: processor: idle: Optimize ACPI idle driver registration
> >   ACPI: processor: Remove unused empty stubs of some functions
> >   ACPI: processor: idle: Rearrange declarations in header file
> >   ACPI: processor: Do not expose global variable acpi_idle_driver
> > 
> > Rafael J. Wysocki (2):
> >   ACPI: processor: Update cpuidle driver check in
> >     __acpi_processor_start()
> >   ACPI: processor: idle: Redefine two functions as void
> > 
> >  drivers/acpi/processor_driver.c |  13 +++-
> >  drivers/acpi/processor_idle.c   | 116 +++++++++++++++++++-------------
> >  include/acpi/processor.h        |  34 ++--------
> >  3 files changed, 86 insertions(+), 77 deletions(-)
> 
> I'll run them on the affected machine once I get to it.

Looks good.

Tested-by: Borislav Petkov (AMD) <bp@alien8.de>

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

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

* Re: [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches
  2026-01-02 10:18   ` Borislav Petkov
@ 2026-01-04  9:57     ` lihuisong (C)
  2026-01-09 21:40     ` Rafael J. Wysocki
  1 sibling, 0 replies; 12+ messages in thread
From: lihuisong (C) @ 2026-01-04  9:57 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: rafael, lenb, AmandeepKaur.Longia, linux-acpi, linux-kernel,
	linuxarm, jonathan.cameron, zhanjie9, zhenglifeng1, yubowen8,
	zhangpengjie2, wangzhi12, prime.zeng


在 2026/1/2 18:18, Borislav Petkov 写道:
> On Wed, Dec 24, 2025 at 03:05:32AM +0100, Borislav Petkov wrote:
>> On Tue, Dec 23, 2025 at 06:09:08PM +0800, Huisong Li wrote:
>>> Huisong Li (4):
>>>    ACPI: processor: idle: Optimize ACPI idle driver registration
>>>    ACPI: processor: Remove unused empty stubs of some functions
>>>    ACPI: processor: idle: Rearrange declarations in header file
>>>    ACPI: processor: Do not expose global variable acpi_idle_driver
>>>
>>> Rafael J. Wysocki (2):
>>>    ACPI: processor: Update cpuidle driver check in
>>>      __acpi_processor_start()
>>>    ACPI: processor: idle: Redefine two functions as void
>>>
>>>   drivers/acpi/processor_driver.c |  13 +++-
>>>   drivers/acpi/processor_idle.c   | 116 +++++++++++++++++++-------------
>>>   include/acpi/processor.h        |  34 ++--------
>>>   3 files changed, 86 insertions(+), 77 deletions(-)
>> I'll run them on the affected machine once I get to it.
> Looks good.
>
> Tested-by: Borislav Petkov (AMD) <bp@alien8.de>
>
Apologize for the crash issue on your platform.
Thank you very much for your test, Borisla.

/Huisong
>

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

* Re: [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches
  2025-12-23 10:09 [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Huisong Li
                   ` (6 preceding siblings ...)
  2025-12-24  2:05 ` [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Borislav Petkov
@ 2026-01-07 10:21 ` lihuisong (C)
  7 siblings, 0 replies; 12+ messages in thread
From: lihuisong (C) @ 2026-01-07 10:21 UTC (permalink / raw)
  To: AmandeepKaur.Longia
  Cc: linux-acpi, linux-kernel, linuxarm, jonathan.cameron, zhanjie9,
	zhenglifeng1, yubowen8, zhangpengjie2, wangzhi12, prime.zeng,
	lenb, bp, rafael

Hi Amandeep,

Could you help test this series on your platform?
It would be perfect if has your Tested-by.

/Huisong

在 2025/12/23 18:09, Huisong Li 写道:
> This series of patches have been reverted due to the crash issue reported
> by Borislav [1] and a missing cpuidle sysfs directory reported by Amandeep.
>
> The root cause was commit 7a8c994cbb2d (ACPI: processor: idle: Optimize
> ACPI idle driver registration).  Since the other patches in the series
> depended on this commit, they were also reverted.
>
> I have analyzed these issues and implemented the following fixes:
> Fix for the Crash:
> The crash occurred because 'max_cstate' (which defaults to 8) was not
> updated before the ACPI idle states were initialized.  As a result, the idle
> driver believed multiple C-states were available, but only the state with
> index 1 was actually initialized in the per-CPU acpi_cstate array.  When the
> cpuidle governor tried to access a C-state index greater than 1, it hit a
> NULL pointer.
> Patch 1/6 fixes this by adding acpi_processor_cstate_first_run_checks() to
> update 'max_cstate' before initialization.
>
> Fix for missing /sys/devices/system/cpu/cpu*/cpuidle directory:
> The previous optimization depended on an external patch [2].  In kernel versions
> without that patch, acpi_processor_start() was being called before the ACPI idle
> driver had finished registering.  This caused the cpuidle device registration
> to fail, resulting in the missing directory.
> Patch 1/6 fixes this by moving acpi_processor_register_idle_driver() ahead of
> the acpi_processor_driver registration.
>
> Note:
> In this series, only patch 1/6 has been modified to address these bugs, more
> detail changes please see the commit.  Patches 2-6/6 remain identical to the
> versions that were previously merged.
>
> [1] https://lore.kernel.org/lkml/20251124200019.GIaSS5U9HhsWBotrQZ@fat_crate.local/
> [2] https://lore.kernel.org/all/20240529133446.28446-2-Jonathan.Cameron@huawei.com/
>
> Huisong Li (4):
>    ACPI: processor: idle: Optimize ACPI idle driver registration
>    ACPI: processor: Remove unused empty stubs of some functions
>    ACPI: processor: idle: Rearrange declarations in header file
>    ACPI: processor: Do not expose global variable acpi_idle_driver
>
> Rafael J. Wysocki (2):
>    ACPI: processor: Update cpuidle driver check in
>      __acpi_processor_start()
>    ACPI: processor: idle: Redefine two functions as void
>
>   drivers/acpi/processor_driver.c |  13 +++-
>   drivers/acpi/processor_idle.c   | 116 +++++++++++++++++++-------------
>   include/acpi/processor.h        |  34 ++--------
>   3 files changed, 86 insertions(+), 77 deletions(-)
>

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

* Re: [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches
  2026-01-02 10:18   ` Borislav Petkov
  2026-01-04  9:57     ` lihuisong (C)
@ 2026-01-09 21:40     ` Rafael J. Wysocki
  1 sibling, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2026-01-09 21:40 UTC (permalink / raw)
  To: Borislav Petkov, Huisong Li
  Cc: AmandeepKaur.Longia, linux-acpi, linux-kernel, linuxarm,
	jonathan.cameron, zhanjie9, zhenglifeng1, yubowen8,
	zhangpengjie2, wangzhi12, prime.zeng

On Fri, Jan 2, 2026 at 11:18 AM Borislav Petkov <bp@alien8.de> wrote:
>
> On Wed, Dec 24, 2025 at 03:05:32AM +0100, Borislav Petkov wrote:
> > On Tue, Dec 23, 2025 at 06:09:08PM +0800, Huisong Li wrote:
> > > Huisong Li (4):
> > >   ACPI: processor: idle: Optimize ACPI idle driver registration
> > >   ACPI: processor: Remove unused empty stubs of some functions
> > >   ACPI: processor: idle: Rearrange declarations in header file
> > >   ACPI: processor: Do not expose global variable acpi_idle_driver
> > >
> > > Rafael J. Wysocki (2):
> > >   ACPI: processor: Update cpuidle driver check in
> > >     __acpi_processor_start()
> > >   ACPI: processor: idle: Redefine two functions as void
> > >
> > >  drivers/acpi/processor_driver.c |  13 +++-
> > >  drivers/acpi/processor_idle.c   | 116 +++++++++++++++++++-------------
> > >  include/acpi/processor.h        |  34 ++--------
> > >  3 files changed, 86 insertions(+), 77 deletions(-)
> >
> > I'll run them on the affected machine once I get to it.
>
> Looks good.
>
> Tested-by: Borislav Petkov (AMD) <bp@alien8.de>

Applied as 6.20 material, thanks!

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

end of thread, other threads:[~2026-01-09 21:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-23 10:09 [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Huisong Li
2025-12-23 10:09 ` [PATCH v1 1/6] ACPI: processor: idle: Optimize ACPI idle driver registration Huisong Li
2025-12-23 10:09 ` [PATCH v1 2/6] ACPI: processor: Remove unused empty stubs of some functions Huisong Li
2025-12-23 10:09 ` [PATCH v1 3/6] ACPI: processor: Update cpuidle driver check in __acpi_processor_start() Huisong Li
2025-12-23 10:09 ` [PATCH v1 4/6] ACPI: processor: idle: Redefine two functions as void Huisong Li
2025-12-23 10:09 ` [PATCH v1 5/6] ACPI: processor: idle: Rearrange declarations in header file Huisong Li
2025-12-23 10:09 ` [PATCH v1 6/6] ACPI: processor: Do not expose global variable acpi_idle_driver Huisong Li
2025-12-24  2:05 ` [PATCH v1 0/6] ACPI: processor: Recovery some reverted patches Borislav Petkov
2026-01-02 10:18   ` Borislav Petkov
2026-01-04  9:57     ` lihuisong (C)
2026-01-09 21:40     ` Rafael J. Wysocki
2026-01-07 10:21 ` lihuisong (C)

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®