Skip to contentSkip to conversation

ACPI: PM: Avoid initializing power management for absent devices

PATCH In review Rafael J. Wysocki 3 participants 3 messages Nov 17 – Nov 18

Subsystems (2)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH v3 1/1 ACPI: PM: Avoid initializing power management for absent devices

From: "Rafael J. Wysocki" <[email protected]>

Commit 2f4ddf2bd1ba ("ACPI: scan: Stop calling acpi_bus_init_power() early") removed a device presence check from acpi_bus_init_power() which in some cases causes power management to be initialized for an ACPI device object and never used going forward. That in turn may prevent power management from working as expected for other devices.

Namely, if a given ACPI device object is not enabled according to its _STA, find_child_checks() will return an error for it which will prevent it from being used as an ACPI companion for a PCI device. Thus if acpi_device_init_power() initializes power management for it and its initial power state turns out to be different from D3cold, it may stay in that power state forever. If it has power resources and they are "on" during the initialization, they may be reference-counted and never turned off. If they are shared with other devices, they will prevent power from going down after attempting to put the other devices into low-power states.

To prevent that from happening, restore the device presence check in acpi_bus_init_power(), but also adjust find_child_checks() to return an error for absent devices (instead of doing that for disabled devices) in accordance with acpi_bus_init_power() and the existing check in acpi_bus_attach().

Fixes 2f4ddf2bd1ba ("ACPI: scan: Stop calling acpi_bus_init_power() early")

---

v2 -> v3:
* Also set power.state to ACPI_D_STATE_INVALID if the device is not present when acpi_bus_init_power() runs (Sashiko)

v1 -> v2:
* Clear power_manageable when returning an error early from acpi_bus_init_power() (Sashiko)
* Print debug message when that happens

Quick turnaround because it fixes a recent regression.

---
 drivers/acpi/device_pm.c |   15 +++++++++++++--
 drivers/acpi/glue.c      |    8 ++------
 2 files changed, 15 insertions(+), 8 deletions(-)
drivers/acpi/device_pm.c +13 -2
@@ -365,14 +365,25 @@ int acpi_bus_init_power(struct acpi_devi
 	 * fails, ACPI power management will not be used for the device going
 	 * forward.
 	 */
+	if (!acpi_device_is_present(device)) {
+		acpi_handle_debug(device->handle,
+				  "Device not present, ACPI PM disabled\n");
+		result = -ENXIO;
+		goto fail;
+	}
+
 	result = acpi_device_init_power(device);
 	if (result) {
-		device->flags.power_manageable = 0;
-		device->power.state = ACPI_D_STATE_INVALID;
 		acpi_handle_info(device->handle,
 				 "Initial power state undetermined, ACPI PM disabled\n");
+		goto fail;
 	}
 
+	return 0;
+
+fail:
+	device->flags.power_manageable = 0;
+	device->power.state = ACPI_D_STATE_INVALID;
 	return result;
 }
 
drivers/acpi/glue.c +2 -6
@@ -109,14 +109,10 @@ static bool acpi_dev_has_children(struct
 
 static int find_child_checks(struct acpi_device *adev, bool check_children)
 {
-	unsigned long long sta;
-	acpi_status status;
-
 	if (check_children && !acpi_dev_has_children(adev))
 		return -ENODEV;
 
-	status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
-	if (status == AE_NOT_FOUND) {
+	if (!acpi_has_method(adev->handle, METHOD_NAME__STA)) {
 		/*
 		 * Special case: backlight device objects without _STA are
 		 * preferred to other objects with the same _ADR value, because
@@ -128,7 +124,7 @@ static int find_child_checks(struct acpi
 		return FIND_CHILD_MIN_SCORE;
 	}
 
-	if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_ENABLED))
+	if (!acpi_device_is_present(adev))
 		return -ENODEV;
 
 	/*
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 25 lines

From: "Rafael J. Wysocki" <[email protected]>

Commit 2f4ddf2bd1ba ("ACPI: scan: Stop calling acpi_bus_init_power() early") removed a device presence check from acpi_bus_init_power() which in some cases causes power management to be initialized for an ACPI device object and never used going forward. That in turn may prevent power management from working as expected for other devices.

Namely, if a given ACPI device object is not enabled according to its _STA, find_child_checks() will return an error for it which will prevent it from being used as an ACPI companion for a PCI device. Thus if acpi_device_init_power() initializes power management for it and its initial power state turns out to be different from D3cold, it may stay in that power state forever. If it has power resources and they are "on" during the initialization, they may be reference-counted and never turned off. If they are shared with other devices, they will prevent power from going down after attempting to put the other devices into low-power states.

To prevent that from happening, restore the device presence check in acpi_bus_init_power(), but also adjust find_child_checks() to return an error for absent devices (instead of doing that for disabled devices) in accordance with acpi_bus_init_power() and the existing check in acpi_bus_attach().

Quoted 4 lines
Fixes 2f4ddf2bd1ba ("ACPI: scan: Stop calling acpi_bus_init_power() early")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Tested-by Reviewed-by on v3 1/1
#2 lore raw
In reply to Rafael J. Wysocki

Hi Rafael,

Quoted 25 lines · Rafael J. Wysocki

From: "Rafael J. Wysocki" <[email protected]>

Commit 2f4ddf2bd1ba ("ACPI: scan: Stop calling acpi_bus_init_power() early") removed a device presence check from acpi_bus_init_power() which in some cases causes power management to be initialized for an ACPI device object and never used going forward. That in turn may prevent power management from working as expected for other devices.

Namely, if a given ACPI device object is not enabled according to its _STA, find_child_checks() will return an error for it which will prevent it from being used as an ACPI companion for a PCI device. Thus if acpi_device_init_power() initializes power management for it and its initial power state turns out to be different from D3cold, it may stay in that power state forever. If it has power resources and they are "on" during the initialization, they may be reference-counted and never turned off. If they are shared with other devices, they will prevent power from going down after attempting to put the other devices into low-power states.

To prevent that from happening, restore the device presence check in acpi_bus_init_power(), but also adjust find_child_checks() to return an error for absent devices (instead of doing that for disabled devices) in accordance with acpi_bus_init_power() and the existing check in acpi_bus_attach().

Quoted 4 lines
Fixes 2f4ddf2bd1ba ("ACPI: scan: Stop calling acpi_bus_init_power() early")