9c86413ce72bec65ab6540191213ae7c1ed7a3b8
[openwrt/staging/svanheule.git] /
1 From: Chen Lin <chen45464546@163.com>
2 Date: Wed, 8 Jun 2022 20:46:53 +0800
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: fix misuse of mem alloc interface
4 netdev[napi]_alloc_frag
5
6 When rx_flag == MTK_RX_FLAGS_HWLRO,
7 rx_data_len = MTK_MAX_LRO_RX_LENGTH(4096 * 3) > PAGE_SIZE.
8 netdev_alloc_frag is for alloction of page fragment only.
9 Reference to other drivers and Documentation/vm/page_frags.rst
10
11 Branch to use __get_free_pages when ring->frag_size > PAGE_SIZE.
12
13 Signed-off-by: Chen Lin <chen45464546@163.com>
14 Link: https://lore.kernel.org/r/1654692413-2598-1-git-send-email-chen45464546@163.com
15 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
16 ---
17
18 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 @@ -917,6 +917,17 @@ static bool mtk_rx_get_desc(struct mtk_e
21 return true;
22 }
23
24 +static void *mtk_max_lro_buf_alloc(gfp_t gfp_mask)
25 +{
26 + unsigned int size = mtk_max_frag_size(MTK_MAX_LRO_RX_LENGTH);
27 + unsigned long data;
28 +
29 + data = __get_free_pages(gfp_mask | __GFP_COMP | __GFP_NOWARN,
30 + get_order(size));
31 +
32 + return (void *)data;
33 +}
34 +
35 /* the qdma core needs scratch memory to be setup */
36 static int mtk_init_fq_dma(struct mtk_eth *eth)
37 {
38 @@ -1485,7 +1496,10 @@ static int mtk_poll_rx(struct napi_struc
39 goto release_desc;
40
41 /* alloc new buffer */
42 - new_data = napi_alloc_frag(ring->frag_size);
43 + if (ring->frag_size <= PAGE_SIZE)
44 + new_data = napi_alloc_frag(ring->frag_size);
45 + else
46 + new_data = mtk_max_lro_buf_alloc(GFP_ATOMIC);
47 if (unlikely(!new_data)) {
48 netdev->stats.rx_dropped++;
49 goto release_desc;
50 @@ -1938,7 +1952,10 @@ static int mtk_rx_alloc(struct mtk_eth *
51 return -ENOMEM;
52
53 for (i = 0; i < rx_dma_size; i++) {
54 - ring->data[i] = netdev_alloc_frag(ring->frag_size);
55 + if (ring->frag_size <= PAGE_SIZE)
56 + ring->data[i] = netdev_alloc_frag(ring->frag_size);
57 + else
58 + ring->data[i] = mtk_max_lro_buf_alloc(GFP_KERNEL);
59 if (!ring->data[i])
60 return -ENOMEM;
61 }