linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] r8169: fix problem with TSO (TX_BUFFS_AVAIL negative value)
@ 2012-05-07 22:39 Julien Ducourthial
  2012-05-07 23:42 ` Francois Romieu
  0 siblings, 1 reply; 5+ messages in thread
From: Julien Ducourthial @ 2012-05-07 22:39 UTC (permalink / raw)
  To: Francois Romieu, Realtek linux nic maintainers, netdev; +Cc: linux-kernel

The r8169 may get stuck or show bad behaviour after activating TSO :
the net_device is not stopped when it has no more TX descriptors.
This problem comes from TX_BUFS_AVAIL which may reach -1 when all
transmit descriptors are in use. The patch simply tries to keep positive
values.

Tested with 8111d(onboard) on a D510MO, and with 8111e(onboard) on a
Zotac 890GXITX.

Signed-off-by: Julien Ducourthial <jducourt@free.fr>
---
 drivers/net/ethernet/realtek/r8169.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/realtek/r8169.c
b/drivers/net/ethernet/realtek/r8169.c
index f545093..d1e3c51 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -61,8 +61,12 @@
 #define R8169_MSG_DEFAULT \
 	(NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
 
-#define TX_BUFFS_AVAIL(tp) \
-	(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1)
+#define TX_SLOTS_AVAIL(tp) \
+	(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx)
+
+/* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */
+#define TX_FRAGS_READY_FOR(tp,nr_frags) \
+	(TX_SLOTS_AVAIL(tp) >= (nr_frags+1))
 
 /* Maximum number of multicast addresses to filter (vs.
Rx-all-multicast).
    The RTL chips use a 64 element hash table based on the Ethernet CRC.
*/
@@ -5115,7 +5119,7 @@ static netdev_tx_t rtl8169_start_xmit(struct
sk_buff *skb,
 	u32 opts[2];
 	int frags;
 
-	if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) {
+	if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) {
 		netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n");
 		goto err_stop_0;
 	}
@@ -5169,7 +5173,7 @@ static netdev_tx_t rtl8169_start_xmit(struct
sk_buff *skb,
 
 	mmiowb();
 
-	if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) {
+	if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
 		/* Avoid wrongly optimistic queue wake-up: rtl_tx thread must
 		 * not miss a ring update when it notices a stopped queue.
 		 */
@@ -5183,7 +5187,7 @@ static netdev_tx_t rtl8169_start_xmit(struct
sk_buff *skb,
 		 * can't.
 		 */
 		smp_mb();
-		if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)
+		if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS))
 			netif_wake_queue(dev);
 	}
 
@@ -5306,7 +5310,7 @@ static void rtl_tx(struct net_device *dev, struct
rtl8169_private *tp)
 		 */
 		smp_mb();
 		if (netif_queue_stopped(dev) &&
-		    (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) {
+		    TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
 			netif_wake_queue(dev);
 		}
 		/*
-- 
1.7.7.6




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

* Re: [PATCH] r8169: fix problem with TSO (TX_BUFFS_AVAIL negative value)
  2012-05-07 22:39 [PATCH] r8169: fix problem with TSO (TX_BUFFS_AVAIL negative value) Julien Ducourthial
@ 2012-05-07 23:42 ` Francois Romieu
  2012-05-08 10:06   ` Francois Romieu
  2012-05-09  4:12   ` Alex Villacís Lasso
  0 siblings, 2 replies; 5+ messages in thread
From: Francois Romieu @ 2012-05-07 23:42 UTC (permalink / raw)
  To: Alex Villací­s Lasso
  Cc: Thomas Pilarski, Julien Ducourthial,
	Realtek linux nic maintainers, netdev, linux-kernel

Julien Ducourthial <jducourt@free.fr> :
> The r8169 may get stuck or show bad behaviour after activating TSO :
> the net_device is not stopped when it has no more TX descriptors.
> This problem comes from TX_BUFS_AVAIL which may reach -1 when all
> transmit descriptors are in use. The patch simply tries to keep positive
> values.

It seems more than good.

Alex, Thomas, can you check if Julien's patch below fixes your broken
kernels as well ? 

diff --git a/drivers/net/ethernet/realtek/r8169.c
b/drivers/net/ethernet/realtek/r8169.c
index f545093..d1e3c51 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -61,8 +61,12 @@
 #define R8169_MSG_DEFAULT \
 	(NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
 
-#define TX_BUFFS_AVAIL(tp) \
-	(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1)
+#define TX_SLOTS_AVAIL(tp) \
+	(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx)
+
+/* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */
+#define TX_FRAGS_READY_FOR(tp,nr_frags) \
+	(TX_SLOTS_AVAIL(tp) >= (nr_frags + 1))
 
 /* Maximum number of multicast addresses to filter (vs.
Rx-all-multicast).
    The RTL chips use a 64 element hash table based on the Ethernet CRC.
*/
@@ -5115,7 +5119,7 @@ static netdev_tx_t rtl8169_start_xmit(struct
sk_buff *skb,
 	u32 opts[2];
 	int frags;
 
-	if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) {
+	if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) {
 		netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n");
 		goto err_stop_0;
 	}
@@ -5169,7 +5173,7 @@ static netdev_tx_t rtl8169_start_xmit(struct
sk_buff *skb,
 
 	mmiowb();
 
-	if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) {
+	if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
 		/* Avoid wrongly optimistic queue wake-up: rtl_tx thread must
 		 * not miss a ring update when it notices a stopped queue.
 		 */
@@ -5183,7 +5187,7 @@ static netdev_tx_t rtl8169_start_xmit(struct
sk_buff *skb,
 		 * can't.
 		 */
 		smp_mb();
-		if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)
+		if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS))
 			netif_wake_queue(dev);
 	}
 
@@ -5306,7 +5310,7 @@ static void rtl_tx(struct net_device *dev, struct
rtl8169_private *tp)
 		 */
 		smp_mb();
 		if (netif_queue_stopped(dev) &&
-		    (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) {
+		    TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
 			netif_wake_queue(dev);
 		}
 		/*
-- 
1.7.7.6

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

* Re: [PATCH] r8169: fix problem with TSO (TX_BUFFS_AVAIL negative value)
  2012-05-07 23:42 ` Francois Romieu
@ 2012-05-08 10:06   ` Francois Romieu
  2012-05-08 10:21     ` Thomas Pilarski
  2012-05-09  4:12   ` Alex Villacís Lasso
  1 sibling, 1 reply; 5+ messages in thread
From: Francois Romieu @ 2012-05-08 10:06 UTC (permalink / raw)
  To: Alex Villací­s Lasso
  Cc: Thomas Pilarski, Julien Ducourthial, Hayes Wang, netdev, linux-kernel

Francois Romieu <romieu@fr.zoreil.com> :
[...]
> Alex, Thomas, can you check if Julien's patch below fixes your broken
> kernels as well ? 

You will have better luck with a patch whose lines are correctly formed.

Patch below applies on top of 3.4-rc6.

(Julien, please check your mail user agent)

diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
index f545093..d1e3c51 100644
--- a/drivers/net/ethernet/realtek/r8169.c
+++ b/drivers/net/ethernet/realtek/r8169.c
@@ -61,8 +61,12 @@
 #define R8169_MSG_DEFAULT \
 	(NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
 
-#define TX_BUFFS_AVAIL(tp) \
-	(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1)
+#define TX_SLOTS_AVAIL(tp) \
+	(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx)
+
+/* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */
+#define TX_FRAGS_READY_FOR(tp,nr_frags) \
+	(TX_SLOTS_AVAIL(tp) >= (nr_frags + 1))
 
 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
    The RTL chips use a 64 element hash table based on the Ethernet CRC. */
@@ -5115,7 +5119,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
 	u32 opts[2];
 	int frags;
 
-	if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) {
+	if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) {
 		netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n");
 		goto err_stop_0;
 	}
@@ -5169,7 +5173,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
 
 	mmiowb();
 
-	if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) {
+	if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
 		/* Avoid wrongly optimistic queue wake-up: rtl_tx thread must
 		 * not miss a ring update when it notices a stopped queue.
 		 */
@@ -5183,7 +5187,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
 		 * can't.
 		 */
 		smp_mb();
-		if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)
+		if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS))
 			netif_wake_queue(dev);
 	}
 
@@ -5306,7 +5310,7 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp)
 		 */
 		smp_mb();
 		if (netif_queue_stopped(dev) &&
-		    (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) {
+		    TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
 			netif_wake_queue(dev);
 		}
 		/*
-- 
Ueimor

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

* Re: [PATCH] r8169: fix problem with TSO (TX_BUFFS_AVAIL negative value)
  2012-05-08 10:06   ` Francois Romieu
@ 2012-05-08 10:21     ` Thomas Pilarski
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Pilarski @ 2012-05-08 10:21 UTC (permalink / raw)
  To: Francois Romieu
  Cc: Alex Villací­s Lasso, Thomas Pilarski,
	Julien Ducourthial, Hayes Wang, netdev, linux-kernel

I have already tested the patch with the kernel 3.3.4 and the module
from bugzilla (https://bugzilla.kernel.org/attachment.cgi?id=72682). The
iommu error still occurs.

Am 08.05.2012 12:06, schrieb Francois Romieu:
> Francois Romieu <romieu@fr.zoreil.com> :
> [...]
>> Alex, Thomas, can you check if Julien's patch below fixes your broken
>> kernels as well ? 
> You will have better luck with a patch whose lines are correctly formed.
>
> Patch below applies on top of 3.4-rc6.
>
> (Julien, please check your mail user agent)
>
> diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
> index f545093..d1e3c51 100644
> --- a/drivers/net/ethernet/realtek/r8169.c
> +++ b/drivers/net/ethernet/realtek/r8169.c
> @@ -61,8 +61,12 @@
>  #define R8169_MSG_DEFAULT \
>  	(NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN)
>  
> -#define TX_BUFFS_AVAIL(tp) \
> -	(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1)
> +#define TX_SLOTS_AVAIL(tp) \
> +	(tp->dirty_tx + NUM_TX_DESC - tp->cur_tx)
> +
> +/* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */
> +#define TX_FRAGS_READY_FOR(tp,nr_frags) \
> +	(TX_SLOTS_AVAIL(tp) >= (nr_frags + 1))
>  
>  /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
>     The RTL chips use a 64 element hash table based on the Ethernet CRC. */
> @@ -5115,7 +5119,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
>  	u32 opts[2];
>  	int frags;
>  
> -	if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) {
> +	if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) {
>  		netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n");
>  		goto err_stop_0;
>  	}
> @@ -5169,7 +5173,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
>  
>  	mmiowb();
>  
> -	if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) {
> +	if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
>  		/* Avoid wrongly optimistic queue wake-up: rtl_tx thread must
>  		 * not miss a ring update when it notices a stopped queue.
>  		 */
> @@ -5183,7 +5187,7 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
>  		 * can't.
>  		 */
>  		smp_mb();
> -		if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)
> +		if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS))
>  			netif_wake_queue(dev);
>  	}
>  
> @@ -5306,7 +5310,7 @@ static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp)
>  		 */
>  		smp_mb();
>  		if (netif_queue_stopped(dev) &&
> -		    (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) {
> +		    TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) {
>  			netif_wake_queue(dev);
>  		}
>  		/*


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

* Re: [PATCH] r8169: fix problem with TSO (TX_BUFFS_AVAIL negative value)
  2012-05-07 23:42 ` Francois Romieu
  2012-05-08 10:06   ` Francois Romieu
@ 2012-05-09  4:12   ` Alex Villacís Lasso
  1 sibling, 0 replies; 5+ messages in thread
From: Alex Villacís Lasso @ 2012-05-09  4:12 UTC (permalink / raw)
  To: Francois Romieu
  Cc: Thomas Pilarski, Julien Ducourthial,
	Realtek linux nic maintainers, netdev, linux-kernel

El 07/05/12 18:42, Francois Romieu escribió:
> Julien Ducourthial<jducourt@free.fr>  :
>> The r8169 may get stuck or show bad behaviour after activating TSO :
>> the net_device is not stopped when it has no more TX descriptors.
>> This problem comes from TX_BUFS_AVAIL which may reach -1 when all
>> transmit descriptors are in use. The patch simply tries to keep positive
>> values.
> It seems more than good.
>
> Alex, Thomas, can you check if Julien's patch below fixes your broken
> kernels as well ?
>
No luck. The backtrace still appears after using the patched driver.

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

end of thread, other threads:[~2012-05-09  4:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-07 22:39 [PATCH] r8169: fix problem with TSO (TX_BUFFS_AVAIL negative value) Julien Ducourthial
2012-05-07 23:42 ` Francois Romieu
2012-05-08 10:06   ` Francois Romieu
2012-05-08 10:21     ` Thomas Pilarski
2012-05-09  4:12   ` Alex Villacís Lasso

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