Patch "driver core: fix deadlock in __device_attach" has been added to the 5.18-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    driver core: fix deadlock in __device_attach

to the 5.18-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     driver-core-fix-deadlock-in-__device_attach.patch
and it can be found in the queue-5.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit dec336b16d3a686d2539a5400cd7bea9de096901
Author: Zhang Wensheng <zhangwensheng5@xxxxxxxxxx>
Date:   Wed May 18 15:45:16 2022 +0800

    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: 765230b5f084 ("driver-core: add asynchronous probing support for drivers")
    Signed-off-by: Zhang Wensheng <zhangwensheng5@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20220518074516.1225580-1-zhangwensheng5@xxxxxxxxxx
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 3fc3b5940bb3..ed02a529a896 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -941,6 +941,7 @@ static void __device_attach_async_helper(void *_dev, async_cookie_t cookie)
 static int __device_attach(struct device *dev, bool allow_async)
 {
 	int ret = 0;
+	bool async = false;
 
 	device_lock(dev);
 	if (dev->p->dead) {
@@ -979,7 +980,7 @@ static int __device_attach(struct device *dev, bool allow_async)
 			 */
 			dev_dbg(dev, "scheduling asynchronous probe\n");
 			get_device(dev);
-			async_schedule_dev(__device_attach_async_helper, dev);
+			async = true;
 		} else {
 			pm_request_idle(dev);
 		}
@@ -989,6 +990,8 @@ static int __device_attach(struct device *dev, bool allow_async)
 	}
 out_unlock:
 	device_unlock(dev);
+	if (async)
+		async_schedule_dev(__device_attach_async_helper, dev);
 	return ret;
 }
 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux