Sean Wang
8d32e06243
net: ethernet: mediatek: fixed deadlock captured by lockdep
Lockdep found an inconsistent lock state when mtk_get_stats64 is called
in user context while NAPI updates MAC statistics in softirq.
Use spin_trylock_bh/spin_unlock_bh fix following lockdep warning.
[ 81.321030] WARNING: inconsistent lock state
[ 81.325266] 4.12.0-rc1-00035-gd9dda65 #32 Not tainted
[ 81.330273] --------------------------------
[ 81.334505] inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
[ 81.340464] ksoftirqd/0/7 [HC0[0]:SC1[1]:HE1:SE0] takes:
[ 81.345731] (&syncp->seq#2){+.?...}, at: [<c054ba3c>] mtk_handle_status_irq.part.6+0x70/0x84
[ 81.354219] {SOFTIRQ-ON-W} state was registered at:
[ 81.359062] lock_acquire+0xfc/0x2b0
[ 81.362696] mtk_stats_update_mac+0x60/0x2c0
[ 81.367017] mtk_get_stats64+0x17c/0x18c
[ 81.370995] dev_get_stats+0x48/0xbc
[ 81.374628] rtnl_fill_stats+0x48/0x128
[ 81.378520] rtnl_fill_ifinfo+0x4ac/0xd1c
[ 81.382584] rtmsg_ifinfo_build_skb+0x7c/0xe0
[ 81.386991] rtmsg_ifinfo.part.5+0x24/0x54
[ 81.391139] rtmsg_ifinfo+0x24/0x28
[ 81.394685] __dev_notify_flags+0xa4/0xac
[ 81.398749] dev_change_flags+0x50/0x58
[ 81.402640] devinet_ioctl+0x768/0x85c
[ 81.406444] inet_ioctl+0x1a4/0x1d0
[ 81.409990] sock_ioctl+0x16c/0x33c
[ 81.413538] do_vfs_ioctl+0xb4/0xa34
[ 81.417169] SyS_ioctl+0x44/0x6c
[ 81.420458] ret_fast_syscall+0x0/0x1c
[ 81.424260] irq event stamp: 3354692
[ 81.427806] hardirqs last enabled at (3354692): [<c0678168>] net_rx_action+0xc0/0x504
[ 81.435660] hardirqs last disabled at (3354691): [<c0678134>] net_rx_action+0x8c/0x504
[ 81.443515] softirqs last enabled at (3354106): [<c0101944>] __do_softirq+0x4b4/0x614
[ 81.451370] softirqs last disabled at (3354109): [<c012f0c4>] run_ksoftirqd+0x44/0x80
[ 81.459134]
[ 81.459134] other info that might help us debug this:
[ 81.465608] Possible unsafe locking scenario:
[ 81.465608]
[ 81.471478] CPU0
[ 81.473900] ----
[ 81.476321] lock(&syncp->seq#2);
[ 81.479701] <Interrupt>
[ 81.482294] lock(&syncp->seq#2);
[ 81.485847]
[ 81.485847] *** DEADLOCK ***
[ 81.485847]
[ 81.491720] 1 lock held by ksoftirqd/0/7:
[ 81.495693] #0: (&(&mac->hw_stats->stats_lock)->rlock){+.+...}, at: [<c054ba14>] mtk_handle_status_irq.part.6+0x48/0x84
[ 81.506579]
[ 81.506579] stack backtrace:
[ 81.510904] CPU: 0 PID: 7 Comm: ksoftirqd/0 Not tainted 4.12.0-rc1-00035-gd9dda65 #32
[ 81.518668] Hardware name: Mediatek Cortex-A7 (Device Tree)
[ 81.524208] [<c0113dc4>] (unwind_backtrace) from [<c010e3f0>] (show_stack+0x20/0x24)
[ 81.531899] [<c010e3f0>] (show_stack) from [<c03f9c64>] (dump_stack+0xb4/0xe0)
[ 81.539072] [<c03f9c64>] (dump_stack) from [<c017e970>] (print_usage_bug+0x234/0x2e0)
[ 81.546846] [<c017e970>] (print_usage_bug) from [<c017f058>] (mark_lock+0x63c/0x7bc)
[ 81.554532] [<c017f058>] (mark_lock) from [<c017fe90>] (__lock_acquire+0x654/0x1bfc)
[ 81.562217] [<c017fe90>] (__lock_acquire) from [<c0181d04>] (lock_acquire+0xfc/0x2b0)
[ 81.569990] [<c0181d04>] (lock_acquire) from [<c054b76c>] (mtk_stats_update_mac+0x60/0x2c0)
[ 81.578283] [<c054b76c>] (mtk_stats_update_mac) from [<c054ba3c>] (mtk_handle_status_irq.part.6+0x70/0x84)
[ 81.587865] [<c054ba3c>] (mtk_handle_status_irq.part.6) from [<c054c2b8>] (mtk_napi_tx+0x358/0x37c)
[ 81.596845] [<c054c2b8>] (mtk_napi_tx) from [<c06782ec>] (net_rx_action+0x244/0x504)
[ 81.604533] [<c06782ec>] (net_rx_action) from [<c01015c4>] (__do_softirq+0x134/0x614)
[ 81.612306] [<c01015c4>] (__do_softirq) from [<c012f0c4>] (run_ksoftirqd+0x44/0x80)
[ 81.619907] [<c012f0c4>] (run_ksoftirqd) from [<c0154680>] (smpboot_thread_fn+0x14c/0x25c)
[ 81.628110] [<c0154680>] (smpboot_thread_fn) from [<c014f8cc>] (kthread+0x150/0x180)
[ 81.635798] [<c014f8cc>] (kthread) from [<c0109290>] (ret_from_fork+0x14/0x24)
Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-07-04 01:43:38 -07:00
..
2017-06-21 23:14:55 +02:00
2017-05-31 14:26:26 -04:00
2017-07-01 07:39:08 -07:00
2017-06-09 01:25:16 +02:00
2017-06-20 07:09:27 -06:00
2017-06-29 14:39:42 +02:00
2017-06-30 12:43:08 -04:00
2017-06-14 16:48:03 -07:00
2017-06-13 17:57:16 +02:00
2017-06-15 01:51:33 +02:00
2017-06-15 01:51:33 +02:00
2017-06-20 13:30:14 -04:00
2017-06-09 08:50:49 -07:00
2017-06-12 10:12:07 +09:00
2017-06-02 11:49:44 +05:30
2017-05-03 16:27:36 +02:00
2017-06-16 11:48:40 -04:00
2017-06-16 17:13:06 +09:00
2017-06-20 13:42:20 +02:00
2017-06-28 13:22:26 -07:00
2017-06-20 10:52:46 +02:00
2017-06-08 10:16:05 -04:00
2017-05-04 19:15:35 -07:00
2017-06-03 03:55:43 -07:00
2017-05-08 17:15:14 -07:00
2017-06-22 10:52:02 +02:00
2017-05-08 17:36:39 -04:00
2017-05-01 23:17:37 +02:00
2017-06-13 20:56:05 +01:00
2017-07-01 07:39:07 -07:00
2017-06-23 00:08:48 -07:00
2017-05-30 11:31:32 +02:00
2017-06-20 21:41:58 +02:00
2017-07-01 07:39:07 -07:00
2017-06-18 08:51:35 +09:00
2017-05-04 07:53:04 -06:00
2017-05-05 19:33:07 -07:00
2017-06-27 15:14:34 -04:00
2017-06-16 11:48:39 -04:00
2017-06-01 17:07:31 -07:00
2017-06-06 10:17:42 +01:00
2017-06-16 11:48:37 -04:00
2017-06-12 08:58:16 +02:00
2017-05-22 09:42:29 +02:00
2017-07-04 01:43:38 -07:00
2017-07-01 14:30:39 -07:00
2017-06-19 14:24:41 -04:00
2017-05-12 15:43:10 -07:00
2017-06-27 17:44:05 -06:00
2017-05-09 10:01:15 -07:00
2017-06-15 11:59:32 -04:00
2017-06-12 15:46:13 -05:00
2017-05-10 19:13:03 -07:00
2017-05-30 12:40:03 +01:00
2017-06-01 15:03:41 +05:30
2017-06-09 10:51:54 +02:00
2017-06-16 17:30:44 +09:00
2017-05-12 12:02:21 -07:00
2017-05-14 13:30:05 +02:00
2017-06-15 12:07:15 -04:00
2017-05-04 19:15:35 -07:00
2017-04-30 22:17:44 +09:00
2017-05-10 11:33:08 -07:00
2017-05-24 10:53:41 +02:00
2017-06-16 11:48:37 -04:00
2017-05-22 20:32:05 +02:00
2017-07-03 02:29:57 -07:00
2017-06-30 12:43:08 -04:00
2017-05-19 13:36:56 -07:00
2017-05-24 16:46:51 +03:00
2017-06-21 17:35:22 -04:00
2017-06-30 12:43:08 -04:00
2017-05-18 23:54:47 -07:00
2017-05-23 20:09:34 -07:00
2017-06-16 11:48:37 -04:00
2017-05-16 23:06:41 +02:00
2017-06-21 17:35:22 -04:00
2017-05-17 11:27:41 +02:00
2017-05-05 11:36:44 -07:00
2017-05-18 10:07:42 -04:00
2017-06-14 12:40:36 +02:00
2017-05-08 17:15:10 -07:00
2017-06-18 23:13:35 +03:00
2017-05-19 10:42:25 +02:00
2017-06-09 09:59:51 -07:00
2017-05-10 21:03:31 +02:00