kernel_optimize_test/drivers/base
Zhang Wensheng 36ee9ffca8 driver core: fix deadlock in __device_attach
[ Upstream commit b232b02bf3c205b13a26dcec08e53baddd8e59ed ]

In __device_attach function, The lock holding logic is as follows:
...
__device_attach
device_lock(dev)      // get lock dev
  async_schedule_dev(__device_attach_async_helper, dev); // func
    async_schedule_node
      async_schedule_node_domain(func)
        entry = kzalloc(sizeof(struct async_entry), GFP_ATOMIC);
	/* when fail or work limit, sync to execute func, but
	   __device_attach_async_helper will get lock dev as
	   well, which will lead to A-A deadlock.  */
	if (!entry || atomic_read(&entry_count) > MAX_WORK) {
	  func;
	else
	  queue_work_node(node, system_unbound_wq, &entry->work)
  device_unlock(dev)

As shown above, when it is allowed to do async probes, because of
out of memory or work limit, async work is not allowed, to do
sync execute instead. it will lead to A-A deadlock because of
__device_attach_async_helper getting lock dev.

To fix the deadlock, move the async_schedule_dev outside device_lock,
as we can see, in async_schedule_node_domain, the parameter of
queue_work_node is system_unbound_wq, so it can accept concurrent
operations. which will also not change the code logic, and will
not lead to deadlock.

Fixes: 765230b5f0 ("driver-core: add asynchronous probing support for drivers")
Signed-off-by: Zhang Wensheng <zhangwensheng5@huawei.com>
Link: https://lore.kernel.org/r/20220518074516.1225580-1-zhangwensheng5@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-06-14 18:32:34 +02:00
..
firmware_loader firmware_loader: use kernel credentials when reading firmware 2022-05-18 10:23:46 +02:00
power PM: core: keep irq flags in device_pm_check_callbacks() 2022-04-08 14:40:32 +02:00
regmap regmap-irq: Update interrupt clear register for proper reset 2022-03-02 11:42:52 +01:00
test drivers/base: build kunit tests without structleak plugin 2021-03-17 17:06:24 +01:00
arch_topology.c arch_topology: Do not set llc_sibling if llc_id is invalid 2022-05-09 09:04:59 +02:00
attribute_container.c
base.h
bus.c driver: base: fix UAF when driver_attach failed 2022-06-14 18:32:34 +02:00
cacheinfo.c
class.c
component.c
container.c
core.c PM: runtime: Add safety net to supplier device release 2022-01-27 10:54:17 +01:00
cpu.c
dd.c driver core: fix deadlock in __device_attach 2022-06-14 18:32:34 +02:00
devcoredump.c
devres.c
devtmpfs.c devtmpfs regression fix: reconfigure on each mount 2022-01-20 09:17:49 +01:00
driver.c
firmware.c
hypervisor.c
init.c
isa.c
Kconfig
Makefile
map.c
memory.c drivers/base/memory: fix an unlikely reference counting issue in __add_memory_block() 2022-06-09 10:21:16 +02:00
module.c
node.c drivers/base/node.c: fix compaction sysfs file leak 2022-06-09 10:21:16 +02:00
pinctrl.c
platform-msi.c
platform.c
property.c device property: Fix fwnode_graph_devcon_match() fwnode leak 2022-01-27 10:54:25 +01:00
soc.c
swnode.c software node: fix wrong node passed to find nargs_prop 2022-01-27 10:53:59 +01:00
syscore.c
topology.c
transport_class.c