netconsole: release the spinlock before __netpoll_cleanup()
Subsystems (3)
PATCH 1/1 netconsole: release the spinlock before __netpoll_cleanup()
Commit 3335f0ca130c201f8680e97f63612053fbc16e22 removed spinlock unlocking before __netpoll_cleanup() in netconsole_netdev_event(), however we still might sleep in __netpoll_cleanup() - via synchronize_srcu(). Revert it and add a comment.
--- drivers/net/netconsole.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/net/netconsole.c +10 -0
@@ -680,7 +680,17 @@ static int netconsole_netdev_event(struct notifier_block *this,* rtnl_lock already held */ if (nt->np.dev) { +/* +* we still might sleep in +* __netpoll_cleanup(), so release +* the lock +*/ +spin_unlock_irqrestore ( + &target_list_lock, + flags);__netpoll_cleanup (&nt->np); +spin_lock_irqsave (&target_list_lock, + flags);dev_put (nt->np.dev); nt->np.dev =NULL ; }
Signature · 1 line
1.7.1
Quoted 5 lines · Veaceslav Falico
Commit
3335f0ca130c201f8680e97f63612053fbc16e22removed spinlock unlocking before__netpoll_cleanup()innetconsole_netdev_event(), however we still might sleep in__netpoll_cleanup()- viasynchronize_srcu(). Revert it and add a comment.
synchronize_srcu() was actually introduced by Neil:
commit ca99ca14c95ae49fb4c9cd3abf5f84d11a7e8a61
Author: Neil Horman <[email protected]> Date: Tue Feb 5 08:05:43 2013 +0000
netpoll: protect napi_poll and poll_controller during dev_[open|
close]
Cc'ing him.
Quoted 35 lines · Veaceslav Falico
Commit
3335f0ca130c201f8680e97f63612053fbc16e22removed spinlock unlocking before__netpoll_cleanup()innetconsole_netdev_event(), however we still might sleep in__netpoll_cleanup()- viasynchronize_srcu(). Revert it and add a comment.Signed-off-by Veaceslav Falico <[email protected]>--- drivers/net/netconsole.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)drivers/net/netconsole.c +10
-0@@ -680,7 +680,17 @@ static int netconsole_netdev_event(struct notifier_block *this,* rtnl_lock already held */ if (nt->np.dev) { +/* +* we still might sleep in +* __netpoll_cleanup(), so release +* the lock +*/ +spin_unlock_irqrestore ( + &target_list_lock, + flags);__netpoll_cleanup (&nt->np); +spin_lock_irqsave (&target_list_lock, + flags);dev_put (nt->np.dev); nt->np.dev =NULL ; }Signature · 1 line
1.7.1
Thanks for noticing this Vaeceslav, but you can't just drop and re-acquire the lock like this, as it protect the list_for_each_entry loop that you're in. You can drop the lock in the above if clause, but then, after the nt->np.dev = NULL, go back an re-aquire the lock, and start the for loop. I thought we had already done this for some other purpose in this code using a label and a goto, but I suppose I was mistaken
Best
Neil
Quoted 1 line
Quoted 34 lines · Neil Horman
Quoted 33 lines · Veaceslav Falico
Commit
3335f0ca130c201f8680e97f63612053fbc16e22removed spinlock unlocking before__netpoll_cleanup()innetconsole_netdev_event(), however we still might sleep in__netpoll_cleanup()- viasynchronize_srcu(). Revert it and add a comment.Signed-off-by Veaceslav Falico <[email protected]>--- drivers/net/netconsole.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)drivers/net/netconsole.c +10
-1@@ -680,7 +680,17 @@ static int netconsole_netdev_event(struct notifier_block *this,* rtnl_lock already held */ if (nt->np.dev) { +/* +* we still might sleep in +* __netpoll_cleanup(), so release +* the lock +*/ +spin_unlock_irqrestore ( + &target_list_lock, + flags);__netpoll_cleanup (&nt->np); +spin_lock_irqsave (&target_list_lock, + flags);dev_put (nt->np.dev); nt->np.dev =NULL ; } --
Quoted 8 lines
Quoted 2 lines
1.7.1
Thanks for noticing this Vaeceslav, but you can't just drop and re-acquire the lock like this, as it protect the
list_for_each_entryloop that you're in. You can drop the lock in the above if clause, but then, after thent->np.dev= NULL, go back an re-aquire the lock, and start the for loop. I thought we had already done this for some other purpose in this code using a label and a goto, but I suppose I was mistaken
You're right, I somehow missed that restart goto, which was removed earlier. Does that feel right (I've also added back the netconsole_target_put()):
Subject: [PATCH] netconsole: release the spinlock before __netpoll_cleanup()
__netpoll_cleanup() might sleep in synchronize_srcu(), which was added to avoid race in another situation, so we can't call it with the spinlock target_list_lock held.
Add spin_unlock/lock before/after it and restart the loop.
--- drivers/net/netconsole.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
drivers/net/netconsole.c +13 -0
@@ -666,6 +666,7 @@ static int netconsole_netdev_event(struct notifier_block *this, goto done;spin_lock_irqsave (&target_list_lock, flags); +restart:list_for_each_entry (nt, &target_list, list) {netconsole_target_get (nt);if (nt->np.dev == dev) {
@@ -680,9 +681,21 @@ static int netconsole_netdev_event(struct notifier_block *this,* rtnl_lock already held */ if (nt->np.dev) { +/* +* we still might sleep in +* __netpoll_cleanup(), so release +* the lock and restart +*/ +spin_unlock_irqrestore ( + &target_list_lock, + flags);__netpoll_cleanup (&nt->np); +spin_lock_irqsave (&target_list_lock, + flags);dev_put (nt->np.dev); nt->np.dev =NULL ; +netconsole_target_put (nt); + goto restart; } nt->enabled =0 ; stopped = true;
Signature · 1 line
1.7.1
Neil Horman
Acked-byQuoted 97 lines · Veaceslav Falico
Quoted 34 lines · Neil Horman
Quoted 33 lines · Veaceslav Falico
Commit
3335f0ca130c201f8680e97f63612053fbc16e22removed spinlock unlocking before__netpoll_cleanup()innetconsole_netdev_event(), however we still might sleep in__netpoll_cleanup()- viasynchronize_srcu(). Revert it and add a comment.Signed-off-by Veaceslav Falico <[email protected]>---
drivers/net/netconsole.c| 10 ++++++++++1 files changed, 10 insertions(+), 0 deletions(-)drivers/net/netconsole.c +10
-1@@ -680,7 +680,17 @@ static int netconsole_netdev_event(struct notifier_block *this,* rtnl_lock already held */ if (nt->np.dev) { +/* +* we still might sleep in +* __netpoll_cleanup(), so release +* the lock +*/ +spin_unlock_irqrestore ( + &target_list_lock, + flags);__netpoll_cleanup (&nt->np); +spin_lock_irqsave (&target_list_lock, + flags);dev_put (nt->np.dev); nt->np.dev =NULL ; } --Quoted 8 lines
Quoted 2 lines
1.7.1
Thanks for noticing this Vaeceslav, but you can't just drop and re-acquire the lock like this, as it protect the
list_for_each_entryloop that you're in. You can drop the lock in the above if clause, but then, after thent->np.dev= NULL, go back an re-aquire the lock, and start the for loop. I thought we had already done this for some other purpose in this code using a label and a goto, but I suppose I was mistakenYou're right, I somehow missed that restart goto, which was removed earlier. Does that feel right (I've also added back the
netconsole_target_put()):Subject: [PATCH] netconsole: release the spinlock before
__netpoll_cleanup()
__netpoll_cleanup()might sleep insynchronize_srcu(), which was added to avoid race in another situation, so we can't call it with the spinlocktarget_list_lockheld.Add spin_unlock/lock before/after it and restart the loop.
Signed-off-by Veaceslav Falico <[email protected]>--- drivers/net/netconsole.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)drivers/net/netconsole.c +13
-0@@ -666,6 +666,7 @@ static int netconsole_netdev_event(struct notifier_block *this, goto done;spin_lock_irqsave (&target_list_lock, flags); +restart:list_for_each_entry (nt, &target_list, list) {netconsole_target_get (nt);if (nt->np.dev == dev) {@@ -680,9 +681,21 @@ static int netconsole_netdev_event(struct notifier_block *this,* rtnl_lock already held */ if (nt->np.dev) { +/* +* we still might sleep in +* __netpoll_cleanup(), so release +* the lock and restart +*/ +spin_unlock_irqrestore ( + &target_list_lock, + flags);__netpoll_cleanup (&nt->np); +spin_lock_irqsave (&target_list_lock, + flags);dev_put (nt->np.dev); nt->np.dev =NULL ; +netconsole_target_put (nt); + goto restart; } nt->enabled =0 ; stopped = true;Signature · 1 line
1.7.1
Yes, this looks better, thank you.
David Miller
maintainerFrom: Veaceslav Falico <[email protected]>
Date: Thu, 7 Mar 2013 11:03:25 +0100
drivers/net/netconsole.c static int netconsole_netdev_event(struct · line 688
Quoted 9 lines
drivers/net/netconsole.c +4
-0@@ -680,9 +681,21 @@ static int netconsole_netdev_event(structnotifier_block *this, * rtnl_lock already held */ if (nt->np.dev) { +/* +* we still might sleep in +* __netpoll_cleanup(), so release +* the lock and restart
Quite a bit of email corruption of this patch.
Also, this code block is probably too deeply indented to be sane, consider creating a small helper function to call instead.
Quoted 14 lines · David Miller
From: Veaceslav Falico <[email protected]>
Date: Thu, 7 Mar 2013 11:03:25 +0100Review static int netconsole_netdev_event(struct · line 688
Quoted 9 lines
(quoted diff) +4
-0@@ -680,9 +681,21 @@ static int netconsole_netdev_event(struct notifier_block *this, * rtnl_lock already held */ if (nt->np.dev) { + /* + * we still might sleep in + * __netpoll_cleanup(), so release + * the lock and restartQuite a bit of email corruption of this patch.
Sorry, somehow messed it.
Quoted 3 lines
Also, this code block is probably too deeply indented to be sane, consider creating a small helper function to call instead.
It gets quite ugly if I try to move it to another function. However, maybe something like that will work - it's effectively the same code, just that I've moved the long part out of the if () { } block. Looks a lot more readable, though one line still breaks 80chars limit. I've reworked the subject/commit message too.
Subject: [PATCH] netconsole: don't call __netpoll_cleanup() while atomic
__netpoll_cleanup() is called in netconsole_netdev_event() while holding a spinlock. Release/acquire the spinlock before/after it and restart the loop.
--- drivers/net/netconsole.c | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-)
drivers/net/netconsole.c +15 -7
@@ -666,6 +666,7 @@ static int netconsole_netdev_event(struct notifier_block *this, goto done;spin_lock_irqsave (&target_list_lock, flags); +restart:list_for_each_entry (nt, &target_list, list) {netconsole_target_get (nt);if (nt->np.dev == dev) {
@@ -679,14 +680,21 @@ static int netconsole_netdev_event(struct notifier_block *this,/* * rtnl_lock already held */ -if (nt->np.dev) { -__netpoll_cleanup (&nt->np); -dev_put (nt->np.dev); - nt->np.dev =NULL ; +if (!nt->np.dev) { + nt->enabled =0 ; + stopped = true; +break ; } - nt->enabled =0 ; - stopped = true; -break ; +/* +* we might sleep in __netpoll_cleanup() +*/ +spin_unlock_irqrestore (&target_list_lock, flags); +__netpoll_cleanup (&nt->np); +spin_lock_irqsave (&target_list_lock, flags); +dev_put (nt->np.dev); + nt->np.dev =NULL ; +netconsole_target_put (nt); + goto restart; } }netconsole_target_put (nt);
Signature · 1 line
1.7.1
Quoted 2 lines · Veaceslav Falico
Quoted 1 line · David Miller
...snip...
Quoted 76 lines
Quoted 1 line
Quite a bit of email corruption of this patch.
Sorry, somehow messed it.
Quoted 3 lines
Also, this code block is probably too deeply indented to be sane, consider creating a small helper function to call instead.
It gets quite ugly if I try to move it to another function. However, maybe something like that will work - it's effectively the same code, just that I've moved the long part out of the if () { } block. Looks a lot more readable, though one line still breaks 80chars limit. I've reworked the subject/commit message too.
Subject: [PATCH] netconsole: don't call
__netpoll_cleanup()while atomic
__netpoll_cleanup()is called innetconsole_netdev_event()while holding a spinlock. Release/acquire the spinlock before/after it and restart theloop.
Signed-off-by Veaceslav Falico <[email protected]>--- drivers/net/netconsole.c | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-)drivers/net/netconsole.c +15
-8@@ -666,6 +666,7 @@ static int netconsole_netdev_event(struct notifier_block *this, goto done;spin_lock_irqsave (&target_list_lock, flags); +restart:list_for_each_entry (nt, &target_list, list) {netconsole_target_get (nt);if (nt->np.dev == dev) {@@ -679,14 +680,21 @@ static int netconsole_netdev_event(struct notifier_block *this,/* * rtnl_lock already held */ - if (nt->np.dev) { -__netpoll_cleanup (&nt->np); -dev_put (nt->np.dev); - nt->np.dev =NULL ; + if (!nt->np.dev) { + nt->enabled =0 ; + stopped = true; +break ; } - nt->enabled =0 ; - stopped = true; -break ; +/* +* we might sleep in __netpoll_cleanup() +*/ +spin_unlock_irqrestore (&target_list_lock, flags); +__netpoll_cleanup (&nt->np); +spin_lock_irqsave (&target_list_lock, flags); +dev_put (nt->np.dev); + nt->np.dev =NULL ; +netconsole_target_put (nt); + goto restart; } }netconsole_target_put (nt); --
Quoted 1 line
1.7.1
Self-NAK this patch, I've triggered another kernel panic with it. Will send another one shortly. Basicly, the whole if (!nt->np.dev) is not needed and nt->enabled=0 should always be set, otherwise we end up with nt->np.dev == NULL and nt->enabled == 1, thus triggering panics in places like write_msg(), where it verifies only if the nt->enabled is true.
Signature · 2 lines
Best regards, Veaceslav Falico
Quoted 74 lines · Veaceslav Falico
Quoted 2 lines · Veaceslav Falico
Quoted 1 line · David Miller
...snip...
Quoted 70 lines
Quoted 1 line
Quite a bit of email corruption of this patch.
Sorry, somehow messed it.
Quoted 3 lines
Also, this code block is probably too deeply indented to be sane, consider creating a small helper function to call instead.
It gets quite ugly if I try to move it to another function. However, maybe something like that will work - it's effectively the same code, just that I've moved the long part out of the if () { } block. Looks a lot more readable, though one line still breaks 80chars limit. I've reworked the subject/commit message too.
Subject: [PATCH] netconsole: don't call
__netpoll_cleanup()while atomic
__netpoll_cleanup()is called innetconsole_netdev_event()while holding a spinlock. Release/acquire the spinlock before/after it and restart theloop.
Signed-off-by Veaceslav Falico <[email protected]>--- drivers/net/netconsole.c | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-)drivers/net/netconsole.c +13
-7@@ -666,6 +666,7 @@ static int netconsole_netdev_event(struct notifier_block *this, goto done;spin_lock_irqsave (&target_list_lock, flags); +restart:list_for_each_entry (nt, &target_list, list) {netconsole_target_get (nt);if (nt->np.dev == dev) {@@ -679,14 +680,21 @@ static int netconsole_netdev_event(struct notifier_block *this,/* * rtnl_lock already held */ - if (nt->np.dev) { -__netpoll_cleanup (&nt->np); -dev_put (nt->np.dev); - nt->np.dev =NULL ; + if (!nt->np.dev) { + nt->enabled =0 ; + stopped = true; +break ; } - nt->enabled =0 ; - stopped = true; -break ; +/* +* we might sleep in __netpoll_cleanup() +*/ +spin_unlock_irqrestore (&target_list_lock, flags); +__netpoll_cleanup (&nt->np); +spin_lock_irqsave (&target_list_lock, flags); +dev_put (nt->np.dev); + nt->np.dev =NULL ;
Quoted 15 lines
Quoted 7 lines
drivers/net/netconsole.c +2
-0+netconsole_target_put (nt); + goto restart;} } netconsole_target_put(nt);--
1.7.1Self-NAK this patch, I've triggered another kernel panic with it. Will send another one shortly. Basicly, the whole if (!nt->np.dev) is not needed and nt->enabled=0 should always be set, otherwise we end up with
nt->np.dev== NULL andnt->enabled== 1, thus triggering panics in places likewrite_msg(), where it verifies only if thent->enabledis true.
Yup, I think you want to make the nt->enabled and stopped statements unconditional, and precedede the whole block with a if(!nt->np.dev) { continue;} statement.
Neil
Quoted 4 lines
Signature · 2 lines
Best regards, Veaceslav Falico
Quoted 90 lines · Neil Horman
Quoted 74 lines · Veaceslav Falico
Quoted 2 lines · Veaceslav Falico
Quoted 1 line · David Miller
...snip...
Quoted 70 lines
Quoted 1 line
Quite a bit of email corruption of this patch.
Sorry, somehow messed it.
Quoted 3 lines
Also, this code block is probably too deeply indented to be sane, consider creating a small helper function to call instead.
It gets quite ugly if I try to move it to another function. However, maybe something like that will work - it's effectively the same code, just that I've moved the long part out of the if () { } block. Looks a lot more readable, though one line still breaks 80chars limit. I've reworked the subject/commit message too.
Subject: [PATCH] netconsole: don't call
__netpoll_cleanup()while atomic
__netpoll_cleanup()is called innetconsole_netdev_event()while holding a spinlock. Release/acquire the spinlock before/after it and restart theloop.
Signed-off-by Veaceslav Falico <[email protected]>--- drivers/net/netconsole.c | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-)drivers/net/netconsole.c +13
-7@@ -666,6 +666,7 @@ static int netconsole_netdev_event(struct notifier_block *this, goto done;spin_lock_irqsave (&target_list_lock, flags); +restart:list_for_each_entry (nt, &target_list, list) {netconsole_target_get (nt);if (nt->np.dev == dev) {@@ -679,14 +680,21 @@ static int netconsole_netdev_event(struct notifier_block *this,/* * rtnl_lock already held */ - if (nt->np.dev) { -__netpoll_cleanup (&nt->np); -dev_put (nt->np.dev); - nt->np.dev =NULL ; + if (!nt->np.dev) { + nt->enabled =0 ; + stopped = true; +break ; } - nt->enabled =0 ; - stopped = true; -break ; +/* +* we might sleep in __netpoll_cleanup() +*/ +spin_unlock_irqrestore (&target_list_lock, flags); +__netpoll_cleanup (&nt->np); +spin_lock_irqsave (&target_list_lock, flags); +dev_put (nt->np.dev); + nt->np.dev =NULL ;Quoted 15 lines
Quoted 7 lines
drivers/net/netconsole.c +2
-0+netconsole_target_put (nt); + goto restart;} } netconsole_target_put(nt);--
1.7.1Self-NAK this patch, I've triggered another kernel panic with it. Will send another one shortly. Basicly, the whole if (!nt->np.dev) is not needed and nt->enabled=0 should always be set, otherwise we end up with
nt->np.dev== NULL andnt->enabled== 1, thus triggering panics in places likewrite_msg(), where it verifies only if thent->enabledis true.
Quoted 3 lines
Yup, I think you want to make the
nt->enabledand stopped statements unconditional, and precedede the whole block with aif(!nt->np.dev){ continue;} statement.
I don't see why the statement is needed at all, if we verify it beforehand:
669 list_for_each_entry(nt, &target_list, list) {
670 netconsole_target_get(nt);
671 if (nt->np.dev == dev) {
so that effectively it can be null only in case the dev, delivered via netconsole_netdev_event() is null, which is a bug by itself. Or am I missing something?
Quoted 6 lines
Neil
Quoted 4 lines
--
Best regards,
Veaceslav Falico
Quoted 97 lines · Veaceslav Falico
Quoted 90 lines · Neil Horman
Quoted 74 lines · Veaceslav Falico
Quoted 2 lines · Veaceslav Falico
Quoted 1 line · David Miller
...snip...
Quoted 70 lines
Quoted 1 line
Quite a bit of email corruption of this patch.
Sorry, somehow messed it.
Quoted 3 lines
Also, this code block is probably too deeply indented to be sane, consider creating a small helper function to call instead.
It gets quite ugly if I try to move it to another function. However, maybe something like that will work - it's effectively the same code, just that I've moved the long part out of the if () { } block. Looks a lot more readable, though one line still breaks 80chars limit. I've reworked the subject/commit message too.
Subject: [PATCH] netconsole: don't call
__netpoll_cleanup()while atomic
__netpoll_cleanup()is called innetconsole_netdev_event()while holding a spinlock. Release/acquire the spinlock before/after it and restart theloop.
Signed-off-by Veaceslav Falico <[email protected]>--- drivers/net/netconsole.c | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-)drivers/net/netconsole.c +13
-7@@ -666,6 +666,7 @@ static int netconsole_netdev_event(struct notifier_block *this, goto done;spin_lock_irqsave (&target_list_lock, flags); +restart:list_for_each_entry (nt, &target_list, list) {netconsole_target_get (nt);if (nt->np.dev == dev) {@@ -679,14 +680,21 @@ static int netconsole_netdev_event(struct notifier_block *this,/* * rtnl_lock already held */ - if (nt->np.dev) { -__netpoll_cleanup (&nt->np); -dev_put (nt->np.dev); - nt->np.dev =NULL ; + if (!nt->np.dev) { + nt->enabled =0 ; + stopped = true; +break ; } - nt->enabled =0 ; - stopped = true; -break ; +/* +* we might sleep in __netpoll_cleanup() +*/ +spin_unlock_irqrestore (&target_list_lock, flags); +__netpoll_cleanup (&nt->np); +spin_lock_irqsave (&target_list_lock, flags); +dev_put (nt->np.dev); + nt->np.dev =NULL ;Quoted 15 lines
Quoted 7 lines
drivers/net/netconsole.c +2
-0+netconsole_target_put (nt); + goto restart;} } netconsole_target_put(nt);--
1.7.1Self-NAK this patch, I've triggered another kernel panic with it. Will send another one shortly. Basicly, the whole if (!nt->np.dev) is not needed and nt->enabled=0 should always be set, otherwise we end up with
nt->np.dev== NULL andnt->enabled== 1, thus triggering panics in places likewrite_msg(), where it verifies only if thent->enabledis true.Quoted 3 lines
Yup, I think you want to make the
nt->enabledand stopped statements unconditional, and precedede the whole block with aif(!nt->np.dev){ continue;} statement.I don't see why the statement is needed at all, if we verify it beforehand:
Quoted 8 lines
669
list_for_each_entry(nt, &target_list, list){
670netconsole_target_get(nt);
671 if (nt->np.dev== dev) {so that effectively it can be null only in case the dev, delivered via
netconsole_netdev_event()is null, which is a bug by itself. Or am I missing something?
Honestly, I'm not sure. After I sent this, I took a look at the history to refresh my memory, and I think your right, its not needed.
Neil
Quoted 7 lines
Quoted 6 lines
Neil
Quoted 4 lines
--
Best regards,
Veaceslav Falico