Skip to content

RFC ACPI: Flexible eject options to remove devices cautiously

Chester Lin linux-acpi lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest3 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3ACPI: scan: add userland notification while handling eject eventsDocumentation/ABI/testing/sysfs-bus-acpi drivers/acpi/device_sysfs.c drivers/acpi/scan.c +1 more+89 -73 replies
2/3ACPI: scan: add cancel_eject and auto_eject attributesDocumentation/ABI/testing/sysfs-bus-acpi drivers/acpi/device_sysfs.c drivers/acpi/internal.h +3 more+193 -150 replies
3/3ACPI: scan: add a request_offline_recursive attributeDocumentation/ABI/testing/sysfs-bus-acpi drivers/acpi/device_sysfs.c drivers/acpi/internal.h +1 more+65 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/3] ACPI: Flexible eject options to remove devices cautiously

* This proposal is derived from https://lkml.org/lkml/2020/1/2/1401

Currently there are two ways to handle ACPI device ejection. When an eject event happens on an ACPI container, the kernel sends a KOBJ_CHANGE event to userland and userland has to deal with offline operation. For other device types, acpi_scan_try_to_offline() is called and it tries to put target device(s) offline and then removes all nodes once they are all offline.

However we found that sometimes applications could intensively access resources on ejectable devices therefore they could have risk if ejection suddenly happens and removes devices without any notification. In stead of executing the offline callbakcs directly, I want to introduce an additional approach, which uses 'request_offline' attributes to remind the kernel to notify userland that some devices have been planning to be removed, so the applications running on those targets can be prepared and determine when offline tasks should be done based on current workload.

This approach is disabled by default so it will not affect systems which still use the original way. Once it's enabled, the kernel will only send change events as offline requests of target nodes to userland, so firmware or userspace callers who raise eject requests will still have to re-trigger eject events if necessary because the kernel will not track all targets' offline status actively. However, I still add an 'auto_eject' attribute for userland if it's required to periodically schedule an eject event until the target has been removed.

To ensure that eject function can work properly since normal users might not have their own offline/online handling, I would propose a generic udev rule to systemd upstream as default in order to deal with change events and take offline/online actions accordingly:

*Example: 80-acpi-hotplug-eject.rules
------------------------------------------------
# Generic rules for handling ACPI hotplug eject.

SUBSYSTEM=="*", ACTION=="change", ENV{EVENT}=="offline", ATTR{online}=="1", \
DEVPATH=="*", ATTR{online}="0"

SUBSYSTEM=="*", ACTION=="change", ENV{EVENT}=="online", ATTR{online}=="0", \
DEVPATH=="*", ATTR{online}="1"
------------------------------------------------

Chester Lin (3):
ACPI: scan: add userland notification while handling eject events
ACPI: scan: add cancel_eject and auto_eject attributes
ACPI: scan: add a request_offline_recursive attribute

 Documentation/ABI/testing/sysfs-bus-acpi |  43 +++++++
 drivers/acpi/device_sysfs.c              | 154 ++++++++++++++++++++++-
 drivers/acpi/internal.h                  |   4 +-
 drivers/acpi/osl.c                       |  37 ++++--
 drivers/acpi/scan.c                      | 108 +++++++++++++++-
 include/acpi/acpi_bus.h                  |   8 ++
 6 files changed, 339 insertions(+), 15 deletions(-)
Signature · 1 line
2.24.0