* [PATCH v1] ACPI: scan: Avoid enumerating devices with clearly invalid _STA values
@ 2024-04-26 16:56 Rafael J. Wysocki
2024-04-28 4:17 ` Zhang, Rui
2024-04-29 8:29 ` Jonathan Cameron
0 siblings, 2 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-04-26 16:56 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Salil Mehta, Jonathan Cameron
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
The return value of _STA with the "present" bit unset and the "enabled"
bit set is clearly invalid as per the ACPI specification, Section 6.3.7
"_STA (Device Status)", so make the ACPI device enumeration code
disregard devices with such _STA return values.
Also, because this implies that status.enabled will only be set if
status.present is set too, acpi_device_is_enabled() can be modified
to simply return the value of the former.
Link: https://uefi.org/specs/ACPI/6.5/06_Device_Configuration.html#sta-device-status
Link: https://lore.kernel.org/linux-acpi/88179311a503493099028c12ca37d430@huawei.com/
Suggested-by: Salil Mehta <salil.mehta@huawei.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/bus.c | 11 +++++++++++
drivers/acpi/scan.c | 2 +-
2 files changed, 12 insertions(+), 1 deletion(-)
Index: linux-pm/drivers/acpi/bus.c
===================================================================
--- linux-pm.orig/drivers/acpi/bus.c
+++ linux-pm/drivers/acpi/bus.c
@@ -112,6 +112,17 @@ int acpi_bus_get_status(struct acpi_devi
if (ACPI_FAILURE(status))
return -ENODEV;
+ if (!device->status.present && device->status.enabled) {
+ pr_info(FW_BUG "Device [%s] status [%08x]: not present and enabled\n",
+ device->pnp.bus_id, (u32)sta);
+ device->status.enabled = 0;
+ /*
+ * The status is clearly invalid, so clear the enabled bit as
+ * well to avoid attempting to use the device.
+ */
+ device->status.functional = 0;
+ }
+
acpi_set_device_status(device, sta);
if (device->status.functional && !device->status.present) {
Index: linux-pm/drivers/acpi/scan.c
===================================================================
--- linux-pm.orig/drivers/acpi/scan.c
+++ linux-pm/drivers/acpi/scan.c
@@ -1962,7 +1962,7 @@ bool acpi_device_is_present(const struct
bool acpi_device_is_enabled(const struct acpi_device *adev)
{
- return adev->status.present && adev->status.enabled;
+ return adev->status.enabled;
}
static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] ACPI: scan: Avoid enumerating devices with clearly invalid _STA values
2024-04-26 16:56 [PATCH v1] ACPI: scan: Avoid enumerating devices with clearly invalid _STA values Rafael J. Wysocki
@ 2024-04-28 4:17 ` Zhang, Rui
2024-04-29 16:06 ` Rafael J. Wysocki
2024-04-29 8:29 ` Jonathan Cameron
1 sibling, 1 reply; 5+ messages in thread
From: Zhang, Rui @ 2024-04-28 4:17 UTC (permalink / raw)
To: rjw, linux-acpi; +Cc: salil.mehta, jonathan.cameron, linux-kernel
On Fri, 2024-04-26 at 18:56 +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> The return value of _STA with the "present" bit unset and the
> "enabled"
> bit set is clearly invalid as per the ACPI specification, Section
> 6.3.7
> "_STA (Device Status)", so make the ACPI device enumeration code
> disregard devices with such _STA return values.
>
> Also, because this implies that status.enabled will only be set if
> status.present is set too, acpi_device_is_enabled() can be modified
> to simply return the value of the former.
>
> Link:
> https://uefi.org/specs/ACPI/6.5/06_Device_Configuration.html#sta-device-status
> Link:
> https://lore.kernel.org/linux-acpi/88179311a503493099028c12ca37d430@huawei.com/
> Suggested-by: Salil Mehta <salil.mehta@huawei.com>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> drivers/acpi/bus.c | 11 +++++++++++
> drivers/acpi/scan.c | 2 +-
> 2 files changed, 12 insertions(+), 1 deletion(-)
>
> Index: linux-pm/drivers/acpi/bus.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/bus.c
> +++ linux-pm/drivers/acpi/bus.c
> @@ -112,6 +112,17 @@ int acpi_bus_get_status(struct acpi_devi
> if (ACPI_FAILURE(status))
> return -ENODEV;
>
> + if (!device->status.present && device->status.enabled) {
> + pr_info(FW_BUG "Device [%s] status [%08x]: not
> present and enabled\n",
> + device->pnp.bus_id, (u32)sta);
> + device->status.enabled = 0;
> + /*
> + * The status is clearly invalid, so clear the
> enabled bit as
> + * well to avoid attempting to use the device.
> + */
seems that this comment is for the line above?
thanks,
rui
> + device->status.functional = 0;
> + }
> +
> acpi_set_device_status(device, sta);
>
> if (device->status.functional && !device->status.present) {
> Index: linux-pm/drivers/acpi/scan.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/scan.c
> +++ linux-pm/drivers/acpi/scan.c
> @@ -1962,7 +1962,7 @@ bool acpi_device_is_present(const struct
>
> bool acpi_device_is_enabled(const struct acpi_device *adev)
> {
> - return adev->status.present && adev->status.enabled;
> + return adev->status.enabled;
> }
>
> static bool acpi_scan_handler_matching(struct acpi_scan_handler
> *handler,
>
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] ACPI: scan: Avoid enumerating devices with clearly invalid _STA values
2024-04-26 16:56 [PATCH v1] ACPI: scan: Avoid enumerating devices with clearly invalid _STA values Rafael J. Wysocki
2024-04-28 4:17 ` Zhang, Rui
@ 2024-04-29 8:29 ` Jonathan Cameron
2024-04-29 16:07 ` Rafael J. Wysocki
1 sibling, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2024-04-29 8:29 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Linux ACPI, LKML, Salil Mehta
On Fri, 26 Apr 2024 18:56:21 +0200
"Rafael J. Wysocki" <rjw@rjwysocki.net> wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> The return value of _STA with the "present" bit unset and the "enabled"
> bit set is clearly invalid as per the ACPI specification, Section 6.3.7
> "_STA (Device Status)", so make the ACPI device enumeration code
> disregard devices with such _STA return values.
>
> Also, because this implies that status.enabled will only be set if
> status.present is set too, acpi_device_is_enabled() can be modified
> to simply return the value of the former.
>
> Link: https://uefi.org/specs/ACPI/6.5/06_Device_Configuration.html#sta-device-status
> Link: https://lore.kernel.org/linux-acpi/88179311a503493099028c12ca37d430@huawei.com/
> Suggested-by: Salil Mehta <salil.mehta@huawei.com>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Seems a sensible tidying up. Hopefully nothing was relying on
this looser behavior. One trivial thing inline.
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
> drivers/acpi/bus.c | 11 +++++++++++
> drivers/acpi/scan.c | 2 +-
> 2 files changed, 12 insertions(+), 1 deletion(-)
>
> Index: linux-pm/drivers/acpi/bus.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/bus.c
> +++ linux-pm/drivers/acpi/bus.c
> @@ -112,6 +112,17 @@ int acpi_bus_get_status(struct acpi_devi
> if (ACPI_FAILURE(status))
> return -ENODEV;
>
> + if (!device->status.present && device->status.enabled) {
> + pr_info(FW_BUG "Device [%s] status [%08x]: not present and enabled\n",
> + device->pnp.bus_id, (u32)sta);
> + device->status.enabled = 0;
> + /*
> + * The status is clearly invalid, so clear the enabled bit as
> + * well to avoid attempting to use the device.
> + */
Comment seems to be in a slightly odd place. Perhaps one line earlier makes
more sense? Or was the intent to mention functional here?
> + device->status.functional = 0;
> + }
> +
> acpi_set_device_status(device, sta);
>
> if (device->status.functional && !device->status.present) {
> Index: linux-pm/drivers/acpi/scan.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/scan.c
> +++ linux-pm/drivers/acpi/scan.c
> @@ -1962,7 +1962,7 @@ bool acpi_device_is_present(const struct
>
> bool acpi_device_is_enabled(const struct acpi_device *adev)
> {
> - return adev->status.present && adev->status.enabled;
> + return adev->status.enabled;
> }
>
> static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler,
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] ACPI: scan: Avoid enumerating devices with clearly invalid _STA values
2024-04-28 4:17 ` Zhang, Rui
@ 2024-04-29 16:06 ` Rafael J. Wysocki
0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-04-29 16:06 UTC (permalink / raw)
To: Zhang, Rui; +Cc: rjw, linux-acpi, salil.mehta, jonathan.cameron, linux-kernel
On Sun, Apr 28, 2024 at 6:17 AM Zhang, Rui <rui.zhang@intel.com> wrote:
>
> On Fri, 2024-04-26 at 18:56 +0200, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >
> > The return value of _STA with the "present" bit unset and the
> > "enabled"
> > bit set is clearly invalid as per the ACPI specification, Section
> > 6.3.7
> > "_STA (Device Status)", so make the ACPI device enumeration code
> > disregard devices with such _STA return values.
> >
> > Also, because this implies that status.enabled will only be set if
> > status.present is set too, acpi_device_is_enabled() can be modified
> > to simply return the value of the former.
> >
> > Link:
> > https://uefi.org/specs/ACPI/6.5/06_Device_Configuration.html#sta-device-status
> > Link:
> > https://lore.kernel.org/linux-acpi/88179311a503493099028c12ca37d430@huawei.com/
> > Suggested-by: Salil Mehta <salil.mehta@huawei.com>
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > ---
> > drivers/acpi/bus.c | 11 +++++++++++
> > drivers/acpi/scan.c | 2 +-
> > 2 files changed, 12 insertions(+), 1 deletion(-)
> >
> > Index: linux-pm/drivers/acpi/bus.c
> > ===================================================================
> > --- linux-pm.orig/drivers/acpi/bus.c
> > +++ linux-pm/drivers/acpi/bus.c
> > @@ -112,6 +112,17 @@ int acpi_bus_get_status(struct acpi_devi
> > if (ACPI_FAILURE(status))
> > return -ENODEV;
> >
> > + if (!device->status.present && device->status.enabled) {
> > + pr_info(FW_BUG "Device [%s] status [%08x]: not
> > present and enabled\n",
> > + device->pnp.bus_id, (u32)sta);
> > + device->status.enabled = 0;
> > + /*
> > + * The status is clearly invalid, so clear the
> > enabled bit as
> > + * well to avoid attempting to use the device.
> > + */
>
> seems that this comment is for the line above?
No, I meant "functional" and wrote "enabled". Not sure why really.
> > + device->status.functional = 0;
> > + }
> > +
> > acpi_set_device_status(device, sta);
> >
> > if (device->status.functional && !device->status.present) {
> > Index: linux-pm/drivers/acpi/scan.c
> > ===================================================================
> > --- linux-pm.orig/drivers/acpi/scan.c
> > +++ linux-pm/drivers/acpi/scan.c
> > @@ -1962,7 +1962,7 @@ bool acpi_device_is_present(const struct
> >
> > bool acpi_device_is_enabled(const struct acpi_device *adev)
> > {
> > - return adev->status.present && adev->status.enabled;
> > + return adev->status.enabled;
> > }
> >
> > static bool acpi_scan_handler_matching(struct acpi_scan_handler
> > *handler,
> >
> >
> >
> >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] ACPI: scan: Avoid enumerating devices with clearly invalid _STA values
2024-04-29 8:29 ` Jonathan Cameron
@ 2024-04-29 16:07 ` Rafael J. Wysocki
0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-04-29 16:07 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: Rafael J. Wysocki, Linux ACPI, LKML, Salil Mehta
On Mon, Apr 29, 2024 at 10:29 AM Jonathan Cameron
<Jonathan.Cameron@huawei.com> wrote:
>
> On Fri, 26 Apr 2024 18:56:21 +0200
> "Rafael J. Wysocki" <rjw@rjwysocki.net> wrote:
>
> > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >
> > The return value of _STA with the "present" bit unset and the "enabled"
> > bit set is clearly invalid as per the ACPI specification, Section 6.3.7
> > "_STA (Device Status)", so make the ACPI device enumeration code
> > disregard devices with such _STA return values.
> >
> > Also, because this implies that status.enabled will only be set if
> > status.present is set too, acpi_device_is_enabled() can be modified
> > to simply return the value of the former.
> >
> > Link: https://uefi.org/specs/ACPI/6.5/06_Device_Configuration.html#sta-device-status
> > Link: https://lore.kernel.org/linux-acpi/88179311a503493099028c12ca37d430@huawei.com/
> > Suggested-by: Salil Mehta <salil.mehta@huawei.com>
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Seems a sensible tidying up. Hopefully nothing was relying on
> this looser behavior. One trivial thing inline.
>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Thanks!
> > ---
> > drivers/acpi/bus.c | 11 +++++++++++
> > drivers/acpi/scan.c | 2 +-
> > 2 files changed, 12 insertions(+), 1 deletion(-)
> >
> > Index: linux-pm/drivers/acpi/bus.c
> > ===================================================================
> > --- linux-pm.orig/drivers/acpi/bus.c
> > +++ linux-pm/drivers/acpi/bus.c
> > @@ -112,6 +112,17 @@ int acpi_bus_get_status(struct acpi_devi
> > if (ACPI_FAILURE(status))
> > return -ENODEV;
> >
> > + if (!device->status.present && device->status.enabled) {
> > + pr_info(FW_BUG "Device [%s] status [%08x]: not present and enabled\n",
> > + device->pnp.bus_id, (u32)sta);
> > + device->status.enabled = 0;
> > + /*
> > + * The status is clearly invalid, so clear the enabled bit as
> > + * well to avoid attempting to use the device.
> > + */
>
> Comment seems to be in a slightly odd place. Perhaps one line earlier makes
> more sense? Or was the intent to mention functional here?
Rui has noticed this already.
I thought "functional" and wrote "enabled". Oh well, I'll send a v2.
> > + device->status.functional = 0;
> > + }
> > +
> > acpi_set_device_status(device, sta);
> >
> > if (device->status.functional && !device->status.present) {
> > Index: linux-pm/drivers/acpi/scan.c
> > ===================================================================
> > --- linux-pm.orig/drivers/acpi/scan.c
> > +++ linux-pm/drivers/acpi/scan.c
> > @@ -1962,7 +1962,7 @@ bool acpi_device_is_present(const struct
> >
> > bool acpi_device_is_enabled(const struct acpi_device *adev)
> > {
> > - return adev->status.present && adev->status.enabled;
> > + return adev->status.enabled;
> > }
> >
> > static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler,
> >
> >
> >
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-29 16:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-26 16:56 [PATCH v1] ACPI: scan: Avoid enumerating devices with clearly invalid _STA values Rafael J. Wysocki
2024-04-28 4:17 ` Zhang, Rui
2024-04-29 16:06 ` Rafael J. Wysocki
2024-04-29 8:29 ` Jonathan Cameron
2024-04-29 16:07 ` Rafael J. Wysocki
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.