generic: 6.1: move stmmac backport fix patches to generic
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 729-15-v6.2-net-ethernet-mtk_wed-fix-sleep-while-atomic-in-mtk_w.patch
1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Thu, 1 Dec 2022 16:26:53 +0100
3 Subject: [PATCH] net: ethernet: mtk_wed: fix sleep while atomic in
4 mtk_wed_wo_queue_refill
5
6 In order to fix the following sleep while atomic bug always alloc pages
7 with GFP_ATOMIC in mtk_wed_wo_queue_refill since page_frag_alloc runs in
8 spin_lock critical section.
9
10 [ 9.049719] Hardware name: MediaTek MT7986a RFB (DT)
11 [ 9.054665] Call trace:
12 [ 9.057096] dump_backtrace+0x0/0x154
13 [ 9.060751] show_stack+0x14/0x1c
14 [ 9.064052] dump_stack_lvl+0x64/0x7c
15 [ 9.067702] dump_stack+0x14/0x2c
16 [ 9.071001] ___might_sleep+0xec/0x120
17 [ 9.074736] __might_sleep+0x4c/0x9c
18 [ 9.078296] __alloc_pages+0x184/0x2e4
19 [ 9.082030] page_frag_alloc_align+0x98/0x1ac
20 [ 9.086369] mtk_wed_wo_queue_refill+0x134/0x234
21 [ 9.090974] mtk_wed_wo_init+0x174/0x2c0
22 [ 9.094881] mtk_wed_attach+0x7c8/0x7e0
23 [ 9.098701] mt7915_mmio_wed_init+0x1f0/0x3a0 [mt7915e]
24 [ 9.103940] mt7915_pci_probe+0xec/0x3bc [mt7915e]
25 [ 9.108727] pci_device_probe+0xac/0x13c
26 [ 9.112638] really_probe.part.0+0x98/0x2f4
27 [ 9.116807] __driver_probe_device+0x94/0x13c
28 [ 9.121147] driver_probe_device+0x40/0x114
29 [ 9.125314] __driver_attach+0x7c/0x180
30 [ 9.129133] bus_for_each_dev+0x5c/0x90
31 [ 9.132953] driver_attach+0x20/0x2c
32 [ 9.136513] bus_add_driver+0x104/0x1fc
33 [ 9.140333] driver_register+0x74/0x120
34 [ 9.144153] __pci_register_driver+0x40/0x50
35 [ 9.148407] mt7915_init+0x5c/0x1000 [mt7915e]
36 [ 9.152848] do_one_initcall+0x40/0x25c
37 [ 9.156669] do_init_module+0x44/0x230
38 [ 9.160403] load_module+0x1f30/0x2750
39 [ 9.164135] __do_sys_init_module+0x150/0x200
40 [ 9.168475] __arm64_sys_init_module+0x18/0x20
41 [ 9.172901] invoke_syscall.constprop.0+0x4c/0xe0
42 [ 9.177589] do_el0_svc+0x48/0xe0
43 [ 9.180889] el0_svc+0x14/0x50
44 [ 9.183929] el0t_64_sync_handler+0x9c/0x120
45 [ 9.188183] el0t_64_sync+0x158/0x15c
46
47 Fixes: 799684448e3e ("net: ethernet: mtk_wed: introduce wed wo support")
48 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
49 Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
50 Link: https://lore.kernel.org/r/67ca94bdd3d9eaeb86e52b3050fbca0bcf7bb02f.1669908312.git.lorenzo@kernel.org
51 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
52 ---
53
54 --- a/drivers/net/ethernet/mediatek/mtk_wed_wo.c
55 +++ b/drivers/net/ethernet/mediatek/mtk_wed_wo.c
56 @@ -133,17 +133,18 @@ mtk_wed_wo_dequeue(struct mtk_wed_wo *wo
57
58 static int
59 mtk_wed_wo_queue_refill(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q,
60 - gfp_t gfp, bool rx)
61 + bool rx)
62 {
63 enum dma_data_direction dir = rx ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
64 int n_buf = 0;
65
66 spin_lock_bh(&q->lock);
67 while (q->queued < q->n_desc) {
68 - void *buf = page_frag_alloc(&q->cache, q->buf_size, gfp);
69 struct mtk_wed_wo_queue_entry *entry;
70 dma_addr_t addr;
71 + void *buf;
72
73 + buf = page_frag_alloc(&q->cache, q->buf_size, GFP_ATOMIC);
74 if (!buf)
75 break;
76
77 @@ -215,7 +216,7 @@ mtk_wed_wo_rx_run_queue(struct mtk_wed_w
78 mtk_wed_mcu_rx_unsolicited_event(wo, skb);
79 }
80
81 - if (mtk_wed_wo_queue_refill(wo, q, GFP_ATOMIC, true)) {
82 + if (mtk_wed_wo_queue_refill(wo, q, true)) {
83 u32 index = (q->head - 1) % q->n_desc;
84
85 mtk_wed_wo_queue_kick(wo, q, index);
86 @@ -432,7 +433,7 @@ mtk_wed_wo_hardware_init(struct mtk_wed_
87 if (ret)
88 goto error;
89
90 - mtk_wed_wo_queue_refill(wo, &wo->q_tx, GFP_KERNEL, false);
91 + mtk_wed_wo_queue_refill(wo, &wo->q_tx, false);
92 mtk_wed_wo_queue_reset(wo, &wo->q_tx);
93
94 regs.desc_base = MTK_WED_WO_CCIF_DUMMY5;
95 @@ -446,7 +447,7 @@ mtk_wed_wo_hardware_init(struct mtk_wed_
96 if (ret)
97 goto error;
98
99 - mtk_wed_wo_queue_refill(wo, &wo->q_rx, GFP_KERNEL, true);
100 + mtk_wed_wo_queue_refill(wo, &wo->q_rx, true);
101 mtk_wed_wo_queue_reset(wo, &wo->q_rx);
102
103 /* rx queue irqmask */