All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor
@ 2019-12-10 17:06 Aviraj CJ
  2019-12-10 17:06 ` [PATCH 2/2] net: stmmac: don't stop NAPI processing when dropping a packet Aviraj CJ
  2019-12-10 20:55 ` [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: Aviraj CJ @ 2019-12-10 17:06 UTC (permalink / raw)
  To: peppe.cavallaro, netdev, gregkh, xe-linux-external; +Cc: Aviraj CJ

We always program the maximum DMA buffer size into the receive descriptor,
although the allocated size may be less. E.g. with the default MTU size
we allocate only 1536 bytes. If somebody sends us a bigger frame, then
memory may get corrupted.

Program DMA using exact buffer sizes.

[Adopted based on upstream commit c13a936f46e3321ad2426443296571fab2feda44
("net: stmmac: use correct DMA buffer size in the RX descriptor")
by Aaro Koskinen <aaro.koskinen@nokia.com> ]

Signed-off-by: Aviraj CJ <acj@cisco.com>
---
 drivers/net/ethernet/stmicro/stmmac/common.h      |  2 +-
 drivers/net/ethernet/stmicro/stmmac/descs_com.h   | 14 ++++++++++----
 drivers/net/ethernet/stmicro/stmmac/enh_desc.c    | 10 +++++++---
 drivers/net/ethernet/stmicro/stmmac/norm_desc.c   | 10 +++++++---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c |  4 ++--
 5 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h
index 623c6ed8764a..803df6a32ba9 100644
--- a/drivers/net/ethernet/stmicro/stmmac/common.h
+++ b/drivers/net/ethernet/stmicro/stmmac/common.h
@@ -301,7 +301,7 @@ struct dma_features {
 struct stmmac_desc_ops {
 	/* DMA RX descriptor ring initialization */
 	void (*init_rx_desc) (struct dma_desc *p, int disable_rx_ic, int mode,
-			      int end);
+			      int end, int bfsize);
 	/* DMA TX descriptor ring initialization */
 	void (*init_tx_desc) (struct dma_desc *p, int mode, int end);
 
diff --git a/drivers/net/ethernet/stmicro/stmmac/descs_com.h b/drivers/net/ethernet/stmicro/stmmac/descs_com.h
index 6f2cc78c5cf5..6b83fc8e6fbe 100644
--- a/drivers/net/ethernet/stmicro/stmmac/descs_com.h
+++ b/drivers/net/ethernet/stmicro/stmmac/descs_com.h
@@ -33,9 +33,10 @@
 /* Specific functions used for Ring mode */
 
 /* Enhanced descriptors */
-static inline void ehn_desc_rx_set_on_ring(struct dma_desc *p, int end)
+static inline void ehn_desc_rx_set_on_ring(struct dma_desc *p, int end, int bfsize)
 {
-	p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1;
+	if (bfsize == BUF_SIZE_16KiB)
+		p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1;
 	if (end)
 		p->des01.erx.end_ring = 1;
 }
@@ -61,9 +62,14 @@ static inline void enh_set_tx_desc_len_on_ring(struct dma_desc *p, int len)
 }
 
 /* Normal descriptors */
-static inline void ndesc_rx_set_on_ring(struct dma_desc *p, int end)
+static inline void ndesc_rx_set_on_ring(struct dma_desc *p, int end, int bfsize)
 {
-	p->des01.rx.buffer2_size = BUF_SIZE_2KiB - 1;
+	int size;
+
+	if (bfsize >= BUF_SIZE_2KiB) {
+		size = min(bfsize - BUF_SIZE_2KiB + 1, BUF_SIZE_2KiB - 1);
+		p->des01.rx.buffer2_size = size;
+	}
 	if (end)
 		p->des01.rx.end_ring = 1;
 }
diff --git a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
index 7d944449f5ef..9ecb3a948f86 100644
--- a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c
@@ -238,16 +238,20 @@ static int enh_desc_get_rx_status(void *data, struct stmmac_extra_stats *x,
 }
 
 static void enh_desc_init_rx_desc(struct dma_desc *p, int disable_rx_ic,
-				  int mode, int end)
+				  int mode, int end, int bfsize)
 {
+	int bfsize1;
+
 	p->des01.all_flags = 0;
 	p->des01.erx.own = 1;
-	p->des01.erx.buffer1_size = BUF_SIZE_8KiB - 1;
+
+	bfsize1 = min(bfsize, BUF_SIZE_8KiB - 1);
+	p->des01.erx.buffer1_size = bfsize1;
 
 	if (mode == STMMAC_CHAIN_MODE)
 		ehn_desc_rx_set_on_chain(p, end);
 	else
-		ehn_desc_rx_set_on_ring(p, end);
+		ehn_desc_rx_set_on_ring(p, end, bfsize);
 
 	if (disable_rx_ic)
 		p->des01.erx.disable_ic = 1;
diff --git a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
index 48c3456445b2..07e0c03cfb10 100644
--- a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
+++ b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c
@@ -121,16 +121,20 @@ static int ndesc_get_rx_status(void *data, struct stmmac_extra_stats *x,
 }
 
 static void ndesc_init_rx_desc(struct dma_desc *p, int disable_rx_ic, int mode,
-			       int end)
+			       int end, int bfsize)
 {
+	int bfsize1;
+
 	p->des01.all_flags = 0;
 	p->des01.rx.own = 1;
-	p->des01.rx.buffer1_size = BUF_SIZE_2KiB - 1;
+
+	bfsize1 = min(bfsize, (BUF_SIZE_2KiB - 1));
+	p->des01.rx.buffer1_size = bfsize1;
 
 	if (mode == STMMAC_CHAIN_MODE)
 		ndesc_rx_set_on_chain(p, end);
 	else
-		ndesc_rx_set_on_ring(p, end);
+		ndesc_rx_set_on_ring(p, end, bfsize);
 
 	if (disable_rx_ic)
 		p->des01.rx.disable_ic = 1;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index f4d6512f066c..e9d41e03121c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -964,11 +964,11 @@ static void stmmac_clear_descriptors(struct stmmac_priv *priv)
 		if (priv->extend_desc)
 			priv->hw->desc->init_rx_desc(&priv->dma_erx[i].basic,
 						     priv->use_riwt, priv->mode,
-						     (i == rxsize - 1));
+						     (i == rxsize - 1), priv->dma_buf_sz);
 		else
 			priv->hw->desc->init_rx_desc(&priv->dma_rx[i],
 						     priv->use_riwt, priv->mode,
-						     (i == rxsize - 1));
+						     (i == rxsize - 1), priv->dma_buf_sz);
 	for (i = 0; i < txsize; i++)
 		if (priv->extend_desc)
 			priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic,
-- 
2.19.1


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

* [PATCH 2/2] net: stmmac: don't stop NAPI processing when dropping a packet
  2019-12-10 17:06 [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor Aviraj CJ
@ 2019-12-10 17:06 ` Aviraj CJ
  2019-12-10 20:55 ` [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor Greg KH
  1 sibling, 0 replies; 6+ messages in thread
From: Aviraj CJ @ 2019-12-10 17:06 UTC (permalink / raw)
  To: peppe.cavallaro, netdev, gregkh, xe-linux-external; +Cc: Aviraj CJ

Currently, if we drop a packet, we exit from NAPI loop before the budget
is consumed. In some situations this will make the RX processing stall
e.g. when flood pinging the system with oversized packets, as the
errorneous packets are not dropped efficiently.

If we drop a packet, we should just continue to the next one as long as
the budget allows.

[ Adopted based on upstream commit 2170bbf19f6ef6b2740f186ee107827f31395218
("net: stmmac: don't stop NAPI processing when dropping a packet")
by Aaro Koskinen <aaro.koskinen@nokia.com> ]

Signed-off-by: Aviraj CJ <acj@cisco.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index e9d41e03121c..3b514ba570b8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2176,8 +2176,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv)
 static int stmmac_rx(struct stmmac_priv *priv, int limit)
 {
 	unsigned int rxsize = priv->dma_rx_size;
-	unsigned int entry = priv->cur_rx % rxsize;
-	unsigned int next_entry;
+	unsigned int next_entry = priv->cur_rx % rxsize;
 	unsigned int count = 0;
 	int coe = priv->hw->rx_csum;
 
@@ -2191,6 +2190,9 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
 	while (count < limit) {
 		int status;
 		struct dma_desc *p;
+		unsigned int entry;
+
+		entry = next_entry;
 
 		if (priv->extend_desc)
 			p = (struct dma_desc *)(priv->dma_erx + entry);
@@ -2239,7 +2241,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
 			/*  check if frame_len fits the preallocated memory */
 			if (frame_len > priv->dma_buf_sz) {
 				priv->dev->stats.rx_length_errors++;
-				break;
+				continue;
 			}
 
 			/* ACS is set; GMAC core strips PAD/FCS for IEEE 802.3
@@ -2260,7 +2262,7 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
 				pr_err("%s: Inconsistent Rx descriptor chain\n",
 				       priv->dev->name);
 				priv->dev->stats.rx_dropped++;
-				break;
+				continue;
 			}
 			prefetch(skb->data - NET_IP_ALIGN);
 			priv->rx_skbuff[entry] = NULL;
@@ -2291,7 +2293,6 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit)
 			priv->dev->stats.rx_packets++;
 			priv->dev->stats.rx_bytes += frame_len;
 		}
-		entry = next_entry;
 	}
 
 	stmmac_rx_refill(priv);
-- 
2.19.1


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

* Re: [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor
  2019-12-10 17:06 [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor Aviraj CJ
  2019-12-10 17:06 ` [PATCH 2/2] net: stmmac: don't stop NAPI processing when dropping a packet Aviraj CJ
@ 2019-12-10 20:55 ` Greg KH
  2019-12-10 21:40   ` Daniel Walker (danielwa)
  1 sibling, 1 reply; 6+ messages in thread
From: Greg KH @ 2019-12-10 20:55 UTC (permalink / raw)
  To: Aviraj CJ; +Cc: peppe.cavallaro, netdev, xe-linux-external

On Tue, Dec 10, 2019 at 09:06:58AM -0800, Aviraj CJ wrote:
> We always program the maximum DMA buffer size into the receive descriptor,
> although the allocated size may be less. E.g. with the default MTU size
> we allocate only 1536 bytes. If somebody sends us a bigger frame, then
> memory may get corrupted.
> 
> Program DMA using exact buffer sizes.
> 
> [Adopted based on upstream commit c13a936f46e3321ad2426443296571fab2feda44
> ("net: stmmac: use correct DMA buffer size in the RX descriptor")
> by Aaro Koskinen <aaro.koskinen@nokia.com> ]

Adopted to what?

What is this patch for, it looks just like the commit you reference
here.

totally confused,

greg k-h

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

* Re: [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor
  2019-12-10 20:55 ` [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor Greg KH
@ 2019-12-10 21:40   ` Daniel Walker (danielwa)
  2019-12-11  1:06     ` David Miller
  2019-12-11  7:38     ` Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: Daniel Walker (danielwa) @ 2019-12-10 21:40 UTC (permalink / raw)
  To: Greg KH
  Cc: Aviraj Cj (acj), peppe.cavallaro, netdev, xe-linux-external(mailer list)

On Tue, Dec 10, 2019 at 09:55:42PM +0100, Greg KH wrote:
> On Tue, Dec 10, 2019 at 09:06:58AM -0800, Aviraj CJ wrote:
> > We always program the maximum DMA buffer size into the receive descriptor,
> > although the allocated size may be less. E.g. with the default MTU size
> > we allocate only 1536 bytes. If somebody sends us a bigger frame, then
> > memory may get corrupted.
> > 
> > Program DMA using exact buffer sizes.
> > 
> > [Adopted based on upstream commit c13a936f46e3321ad2426443296571fab2feda44
> > ("net: stmmac: use correct DMA buffer size in the RX descriptor")
> > by Aaro Koskinen <aaro.koskinen@nokia.com> ]
> 
> Adopted to what?
> 
> What is this patch for, it looks just like the commit you reference
> here.
> 
> totally confused,


We're using the patches on the v4.4 -stable branch. It doesn't have these patches and
the backport had rejects.

Daniel

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

* Re: [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor
  2019-12-10 21:40   ` Daniel Walker (danielwa)
@ 2019-12-11  1:06     ` David Miller
  2019-12-11  7:38     ` Greg KH
  1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2019-12-11  1:06 UTC (permalink / raw)
  To: danielwa; +Cc: gregkh, acj, peppe.cavallaro, netdev, xe-linux-external

From: "Daniel Walker (danielwa)" <danielwa@cisco.com>
Date: Tue, 10 Dec 2019 21:40:17 +0000

> On Tue, Dec 10, 2019 at 09:55:42PM +0100, Greg KH wrote:
>> On Tue, Dec 10, 2019 at 09:06:58AM -0800, Aviraj CJ wrote:
>> > We always program the maximum DMA buffer size into the receive descriptor,
>> > although the allocated size may be less. E.g. with the default MTU size
>> > we allocate only 1536 bytes. If somebody sends us a bigger frame, then
>> > memory may get corrupted.
>> > 
>> > Program DMA using exact buffer sizes.
>> > 
>> > [Adopted based on upstream commit c13a936f46e3321ad2426443296571fab2feda44
>> > ("net: stmmac: use correct DMA buffer size in the RX descriptor")
>> > by Aaro Koskinen <aaro.koskinen@nokia.com> ]
>> 
>> Adopted to what?
>> 
>> What is this patch for, it looks just like the commit you reference
>> here.
>> 
>> totally confused,
> 
> 
> We're using the patches on the v4.4 -stable branch. It doesn't have these patches and
> the backport had rejects.

As submitted the patch looks like something destined for mainline.

Not specifying the context into which the change is meant to be placed
wastes a lot of precious developer time.

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

* Re: [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor
  2019-12-10 21:40   ` Daniel Walker (danielwa)
  2019-12-11  1:06     ` David Miller
@ 2019-12-11  7:38     ` Greg KH
  1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2019-12-11  7:38 UTC (permalink / raw)
  To: Daniel Walker (danielwa)
  Cc: Aviraj Cj (acj), peppe.cavallaro, netdev, xe-linux-external(mailer list)

On Tue, Dec 10, 2019 at 09:40:17PM +0000, Daniel Walker (danielwa) wrote:
> On Tue, Dec 10, 2019 at 09:55:42PM +0100, Greg KH wrote:
> > On Tue, Dec 10, 2019 at 09:06:58AM -0800, Aviraj CJ wrote:
> > > We always program the maximum DMA buffer size into the receive descriptor,
> > > although the allocated size may be less. E.g. with the default MTU size
> > > we allocate only 1536 bytes. If somebody sends us a bigger frame, then
> > > memory may get corrupted.
> > > 
> > > Program DMA using exact buffer sizes.
> > > 
> > > [Adopted based on upstream commit c13a936f46e3321ad2426443296571fab2feda44
> > > ("net: stmmac: use correct DMA buffer size in the RX descriptor")
> > > by Aaro Koskinen <aaro.koskinen@nokia.com> ]
> > 
> > Adopted to what?
> > 
> > What is this patch for, it looks just like the commit you reference
> > here.
> > 
> > totally confused,
> 
> 
> We're using the patches on the v4.4 -stable branch. It doesn't have these patches and
> the backport had rejects.

Ok, but commit "c13a936f46e3321ad2426443296571fab2feda44" is not in
Linus's tree, and so I think you really mean 583e63614149 ("net: stmmac:
use correct DMA buffer size in the RX descriptor") which is only
included in 4.19 and newer kernels.

So why would this need to go to 4.4.y?

And if so, it needs to be explicitly stated as such, you all have read
the stable kernel rules file, right?

Please fix up and resend properly, as well as providing a version for
newer kernels also if you really want this in a 4.4.y release.

As David said, to not do so just causes a total waste of developer time
trying to figure out what you all are wanting to do here...

thanks,

greg k-h

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

end of thread, other threads:[~2019-12-11  7:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-10 17:06 [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor Aviraj CJ
2019-12-10 17:06 ` [PATCH 2/2] net: stmmac: don't stop NAPI processing when dropping a packet Aviraj CJ
2019-12-10 20:55 ` [PATCH 1/2] net: stmmac: use correct DMA buffer size in the RX descriptor Greg KH
2019-12-10 21:40   ` Daniel Walker (danielwa)
2019-12-11  1:06     ` David Miller
2019-12-11  7:38     ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.