netdev, sched/wait: Fix sleeping inside wait event
authorPeter Zijlstra <[email protected]>
Wed, 29 Oct 2014 16:04:56 +0000 (17:04 +0100)
committerIngo Molnar <[email protected]>
Tue, 4 Nov 2014 06:17:48 +0000 (07:17 +0100)
rtnl_lock_unregistering*() take rtnl_lock() -- a mutex -- inside a
wait loop. The wait loop relies on current->state to function, but so
does mutex_lock(), nesting them makes for the inner to destroy the
outer state.

Fix this using the new wait_woken() bits.

Reported-by: Fengguang Wu <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Acked-by: David S. Miller <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Cong Wang <[email protected]>
Cc: David Gibson <[email protected]>
Cc: Eric Biederman <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jamal Hadi Salim <[email protected]>
Cc: Jerry Chu <[email protected]>
Cc: Jiri Pirko <[email protected]>
Cc: John Fastabend <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Nicolas Dichtel <[email protected]>
Cc: [email protected] <[email protected]>
Cc: stephen hemminger <[email protected]>
Cc: Tom Gundersen <[email protected]>
Cc: Tom Herbert <[email protected]>
Cc: Veaceslav Falico <[email protected]>
Cc: Vlad Yasevich <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
net/core/dev.c
net/core/rtnetlink.c

index b793e3521a3631319bf4d0e7c17c0c9a933331da..c5a9d73147a6a96d577219167b18dd0c3a9bcb22 100644 (file)
@@ -7196,11 +7196,10 @@ static void __net_exit rtnl_lock_unregistering(struct list_head *net_list)
         */
        struct net *net;
        bool unregistering;
-       DEFINE_WAIT(wait);
+       DEFINE_WAIT_FUNC(wait, woken_wake_function);
 
+       add_wait_queue(&netdev_unregistering_wq, &wait);
        for (;;) {
-               prepare_to_wait(&netdev_unregistering_wq, &wait,
-                               TASK_UNINTERRUPTIBLE);
                unregistering = false;
                rtnl_lock();
                list_for_each_entry(net, net_list, exit_list) {
@@ -7212,9 +7211,10 @@ static void __net_exit rtnl_lock_unregistering(struct list_head *net_list)
                if (!unregistering)
                        break;
                __rtnl_unlock();
-               schedule();
+
+               wait_woken(&wait, TASK_UNINTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
        }
-       finish_wait(&netdev_unregistering_wq, &wait);
+       remove_wait_queue(&netdev_unregistering_wq, &wait);
 }
 
 static void __net_exit default_device_exit_batch(struct list_head *net_list)
index a6882686ca3a10fc3be7ced6299dc7385ffd239d..b095296f711f06f26d7c989699ac907a27eb073d 100644 (file)
@@ -365,11 +365,10 @@ static void rtnl_lock_unregistering_all(void)
 {
        struct net *net;
        bool unregistering;
-       DEFINE_WAIT(wait);
+       DEFINE_WAIT_FUNC(wait, woken_wake_function);
 
+       add_wait_queue(&netdev_unregistering_wq, &wait);
        for (;;) {
-               prepare_to_wait(&netdev_unregistering_wq, &wait,
-                               TASK_UNINTERRUPTIBLE);
                unregistering = false;
                rtnl_lock();
                for_each_net(net) {
@@ -381,9 +380,10 @@ static void rtnl_lock_unregistering_all(void)
                if (!unregistering)
                        break;
                __rtnl_unlock();
-               schedule();
+
+               wait_woken(&wait, TASK_UNINTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
        }
-       finish_wait(&netdev_unregistering_wq, &wait);
+       remove_wait_queue(&netdev_unregistering_wq, &wait);
 }
 
 /**