LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] mv643xx_eth: Fix race condition in mv643xx_eth_free_tx_descs
@ 2007-01-23 16:52 Dale Farnsworth
  2007-01-23 17:02 ` Thibaut VARENE
  2007-01-23 21:29 ` Jeff Garzik
  0 siblings, 2 replies; 3+ messages in thread
From: Dale Farnsworth @ 2007-01-23 16:52 UTC (permalink / raw)
  To: Jeff Garzik
  Cc: Thibaut VARENE, Jarek Poplawski, mlachwani, netdev, linux-kernel

>From Dale Farnsworth <dale@farnsworth.org>

mv643xx_eth: Fix race condition in mv643xx_eth_free_tx_descs

This bug was found and isolated by Thibaut VARENE <T-Bone@parisc-linux.org>
and Jarek Poplawski <jarkao2@o2.pl>.  This patch is a modification of their
fixes.  We acquire and release the lock for each descriptor that is freed
to minimize the time the lock is held.

---

 drivers/net/mv643xx_eth.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index c41ae42..b3bf864 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -314,6 +314,13 @@ int mv643xx_eth_free_tx_descs(struct net
 
 	while (mp->tx_desc_count > 0) {
 		spin_lock_irqsave(&mp->lock, flags);
+
+		/* tx_desc_count might have changed before acquiring the lock */
+		if (mp->tx_desc_count <= 0) {
+			spin_unlock_irqrestore(&mp->lock, flags);
+			return released;
+		}
+
 		tx_index = mp->tx_used_desc_q;
 		desc = &mp->p_tx_desc_area[tx_index];
 		cmd_sts = desc->cmd_sts;
@@ -332,13 +339,13 @@ int mv643xx_eth_free_tx_descs(struct net
 		if (skb)
 			mp->tx_skb[tx_index] = NULL;
 
-		spin_unlock_irqrestore(&mp->lock, flags);
-
 		if (cmd_sts & ETH_ERROR_SUMMARY) {
 			printk("%s: Error in TX\n", dev->name);
 			mp->stats.tx_errors++;
 		}
 
+		spin_unlock_irqrestore(&mp->lock, flags);
+
 		if (cmd_sts & ETH_TX_FIRST_DESC)
 			dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE);
 		else

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

* Re: [PATCH] mv643xx_eth: Fix race condition in mv643xx_eth_free_tx_descs
  2007-01-23 16:52 [PATCH] mv643xx_eth: Fix race condition in mv643xx_eth_free_tx_descs Dale Farnsworth
@ 2007-01-23 17:02 ` Thibaut VARENE
  2007-01-23 21:29 ` Jeff Garzik
  1 sibling, 0 replies; 3+ messages in thread
From: Thibaut VARENE @ 2007-01-23 17:02 UTC (permalink / raw)
  To: Dale Farnsworth
  Cc: Jeff Garzik, Jarek Poplawski, mlachwani, netdev, linux-kernel

On 1/23/07, Dale Farnsworth <dale@farnsworth.org> wrote:
> From Dale Farnsworth <dale@farnsworth.org>
>
> mv643xx_eth: Fix race condition in mv643xx_eth_free_tx_descs
>
> This bug was found and isolated by Thibaut VARENE <T-Bone@parisc-linux.org>
> and Jarek Poplawski <jarkao2@o2.pl>.  This patch is a modification of their
> fixes.  We acquire and release the lock for each descriptor that is freed
> to minimize the time the lock is held.
>
> ---
>
>  drivers/net/mv643xx_eth.c |   11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
> index c41ae42..b3bf864 100644
> --- a/drivers/net/mv643xx_eth.c
> +++ b/drivers/net/mv643xx_eth.c
> @@ -332,13 +339,13 @@ int mv643xx_eth_free_tx_descs(struct net
>                 if (skb)
>                         mp->tx_skb[tx_index] = NULL;
>
> -               spin_unlock_irqrestore(&mp->lock, flags);
> -
>                 if (cmd_sts & ETH_ERROR_SUMMARY) {
>                         printk("%s: Error in TX\n", dev->name);
>                         mp->stats.tx_errors++;
>                 }

Note that this printk probably won't show immediately because IRQs are
disabled. But that's maybe not a big deal.

HTH

-- 
Thibaut VARENE
http://www.parisc-linux.org/~varenet/

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

* Re: [PATCH] mv643xx_eth: Fix race condition in mv643xx_eth_free_tx_descs
  2007-01-23 16:52 [PATCH] mv643xx_eth: Fix race condition in mv643xx_eth_free_tx_descs Dale Farnsworth
  2007-01-23 17:02 ` Thibaut VARENE
@ 2007-01-23 21:29 ` Jeff Garzik
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Garzik @ 2007-01-23 21:29 UTC (permalink / raw)
  To: Dale Farnsworth
  Cc: Thibaut VARENE, Jarek Poplawski, mlachwani, netdev, linux-kernel

Dale Farnsworth wrote:
>>From Dale Farnsworth <dale@farnsworth.org>
> 
> mv643xx_eth: Fix race condition in mv643xx_eth_free_tx_descs
> 
> This bug was found and isolated by Thibaut VARENE <T-Bone@parisc-linux.org>
> and Jarek Poplawski <jarkao2@o2.pl>.  This patch is a modification of their
> fixes.  We acquire and release the lock for each descriptor that is freed
> to minimize the time the lock is held.
> 
> ---
> 
>  drivers/net/mv643xx_eth.c |   11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)

applied



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

end of thread, other threads:[~2007-01-23 21:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-23 16:52 [PATCH] mv643xx_eth: Fix race condition in mv643xx_eth_free_tx_descs Dale Farnsworth
2007-01-23 17:02 ` Thibaut VARENE
2007-01-23 21:29 ` Jeff Garzik

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