netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netconsole: don't call __netpoll_cleanup() while atomic
@ 2013-03-11 10:21 Veaceslav Falico
  2013-03-11 11:38 ` Neil Horman
  0 siblings, 1 reply; 3+ messages in thread
From: Veaceslav Falico @ 2013-03-11 10:21 UTC (permalink / raw)
  To: netdev; +Cc: amwang, davem, vfalico, nhorman

__netpoll_cleanup() is called in netconsole_netdev_event() while holding a
spinlock. Release/acquire the spinlock before/after it and restart the
loop. Also, disable the netconsole completely, because we won't have chance
after the restart of the loop, and might end up in a situation where
nt->enabled == 1 and nt->np.dev == NULL.

Signed-off-by: Veaceslav Falico <vfalico@redhat.com>
---
 drivers/net/netconsole.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 37add21..59ac143 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -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) {
@@ -678,15 +679,17 @@ static int netconsole_netdev_event(struct notifier_block *this,
 			case NETDEV_UNREGISTER:
 				/*
 				 * rtnl_lock already held
+				 * we might sleep in __netpoll_cleanup()
 				 */
-				if (nt->np.dev) {
-					__netpoll_cleanup(&nt->np);
-					dev_put(nt->np.dev);
-					nt->np.dev = NULL;
-				}
+				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;
 				nt->enabled = 0;
 				stopped = true;
-				break;
+				netconsole_target_put(nt);
+				goto restart;
 			}
 		}
 		netconsole_target_put(nt);
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] netconsole: don't call __netpoll_cleanup() while atomic
  2013-03-11 10:21 [PATCH] netconsole: don't call __netpoll_cleanup() while atomic Veaceslav Falico
@ 2013-03-11 11:38 ` Neil Horman
  2013-03-12 10:59   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Neil Horman @ 2013-03-11 11:38 UTC (permalink / raw)
  To: Veaceslav Falico; +Cc: netdev, amwang, davem

On Mon, Mar 11, 2013 at 11:21:48AM +0100, Veaceslav Falico wrote:
> __netpoll_cleanup() is called in netconsole_netdev_event() while holding a
> spinlock. Release/acquire the spinlock before/after it and restart the
> loop. Also, disable the netconsole completely, because we won't have chance
> after the restart of the loop, and might end up in a situation where
> nt->enabled == 1 and nt->np.dev == NULL.
> 
> Signed-off-by: Veaceslav Falico <vfalico@redhat.com>
> ---
>  drivers/net/netconsole.c |   15 +++++++++------
>  1 files changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index 37add21..59ac143 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -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) {
> @@ -678,15 +679,17 @@ static int netconsole_netdev_event(struct notifier_block *this,
>  			case NETDEV_UNREGISTER:
>  				/*
>  				 * rtnl_lock already held
> +				 * we might sleep in __netpoll_cleanup()
>  				 */
> -				if (nt->np.dev) {
> -					__netpoll_cleanup(&nt->np);
> -					dev_put(nt->np.dev);
> -					nt->np.dev = NULL;
> -				}
> +				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;
>  				nt->enabled = 0;
>  				stopped = true;
> -				break;
> +				netconsole_target_put(nt);
> +				goto restart;
>  			}
>  		}
>  		netconsole_target_put(nt);
> -- 
> 1.7.1
> 
> 
Acked-by: Neil Horman <nhorman@tuxdriver.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] netconsole: don't call __netpoll_cleanup() while atomic
  2013-03-11 11:38 ` Neil Horman
@ 2013-03-12 10:59   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2013-03-12 10:59 UTC (permalink / raw)
  To: nhorman; +Cc: vfalico, netdev, amwang

From: Neil Horman <nhorman@tuxdriver.com>
Date: Mon, 11 Mar 2013 07:38:56 -0400

> On Mon, Mar 11, 2013 at 11:21:48AM +0100, Veaceslav Falico wrote:
>> __netpoll_cleanup() is called in netconsole_netdev_event() while holding a
>> spinlock. Release/acquire the spinlock before/after it and restart the
>> loop. Also, disable the netconsole completely, because we won't have chance
>> after the restart of the loop, and might end up in a situation where
>> nt->enabled == 1 and nt->np.dev == NULL.
>> 
>> Signed-off-by: Veaceslav Falico <vfalico@redhat.com>
 ...
> Acked-by: Neil Horman <nhorman@tuxdriver.com>

Applied.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-03-12 10:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-11 10:21 [PATCH] netconsole: don't call __netpoll_cleanup() while atomic Veaceslav Falico
2013-03-11 11:38 ` Neil Horman
2013-03-12 10:59   ` David Miller

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).