Skip to contentSkip to conversation

net: stmmac: multiple queue fixes

PATCH In review Joao Pinto 5 participants 27 messages Mar 24, 2017 – Mar 29, 2017

Subsystems (4)
lore
Share & tools
lore

Joao Pinto

author
#0 lore raw

cover net: stmmac: multiple queue fixes

This patch set contains two fixes for problems I detected when ran the driver in single queue mode.

Please test in your setups to check if you get better results.

Joao Pinto (2):
net: stmmac: fix netdev release
net: stmmac: fix number of tx queues in stmmac_poll

 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
Signature · 1 line
2.9.3
author
#1 lore raw

PATCH 1/2 net: stmmac: fix netdev release

This patch fixes the kernel crash problem that happens when the driver exits. The dma resouces must be freed after netdev resouces get freed and in driver removed, multiple napi's should be deleted before removing netdev resouces or it will hang.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +11 -6
index 4b418d2..3827952 100644
@@ -2659,9 +2659,6 @@ static int stmmac_release(struct net_device *dev)
 	/* Stop TX/RX DMA and clear the descriptors */
 	stmmac_stop_all_dma(priv);
 
-	/* Release and free the Rx/Tx resources */
-	free_dma_desc_resources(priv);
-
 	/* Disable the MAC Rx/Tx */
 	stmmac_set_mac(priv->ioaddr, false);
 
@@ -4080,7 +4077,7 @@ int stmmac_dvr_probe(struct device *device,
 	/* Init MAC and get the capabilities */
 	ret = stmmac_hw_init(priv);
 	if (ret)
-		goto error_hw_init;
+		return ret;
 
 	/* Configure real RX and TX queues */
 	ndev->real_num_rx_queues = priv->plat->rx_queues_to_use;
@@ -4207,9 +4204,8 @@ int stmmac_dvr_probe(struct device *device,
 		netif_napi_del(&rx_q->napi);
 	}
 init_dma_error:
-	free_dma_desc_resources(priv);
-error_hw_init:
 	free_netdev(ndev);
+	free_dma_desc_resources(priv);
 
 	return ret;
 }
@@ -4225,6 +4221,7 @@ int stmmac_dvr_remove(struct device *dev)
 {
 	struct net_device *ndev = dev_get_drvdata(dev);
 	struct stmmac_priv *priv = netdev_priv(ndev);
+	u32 queue = 0;
 
 	netdev_info(priv->dev, "%s: removing driver", __func__);
 
@@ -4241,7 +4238,15 @@ int stmmac_dvr_remove(struct device *dev)
 	    priv->hw->pcs != STMMAC_PCS_TBI &&
 	    priv->hw->pcs != STMMAC_PCS_RTBI)
 		stmmac_mdio_unregister(ndev);
+
+	for (queue = 0; queue < priv->plat->rx_queues_to_use; queue++) {
+		struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue];
+
+		netif_napi_del(&rx_q->napi);
+	}
+
 	free_netdev(ndev);
+	free_dma_desc_resources(priv);
 
 	return 0;
 }
Signature · 1 line
2.9.3
author
#2 lore raw

PATCH 2/2 net: stmmac: fix number of tx queues in stmmac_poll

In reply to Joao Pinto

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3
#3 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Quoted 24 lines · Joao Pinto

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only. The dwmac-sunxi is still broken.

author
#4 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 19 lines · Joao Pinto
Quoted 18 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only.

Ok, great!

Quoted 2 lines

The dwmac-sunxi is still broken.

What is the difference between the setups?

Thanks,
Joao

#5 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Quoted 29 lines · Joao Pinto

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 19 lines · Joao Pinto
Quoted 18 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only.

Quoted 2 lines

Ok, great!

Sorry, in the we, I see that my gigabit dwmac-sun8i didnt work... (but didnt have time to find why).

Quoted 4 lines
Quoted 2 lines

The dwmac-sunxi is still broken.

What is the difference between the setups?

dwmac-sun8i use chain mode, dwmac-sunxi use ring mode

author
#6 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Às 10:09 AM de 3/27/2017, Corentin Labbe escreveu:

Quoted 30 lines · Joao Pinto
Quoted 29 lines

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 27 lines · Joao Pinto
Quoted 24 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only.

Quoted 6 lines
Quoted 2 lines

Ok, great!

Sorry, in the we, I see that my gigabit dwmac-sun8i didnt work... (but didnt have time to find why).

Quoted 1 line
Quoted 1 line

The dwmac-sunxi is still broken.

Ok, let's see what others report.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

What is the difference between the setups?

dwmac-sun8i use chain mode, dwmac-sunxi use ring mode

@Thierry and Niklas: Hi! Your setup is working well with these 2 fix patches?

Thnaks.

#7 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Quoted 42 lines · Joao Pinto

Às 10:09 AM de 3/27/2017, Corentin Labbe escreveu:

Quoted 30 lines · Joao Pinto
Quoted 29 lines

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 27 lines · Joao Pinto
Quoted 24 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only.

Quoted 6 lines
Quoted 2 lines

Ok, great!

Sorry, in the we, I see that my gigabit dwmac-sun8i didnt work... (but didnt have time to find why).

Quoted 1 line
Quoted 1 line

The dwmac-sunxi is still broken.

Ok, let's see what others report.

Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

What is the difference between the setups?

dwmac-sun8i use chain mode, dwmac-sunxi use ring mode

@Thierry and Niklas: Hi! Your setup is working well with these 2 fix patches?

Hello Joao,

I have not tested these 2 patches.

Previously, when I tested next-20170321, artpec-6 SoC got TX queue timeouts. When testing today's linux-next, next-20170327, things are working again :)

So I guess one of the following patches fixed our problem:

270c7759fbbc net: stmmac: add set_mac to the stmmac_ops b4f0a6615556 net: stmmac: fix dma operation mode config for older versions 33e85b8dd69e net: stmmac: Restore DT backwards-compatibility f39768744fd6 net: stmmac: Always enable MAC RX queues abe80fdc6ee6 net: stmmac: RX queue routing configuration a8f5102af2a7 net: stmmac: TX and RX queue priority configuration aff3d9eff843 net: stmmac: enable multiple buffers

Regards,
Niklas

author
#8 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Às 2:28 PM de 3/27/2017, Niklas Cassel escreveu:

Quoted 63 lines · Joao Pinto
Quoted 42 lines

Às 10:09 AM de 3/27/2017, Corentin Labbe escreveu:

Quoted 30 lines · Joao Pinto
Quoted 29 lines

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 27 lines · Joao Pinto
Quoted 24 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only.

Quoted 6 lines
Quoted 2 lines

Ok, great!

Sorry, in the we, I see that my gigabit dwmac-sun8i didnt work... (but didnt have time to find why).

Quoted 1 line
Quoted 1 line

The dwmac-sunxi is still broken.

Ok, let's see what others report.

Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

What is the difference between the setups?

dwmac-sun8i use chain mode, dwmac-sunxi use ring mode

@Thierry and Niklas: Hi! Your setup is working well with these 2 fix patches?

Hello Joao,

I have not tested these 2 patches.

Previously, when I tested next-20170321, artpec-6 SoC got TX queue timeouts. When testing today's linux-next, next-20170327, things are working again :)

So I guess one of the following patches fixed our problem:

Quoted 7 lines

270c7759fbbc net: stmmac: add set_mac to the stmmac_ops b4f0a6615556 net: stmmac: fix dma operation mode config for older versions 33e85b8dd69e net: stmmac: Restore DT backwards-compatibility f39768744fd6 net: stmmac: Always enable MAC RX queues abe80fdc6ee6 net: stmmac: RX queue routing configuration a8f5102af2a7 net: stmmac: TX and RX queue priority configuration aff3d9eff843 net: stmmac: enable multiple buffers

Yes for sure :) Great! Thanks.

Quoted 4 lines

Regards,
Niklas

author
#9 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Hin Thierry,

Às 2:34 PM de 3/27/2017, Joao Pinto escreveu:

Quoted 72 lines

Às 2:28 PM de 3/27/2017, Niklas Cassel escreveu:

Quoted 63 lines · Joao Pinto
Quoted 42 lines

Às 10:09 AM de 3/27/2017, Corentin Labbe escreveu:

Quoted 30 lines · Joao Pinto
Quoted 29 lines

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 27 lines · Joao Pinto
Quoted 24 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only.

Quoted 6 lines
Quoted 2 lines

Ok, great!

Sorry, in the we, I see that my gigabit dwmac-sun8i didnt work... (but didnt have time to find why).

Quoted 1 line
Quoted 1 line

The dwmac-sunxi is still broken.

Ok, let's see what others report.

Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

What is the difference between the setups?

dwmac-sun8i use chain mode, dwmac-sunxi use ring mode

@Thierry and Niklas: Hi! Your setup is working well with these 2 fix patches?

Hello Joao,

I have not tested these 2 patches.

Previously, when I tested next-20170321, artpec-6 SoC got TX queue timeouts. When testing today's linux-next, next-20170327, things are working again :)

So I guess one of the following patches fixed our problem:

Quoted 7 lines

270c7759fbbc net: stmmac: add set_mac to the stmmac_ops b4f0a6615556 net: stmmac: fix dma operation mode config for older versions 33e85b8dd69e net: stmmac: Restore DT backwards-compatibility f39768744fd6 net: stmmac: Always enable MAC RX queues abe80fdc6ee6 net: stmmac: RX queue routing configuration a8f5102af2a7 net: stmmac: TX and RX queue priority configuration aff3d9eff843 net: stmmac: enable multiple buffers

Quoted 1 line

Yes for sure :) Great! Thanks.

Could you please confirm your setup works with these final 2 patches?

Thanks.

Quoted 6 lines
Quoted 5 lines

Regards,
Niklas

author
#10 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

In reply to Corentin Labbe

Hi David,

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 20 lines · Joao Pinto
Quoted 19 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
Quoted 9 lines
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only. The dwmac-sunxi is still broken.

This patch series can be upstreamed please, since they make 2 fixes, one of them solving the problem in dwmac-sun8i.

Thanks.

#11 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Quoted 33 lines · Joao Pinto

Hi David,

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 20 lines · Joao Pinto
Quoted 19 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
Quoted 9 lines
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only. The dwmac-sunxi is still broken.

Quoted 4 lines

This patch series can be upstreamed please, since they make 2 fixes, one of them solving the problem in dwmac-sun8i.

Thanks.

As I said in a previous answer, finaly dwmac-sun8i is still broken. Adding thoses 2 patch will just made the revert harder.

Regards

author
#12 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Às 6:00 PM de 3/27/2017, Corentin Labbe escreveu:

Quoted 34 lines · Joao Pinto
Quoted 33 lines

Hi David,

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 29 lines · Joao Pinto
Quoted 24 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only. The dwmac-sunxi is still broken.

Quoted 7 lines
Quoted 4 lines

This patch series can be upstreamed please, since they make 2 fixes, one of them solving the problem in dwmac-sun8i.

Thanks.

As I said in a previous answer, finaly dwmac-sun8i is still broken. Adding thoses 2 patch will just made the revert harder.

Oh, ok. You are using version >=4.00 or older versions?

Quoted 3 lines

Regards

#13 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Quoted 38 lines · Joao Pinto

Às 6:00 PM de 3/27/2017, Corentin Labbe escreveu:

Quoted 37 lines · Joao Pinto
Quoted 36 lines

Hi David,

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 20 lines · Joao Pinto
Quoted 19 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
Quoted 9 lines
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only. The dwmac-sunxi is still broken.

This patch series can be upstreamed please, since they make 2 fixes, one of them solving the problem in dwmac-sun8i.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Thanks.

As I said in a previous answer, finaly dwmac-sun8i is still broken. Adding thoses 2 patch will just made the revert harder.

Oh, ok. You are using version >=4.00 or older versions?

older for both

maintainer
#14 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

In reply to Corentin Labbe

From: Corentin Labbe <[email protected]>
Date: Mon, 27 Mar 2017 19:00:58 +0200

Quoted 34 lines · Joao Pinto
Quoted 33 lines

Hi David,

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 29 lines · Joao Pinto
Quoted 24 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only. The dwmac-sunxi is still broken.

Quoted 7 lines
Quoted 4 lines

This patch series can be upstreamed please, since they make 2 fixes, one of them solving the problem in dwmac-sun8i.

Thanks.

As I said in a previous answer, finaly dwmac-sun8i is still broken. Adding thoses 2 patch will just made the revert harder.

I agree.

author
#15 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Às 6:28 PM de 3/27/2017, David Miller escreveu:

Quoted 40 lines

From: Corentin Labbe <[email protected]>
Date: Mon, 27 Mar 2017 19:00:58 +0200

Quoted 37 lines · Joao Pinto
Quoted 36 lines

Hi David,

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 20 lines · Joao Pinto
Quoted 19 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
Quoted 9 lines
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only. The dwmac-sunxi is still broken.

This patch series can be upstreamed please, since they make 2 fixes, one of them solving the problem in dwmac-sun8i.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Thanks.

As I said in a previous answer, finaly dwmac-sun8i is still broken. Adding thoses 2 patch will just made the revert harder.

I agree.

For what I am understanding, SoCs base on Core versions >= 4.00 are working properly and for some reason SoCs based on older versions are not working.

This fix is necessary, since if you have a diferent configured tx_queues_to_use in the driver and priv->dma_cap.number_tx_queues in the core, this can lead to kernel crashes.

The other fix (netdev resources release) is also necessary, since when you release the driver its crashes, because the rx queue struct is freed before releasing the netdevs.

We can revert, but I think it might not solve the issue. We can break the "multiple buffers" patch into "rx multilple buffers" and "tx multiple buffers", but will that actually work? We can give it a try, I don't mind making a new multiple buffers patch broken into 2, that can be tested by new cores and older cores.

Joao

#16 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

Quoted 59 lines · Joao Pinto

Às 6:28 PM de 3/27/2017, David Miller escreveu:

Quoted 40 lines

From: Corentin Labbe <[email protected]>
Date: Mon, 27 Mar 2017 19:00:58 +0200

Quoted 37 lines · Joao Pinto
Quoted 36 lines

Hi David,

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 20 lines · Joao Pinto
Quoted 19 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
Quoted 9 lines
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only. The dwmac-sunxi is still broken.

This patch series can be upstreamed please, since they make 2 fixes, one of them solving the problem in dwmac-sun8i.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Thanks.

As I said in a previous answer, finaly dwmac-sun8i is still broken. Adding thoses 2 patch will just made the revert harder.

I agree.

For what I am understanding, SoCs base on Core versions >= 4.00 are working properly and for some reason SoCs based on older versions are not working.

This fix is necessary, since if you have a diferent configured tx_queues_to_use in the driver and priv->dma_cap.number_tx_queues in the core, this can lead to kernel crashes.

The other fix (netdev resources release) is also necessary, since when you release the driver its crashes, because the rx queue struct is freed before releasing the netdevs.

Quoted 6 lines

We can revert, but I think it might not solve the issue. We can break the "multiple buffers" patch into "rx multilple buffers" and "tx multiple buffers", but will that actually work? We can give it a try, I don't mind making a new multiple buffers patch broken into 2, that can be tested by new cores and older cores.

Reverting at least will bring back my archs to good status:)
Spliting will not solve magically the issue, but will permit to easily detect which part is faulty. And I am sure that it is possible to split more than in 2.
The more small the patch will be, the easier it will.

Regards

maintainer
#17 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

In reply to Joao Pinto

From: Joao Pinto <[email protected]>
Date: Mon, 27 Mar 2017 18:44:22 +0100

Quoted 2 lines

For what I am understanding, SoCs base on Core versions >= 4.00 are working properly and for some reason SoCs based on older versions are not working.

Please send me a revert, and work offline with these people to resolve all of the regressions you introduced.

Once you resolved all of the regressions, we can put the changes back in.

Thank you.

#18 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

In reply to Joao Pinto
Quoted 59 lines · Joao Pinto

Às 6:28 PM de 3/27/2017, David Miller escreveu:

Quoted 40 lines

From: Corentin Labbe <[email protected]>
Date: Mon, 27 Mar 2017 19:00:58 +0200

Quoted 37 lines · Joao Pinto
Quoted 36 lines

Hi David,

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 20 lines · Joao Pinto
Quoted 19 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
Quoted 9 lines
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only. The dwmac-sunxi is still broken.

This patch series can be upstreamed please, since they make 2 fixes, one of them solving the problem in dwmac-sun8i.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Thanks.

As I said in a previous answer, finaly dwmac-sun8i is still broken. Adding thoses 2 patch will just made the revert harder.

I agree.

For what I am understanding, SoCs base on Core versions >= 4.00 are working properly and for some reason SoCs based on older versions are not working.

This fix is necessary, since if you have a diferent configured tx_queues_to_use in the driver and priv->dma_cap.number_tx_queues in the core, this can lead to kernel crashes.

The other fix (netdev resources release) is also necessary, since when you release the driver its crashes, because the rx queue struct is freed before releasing the netdevs.

Quoted 5 lines

We can revert, but I think it might not solve the issue. We can break the "multiple buffers" patch into "rx multilple buffers" and "tx multiple buffers", but will that actually work? We can give it a try, I don't mind making a new multiple buffers patch broken into 2, that can be tested by new cores and older cores.

I've hit a bug on stmmac where RX is broken after boot. Sometimes it works, and sometimes it doesn't.
I usually notice that DHCP never receives an offer,
but it's possible to reproduce the problem without DHCP, where a simple ping will not work after setting an address manually.

I've bisected it to commit aff3d9eff843 ("net: stmmac: enable multiple buffers"). (Note that I had to cherry-pick 22446ad8e118 ("net: stmmac: Restore DT backwards-compatibility") to avoid TX queue timeouts, and the patch included in the beginning of this
mail thread "net: stmmac: fix number of tx queues in stmmac_poll" to avoid random crashes in stmmac_tx_clean.

Looking at wireshark I can see that we send out a DHCP discover, so TX seems to be working.
A DHCP offer is sent out from the server, but it is never received.

Our setup has 1 RX queue and 2 TX queues.
According to the databook, the field Receive Queue Size in register MTL_RxQ0_Operation_Mode is read-only when number of RX queues == 1, so I guess the problem is not related to RX queue size. It's quite annoying since it does not trigger every single boot.

Has anyone else noticed broken RX after boot since commit aff3d9eff843 and newer?

#19 lore raw

PATCH 1/3 net: stmmac: Remove unneeded checks for NULL pointer

From: Thierry Reding <[email protected]>

Taking the address of an element within a non-NULL array will never be zero. This condition isn't checked anywhere else, so drop it in these two instances as well.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -6
index c78f444ad423..106ace3781b3 100644
@@ -1332,9 +1332,6 @@ static void free_rx_dma_desc_resources(struct stmmac_priv *priv)
 	for (queue = 0; queue < rx_count; queue++) {
 		struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue];
 
-		if (!rx_q)
-			break;
-
 		/* Release the DMA RX socket buffers */
 		dma_free_rx_skbufs(priv, queue);
 
@@ -1373,9 +1370,6 @@ static void free_tx_dma_desc_resources(struct stmmac_priv *priv)
 	for (queue = 0; queue < tx_count; queue++) {
 		struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue];
 
-		if (!tx_q)
-			break;
-
 		/* Release the DMA TX socket buffers */
 		dma_free_tx_skbufs(priv, queue);
 
Signature · 1 line
2.12.0
#20 lore raw

PATCH 2/3 net: stmmac: Always use the number of configured TX queues

From: Thierry Reding <[email protected]>

Even if hardware supports multiple queues, software can choose to only use a subset of them. Make sure we never try to access uninitialized queues.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 106ace3781b3..ec5bba85c529 100644
@@ -3423,7 +3423,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.12.0
#21 lore raw

Re: [PATCH 2/3] net: stmmac: Always use the number of configured TX queues

Quoted 17 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Even if hardware supports multiple queues, software can choose to only use a subset of them. Make sure we never try to access uninitialized queues.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
index 106ace3781b3..ec5bba85c529 100644

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_poll(struct napi_struct *napi, int budget) · line 3429

Quoted 8 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
@@ -3423,7 +3423,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
 	u32 queue = 0;

Thanks Thierry,
but this look like an equivalent patch to Joao's "net: stmmac: fix number of tx queues in stmmac_poll" which I already used during bisecting to avoid random crashes in stmmac_tx_clean.

Have you noticed random RX brokenness after boot in recent linux-next tags?

It feels like it might trigger more often after a cold boot, but that could just be my brain seeing patterns that aren't really there :)

#22 lore raw

Re: [PATCH 2/3] net: stmmac: Always use the number of configured TX queues

Quoted 26 lines · Niklas Cassel
Quoted 23 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Even if hardware supports multiple queues, software can choose to only use a subset of them. Make sure we never try to access uninitialized queues.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 106ace3781b3..ec5bba85c529 100644
@@ -3423,7 +3423,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
 	u32 work_done = 0;
Quoted 8 lines

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c static int stmmac_poll(struct napi_struct *napi, int budget) · line 3429

Quoted 2 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	u32 queue = 0;

Thanks Thierry,
but this look like an equivalent patch to Joao's "net: stmmac: fix number of tx queues in stmmac_poll" which I already used during bisecting to avoid random crashes in stmmac_tx_clean.

Yeah, patch 3/3 is the important one in this batch. I just sent out the complete set of 3 because it's what I use on top of linux-next to make stmmac work again on my setup.

Quoted 2 lines

Have you noticed random RX brokenness after boot in recent linux-next tags?

Yes, I was seeing about 8 in 10 bad boots and 2 in 10 good ones.

Quoted 3 lines

It feels like it might trigger more often after a cold boot, but that could just be my brain seeing patterns that aren't really there :)

It'd be good if you could try applying patch 3/3 since that got me back to 10/10 successful boots. It's somewhat surprising because I had gone through the code looking for uninitialized data that would explain why kcalloc() instead of kmalloc_array() would fix things but didn't find anything.

Still, that patch works for me, so maybe I was just overlooking something.

Thierry

#23 lore raw

PATCH 3/3 net: stmmac: Prefer kcalloc() over kmalloc_array()

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Some of the data in the new queue structures seems to not be properly initialized, causing undefined behaviour (networking will work about 2 out of 10 tries). kcalloc() will zero the allocated memory and results in 10 out of 10 successful boots.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 37 +++++++++++------------
 1 file changed, 17 insertions(+), 20 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +17 -20
index ec5bba85c529..845320bc3333 100644
@@ -1412,13 +1412,12 @@ static void free_dma_desc_resources(struct stmmac_priv *priv)
 static int alloc_rx_dma_desc_resources(struct stmmac_priv *priv)
 {
 	u32 rx_count = priv->plat->rx_queues_to_use;
+	struct stmmac_rx_queue *rx_q;
 	int ret = -ENOMEM;
 	u32 queue = 0;
 
 	/* Allocate RX queues array */
-	priv->rx_queue = kmalloc_array(rx_count,
-				       sizeof(struct stmmac_rx_queue),
-				       GFP_KERNEL);
+	priv->rx_queue = kcalloc(rx_count, sizeof(*rx_q), GFP_KERNEL);
 	if (!priv->rx_queue) {
 		kfree(priv->rx_queue);
 		return -ENOMEM;
@@ -1426,20 +1425,19 @@ static int alloc_rx_dma_desc_resources(struct stmmac_priv *priv)
 
 	/* RX queues buffers and DMA */
 	for (queue = 0; queue < rx_count; queue++) {
-		struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue];
+		rx_q = &priv->rx_queue[queue];
 
 		rx_q->queue_index = queue;
 		rx_q->priv_data = priv;
 
-		rx_q->rx_skbuff_dma = kmalloc_array(DMA_RX_SIZE,
-							sizeof(dma_addr_t),
-							GFP_KERNEL);
+		rx_q->rx_skbuff_dma = kcalloc(DMA_RX_SIZE, sizeof(dma_addr_t),
+					      GFP_KERNEL);
 		if (!rx_q->rx_skbuff_dma)
 			goto err_dma_buffers;
 
-		rx_q->rx_skbuff = kmalloc_array(DMA_RX_SIZE,
-						    sizeof(struct sk_buff *),
-						    GFP_KERNEL);
+		rx_q->rx_skbuff = kcalloc(DMA_RX_SIZE,
+					  sizeof(struct sk_buff *),
+					  GFP_KERNEL);
 		if (!rx_q->rx_skbuff)
 			goto err_dma_buffers;
 
@@ -1477,33 +1475,32 @@ static int alloc_rx_dma_desc_resources(struct stmmac_priv *priv)
 static int alloc_tx_dma_desc_resources(struct stmmac_priv *priv)
 {
 	u32 tx_count = priv->plat->tx_queues_to_use;
+	struct stmmac_tx_queue *tx_q;
 	int ret = -ENOMEM;
 	u32 queue = 0;
 
 	/* Allocate TX queues array */
-	priv->tx_queue = kmalloc_array(tx_count,
-				       sizeof(struct stmmac_tx_queue),
-				       GFP_KERNEL);
+	priv->tx_queue = kcalloc(tx_count, sizeof(*tx_q), GFP_KERNEL);
 	if (!priv->tx_queue)
 		return -ENOMEM;
 
 	/* TX queues buffers and DMA */
 	for (queue = 0; queue < tx_count; queue++) {
-		struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue];
+		tx_q = &priv->tx_queue[queue];
 
 		tx_q->queue_index = queue;
 		tx_q->priv_data = priv;
 
-		tx_q->tx_skbuff_dma = kmalloc_array(DMA_TX_SIZE,
-					  sizeof(struct stmmac_tx_info),
-					  GFP_KERNEL);
+		tx_q->tx_skbuff_dma = kcalloc(DMA_TX_SIZE,
+					      sizeof(struct stmmac_tx_info),
+					      GFP_KERNEL);
 
 		if (!tx_q->tx_skbuff_dma)
 			goto err_dma_buffers;
 
-		tx_q->tx_skbuff = kmalloc_array(DMA_TX_SIZE,
-						    sizeof(struct sk_buff *),
-						    GFP_KERNEL);
+		tx_q->tx_skbuff = kcalloc(DMA_TX_SIZE,
+					  sizeof(struct sk_buff *),
+					  GFP_KERNEL);
 		if (!tx_q->tx_skbuff)
 			goto err_dma_buffers;
 
Signature · 1 line
2.12.0
Tested-by on v1 3/3
#24 lore raw

Re: [PATCH 3/3] net: stmmac: Prefer kcalloc() over kmalloc_array()

(resending mail without SPAM header)

Hi Thierry

Sorry that I missed your previous email, for some reason it got stuck in the spam filter.

Really good catch. This patch fixes the random RX brokenness for me. Thanks!

It would be nice with a Fixes tag though, but lately there's been so many changes, so it might be hard to point to a single commit.

Nevertheless:

Quoted 103 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Some of the data in the new queue structures seems to not be properly initialized, causing undefined behaviour (networking will work about 2 out of 10 tries). kcalloc() will zero the allocated memory and results in 10 out of 10 successful boots.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 37 +++++++++++------------
 1 file changed, 17 insertions(+), 20 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +17 -20
index ec5bba85c529..845320bc3333 100644
@@ -1412,13 +1412,12 @@ static void free_dma_desc_resources(struct stmmac_priv *priv)
 static int alloc_rx_dma_desc_resources(struct stmmac_priv *priv)
 {
 	u32 rx_count = priv->plat->rx_queues_to_use;
+	struct stmmac_rx_queue *rx_q;
 	int ret = -ENOMEM;
 	u32 queue = 0;
 
 	/* Allocate RX queues array */
-	priv->rx_queue = kmalloc_array(rx_count,
-				       sizeof(struct stmmac_rx_queue),
-				       GFP_KERNEL);
+	priv->rx_queue = kcalloc(rx_count, sizeof(*rx_q), GFP_KERNEL);
 	if (!priv->rx_queue) {
 		kfree(priv->rx_queue);
 		return -ENOMEM;
@@ -1426,20 +1425,19 @@ static int alloc_rx_dma_desc_resources(struct stmmac_priv *priv)
 
 	/* RX queues buffers and DMA */
 	for (queue = 0; queue < rx_count; queue++) {
-		struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue];
+		rx_q = &priv->rx_queue[queue];
 
 		rx_q->queue_index = queue;
 		rx_q->priv_data = priv;
 
-		rx_q->rx_skbuff_dma = kmalloc_array(DMA_RX_SIZE,
-							sizeof(dma_addr_t),
-							GFP_KERNEL);
+		rx_q->rx_skbuff_dma = kcalloc(DMA_RX_SIZE, sizeof(dma_addr_t),
+					      GFP_KERNEL);
 		if (!rx_q->rx_skbuff_dma)
 			goto err_dma_buffers;
 
-		rx_q->rx_skbuff = kmalloc_array(DMA_RX_SIZE,
-						    sizeof(struct sk_buff *),
-						    GFP_KERNEL);
+		rx_q->rx_skbuff = kcalloc(DMA_RX_SIZE,
+					  sizeof(struct sk_buff *),
+					  GFP_KERNEL);
 		if (!rx_q->rx_skbuff)
 			goto err_dma_buffers;
 
@@ -1477,33 +1475,32 @@ static int alloc_rx_dma_desc_resources(struct stmmac_priv *priv)
 static int alloc_tx_dma_desc_resources(struct stmmac_priv *priv)
 {
 	u32 tx_count = priv->plat->tx_queues_to_use;
+	struct stmmac_tx_queue *tx_q;
 	int ret = -ENOMEM;
 	u32 queue = 0;
 
 	/* Allocate TX queues array */
-	priv->tx_queue = kmalloc_array(tx_count,
-				       sizeof(struct stmmac_tx_queue),
-				       GFP_KERNEL);
+	priv->tx_queue = kcalloc(tx_count, sizeof(*tx_q), GFP_KERNEL);
 	if (!priv->tx_queue)
 		return -ENOMEM;
 
 	/* TX queues buffers and DMA */
 	for (queue = 0; queue < tx_count; queue++) {
-		struct stmmac_tx_queue *tx_q = &priv->tx_queue[queue];
+		tx_q = &priv->tx_queue[queue];
 
 		tx_q->queue_index = queue;
 		tx_q->priv_data = priv;
 
-		tx_q->tx_skbuff_dma = kmalloc_array(DMA_TX_SIZE,
-					  sizeof(struct stmmac_tx_info),
-					  GFP_KERNEL);
+		tx_q->tx_skbuff_dma = kcalloc(DMA_TX_SIZE,
+					      sizeof(struct stmmac_tx_info),
+					      GFP_KERNEL);
 
 		if (!tx_q->tx_skbuff_dma)
 			goto err_dma_buffers;
 
-		tx_q->tx_skbuff = kmalloc_array(DMA_TX_SIZE,
-						    sizeof(struct sk_buff *),
-						    GFP_KERNEL);
+		tx_q->tx_skbuff = kcalloc(DMA_TX_SIZE,
+					  sizeof(struct sk_buff *),
+					  GFP_KERNEL);
 		if (!tx_q->tx_skbuff)
 			goto err_dma_buffers;
 
#25 lore raw

Re: [PATCH net-next 2/2] net: stmmac: fix number of tx queues in stmmac_poll

In reply to Niklas Cassel
Quoted 84 lines · Niklas Cassel
Quoted 59 lines · Joao Pinto

Às 6:28 PM de 3/27/2017, David Miller escreveu:

Quoted 40 lines

From: Corentin Labbe <[email protected]>
Date: Mon, 27 Mar 2017 19:00:58 +0200

Quoted 37 lines · Joao Pinto
Quoted 36 lines

Hi David,

Às 7:26 AM de 3/25/2017, Corentin Labbe escreveu:

Quoted 20 lines · Joao Pinto
Quoted 19 lines

For cores that have more than 1 TX queue configured, the kernel would crash, since only one TX queue is permitted by default.

---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +1 -1
index 3827952..1eab084 100644
@@ -3429,7 +3429,7 @@ static int stmmac_poll(struct napi_struct *napi, int budget)
 	struct stmmac_rx_queue *rx_q =
 		container_of(napi, struct stmmac_rx_queue, napi);
 	struct stmmac_priv *priv = rx_q->priv_data;
-	u32 tx_count = priv->dma_cap.number_tx_queues;
+	u32 tx_count = priv->plat->tx_queues_to_use;
 	u32 chan = rx_q->queue_index;
Quoted 9 lines
Quoted 5 lines
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -0
 	u32 work_done = 0;
 	u32 queue = 0;
Signature · 1 line
2.9.3

This patch fix the performance issue on dwmac-sun8i only. The dwmac-sunxi is still broken.

This patch series can be upstreamed please, since they make 2 fixes, one of them solving the problem in dwmac-sun8i.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Thanks.

As I said in a previous answer, finaly dwmac-sun8i is still broken. Adding thoses 2 patch will just made the revert harder.

I agree.

For what I am understanding, SoCs base on Core versions >= 4.00 are working properly and for some reason SoCs based on older versions are not working.

This fix is necessary, since if you have a diferent configured tx_queues_to_use in the driver and priv->dma_cap.number_tx_queues in the core, this can lead to kernel crashes.

The other fix (netdev resources release) is also necessary, since when you release the driver its crashes, because the rx queue struct is freed before releasing the netdevs.

Quoted 5 lines

We can revert, but I think it might not solve the issue. We can break the "multiple buffers" patch into "rx multilple buffers" and "tx multiple buffers", but will that actually work? We can give it a try, I don't mind making a new multiple buffers patch broken into 2, that can be tested by new cores and older cores.

I've hit a bug on stmmac where RX is broken after boot. Sometimes it works, and sometimes it doesn't.
I usually notice that DHCP never receives an offer,
but it's possible to reproduce the problem without DHCP, where a simple ping will not work after setting an address manually.

I've bisected it to commit aff3d9eff843 ("net: stmmac: enable multiple buffers"). (Note that I had to cherry-pick 22446ad8e118 ("net: stmmac: Restore DT backwards-compatibility") to avoid TX queue timeouts, and the patch included in the beginning of this
mail thread "net: stmmac: fix number of tx queues in stmmac_poll" to avoid random crashes in stmmac_tx_clean.

Looking at wireshark I can see that we send out a DHCP discover, so TX seems to be working.
A DHCP offer is sent out from the server, but it is never received.

Quoted 7 lines

Our setup has 1 RX queue and 2 TX queues.
According to the databook, the field Receive Queue Size in register MTL_RxQ0_Operation_Mode is read-only when number of RX queues == 1, so I guess the problem is not related to RX queue size. It's quite annoying since it does not trigger every single boot.

Has anyone else noticed broken RX after boot since commit aff3d9eff843 and newer?

Yeah, I've been hitting the same, or at least very similar, issue. I'm going to attach my local stack of three patches, of which the first is only cleanup, the second is the same as the one that Joao had sent out earlier and patch three seems to be the one that gets things back on track for me. I haven't quite figured out why yet, but it'd be interesting to see if it fixes things for others.

Thierry

#26 lore raw
In reply to Joao Pinto
Quoted 12 lines · Joao Pinto

This patch set contains two fixes for problems I detected when ran the driver in single queue mode.

Please test in your setups to check if you get better results.

Joao Pinto (2):
net: stmmac: fix netdev release
net: stmmac: fix number of tx queues in stmmac_poll

 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Hello Joao,

I think that it would be helpful if these commit messages were a little more elaborate.
Both of these commit messages just say "fixes kernel crash". Please include the relevant part of the stack trace so that others will know if the bug you are fixing is the same as theirs.

Regards,
Niklas