Get device's parent from parent field, fix sleeping IRQs disabled
Subsystems (2)
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->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<------------------------
I guess one could argue it wasn't great to begin with that getting fwnode's parent required a semaphore to begin with, nevertheless John's patch made it a concrete problem. Added Cc: stable, too.
Sakari Ailus (3):
ACPI: Make acpi_fwnode_handle safer
ACPI: Get acpi_device's parent from the parent field
ACPI: Make acpi_node_get_parent() local
drivers/acpi/property.c | 15 ++++++--------- include/acpi/acpi_bus.h | 2 +- include/linux/acpi.h | 7 ------- 3 files changed, 7 insertions(+), 17 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/3 ACPI: Make acpi_fwnode_handle safer
Check that the fwnode argument passed to acpi_fwnode_handle is non-NULL, and return NULL if it is, otherwise the fwnode. Thus the caller doesn't have to ensure the argument is a valid non-NULL fwnode.
--- include/acpi/acpi_bus.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/acpi/acpi_bus.h +1 -1
@@ -445,7 +445,7 @@ static inline bool acpi_data_node_match(const struct fwnode_handle *fwnode,static inline struct fwnode_handle *acpi_fwnode_handle (struct acpi_device *adev) { -return &adev->fwnode; +return adev ? &adev->fwnode :NULL ; }static inline void *acpi_driver_data (struct acpi_device *d)
Signature · 1 line
2.30.2
Re: [PATCH 1/3] ACPI: Make acpi_fwnode_handle safer
Quoted 1 line · Sakari Ailus
Check that the fwnode argument passed to
acpi_fwnode_handleis non-NULL,
acpi_fwnode_handle()
Quoted 2 lines
and return NULL if it is, otherwise the fwnode. Thus the caller doesn't have to ensure the argument is a valid non-NULL fwnode.
Quoted 23 lines
Cc [email protected] # v5.15 and upSigned-off-by Sakari Ailus <[email protected]>--- include/acpi/acpi_bus.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/acpi/acpi_bus.h +1
-1@@ -445,7 +445,7 @@ static inline bool acpi_data_node_match(const struct fwnode_handle *fwnode,static inline struct fwnode_handle *acpi_fwnode_handle (struct acpi_device *adev) { -return &adev->fwnode; +return adev ? &adev->fwnode :NULL ; }static inline void *acpi_driver_data (struct acpi_device *d)Signature · 1 line
2.30.2
Signature · 2 lines
With Best Regards, Andy Shevchenko
Rafael J. Wysocki
maintainerRe: [PATCH 1/3] ACPI: Make acpi_fwnode_handle safer
In reply to Sakari AilusQuoted 6 lines · Sakari Ailus
Check that the fwnode argument passed to
acpi_fwnode_handleis non-NULL, and return NULL if it is, otherwise the fwnode. Thus the caller doesn't have to ensure the argument is a valid non-NULL fwnode.Cc [email protected] # v5.15 and up
Why?
Quoted 1 line
Signed-off-by Sakari Ailus <[email protected]>
That's because you want to avoid a NULL check in the second patch and it adds a ton of redundant NULL checks all over the place.
Like for example in include/acpi/acpi.h:
#define ACPI_COMPANION_SET(dev, adev) set_primary_fwnode(dev, (adev) ? \
acpi_fwnode_handle(adev) : NULL)
You should at least get rid of this one.
Quoted 18 lines
--- include/acpi/acpi_bus.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/acpi/acpi_bus.h +1
-2@@ -445,7 +445,7 @@ static inline bool acpi_data_node_match(const struct fwnode_handle *fwnode,static inline struct fwnode_handle *acpi_fwnode_handle (struct acpi_device *adev) { -return &adev->fwnode; +return adev ? &adev->fwnode :NULL ; }static inline void *acpi_driver_data (struct acpi_device *d) --
Re: [PATCH 1/3] ACPI: Make acpi_fwnode_handle safer
Hi Rafael,
Quoted 16 lines · Rafael J. Wysocki
Quoted 6 lines · Sakari Ailus
Check that the fwnode argument passed to
acpi_fwnode_handleis non-NULL, and return NULL if it is, otherwise the fwnode. Thus the caller doesn't have to ensure the argument is a valid non-NULL fwnode.Cc [email protected] # v5.15 and upWhy?
Quoted 1 line
Signed-off-by Sakari Ailus <[email protected]>That's because you want to avoid a NULL check in the second patch and it adds a ton of redundant NULL checks all over the place.
Quoted 6 lines
Like for example in
include/acpi/acpi.h:#define
ACPI_COMPANION_SET(dev, adev)set_primary_fwnode(dev, (adev) ? \
acpi_fwnode_handle(adev): NULL)You should at least get rid of this one.
That's a fair point.
acpi_fwnode_handle() doesn't have a tonne of users so it's entirely feasible to change the users as necessary but in either case I guess I'll drop this from stable as it's likely to conflict with some of these.
Signature · 3 lines
Regards, Sakari Ailus
Re: [PATCH 1/3] ACPI: Make acpi_fwnode_handle safer
In reply to Rafael J. WysockiQuoted 16 lines · Rafael J. Wysocki
Quoted 6 lines · Sakari Ailus
Check that the fwnode argument passed to
acpi_fwnode_handleis non-NULL, and return NULL if it is, otherwise the fwnode. Thus the caller doesn't have to ensure the argument is a valid non-NULL fwnode.Cc [email protected] # v5.15 and upWhy?
Quoted 1 line
Signed-off-by Sakari Ailus <[email protected]>That's because you want to avoid a NULL check in the second patch and it adds a ton of redundant NULL checks all over the place.
Quoted 6 lines
Like for example in
include/acpi/acpi.h:#define
ACPI_COMPANION_SET(dev, adev)set_primary_fwnode(dev, (adev) ? \
acpi_fwnode_handle(adev): NULL)You should at least get rid of this one.
I went through the users and it seems they don't actually even benefit from this. So I'll drop the patch.
Most of these little macros are made safer that way but in this case it seems callers have already acpi_device around, or do checks for other purposes as well.
Signature · 1 line
Sakari Ailus
PATCH 2/3 ACPI: Get acpi_device's parent from the parent field
In reply to Sakari AilusPrintk 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 acpi_device has a parent field already. Use that field to get the parent instead of relying on acpi_get_parent().
Depends-on: ("ACPI: Make acpi_fwnode_handle safer")
--- drivers/acpi/property.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/acpi/property.c +4 -8
@@ -1089,16 +1089,12 @@ 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 */ return to_acpi_data_node (fwnode)->parent; - }else if (is_acpi_device_node (fwnode)) { -acpi_handle handle, parent_handle; + } - handle =to_acpi_device_node (fwnode)->handle; -if (ACPI_SUCCESS (acpi_get_parent (handle, &parent_handle))) { -struct acpi_device *adev; +if (is_acpi_device_node (fwnode)) { +struct acpi_device *device =to_acpi_device_node (fwnode); -if (!acpi_bus_get_device (parent_handle, &adev)) -return acpi_fwnode_handle (adev); - } +return acpi_fwnode_handle (device->parent); }return NULL ;
Signature · 1 line
2.30.2
Re: [PATCH 2/3] ACPI: Get acpi_device's parent from the parent field
Quoted 9 lines · Sakari Ailus
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 todown()a semaphore. But local IRQs are now disabled invprintk_store()before the mutex is acquired. This is obviously a problem.Luckily struct
acpi_devicehas a parent field already. Use that field to get the parent instead of relying onacpi_get_parent().
I think the best if Rafael can confirm that we may use it like this. If he approved, nothing would stop me to give you
Quoted 37 lines
Fixes 002eb6ad0751 ("printk: track/limit recursion")Cc [email protected] # v5.15 and upDepends-on: ("ACPI: Make
acpi_fwnode_handlesafer")Signed-off-by Sakari Ailus <[email protected]>--- drivers/acpi/property.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)drivers/acpi/property.c +4
-8@@ -1089,16 +1089,12 @@ 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 */ return to_acpi_data_node (fwnode)->parent; - }else if (is_acpi_device_node (fwnode)) { -acpi_handle handle, parent_handle; + } - handle =to_acpi_device_node (fwnode)->handle; -if (ACPI_SUCCESS (acpi_get_parent (handle, &parent_handle))) { -struct acpi_device *adev; +if (is_acpi_device_node (fwnode)) { +struct acpi_device *device =to_acpi_device_node (fwnode); -if (!acpi_bus_get_device (parent_handle, &adev)) -return acpi_fwnode_handle (adev); - } +return acpi_fwnode_handle (device->parent); }return NULL ;Signature · 1 line
2.30.2
Signature · 2 lines
With Best Regards, Andy Shevchenko
Rafael J. Wysocki
maintainerRe: [PATCH 2/3] ACPI: Get acpi_device's parent from the parent field
Quoted 10 lines · Andy Shevchenko
Quoted 8 lines · Sakari Ailus
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 todown()a semaphore. But local IRQs are now disabled invprintk_store()before the mutex is acquired. This is obviously a problem.Luckily struct
acpi_devicehas a parent field already.
Which I'm going to eliminate, because it is redundant.
The dev object embedded in struct acpi_device has a parent field pointing to the same object and that one is used by the driver core.
Quoted 5 lines
Quoted 1 line
Use that field to get the parent instead of relying on
acpi_get_parent().I think the best if Rafael can confirm that we may use it like this. If he approved, nothing would stop me to give you
Reviewed-by Andy Shevchenko <[email protected]>
In fact, I would prefer the parent field of the dev object embedded in struct acpi_device to be used and for completeness it should be tested against NULL unless you know that the parent is not going away ATM.
Quoted 20 lines
Quoted 20 lines
Fixes 002eb6ad0751 ("printk: track/limit recursion")Cc [email protected] # v5.15 and upDepends-on: ("ACPI: Make
acpi_fwnode_handlesafer")Signed-off-by Sakari Ailus <[email protected]>--- drivers/acpi/property.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)drivers/acpi/property.c +1
-2@@ -1089,16 +1089,12 @@ 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 */ return to_acpi_data_node (fwnode)->parent; - }else if (is_acpi_device_node (fwnode)) { -acpi_handle handle, parent_handle; + }
Quoted 5 lines
drivers/acpi/property.c struct fwnode_handle *acpi_node_get_parent(const struct fwnode_handle *fwnode) · line 1095
Quoted 5 lines
drivers/acpi/property.c +2
-3- handle =to_acpi_device_node (fwnode)->handle; -if (ACPI_SUCCESS (acpi_get_parent (handle, &parent_handle))) { -struct acpi_device *adev; +if (is_acpi_device_node (fwnode)) { +struct acpi_device *device =to_acpi_device_node (fwnode);
Call this variable adev please.
Quoted 5 lines
drivers/acpi/property.c struct fwnode_handle *acpi_node_get_parent(const struct fwnode_handle *fwnode) · line 1097
Quoted 5 lines
drivers/acpi/property.c +1
-3-if (!acpi_bus_get_device (parent_handle, &adev)) -return acpi_fwnode_handle (adev); - } +return acpi_fwnode_handle (device->parent);
And then
adev = to_acpi_device(&device->dev.parent);
if (adev)
return acpi_fwnode_handle(adev);Quoted 13 lines
Quoted 7 lines
drivers/acpi/property.c +0
-1}return NULL ; --2.30.2
--
With Best Regards,
Andy Shevchenko
Re: [PATCH 2/3] ACPI: Get acpi_device's parent from the parent field
Hi Rafael,
Quoted 11 lines · Rafael J. Wysocki
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Sakari Ailus
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 todown()a semaphore. But local IRQs are now disabled invprintk_store()before the mutex is acquired. This is obviously a problem.
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Luckily struct
acpi_devicehas a parent field already.Which I'm going to eliminate, because it is redundant.
The dev object embedded in struct
acpi_devicehas a parent field pointing to the same object and that one is used by the driver core.
Indeed, I'll do that in v2.
Quoted 45 lines
Quoted 6 lines
Quoted 2 lines
Use that field to get the parent instead of relying on
acpi_get_parent().I think the best if Rafael can confirm that we may use it like this. If he approved, nothing would stop me to give you
Reviewed-by Andy Shevchenko <[email protected]>In fact, I would prefer the parent field of the dev object embedded in struct
acpi_deviceto be used and for completeness it should be tested against NULL unless you know that the parent is not going away ATM.Quoted 20 lines
Quoted 20 lines
Fixes 002eb6ad0751 ("printk: track/limit recursion")Cc [email protected] # v5.15 and upDepends-on: ("ACPI: Make
acpi_fwnode_handlesafer")Signed-off-by Sakari Ailus <[email protected]>--- drivers/acpi/property.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)drivers/acpi/property.c +1
-2@@ -1089,16 +1089,12 @@ 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 */ return to_acpi_data_node (fwnode)->parent; - }else if (is_acpi_device_node (fwnode)) { -acpi_handle handle, parent_handle; + }Quoted 5 lines
drivers/acpi/property.c struct fwnode_handle *acpi_node_get_parent(const struct fwnode_handle *fwnode) · line 1095
Quoted 5 lines
drivers/acpi/property.c +2
-3- handle =to_acpi_device_node (fwnode)->handle; -if (ACPI_SUCCESS (acpi_get_parent (handle, &parent_handle))) { -struct acpi_device *adev; +if (is_acpi_device_node (fwnode)) { +struct acpi_device *device =to_acpi_device_node (fwnode);Call this variable adev please.
Quoted 5 lines
drivers/acpi/property.c struct fwnode_handle *acpi_node_get_parent(const struct fwnode_handle *fwnode) · line 1097
Quoted 5 lines
drivers/acpi/property.c +1
-3-if (!acpi_bus_get_device (parent_handle, &adev)) -return acpi_fwnode_handle (adev); - } +return acpi_fwnode_handle (device->parent);
Quoted 5 lines
And then
adev = to_acpi_device(&device->dev.parent); if (adev) return acpi_fwnode_handle(adev);
Ack.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/acpi/property.c +0
-0}return NULL ;
Signature · 3 lines
Kind regards, Sakari Ailus
PATCH 3/3 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
@@ -1168,7 +1168,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 *,
@@ -1273,12 +1272,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
Re: [PATCH 3/3] ACPI: Make acpi_node_get_parent() local
Quoted 2 lines · Sakari Ailus
acpi_node_get_parent()isn't used outsidedrivers/acpi/property.c. Make it local.
Always in favour for such patches!
Quoted 49 lines
Signed-off-by Sakari Ailus <[email protected]>--- 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@@ -1168,7 +1168,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 *,@@ -1273,12 +1272,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
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 3/3] ACPI: Make acpi_node_get_parent() local
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Sakari Ailus
acpi_node_get_parent()isn't used outsidedrivers/acpi/property.c. Make it local.Always in favour for such patches!
Reviewed-by Andy Shevchenko <[email protected]>
Thanks, Andy!
Signature · 1 line
Sakari Ailus
added CC: printk maintainer (Petr Mladek)
Quoted 32 lines · Sakari Ailus
This set changes getting fwnode's parent on ACPI fwnode so it no longer needs a semaphore, using struct
acpi_device->parentfield instead of callingacpi_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
...
Quoted 5 lines
--------8<------------------------
I guess one could argue it wasn't great to begin with that getting fwnode's parent required a semaphore to begin with, nevertheless John's patch made it a concrete problem. Added Cc: stable, too.
Well, before my work it was vprintk_emit() that was disabling local interrupts. So this has always been broken.
Really it should be:
printing fwnode names")
Regardless, the fix should go into 5.10 and 5.14 stables.
John Ogness
Quoted 35 lines · John Ogness
added CC: printk maintainer (Petr Mladek)
Quoted 24 lines · Sakari Ailus
This set changes getting fwnode's parent on ACPI fwnode so it no longer needs a semaphore, using struct
acpi_device->parentfield instead of callingacpi_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/0x4f0Quoted 8 lines
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
Quoted 6 lines
...
Quoted 5 lines
--------8<------------------------
I guess one could argue it wasn't great to begin with that getting fwnode's parent required a semaphore to begin with, nevertheless John's patch made it a concrete problem. Added Cc: stable, too.
It looks like a generic problem.
If I get it properly, we should make sure that any struct fwnode_operations implementation will _not_ use sleeping locks in the .get_parent() callback. Or anything that is called indirectly from from vsprintf.
Adding Andy into Cc.
Quoted 7 lines
Well, before my work it was
vprintk_emit()that was disabling local interrupts. So this has always been broken.Really it should be:
Fixes 3bd32d6a2ee6 ("lib/vsprintf: Add %pfw conversion specifier forprinting fwnode names")
Yes, I consider this to be the culprit.
Quoted 1 line
Regardless, the fix should go into 5.10 and 5.14 stables.
Please add the Fixes tag and the following into the commit message:
Best Regards,
Petr
Quoted 41 lines · Petr Mladek
Quoted 33 lines · John Ogness
Quoted 24 lines · Sakari Ailus
This set changes getting fwnode's parent on ACPI fwnode so it no longer needs a semaphore, using struct
acpi_device->parentfield instead of callingacpi_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/0x4f0Quoted 8 lines
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/0x6fQuoted 6 lines
...
Quoted 5 lines
--------8<------------------------
I guess one could argue it wasn't great to begin with that getting fwnode's parent required a semaphore to begin with, nevertheless John's patch made it a concrete problem. Added Cc: stable, too.
Quoted 6 lines
It looks like a generic problem.
If I get it properly, we should make sure that any struct
fwnode_operationsimplementation will _not_ use sleeping locks in the .get_parent() callback. Or anything that is called indirectly from from vsprintf.
Not sure how I may help here, but if there is a requirement to all *printf() to be non-sleepable, then yes, this should be done in that way. I'm not sure if every single %p extension does this...
It may require to update fwnode (source code) documentation to reflect the requirement. Also might_sleep() / migth_sleep_if() in the API calls may shed a light on (potential) issues.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Petr, John,
Quoted 43 lines · Petr Mladek
Quoted 35 lines · John Ogness
added CC: printk maintainer (Petr Mladek)
Quoted 24 lines · Sakari Ailus
This set changes getting fwnode's parent on ACPI fwnode so it no longer needs a semaphore, using struct
acpi_device->parentfield instead of callingacpi_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/0x4f0Quoted 8 lines
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/0x6fQuoted 6 lines
...
Quoted 5 lines
--------8<------------------------
I guess one could argue it wasn't great to begin with that getting fwnode's parent required a semaphore to begin with, nevertheless John's patch made it a concrete problem. Added Cc: stable, too.
Quoted 8 lines
It looks like a generic problem.
If I get it properly, we should make sure that any struct
fwnode_operationsimplementation will _not_ use sleeping locks in the .get_parent() callback. Or anything that is called indirectly from from vsprintf.Adding Andy into Cc.
That holds for OF and swnode already, ACPI was an exception to this.
Quoted 3 lines
Quoted 3 lines
Well, before my work it was
vprintk_emit()that was disabling local interrupts. So this has always been broken.
Fair enough.
Quoted 6 lines
Quoted 5 lines
Really it should be:
Fixes 3bd32d6a2ee6 ("lib/vsprintf: Add %pfw conversion specifier forprinting fwnode names")
Quoted 7 lines
Yes, I consider this to be the culprit.
Quoted 1 line
Regardless, the fix should go into 5.10 and 5.14 stables.
Please add the Fixes tag and the following into the commit message:
Cc [email protected] # v5.5+
I'll use that in v2.
Signature · 3 lines
Regards, Sakari Ailus
(and really add Andy)
Quoted 35 lines · John Ogness
added CC: printk maintainer (Petr Mladek)
Quoted 24 lines · Sakari Ailus
This set changes getting fwnode's parent on ACPI fwnode so it no longer needs a semaphore, using struct
acpi_device->parentfield instead of callingacpi_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/0x4f0Quoted 8 lines
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
Quoted 6 lines
...
Quoted 5 lines
--------8<------------------------
I guess one could argue it wasn't great to begin with that getting fwnode's parent required a semaphore to begin with, nevertheless John's patch made it a concrete problem. Added Cc: stable, too.
It looks like a generic problem.
If I get it properly, we should make sure that any struct fwnode_operations implementation will _not_ use sleeping locks in the .get_parent() callback. Or anything that is called indirectly from from vsprintf.
Adding Andy into Cc.
Quoted 7 lines
Well, before my work it was
vprintk_emit()that was disabling local interrupts. So this has always been broken.Really it should be:
Fixes 3bd32d6a2ee6 ("lib/vsprintf: Add %pfw conversion specifier forprinting fwnode names")
Yes, I consider this to be the culprit.
Quoted 1 line
Regardless, the fix should go into 5.10 and 5.14 stables.
Please add the Fixes tag and the following into the commit message:
Best Regards,
Petr