Skip to content

Commit

Permalink
[PATCH] uml: fix proc-vs-interrupt context spinlock deadlock
Browse files Browse the repository at this point in the history
This spinlock can be taken on interrupt too, so spin_lock_irq[save] must be
used.

However, Documentation/networking/netdevices.txt explains we are called with
rtnl_lock() held - so we don't need to care about other concurrent opens.
Verified also in LDD3 and by direct checking.  Also verified that the network
layer (through a state machine) guarantees us that nobody will close the
interface while it's being used.  Please correct me if I'm wrong.

Also, we must check we don't sleep with irqs disabled!!!  But anyway, this is
not news - we already can't sleep while holding a spinlock.  Who says this is
guaranted really by the present code?

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Jeff Garzik <jeff@garzik.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Paolo 'Blaisorblade' Giarrusso authored and Linus Torvalds committed Sep 27, 2006
1 parent 0683750 commit 48af05e
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions arch/um/drivers/net_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ static int uml_net_open(struct net_device *dev)
struct uml_net_private *lp = dev->priv;
int err;

spin_lock(&lp->lock);

if(lp->fd >= 0){
err = -ENXIO;
goto out;
Expand Down Expand Up @@ -149,8 +147,6 @@ static int uml_net_open(struct net_device *dev)
*/
while((err = uml_net_rx(dev)) > 0) ;

spin_unlock(&lp->lock);

spin_lock(&opened_lock);
list_add(&lp->list, &opened);
spin_unlock(&opened_lock);
Expand All @@ -160,7 +156,6 @@ static int uml_net_open(struct net_device *dev)
if(lp->close != NULL) (*lp->close)(lp->fd, &lp->user);
lp->fd = -1;
out:
spin_unlock(&lp->lock);
return err;
}

Expand All @@ -169,15 +164,12 @@ static int uml_net_close(struct net_device *dev)
struct uml_net_private *lp = dev->priv;

netif_stop_queue(dev);
spin_lock(&lp->lock);

free_irq(dev->irq, dev);
if(lp->close != NULL)
(*lp->close)(lp->fd, &lp->user);
lp->fd = -1;

spin_unlock(&lp->lock);

spin_lock(&opened_lock);
list_del(&lp->list);
spin_unlock(&opened_lock);
Expand Down Expand Up @@ -246,9 +238,9 @@ static int uml_net_set_mac(struct net_device *dev, void *addr)
struct uml_net_private *lp = dev->priv;
struct sockaddr *hwaddr = addr;

spin_lock(&lp->lock);
spin_lock_irq(&lp->lock);
set_ether_mac(dev, hwaddr->sa_data);
spin_unlock(&lp->lock);
spin_unlock_irq(&lp->lock);

return(0);
}
Expand All @@ -258,7 +250,7 @@ static int uml_net_change_mtu(struct net_device *dev, int new_mtu)
struct uml_net_private *lp = dev->priv;
int err = 0;

spin_lock(&lp->lock);
spin_lock_irq(&lp->lock);

new_mtu = (*lp->set_mtu)(new_mtu, &lp->user);
if(new_mtu < 0){
Expand All @@ -269,7 +261,7 @@ static int uml_net_change_mtu(struct net_device *dev, int new_mtu)
dev->mtu = new_mtu;

out:
spin_unlock(&lp->lock);
spin_unlock_irq(&lp->lock);
return err;
}

Expand Down

0 comments on commit 48af05e

Please sign in to comment.