Get device's parent from parent field, fix sleeping IRQs disabled
v3 cover Get device's parent from parent field, fix sleeping IRQs disabled
Hi all,
This set changes getting fwnode's parent on ACPI fwnode so it no longer needs a semaphore, using struct acpi_device.dev.parent field instead of calling acpi_get_parent(). The semaphore is being acquired when the device's full path is printed which now takes place local IRQs disabled:
--------8<------------------------
BUG: sleeping function called from invalid context at kernel/locking/semaphore.c:163
...
Call Trace: <TASK> dump_stack_lvl+0x57/0x7d __might_resched.cold+0xf4/0x12f down_timeout+0x21/0x70 acpi_os_wait_semaphore+0x63/0x180 acpi_ut_acquire_mutex+0x123/0x1ba acpi_get_parent+0x30/0x71 acpi_node_get_parent+0x64/0x90 ? lock_acquire+0x1a0/0x300 fwnode_count_parents+0x6d/0xb0 fwnode_full_name_string+0x18/0x90 fwnode_string+0xd7/0x140 vsnprintf+0x1ec/0x4f0 va_format.constprop.0+0x6a/0x130 vsnprintf+0x1ec/0x4f0 vprintk_store+0x271/0x5a0 ? rcu_read_lock_sched_held+0x12/0x70 ? lock_release+0x228/0x310 ? acpi_initialize_hp_context+0x50/0x50 vprintk_emit+0xd5/0x340 _printk+0x58/0x6f __dynamic_pr_debug+0xe2/0x100 __v4l2_fwnode_endpoint_parse+0x10c/0x450 [v4l2_fwnode] v4l2_fwnode_endpoint_parse+0x11/0x40 [v4l2_fwnode] cio2_pci_probe.cold+0x7fb/0x969 [ipu3_cio2] ? _raw_spin_unlock_irqrestore+0x42/0x70 pci_device_probe+0xb6/0x140 really_probe+0x1f5/0x3f0 __driver_probe_device+0xfe/0x180 driver_probe_device+0x1e/0x90 __driver_attach+0xc4/0x1d0 ? __device_attach_driver+0xe0/0xe0 ? __device_attach_driver+0xe0/0xe0 bus_for_each_dev+0x7b/0xc0 bus_add_driver+0x14c/0x1f0 driver_register+0x8b/0xe0 ? 0xffffffffa0428000 do_one_initcall+0x5b/0x300 ? rcu_read_lock_sched_held+0x12/0x70 ? trace_kmalloc+0x29/0xd0 ? kmem_cache_alloc_trace+0x11d/0x630 do_init_module+0x5c/0x260 __do_sys_finit_module+0xae/0x110 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x44/0xae
--------8<------------------------
since v2:
- Move unwrapping the line assigning dev in acpi_node_get_parent() to the first patch.
- Drop removal of a redundant else clause in the first patch.
since v1:
- Drop the patch making acpi_fwnode_handle() NULL-safe.
- Use original %pfw patch on Fixes: line, cc stable beginning from v5.5.
- Get the parent from struct acpi_device.dev.parent, not struct acpi_device.parent.
Sakari Ailus (2):
ACPI: Get acpi_device's parent from the parent field
ACPI: Make acpi_node_get_parent() local
drivers/acpi/property.c | 14 +++++--------- include/linux/acpi.h | 7 ------- 2 files changed, 5 insertions(+), 16 deletions(-)
Signature · 1 line
2.30.2
PATCH v3 1/2 ACPI: Get acpi_device's parent from the parent field
Printk modifier %pfw is used to print the full path of the device name. This is obtained device by device until a device no longer has a parent.
On ACPI getting the parent fwnode is done by calling acpi_get_parent() which tries to down() a semaphore. But local IRQs are now disabled in vprintk_store() before the mutex is acquired. This is obviously a problem.
Luckily struct device, embedded in struct acpi_device, has a parent field already. Use that field to get the parent instead of relying on acpi_get_parent().
--- drivers/acpi/property.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/acpi/property.c +3 -8
@@ -1090,15 +1090,10 @@ struct fwnode_handle *acpi_node_get_parent(const struct fwnode_handle *fwnode)/* All data nodes have parent pointer so just return that */ return to_acpi_data_node (fwnode)->parent; }else if (is_acpi_device_node (fwnode)) { -acpi_handle handle, parent_handle; +struct device *dev =to_acpi_device_node (fwnode)->dev.parent; - handle =to_acpi_device_node (fwnode)->handle; -if (ACPI_SUCCESS (acpi_get_parent (handle, &parent_handle))) { -struct acpi_device *adev; - -if (!acpi_bus_get_device (parent_handle, &adev)) -return acpi_fwnode_handle (adev); - } +if (dev) +return acpi_fwnode_handle (to_acpi_device (dev)); }return NULL ;
Signature · 1 line
2.30.2
PATCH v3 2/2 ACPI: Make acpi_node_get_parent() local
In reply to Sakari Ailusacpi_node_get_parent() isn't used outside drivers/acpi/property.c. Make it local.
--- drivers/acpi/property.c | 3 ++- include/linux/acpi.h | 7 ------- 2 files changed, 2 insertions(+), 8 deletions(-)
drivers/acpi/property.c +2 -1
@@ -1084,7 +1084,8 @@ struct fwnode_handle *acpi_get_next_subnode(const struct fwnode_handle *fwnode,* Returns parent node of an ACPI device or data firmware node or %NULL if * not available. */ -struct fwnode_handle *acpi_node_get_parent (const struct fwnode_handle *fwnode) +static struct fwnode_handle * +acpi_node_get_parent (const struct fwnode_handle *fwnode) {if (is_acpi_data_node (fwnode)) {/* All data nodes have parent pointer so just return that */
include/linux/acpi.h +0 -7
@@ -1170,7 +1170,6 @@ int acpi_node_prop_get(const struct fwnode_handle *fwnode, const char *propname,struct fwnode_handle *acpi_get_next_subnode (const struct fwnode_handle *fwnode,struct fwnode_handle *child); -struct fwnode_handle *acpi_node_get_parent (const struct fwnode_handle *fwnode);struct acpi_probe_entry ; typedef bool (*acpi_probe_entry_validate_subtbl)(struct acpi_subtable_header *,
@@ -1275,12 +1274,6 @@ acpi_get_next_subnode(const struct fwnode_handle *fwnode,return NULL ; } -static inline struct fwnode_handle * -acpi_node_get_parent (const struct fwnode_handle *fwnode) -{ -return NULL ; -} -static inline struct fwnode_handle *acpi_graph_get_next_endpoint (const struct fwnode_handle *fwnode,struct fwnode_handle *prev)
Signature · 1 line
2.30.2
Rafael J. Wysocki
maintainerQuoted 81 lines · Sakari Ailus
Hi all,
This set changes getting fwnode's parent on ACPI fwnode so it no longer needs a semaphore, using struct acpi_device.dev.parent field instead of calling
acpi_get_parent(). The semaphore is being acquired when the device's full path is printed which now takes place local IRQs disabled:--------8<------------------------
BUG: sleeping function called from invalid context at kernel/locking/semaphore.c:163...
Call Trace: <TASK> dump_stack_lvl+0x57/0x7d __might_resched.cold+0xf4/0x12f down_timeout+0x21/0x70 acpi_os_wait_semaphore+0x63/0x180 acpi_ut_acquire_mutex+0x123/0x1ba acpi_get_parent+0x30/0x71 acpi_node_get_parent+0x64/0x90 ? lock_acquire+0x1a0/0x300 fwnode_count_parents+0x6d/0xb0 fwnode_full_name_string+0x18/0x90 fwnode_string+0xd7/0x140 vsnprintf+0x1ec/0x4f0 va_format.constprop.0+0x6a/0x130 vsnprintf+0x1ec/0x4f0 vprintk_store+0x271/0x5a0 ? rcu_read_lock_sched_held+0x12/0x70 ? lock_release+0x228/0x310 ? acpi_initialize_hp_context+0x50/0x50 vprintk_emit+0xd5/0x340 _printk+0x58/0x6f __dynamic_pr_debug+0xe2/0x100 __v4l2_fwnode_endpoint_parse+0x10c/0x450 [v4l2_fwnode] v4l2_fwnode_endpoint_parse+0x11/0x40 [v4l2_fwnode] cio2_pci_probe.cold+0x7fb/0x969 [ipu3_cio2] ? _raw_spin_unlock_irqrestore+0x42/0x70 pci_device_probe+0xb6/0x140 really_probe+0x1f5/0x3f0 __driver_probe_device+0xfe/0x180 driver_probe_device+0x1e/0x90 __driver_attach+0xc4/0x1d0 ? __device_attach_driver+0xe0/0xe0 ? __device_attach_driver+0xe0/0xe0 bus_for_each_dev+0x7b/0xc0 bus_add_driver+0x14c/0x1f0 driver_register+0x8b/0xe0 ? 0xffffffffa0428000 do_one_initcall+0x5b/0x300 ? rcu_read_lock_sched_held+0x12/0x70 ? trace_kmalloc+0x29/0xd0 ? kmem_cache_alloc_trace+0x11d/0x630 do_init_module+0x5c/0x260 __do_sys_finit_module+0xae/0x110 do_syscall_64+0x3b/0x90 entry_SYSCALL_64_after_hwframe+0x44/0xae--------8<------------------------
since v2:
- Move unwrapping the line assigning dev in
acpi_node_get_parent()to the first patch.- Drop removal of a redundant else clause in the first patch.
since v1:
- Drop the patch making
acpi_fwnode_handle()NULL-safe.- Use original %pfw patch on Fixes: line, cc stable beginning from v5.5.
- Get the parent from struct acpi_device.dev.parent, not struct acpi_device.parent.
Sakari Ailus (2):
ACPI: Get acpi_device's parent from the parent field
ACPI: Makeacpi_node_get_parent()local
Quoted 5 lines
drivers/acpi/property.c | 14 +++++--------- include/linux/acpi.h | 7 ------- 2 files changed, 5 insertions(+), 16 deletions(-)--
Both [1-2/2] applied as 5.16-rc material, thanks!