Skip to contentSkip to conversation

tg3: fix ring init when there are more TX than RX channels

PATCH In review Thadeu Lima de Souza Cascardo 2 participants 4 messages Nov 25, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tg3: fix ring init when there are more TX than RX channels

If TX channels are set to 4 and RX channels are set to less than 4, using ethtool -L, the driver will try to initialize more RX channels than it has allocated, causing an oops.

This fix only initializes the RX ring if it has been allocated.

---
 drivers/net/ethernet/broadcom/tg3.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/tg3.c +2 -1
index dbb41c19..77f8f83 100644
@@ -8563,7 +8563,8 @@ static int tg3_init_rings(struct tg3 *tp)
 		if (tnapi->rx_rcb)
 			memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
 
-		if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
+		if (tnapi->prodring.rx_std &&
+		    tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
 			tg3_free_rings(tp);
 			return -ENOMEM;
 		}
Signature · 1 line
1.7.10.4
maintainer
#1 lore raw

From: Thadeu Lima de Souza Cascardo <[email protected]>
Date: Tue, 25 Nov 2014 14:21:11 -0200

drivers/net/ethernet/broadcom/tg3.c static int tg3_init_rings(struct tg3 *tp) · line 8569

Quoted 9 lines
drivers/net/ethernet/broadcom/tg3.c +2 -1
@@ -8563,7 +8563,8 @@ static int tg3_init_rings(struct tg3 *tp)
 		if (tnapi->rx_rcb)
 			memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
 
-		if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
+		if (tnapi->prodring.rx_std &&
+		    tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
 			tg3_free_rings(tp);
 			return -ENOMEM;

Maybe a better test is "i < tp->rxq_cnt"? This is what is used in tg3_mem_rx_acquire() to determine if tg3_rx_prodring_init() happens.

#2 lore raw
Quoted 7 lines · David Miller

From: Thadeu Lima de Souza Cascardo <[email protected]>
Date: Tue, 25 Nov 2014 14:21:11 -0200

Quoted 4 lines
(quoted diff) +0 -0
@@ -8563,7 +8563,8 @@ static int tg3_init_rings(struct tg3 *tp)
 		if (tnapi->rx_rcb)
 			memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
 
Quoted 9 lines

Review static int tg3_init_rings(struct tg3 *tp) · line 8569

Quoted 5 lines
(quoted diff) +2 -1
-		if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
+		if (tnapi->prodring.rx_std &&
+		    tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
 			tg3_free_rings(tp);
 			return -ENOMEM;

Maybe a better test is "i < tp->rxq_cnt"? This is what is used in tg3_mem_rx_acquire() to determine if tg3_rx_prodring_init() happens.

Well, what we have in net-next/master does:

	for (i = 0; i < limit; i++) {
		struct tg3_napi *tnapi = &tp->napi[i];

		if (tg3_rx_prodring_init(tp, &tnapi->prodring))
			goto err_out;

where limit is:

	limit = tp->rxq_cnt;

	if (tg3_flag(tp, ENABLE_RSS))
		limit++;

So, I thought that, instead of rewriting that same logic in tg3_init_rings, that we should better just check that the rx_std has been allocated, which is going to happen in tg3_rx_prodring_init.

So, the alternative would be:

drivers/net/ethernet/broadcom/tg3.c +7 -2
index dbb41c19..51d45aa 100644
@@ -8540,7 +8540,11 @@ static void tg3_free_rings(struct tg3 *tp)
  */
 static int tg3_init_rings(struct tg3 *tp)
 {
-	int i;
+	int i, limit;
+
+	limit = tp->rxq_cnt;
+	if (tg3_flag(tp, ENABLE_RSS))
+		limit++;
 
 	/* Free up all the SKBs. */
 	tg3_free_rings(tp);
@@ -8563,7 +8567,8 @@ static int tg3_init_rings(struct tg3 *tp)
 		if (tnapi->rx_rcb)
 			memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
 
-		if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
+		if (i < limit &&
+		    tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
 			tg3_free_rings(tp);
 			return -ENOMEM;
 		}
maintainer
#3 lore raw

From: [email protected]
Date: Tue, 25 Nov 2014 17:57:21 -0200

Quoted 33 lines · David Miller
Quoted 7 lines

From: Thadeu Lima de Souza Cascardo <[email protected]>
Date: Tue, 25 Nov 2014 14:21:11 -0200

Quoted 4 lines
drivers/net/ethernet/broadcom/tg3.c +0 -0
@@ -8563,7 +8563,8 @@ static int tg3_init_rings(struct tg3 *tp)
 		if (tnapi->rx_rcb)
 			memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
 
Quoted 9 lines

drivers/net/ethernet/broadcom/tg3.c static int tg3_init_rings(struct tg3 *tp) · line 8573

Quoted 5 lines
drivers/net/ethernet/broadcom/tg3.c +2 -1
-		if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
+		if (tnapi->prodring.rx_std &&
+		    tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
 			tg3_free_rings(tp);
 			return -ENOMEM;

Maybe a better test is "i < tp->rxq_cnt"? This is what is used in tg3_mem_rx_acquire() to determine if tg3_rx_prodring_init() happens.

Well, what we have in net-next/master does:

	for (i = 0; i < limit; i++) {
		struct tg3_napi *tnapi = &tp->napi[i];

		if (tg3_rx_prodring_init(tp, &tnapi->prodring))
			goto err_out;

where limit is:

	limit = tp->rxq_cnt;

	if (tg3_flag(tp, ENABLE_RSS))
		limit++;
Quoted 5 lines

So, I thought that, instead of rewriting that same logic in tg3_init_rings, that we should better just check that the rx_std has been allocated, which is going to happen in tg3_rx_prodring_init.

So, the alternative would be:

Ok, come to think of it, your original test is fine and I've applied that patch and queued it up for -stable.

Thanks.