From 546bda0ac31e56305f16b553f1a533dc01a96a9f Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 19 Dec 2019 16:44:49 +0100 Subject: [PATCH] 4.14-stable patches added patches: net-stmmac-don-t-stop-napi-processing-when-dropping-a-packet.patch net-stmmac-use-correct-dma-buffer-size-in-the-rx-descriptor.patch --- ...pi-processing-when-dropping-a-packet.patch | 90 +++++++++ ...dma-buffer-size-in-the-rx-descriptor.patch | 172 ++++++++++++++++++ queue-4.14/series | 2 + 3 files changed, 264 insertions(+) create mode 100644 queue-4.14/net-stmmac-don-t-stop-napi-processing-when-dropping-a-packet.patch create mode 100644 queue-4.14/net-stmmac-use-correct-dma-buffer-size-in-the-rx-descriptor.patch diff --git a/queue-4.14/net-stmmac-don-t-stop-napi-processing-when-dropping-a-packet.patch b/queue-4.14/net-stmmac-don-t-stop-napi-processing-when-dropping-a-packet.patch new file mode 100644 index 00000000000..6657911f1a1 --- /dev/null +++ b/queue-4.14/net-stmmac-don-t-stop-napi-processing-when-dropping-a-packet.patch @@ -0,0 +1,90 @@ +From 07b3975352374c3f5ebb4a42ef0b253fe370542d Mon Sep 17 00:00:00 2001 +From: Aaro Koskinen +Date: Wed, 27 Mar 2019 22:35:37 +0200 +Subject: net: stmmac: don't stop NAPI processing when dropping a packet + +From: Aaro Koskinen + +commit 07b3975352374c3f5ebb4a42ef0b253fe370542d upstream. + +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. + +Signed-off-by: Aaro Koskinen +Signed-off-by: David S. Miller +[acj: backport v4.14 -stable +- adjust context] +Signed-off-by: Aviraj CJ +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 14 +++++++------- + 1 file changed, 7 insertions(+), 7 deletions(-) + +--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c ++++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +@@ -3323,9 +3323,8 @@ static inline void stmmac_rx_refill(stru + static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue) + { + struct stmmac_rx_queue *rx_q = &priv->rx_queue[queue]; +- unsigned int entry = rx_q->cur_rx; + int coe = priv->hw->rx_csum; +- unsigned int next_entry; ++ unsigned int next_entry = rx_q->cur_rx; + unsigned int count = 0; + + if (netif_msg_rx_status(priv)) { +@@ -3340,10 +3339,12 @@ static int stmmac_rx(struct stmmac_priv + priv->hw->desc->display_ring(rx_head, DMA_RX_SIZE, true); + } + while (count < limit) { +- int status; ++ int entry, status; + struct dma_desc *p; + struct dma_desc *np; + ++ entry = next_entry; ++ + if (priv->extend_desc) + p = (struct dma_desc *)(rx_q->dma_erx + entry); + else +@@ -3410,7 +3411,7 @@ static int stmmac_rx(struct stmmac_priv + "len %d larger than size (%d)\n", + 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 +@@ -3446,7 +3447,7 @@ static int stmmac_rx(struct stmmac_priv + dev_warn(priv->device, + "packet dropped\n"); + priv->dev->stats.rx_dropped++; +- break; ++ continue; + } + + dma_sync_single_for_cpu(priv->device, +@@ -3471,7 +3472,7 @@ static int stmmac_rx(struct stmmac_priv + "%s: Inconsistent Rx chain\n", + priv->dev->name); + priv->dev->stats.rx_dropped++; +- break; ++ continue; + } + prefetch(skb->data - NET_IP_ALIGN); + rx_q->rx_skbuff[entry] = NULL; +@@ -3506,7 +3507,6 @@ static int stmmac_rx(struct stmmac_priv + priv->dev->stats.rx_packets++; + priv->dev->stats.rx_bytes += frame_len; + } +- entry = next_entry; + } + + stmmac_rx_refill(priv, queue); diff --git a/queue-4.14/net-stmmac-use-correct-dma-buffer-size-in-the-rx-descriptor.patch b/queue-4.14/net-stmmac-use-correct-dma-buffer-size-in-the-rx-descriptor.patch new file mode 100644 index 00000000000..070f11dba0a --- /dev/null +++ b/queue-4.14/net-stmmac-use-correct-dma-buffer-size-in-the-rx-descriptor.patch @@ -0,0 +1,172 @@ +From 583e6361414903c5206258a30e5bd88cb03c0254 Mon Sep 17 00:00:00 2001 +From: Aaro Koskinen +Date: Wed, 27 Mar 2019 22:35:35 +0200 +Subject: net: stmmac: use correct DMA buffer size in the RX descriptor + +From: Aaro Koskinen + +commit 583e6361414903c5206258a30e5bd88cb03c0254 upstream. + +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. + +Fix by using exact buffer sizes. + +Signed-off-by: Aaro Koskinen +Signed-off-by: David S. Miller +[acj: backport v4.14 -stable +- adjust context +- skipped the section modifying non-existent functions in dwxgmac2_descs.c and +hwif.h ] +Signed-off-by: Aviraj CJ +Signed-off-by: Greg Kroah-Hartman +--- + drivers/net/ethernet/stmicro/stmmac/common.h | 2 - + drivers/net/ethernet/stmicro/stmmac/descs_com.h | 22 +++++++++++++-------- + drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c | 2 - + 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 | 8 ++++--- + 6 files changed, 35 insertions(+), 19 deletions(-) + +--- a/drivers/net/ethernet/stmicro/stmmac/common.h ++++ b/drivers/net/ethernet/stmicro/stmmac/common.h +@@ -367,7 +367,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); + +--- a/drivers/net/ethernet/stmicro/stmmac/descs_com.h ++++ b/drivers/net/ethernet/stmicro/stmmac/descs_com.h +@@ -29,11 +29,13 @@ + /* 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->des1 |= cpu_to_le32((BUF_SIZE_8KiB +- << ERDES1_BUFFER2_SIZE_SHIFT) +- & ERDES1_BUFFER2_SIZE_MASK); ++ if (bfsize == BUF_SIZE_16KiB) ++ p->des1 |= cpu_to_le32((BUF_SIZE_8KiB ++ << ERDES1_BUFFER2_SIZE_SHIFT) ++ & ERDES1_BUFFER2_SIZE_MASK); + + if (end) + p->des1 |= cpu_to_le32(ERDES1_END_RING); +@@ -59,11 +61,15 @@ static inline void enh_set_tx_desc_len_o + } + + /* 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->des1 |= cpu_to_le32(((BUF_SIZE_2KiB - 1) +- << RDES1_BUFFER2_SIZE_SHIFT) +- & RDES1_BUFFER2_SIZE_MASK); ++ if (bfsize >= BUF_SIZE_2KiB) { ++ int bfsize2; ++ ++ bfsize2 = min(bfsize - BUF_SIZE_2KiB + 1, BUF_SIZE_2KiB - 1); ++ p->des1 |= cpu_to_le32((bfsize2 << RDES1_BUFFER2_SIZE_SHIFT) ++ & RDES1_BUFFER2_SIZE_MASK); ++ } + + if (end) + p->des1 |= cpu_to_le32(RDES1_END_RING); +--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c ++++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c +@@ -293,7 +293,7 @@ exit: + } + + static void dwmac4_rd_init_rx_desc(struct dma_desc *p, int disable_rx_ic, +- int mode, int end) ++ int mode, int end, int bfsize) + { + p->des3 = cpu_to_le32(RDES3_OWN | RDES3_BUFFER1_VALID_ADDR); + +--- a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c ++++ b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c +@@ -265,15 +265,19 @@ static int enh_desc_get_rx_status(void * + } + + 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->des0 |= cpu_to_le32(RDES0_OWN); +- p->des1 |= cpu_to_le32(BUF_SIZE_8KiB & ERDES1_BUFFER1_SIZE_MASK); ++ ++ bfsize1 = min(bfsize, BUF_SIZE_8KiB); ++ p->des1 |= cpu_to_le32(bfsize1 & ERDES1_BUFFER1_SIZE_MASK); + + if (mode == STMMAC_CHAIN_MODE) + ehn_desc_rx_set_on_chain(p); + else +- ehn_desc_rx_set_on_ring(p, end); ++ ehn_desc_rx_set_on_ring(p, end, bfsize); + + if (disable_rx_ic) + p->des1 |= cpu_to_le32(ERDES1_DISABLE_IC); +--- a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c ++++ b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c +@@ -133,15 +133,19 @@ static int ndesc_get_rx_status(void *dat + } + + 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->des0 |= cpu_to_le32(RDES0_OWN); +- p->des1 |= cpu_to_le32((BUF_SIZE_2KiB - 1) & RDES1_BUFFER1_SIZE_MASK); ++ ++ bfsize1 = min(bfsize, BUF_SIZE_2KiB - 1); ++ p->des1 |= cpu_to_le32(bfsize1 & RDES1_BUFFER1_SIZE_MASK); + + 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->des1 |= cpu_to_le32(RDES1_DISABLE_IC); +--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c ++++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +@@ -1072,11 +1072,13 @@ static void stmmac_clear_rx_descriptors( + if (priv->extend_desc) + priv->hw->desc->init_rx_desc(&rx_q->dma_erx[i].basic, + priv->use_riwt, priv->mode, +- (i == DMA_RX_SIZE - 1)); ++ (i == DMA_RX_SIZE - 1), ++ priv->dma_buf_sz); + else + priv->hw->desc->init_rx_desc(&rx_q->dma_rx[i], + priv->use_riwt, priv->mode, +- (i == DMA_RX_SIZE - 1)); ++ (i == DMA_RX_SIZE - 1), ++ priv->dma_buf_sz); + } + + /** +@@ -3299,7 +3301,7 @@ static inline void stmmac_rx_refill(stru + dma_wmb(); + + if (unlikely(priv->synopsys_id >= DWMAC_CORE_4_00)) +- priv->hw->desc->init_rx_desc(p, priv->use_riwt, 0, 0); ++ priv->hw->desc->init_rx_desc(p, priv->use_riwt, 0, 0, priv->dma_buf_sz); + else + priv->hw->desc->set_rx_owner(p); + diff --git a/queue-4.14/series b/queue-4.14/series index 019daa28344..0c6d27702fa 100644 --- a/queue-4.14/series +++ b/queue-4.14/series @@ -33,3 +33,5 @@ dm-btree-increase-rebalance-threshold-in-__rebalance2.patch scsi-iscsi-fix-a-potential-deadlock-in-the-timeout-handler.patch drm-radeon-fix-r1xx-r2xx-register-checker-for-pot-textures.patch xhci-fix-usb3-device-initiated-resume-race-with-roothub-autosuspend.patch +net-stmmac-use-correct-dma-buffer-size-in-the-rx-descriptor.patch +net-stmmac-don-t-stop-napi-processing-when-dropping-a-packet.patch -- 2.47.3