Skip to content

Commit d22ddcb

Browse files
committed
ACPI / hotplug: Add demand_offline hotplug profile flag
Add a new ACPI hotplug profile flag, demand_offline, such that if set for the given ACPI device object's scan handler, it will cause acpi_scan_hot_remove() to check if that device object's physical companions are offline upfront and fail the hot removal if that is not the case. That flag will be useful to overcome a problem with containers on some system where they can only be hot-removed after some cleanup operations carried out by user space, which needs to be notified of the container hot-removal before the kernel attempts to offline devices in the container. In those cases the current implementation of acpi_scan_hot_remove() is not sufficient, because it first tries to offline the devices in the container and only if that is suffcessful it tries to offline the container itself. As a result, the container hot-removal notification is not delivered to user space at the right time. Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent bfecc2b commit d22ddcb

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

drivers/acpi/scan.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, cha
126126
}
127127
static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
128128

129+
static bool acpi_scan_is_offline(struct acpi_device *adev)
130+
{
131+
struct acpi_device_physical_node *pn;
132+
bool offline = true;
133+
134+
mutex_lock(&adev->physical_node_lock);
135+
136+
list_for_each_entry(pn, &adev->physical_node_list, node)
137+
if (device_supports_offline(pn->dev) && !pn->dev->offline) {
138+
kobject_uevent(&pn->dev->kobj, KOBJ_CHANGE);
139+
offline = false;
140+
break;
141+
}
142+
143+
mutex_unlock(&adev->physical_node_lock);
144+
return offline;
145+
}
146+
129147
static acpi_status acpi_bus_offline(acpi_handle handle, u32 lvl, void *data,
130148
void **ret_p)
131149
{
@@ -196,12 +214,11 @@ static acpi_status acpi_bus_online(acpi_handle handle, u32 lvl, void *data,
196214
return AE_OK;
197215
}
198216

199-
static int acpi_scan_hot_remove(struct acpi_device *device)
217+
static int acpi_scan_try_to_offline(struct acpi_device *device)
200218
{
201219
acpi_handle handle = device->handle;
202-
struct device *errdev;
220+
struct device *errdev = NULL;
203221
acpi_status status;
204-
unsigned long long sta;
205222

206223
/*
207224
* Carry out two passes here and ignore errors in the first pass,
@@ -212,7 +229,6 @@ static int acpi_scan_hot_remove(struct acpi_device *device)
212229
*
213230
* If the first pass is successful, the second one isn't needed, though.
214231
*/
215-
errdev = NULL;
216232
status = acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
217233
NULL, acpi_bus_offline, (void *)false,
218234
(void **)&errdev);
@@ -241,6 +257,23 @@ static int acpi_scan_hot_remove(struct acpi_device *device)
241257
return -EBUSY;
242258
}
243259
}
260+
return 0;
261+
}
262+
263+
static int acpi_scan_hot_remove(struct acpi_device *device)
264+
{
265+
acpi_handle handle = device->handle;
266+
unsigned long long sta;
267+
acpi_status status;
268+
269+
if (device->handler->hotplug.demand_offline && !acpi_force_hot_remove) {
270+
if (!acpi_scan_is_offline(device))
271+
return -EBUSY;
272+
} else {
273+
int error = acpi_scan_try_to_offline(device);
274+
if (error)
275+
return error;
276+
}
244277

245278
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
246279
"Hot-removing device %s...\n", dev_name(&device->dev)));

include/acpi/acpi_bus.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ struct acpi_device;
9191

9292
struct acpi_hotplug_profile {
9393
struct kobject kobj;
94-
bool enabled:1;
9594
int (*scan_dependent)(struct acpi_device *adev);
95+
bool enabled:1;
96+
bool demand_offline:1;
9697
};
9798

9899
static inline struct acpi_hotplug_profile *to_acpi_hotplug_profile(

0 commit comments

Comments
 (0)