mediatek: update to latest kernel patchset from v4.13-rc
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.9 / 0054-net-ethernet-mediatek-fixed-deadlock-captured-by-loc.patch
1 From 746bf1c3e561aba396cd40e6540245646461117d Mon Sep 17 00:00:00 2001
2 From: Sean Wang <sean.wang@mediatek.com>
3 Date: Tue, 4 Jul 2017 11:17:36 +0800
4 Subject: [PATCH 54/57] net: ethernet: mediatek: fixed deadlock captured by
5 lockdep
6
7 Lockdep found an inconsistent lock state when mtk_get_stats64 is called
8 in user context while NAPI updates MAC statistics in softirq.
9
10 Use spin_trylock_bh/spin_unlock_bh fix following lockdep warning.
11
12 [ 81.321030] WARNING: inconsistent lock state
13 [ 81.325266] 4.12.0-rc1-00035-gd9dda65 #32 Not tainted
14 [ 81.330273] --------------------------------
15 [ 81.334505] inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
16 [ 81.340464] ksoftirqd/0/7 [HC0[0]:SC1[1]:HE1:SE0] takes:
17 [ 81.345731] (&syncp->seq#2){+.?...}, at: [<c054ba3c>] mtk_handle_status_irq.part.6+0x70/0x84
18 [ 81.354219] {SOFTIRQ-ON-W} state was registered at:
19 [ 81.359062] lock_acquire+0xfc/0x2b0
20 [ 81.362696] mtk_stats_update_mac+0x60/0x2c0
21 [ 81.367017] mtk_get_stats64+0x17c/0x18c
22 [ 81.370995] dev_get_stats+0x48/0xbc
23 [ 81.374628] rtnl_fill_stats+0x48/0x128
24 [ 81.378520] rtnl_fill_ifinfo+0x4ac/0xd1c
25 [ 81.382584] rtmsg_ifinfo_build_skb+0x7c/0xe0
26 [ 81.386991] rtmsg_ifinfo.part.5+0x24/0x54
27 [ 81.391139] rtmsg_ifinfo+0x24/0x28
28 [ 81.394685] __dev_notify_flags+0xa4/0xac
29 [ 81.398749] dev_change_flags+0x50/0x58
30 [ 81.402640] devinet_ioctl+0x768/0x85c
31 [ 81.406444] inet_ioctl+0x1a4/0x1d0
32 [ 81.409990] sock_ioctl+0x16c/0x33c
33 [ 81.413538] do_vfs_ioctl+0xb4/0xa34
34 [ 81.417169] SyS_ioctl+0x44/0x6c
35 [ 81.420458] ret_fast_syscall+0x0/0x1c
36 [ 81.424260] irq event stamp: 3354692
37 [ 81.427806] hardirqs last enabled at (3354692): [<c0678168>] net_rx_action+0xc0/0x504
38 [ 81.435660] hardirqs last disabled at (3354691): [<c0678134>] net_rx_action+0x8c/0x504
39 [ 81.443515] softirqs last enabled at (3354106): [<c0101944>] __do_softirq+0x4b4/0x614
40 [ 81.451370] softirqs last disabled at (3354109): [<c012f0c4>] run_ksoftirqd+0x44/0x80
41 [ 81.459134]
42 [ 81.459134] other info that might help us debug this:
43 [ 81.465608] Possible unsafe locking scenario:
44 [ 81.465608]
45 [ 81.471478] CPU0
46 [ 81.473900] ----
47 [ 81.476321] lock(&syncp->seq#2);
48 [ 81.479701] <Interrupt>
49 [ 81.482294] lock(&syncp->seq#2);
50 [ 81.485847]
51 [ 81.485847] *** DEADLOCK ***
52 [ 81.485847]
53 [ 81.491720] 1 lock held by ksoftirqd/0/7:
54 [ 81.495693] #0: (&(&mac->hw_stats->stats_lock)->rlock){+.+...}, at: [<c054ba14>] mtk_handle_status_irq.part.6+0x48/0x84
55 [ 81.506579]
56 [ 81.506579] stack backtrace:
57 [ 81.510904] CPU: 0 PID: 7 Comm: ksoftirqd/0 Not tainted 4.12.0-rc1-00035-gd9dda65 #32
58 [ 81.518668] Hardware name: Mediatek Cortex-A7 (Device Tree)
59 [ 81.524208] [<c0113dc4>] (unwind_backtrace) from [<c010e3f0>] (show_stack+0x20/0x24)
60 [ 81.531899] [<c010e3f0>] (show_stack) from [<c03f9c64>] (dump_stack+0xb4/0xe0)
61 [ 81.539072] [<c03f9c64>] (dump_stack) from [<c017e970>] (print_usage_bug+0x234/0x2e0)
62 [ 81.546846] [<c017e970>] (print_usage_bug) from [<c017f058>] (mark_lock+0x63c/0x7bc)
63 [ 81.554532] [<c017f058>] (mark_lock) from [<c017fe90>] (__lock_acquire+0x654/0x1bfc)
64 [ 81.562217] [<c017fe90>] (__lock_acquire) from [<c0181d04>] (lock_acquire+0xfc/0x2b0)
65 [ 81.569990] [<c0181d04>] (lock_acquire) from [<c054b76c>] (mtk_stats_update_mac+0x60/0x2c0)
66 [ 81.578283] [<c054b76c>] (mtk_stats_update_mac) from [<c054ba3c>] (mtk_handle_status_irq.part.6+0x70/0x84)
67 [ 81.587865] [<c054ba3c>] (mtk_handle_status_irq.part.6) from [<c054c2b8>] (mtk_napi_tx+0x358/0x37c)
68 [ 81.596845] [<c054c2b8>] (mtk_napi_tx) from [<c06782ec>] (net_rx_action+0x244/0x504)
69 [ 81.604533] [<c06782ec>] (net_rx_action) from [<c01015c4>] (__do_softirq+0x134/0x614)
70 [ 81.612306] [<c01015c4>] (__do_softirq) from [<c012f0c4>] (run_ksoftirqd+0x44/0x80)
71 [ 81.619907] [<c012f0c4>] (run_ksoftirqd) from [<c0154680>] (smpboot_thread_fn+0x14c/0x25c)
72 [ 81.628110] [<c0154680>] (smpboot_thread_fn) from [<c014f8cc>] (kthread+0x150/0x180)
73 [ 81.635798] [<c014f8cc>] (kthread) from [<c0109290>] (ret_from_fork+0x14/0x24)
74
75 Signed-off-by: Sean Wang <sean.wang@mediatek.com>
76 ---
77 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 8 ++++----
78 1 file changed, 4 insertions(+), 4 deletions(-)
79
80 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
81 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
82 @@ -493,9 +493,9 @@ static struct rtnl_link_stats64 * mtk_ge
83 unsigned int start;
84
85 if (netif_running(dev) && netif_device_present(dev)) {
86 - if (spin_trylock(&hw_stats->stats_lock)) {
87 + if (spin_trylock_bh(&hw_stats->stats_lock)) {
88 mtk_stats_update_mac(mac);
89 - spin_unlock(&hw_stats->stats_lock);
90 + spin_unlock_bh(&hw_stats->stats_lock);
91 }
92 }
93
94 @@ -2229,9 +2229,9 @@ static void mtk_get_ethtool_stats(struct
95 return;
96
97 if (netif_running(dev) && netif_device_present(dev)) {
98 - if (spin_trylock(&hwstats->stats_lock)) {
99 + if (spin_trylock_bh(&hwstats->stats_lock)) {
100 mtk_stats_update_mac(mac);
101 - spin_unlock(&hwstats->stats_lock);
102 + spin_unlock_bh(&hwstats->stats_lock);
103 }
104 }
105