ACPI: PM: Avoid initializing power management for absent devices
Rafael J. Wysocki
maintainerPATCH 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().
--- drivers/acpi/device_pm.c | 3 +++ drivers/acpi/glue.c | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-)
drivers/acpi/device_pm.c +3 -0
@@ -360,6 +360,9 @@ int acpi_bus_init_power(struct acpi_deviif (device->power.state !=ACPI_STATE_UNKNOWN )return 0 ; +if (!acpi_device_is_present (device)) +return -ENXIO ; +/* * The ACPI device power state can be only initialized once. If this * fails, ACPI power management will not be used for the device going
drivers/acpi/glue.c +2 -6
@@ -109,14 +109,10 @@ static bool acpi_dev_has_children(structstatic 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 acpireturn FIND_CHILD_MIN_SCORE ; } -if (ACPI_FAILURE (status) || !(sta &ACPI_STA_DEVICE_ENABLED )) +if (!acpi_device_is_present (adev))return -ENODEV ;/*
Quoted 30 lines · Rafael J. Wysocki
From: "Rafael J. Wysocki" <[email protected]>
Commit
2f4ddf2bd1ba("ACPI: scan: Stop callingacpi_bus_init_power()early") removed a device presence check fromacpi_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 ifacpi_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 adjustfind_child_checks()to return an error for absent devices (instead of doing that for disabled devices)
in accordance withacpi_bus_init_power()and the existing check inacpi_bus_attach().
Quoted 5 lines
Fixes 2f4ddf2bd1ba ("ACPI: scan: Stop calling acpi_bus_init_power()early")
Reported-by Alan Borzeszkowski <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>---
Quoted 52 lines
drivers/acpi/device_pm.c | 3 +++
drivers/acpi/glue.c | 8 ++------2 files changed, 5 insertions(+), 6 deletions(-)drivers/acpi/device_pm.c +0
-0@@ -360,6 +360,9 @@ int acpi_bus_init_power(struct acpi_devi if (device->power.state != ACPI_STATE_UNKNOWN) return 0;drivers/acpi/device_pm.c +3
-0+if (!acpi_device_is_present (device)) +return -ENXIO ; +/*
* The ACPI device power state can be only initialized once. If this
* fails, ACPI power management will not be used for the device goingdrivers/acpi/glue.c +0
-0@@ -109,14 +109,10 @@ static bool acpi_dev_has_children(struct
static intfind_child_checks(struct acpi_device *adev, bool check_children)
{drivers/acpi/glue.c +0
-3-unsigned long long sta; -acpi_status status; -if (
check_children&& !acpi_dev_has_children(adev)) return-ENODEV;drivers/acpi/glue.c +0
-1- status = acpi_evaluate_integer(adev->handle, "_STA", NULL,&sta);
drivers/acpi/glue.c +1
-1-if (status ==AE_NOT_FOUND ) { +if (!acpi_has_method (adev->handle,METHOD_NAME__STA )) {/*
* Special case: backlight device objects without_STAare
* preferred to other objects with the same_ADRvalue, becausedrivers/acpi/glue.c +0
-0@@ -128,7 +124,7 @@ static int find_child_checks(struct acpi return FIND_CHILD_MIN_SCORE; }drivers/acpi/glue.c +0
-1- if (ACPI_FAILURE(status) || !(sta &
ACPI_STA_DEVICE_ENABLED))drivers/acpi/glue.c +1
-0+if (!acpi_device_is_present (adev))return
-ENODEV;
/*
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] ACPI: PM: acpi_bus_init_power() leaves absent devices power_manageable in unknown state --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] ACPI: PM: acpi_bus_init_power() leaves absent devices power_manageable in unknown state
--
commit e1ff9e3263028781a317610ed251f6f169a95bfb
Author: Rafael J. Wysocki <[email protected]>
ACPI: PM: Avoid initializing power management for absent devices
This commit restores the device presence check in acpi_bus_init_power() and updates find_child_checks() to reject absent devices rather than disabled ones.
Quoted 5 lines
drivers/acpi/device_pm.c +0
-0
drivers/acpi/device_pm.c int acpi_bus_init_power(struct acpi_device *device) · line 368
Quoted 9 lines
drivers/acpi/device_pm.c +3
-0@@ -360,6 +360,9 @@ int acpi_bus_init_power(struct acpi_device *device)if (device->power.state !=ACPI_STATE_UNKNOWN )return 0 ; +if (!acpi_device_is_present (device)) +return -ENXIO ; +/* * The ACPI device power state can be only initialized once. If this * fails, ACPI power management will not be used for the device going
[Severity: High]
Does returning -ENXIO early here leave device->flags.power_manageable set to 1 with device->power.state stuck at ACPI_STATE_UNKNOWN (0xff)?
acpi_bus_get_power_flags() sets power_manageable = 1 and power.state = ACPI_STATE_UNKNOWN for any device with _PS0 or _PR0, and 2f4ddf2bd1ba ("ACPI: scan: Stop calling acpi_bus_init_power() early") stopped clearing power_manageable when acpi_bus_attach() skips a non-present device.
When a physical PCI device is bound to a single matching _ADR companion whose _STA reports not present (via check_one_child(), which bypasses find_child_checks()), acpi_bus_attach() logs FW_BUG and falls through to acpi_bus_init_power() without updating device->status:
drivers/acpi/scan.c:acpi_bus_attach() {
...
pci = acpi_dev_get_pci_dev(device);
if (pci) {
if (!acpi_device_is_present(device))
pci_info(pci, FW_BUG "ACPI status differs from reality\n");
pci_dev_put(pci);
} else if (!acpi_dev_ready_for_enumeration(device)) {
...
acpi_bus_init_power(device);
}With this early return, acpi_bus_init_power() fails without taking D0 power resource references or clearing power_manageable. Because acpi_pci_power_manageable() and acpi_bus_power_manageable() still see power_manageable == 1, subsequent power transitions on the PCI companion (or on absent _ADR-bound SATA/USB devices) call acpi_device_set_power(), which fails with -ENODEV because state < device->power.state (0xff) is always true.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1