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
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
11 Branch to use __get_free_pages when ring->frag_size > PAGE_SIZE.
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>
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
24 +static void *mtk_max_lro_buf_alloc(gfp_t gfp_mask)
26 + unsigned int size = mtk_max_frag_size(MTK_MAX_LRO_RX_LENGTH);
29 + data = __get_free_pages(gfp_mask | __GFP_COMP | __GFP_NOWARN,
32 + return (void *)data;
35 /* the qdma core needs scratch memory to be setup */
36 static int mtk_init_fq_dma(struct mtk_eth *eth)
38 @@ -1485,7 +1496,10 @@ static int mtk_poll_rx(struct napi_struc
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);
46 + new_data = mtk_max_lro_buf_alloc(GFP_ATOMIC);
47 if (unlikely(!new_data)) {
48 netdev->stats.rx_dropped++;
50 @@ -1938,7 +1952,10 @@ static int mtk_rx_alloc(struct mtk_eth *
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);
58 + ring->data[i] = mtk_max_lro_buf_alloc(GFP_KERNEL);