linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paolo 'Blaisorblade' Giarrusso" <blaisorblade@yahoo.it>
To: Andrew Morton <akpm@osdl.org>
Cc: Jeff Dike <jdike@addtoit.com>,
	linux-kernel@vger.kernel.org,
	user-mode-linux-devel@lists.sourceforge.net
Subject: [PATCH 4/9] uml: fix spinlock recursion and sleep-inside-spinlock in error path
Date: Wed, 18 Jan 2006 01:19:33 +0100	[thread overview]
Message-ID: <20060118001931.14622.17211.stgit@zion.home.lan> (raw)
In-Reply-To: <20060117235659.14622.18544.stgit@zion.home.lan>


From: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>

In this error path, when the interface has had a problem, we call dev_close(),
which is disallowed for two reasons:

*) takes again the UML internal spinlock, inside the ->stop method of this
   device
*) can be called in process context only, while we're in interrupt context.

I've also thought that calling dev_close() may be a wrong policy to follow, but
it's not up to me to decide that.

However, we may end up with multiple dev_close() queued on the same device.
But the initial test for (dev->flags & IFF_UP) makes this harmless, though -
and dev_close() is supposed to care about races with itself. So there's no harm
in delaying the shutdown, IMHO.

Something to mark the interface as "going to shutdown" would be appreciated, but
dev_deactivate has the same problems as dev_close(), so we can't use it either.

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
---

 arch/um/drivers/net_kern.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
index 98350bb..178f68b 100644
--- a/arch/um/drivers/net_kern.c
+++ b/arch/um/drivers/net_kern.c
@@ -68,6 +68,11 @@ static int uml_net_rx(struct net_device 
 	return pkt_len;
 }
 
+static void uml_dev_close(void* dev)
+{
+	dev_close( (struct net_device *) dev);
+}
+
 irqreturn_t uml_net_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
 	struct net_device *dev = dev_id;
@@ -80,15 +85,21 @@ irqreturn_t uml_net_interrupt(int irq, v
 	spin_lock(&lp->lock);
 	while((err = uml_net_rx(dev)) > 0) ;
 	if(err < 0) {
+		DECLARE_WORK(close_work, uml_dev_close, dev);
 		printk(KERN_ERR 
 		       "Device '%s' read returned %d, shutting it down\n", 
 		       dev->name, err);
-		dev_close(dev);
+		/* dev_close can't be called in interrupt context, and takes
+		 * again lp->lock.
+		 * And dev_close() can be safely called multiple times on the
+		 * same device, since it tests for (dev->flags & IFF_UP). So
+		 * there's no harm in delaying the device shutdown. */
+		schedule_work(&close_work);
 		goto out;
 	}
 	reactivate_fd(lp->fd, UM_ETH_IRQ);
 
- out:
+out:
 	spin_unlock(&lp->lock);
 	return(IRQ_HANDLED);
 }


  parent reply	other threads:[~2006-01-18  0:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20060117235659.14622.18544.stgit@zion.home.lan>
2006-01-18  0:19 ` [PATCH 1/9] uml: avoid sysfs warning on hot-unplug Paolo 'Blaisorblade' Giarrusso
2006-01-18  2:53   ` Jeff Dike
2006-01-18 11:11     ` Blaisorblade
2006-01-18  0:19 ` [PATCH 2/9] uml: make daemon transport behave properly Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:19 ` [PATCH 3/9] uml: networking - clear transport-specific structure Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:19 ` Paolo 'Blaisorblade' Giarrusso [this message]
2006-01-18  0:52   ` [PATCH 4/9] uml: fix spinlock recursion and sleep-inside-spinlock in error path Andrew Morton
2006-01-18 11:44     ` [uml-devel] " Blaisorblade
2006-01-18  0:19 ` [PATCH 5/9] uml: sigio code - reduce spinlock hold time Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:19 ` [PATCH 6/9] uml: avoid malloc to sleep in atomic sections Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:56   ` Andrew Morton
2006-01-18 11:47     ` Blaisorblade
2006-01-18  0:19 ` [PATCH 7/9] uml: arch Kconfig menu cleanups Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:19 ` [PATCH 8/9] uml: allow again to move backing file and to override saved location Paolo 'Blaisorblade' Giarrusso
2006-01-18  0:19 ` [PATCH 9/9] uml ubd code: fix a bit of whitespace Paolo 'Blaisorblade' Giarrusso

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=20060118001931.14622.17211.stgit@zion.home.lan \
    --to=blaisorblade@yahoo.it \
    --cc=akpm@osdl.org \
    --cc=jdike@addtoit.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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).