Commit f2d4feac authored by Simon Guinot's avatar Simon Guinot Committed by Luis Henriques

net: mvneta: fix refilling for Rx DMA buffers

commit a84e3289 upstream.

With the actual code, if a memory allocation error happens while
refilling a Rx descriptor, then the original Rx buffer is both passed
to the networking stack (in a SKB) and let in the Rx ring. This leads
to various kernel oops and crashes.

As a fix, this patch moves Rx descriptor refilling ahead of building
SKB with the associated Rx buffer. In case of a memory allocation
failure, data is dropped and the original DMA buffer is put back into
the Rx ring.
Signed-off-by: default avatarSimon Guinot <simon.guinot@sequanux.org>
Fixes: c5aff182 ("net: mvneta: driver for Marvell Armada 370/XP network unit")
Tested-by: default avatarYoann Sculo <yoann@sculo.fr>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 54f22a7f
...@@ -1433,7 +1433,7 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo, ...@@ -1433,7 +1433,7 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo,
struct mvneta_rx_queue *rxq) struct mvneta_rx_queue *rxq)
{ {
struct net_device *dev = pp->dev; struct net_device *dev = pp->dev;
int rx_done, rx_filled; int rx_done;
u32 rcvd_pkts = 0; u32 rcvd_pkts = 0;
u32 rcvd_bytes = 0; u32 rcvd_bytes = 0;
...@@ -1444,7 +1444,6 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo, ...@@ -1444,7 +1444,6 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo,
rx_todo = rx_done; rx_todo = rx_done;
rx_done = 0; rx_done = 0;
rx_filled = 0;
/* Fairness NAPI loop */ /* Fairness NAPI loop */
while (rx_done < rx_todo) { while (rx_done < rx_todo) {
...@@ -1455,7 +1454,6 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo, ...@@ -1455,7 +1454,6 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo,
int rx_bytes, err; int rx_bytes, err;
rx_done++; rx_done++;
rx_filled++;
rx_status = rx_desc->status; rx_status = rx_desc->status;
rx_bytes = rx_desc->data_size - (ETH_FCS_LEN + MVNETA_MH_SIZE); rx_bytes = rx_desc->data_size - (ETH_FCS_LEN + MVNETA_MH_SIZE);
data = (unsigned char *)rx_desc->buf_cookie; data = (unsigned char *)rx_desc->buf_cookie;
...@@ -1495,6 +1493,14 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo, ...@@ -1495,6 +1493,14 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo,
continue; continue;
} }
/* Refill processing */
err = mvneta_rx_refill(pp, rx_desc);
if (err) {
netdev_err(dev, "Linux processing - Can't refill\n");
rxq->missed++;
goto err_drop_frame;
}
skb = build_skb(data, pp->frag_size > PAGE_SIZE ? 0 : pp->frag_size); skb = build_skb(data, pp->frag_size > PAGE_SIZE ? 0 : pp->frag_size);
if (!skb) if (!skb)
goto err_drop_frame; goto err_drop_frame;
...@@ -1514,14 +1520,6 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo, ...@@ -1514,14 +1520,6 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo,
mvneta_rx_csum(pp, rx_status, skb); mvneta_rx_csum(pp, rx_status, skb);
napi_gro_receive(&pp->napi, skb); napi_gro_receive(&pp->napi, skb);
/* Refill processing */
err = mvneta_rx_refill(pp, rx_desc);
if (err) {
netdev_err(dev, "Linux processing - Can't refill\n");
rxq->missed++;
rx_filled--;
}
} }
if (rcvd_pkts) { if (rcvd_pkts) {
...@@ -1534,7 +1532,7 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo, ...@@ -1534,7 +1532,7 @@ static int mvneta_rx(struct mvneta_port *pp, int rx_todo,
} }
/* Update rxq management counters */ /* Update rxq management counters */
mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_filled); mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done);
return rx_done; return rx_done;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment