linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Peter Zijlstra <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: mingo@kernel.org, edumazet@google.com,
	david@gibson.dropbear.id.au, linux-kernel@vger.kernel.org,
	peterz@infradead.org, tglx@linutronix.de, jhs@mojatatu.com,
	teg@jklm.no, nicolas.dichtel@6wind.com, cwang@twopensource.com,
	vyasevic@redhat.com, ebiederm@xmission.com, jiri@resnulli.us,
	vfalico@gmail.com, oleg@redhat.com,
	torvalds@linux-foundation.org, hkchu@google.com,
	stephen@networkplumber.org, john.fastabend@gmail.com,
	therbert@google.com, fengguang.wu@intel.com,
	sfeldma@cumulusnetworks.com, davem@davemloft.net, hpa@zytor.com
Subject: [tip:sched/core] netdev, sched/wait: Fix sleeping inside wait event
Date: Tue, 4 Nov 2014 08:09:20 -0800	[thread overview]
Message-ID: <tip-ff960a731788a7408b6f66ec4fd772ff18833211@git.kernel.org> (raw)
In-Reply-To: <20141029173110.GE15602@worktop.programming.kicks-ass.net>

Commit-ID:  ff960a731788a7408b6f66ec4fd772ff18833211
Gitweb:     http://git.kernel.org/tip/ff960a731788a7408b6f66ec4fd772ff18833211
Author:     Peter Zijlstra <peterz@infradead.org>
AuthorDate: Wed, 29 Oct 2014 17:04:56 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 4 Nov 2014 07:17:48 +0100

netdev, sched/wait: Fix sleeping inside wait event

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 <fengguang.wu@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: David S. Miller <davem@davemloft.net>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Cong Wang <cwang@twopensource.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Jerry Chu <hkchu@google.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Cc: sfeldma@cumulusnetworks.com <sfeldma@cumulusnetworks.com>
Cc: stephen hemminger <stephen@networkplumber.org>
Cc: Tom Gundersen <teg@jklm.no>
Cc: Tom Herbert <therbert@google.com>
Cc: Veaceslav Falico <vfalico@gmail.com>
Cc: Vlad Yasevich <vyasevic@redhat.com>
Cc: netdev@vger.kernel.org
Link: http://lkml.kernel.org/r/20141029173110.GE15602@worktop.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 net/core/dev.c       | 10 +++++-----
 net/core/rtnetlink.c | 10 +++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index b793e35..c5a9d73 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -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)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index a688268..b095296 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -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);
 }
 
 /**

  parent reply	other threads:[~2014-11-04 16:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-28 14:25 WARNING: CPU: 0 PID: 61 at kernel/sched/core.c:7312 __might_sleep() Fengguang Wu
2014-10-29 16:16 ` [PATCH] netdev: Fix sleeping inside wait event Peter Zijlstra
2014-10-29 16:29   ` Cong Wang
2014-10-29 17:13     ` Peter Zijlstra
2014-10-29 17:31       ` Peter Zijlstra
2014-10-29 17:38         ` David Miller
2014-11-04 16:09         ` tip-bot for Peter Zijlstra [this message]
2014-10-29 17:37   ` David Miller
2015-02-01  3:43 ` __might_sleep() warnings on v3.19-rc6 Fengguang Wu
2015-02-01 23:03   ` NeilBrown
2015-02-02  4:58     ` NeilBrown
2015-02-02  5:08     ` Linus Torvalds
2015-02-02  6:09       ` NeilBrown
2015-02-05 16:16   ` Chris Mason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-ff960a731788a7408b6f66ec4fd772ff18833211@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=cwang@twopensource.com \
    --cc=davem@davemloft.net \
    --cc=david@gibson.dropbear.id.au \
    --cc=ebiederm@xmission.com \
    --cc=edumazet@google.com \
    --cc=fengguang.wu@intel.com \
    --cc=hkchu@google.com \
    --cc=hpa@zytor.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=john.fastabend@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=nicolas.dichtel@6wind.com \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sfeldma@cumulusnetworks.com \
    --cc=stephen@networkplumber.org \
    --cc=teg@jklm.no \
    --cc=tglx@linutronix.de \
    --cc=therbert@google.com \
    --cc=torvalds@linux-foundation.org \
    --cc=vfalico@gmail.com \
    --cc=vyasevic@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).