rtnetlink: add rtnl_lock debug log
Subsystems (5)
PATCH 1/1 rtnetlink: add rtnl_lock debug log
We often encounter system hangs caused by certain processes holding rtnl_lock for a long time. Even if there is a lock detection mechanism in Linux, it is a bit troublesome and affects the system performance. We hope to add a lightweight debugging mechanism for detecting rtnl_lock.
Up to now, we have discovered and solved some potential bugs through such debug information of this lightweight rtnl_lock, which is helpful for us.
When you say Y for RTNL_LOCK_DEBUG, then the kernel will detect if any function hold rtnl_lock too long and some key information will be printed to help identify the issue point.
i.e: from the following logs, we can clear know that the pid=5546 RfxSender_4 process hold rtnl_lock for a long time, causing the system hang. And we can also speculate that the delay operation may be performed in devinet_ioctl(), resulting in rtnl_lock was not released in time.
<6>[ 141.151364] ----------- rtnl_print_btrace start ----------- <6>[ 141.152079] RfxSender_4[5546][R] hold rtnl_lock more than 2 sec, start time: 139129481562 <4>[ 141.153114] rtnl_lock+0x88/0xfc <4>[ 141.153523] devinet_ioctl+0x190/0x1268 <4>[ 141.154007] inet_ioctl+0x108/0x1f4 <4>[ 141.154449] sock_do_ioctl+0x88/0x200 <4>[ 141.154911] sock_ioctl+0x4b0/0x884 <4>[ 141.155367] do_vfs_ioctl+0x6b0/0xcc4 <4>[ 141.155830] __arm64_sys_ioctl+0xc0/0xec <4>[ 141.156326] el0_svc_common+0x130/0x2c0 <4>[ 141.156810] el0_svc_handler+0xd0/0xe0 <4>[ 141.157283] el0_svc+0x8/0xc <4>[ 141.157646] Call trace: <4>[ 141.157956] dump_backtrace+0x0/0x240 <4>[ 141.158418] show_stack+0x18/0x24 <4>[ 141.158836] rtnl_print_btrace+0x138/0x1cc <4>[ 141.159362] call_timer_fn+0x120/0x47c <4>[ 141.159834] expire_timers+0x28c/0x420 <4>[ 141.160306] __run_timers+0x3d0/0x494 <4>[ 141.160768] run_timer_softirq+0x24/0x48 <4>[ 141.161262] __do_softirq+0x26c/0x968 <4>[ 141.161725] irq_exit+0x1f8/0x2b4 <4>[ 141.162145] __handle_domain_irq+0xdc/0x15c <4>[ 141.162672] gic_handle_irq+0xe4/0x188 <4>[ 141.163144] el1_irq+0x104/0x200 <4>[ 141.163559] __const_udelay+0x118/0x1b0 <4>[ 141.164044] devinet_ioctl+0x1a0/0x1268 <4>[ 141.164527] inet_ioctl+0x108/0x1f4 <4>[ 141.164968] sock_do_ioctl+0x88/0x200 <4>[ 141.165428] sock_ioctl+0x4b0/0x884 <4>[ 141.165868] do_vfs_ioctl+0x6b0/0xcc4 <4>[ 141.166330] __arm64_sys_ioctl+0xc0/0xec <4>[ 141.166825] el0_svc_common+0x130/0x2c0 <4>[ 141.167308] el0_svc_handler+0xd0/0xe0 <4>[ 141.167786] el0_svc+0x8/0xc <6>[ 141.168153] ------------ rtnl_print_btrace end -----------
<6>[ 147.321389] rtnl_lock is held by [5546] from
[139129481562] to [147321378812]
--- lib/Kconfig.debug | 9 +++++ net/core/rtnetlink.c | 86 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+)
lib/Kconfig.debug +9 -0
@@ -2019,6 +2019,15 @@ config KCOV_IRQ_AREA_SIZE soft interrupts. This specifies the size of those areas in the number of unsigned long words. +config RTNL_LOCK_DEBUG + bool "rtnl_lock debugging, deadlock detection" + select STACKTRACE + help + If you say Y here then the kernel will detect whether any process + hold rtnl_lock too long and some key information will be printed + to help identify the issue point. + If unsure, say N. + menuconfig RUNTIME_TESTING_MENU bool "Runtime Testing" def_bool y
net/core/rtnetlink.c +86 -0
104 lines not on this page · raw message
Signature · 1 line
2.18.0
Quoted 11 lines · Rocco Yue
We often encounter system hangs caused by certain processes holding
rtnl_lockfor a long time. Even if there is a lock detection mechanism in Linux, it is a bit troublesome and affects the system performance. We hope to add a lightweight debugging mechanism for detectingrtnl_lock.Up to now, we have discovered and solved some potential bugs through such debug information of this lightweight
rtnl_lock, which is helpful for us.
Quoted 5 lines
When you say Y for
RTNL_LOCK_DEBUG, then the kernel will detect if any function holdrtnl_locktoo long and some key information will be printed to help identify the issue point.i.e: from the following logs, we can clear know that the pid=5546
clearly
Quoted 1 line
RfxSender_4process holdrtnl_lockfor a long time, causing the
holds
Quoted 1 line
system hang. And we can also speculate that the delay operation
to hang
Quoted 4 lines
may be performed in
devinet_ioctl(), resulting inrtnl_lockwas not released in time.<6>[ 141.151364] ----------- rtnl_print_btrace start -----------
Can you, please, shrink this to the point?
Quoted 39 lines
<6>[ 141.152079] RfxSender_4[5546][R] hold rtnl_lock more than 2 sec, start time: 139129481562 <4>[ 141.153114] rtnl_lock+0x88/0xfc <4>[ 141.153523] devinet_ioctl+0x190/0x1268 <4>[ 141.154007] inet_ioctl+0x108/0x1f4 <4>[ 141.154449] sock_do_ioctl+0x88/0x200 <4>[ 141.154911] sock_ioctl+0x4b0/0x884 <4>[ 141.155367] do_vfs_ioctl+0x6b0/0xcc4 <4>[ 141.155830] __arm64_sys_ioctl+0xc0/0xec <4>[ 141.156326] el0_svc_common+0x130/0x2c0 <4>[ 141.156810] el0_svc_handler+0xd0/0xe0 <4>[ 141.157283] el0_svc+0x8/0xc <4>[ 141.157646] Call trace: <4>[ 141.157956] dump_backtrace+0x0/0x240 <4>[ 141.158418] show_stack+0x18/0x24 <4>[ 141.158836] rtnl_print_btrace+0x138/0x1cc <4>[ 141.159362] call_timer_fn+0x120/0x47c <4>[ 141.159834] expire_timers+0x28c/0x420 <4>[ 141.160306] __run_timers+0x3d0/0x494 <4>[ 141.160768] run_timer_softirq+0x24/0x48 <4>[ 141.161262] __do_softirq+0x26c/0x968 <4>[ 141.161725] irq_exit+0x1f8/0x2b4 <4>[ 141.162145] __handle_domain_irq+0xdc/0x15c <4>[ 141.162672] gic_handle_irq+0xe4/0x188 <4>[ 141.163144] el1_irq+0x104/0x200 <4>[ 141.163559] __const_udelay+0x118/0x1b0 <4>[ 141.164044] devinet_ioctl+0x1a0/0x1268 <4>[ 141.164527] inet_ioctl+0x108/0x1f4 <4>[ 141.164968] sock_do_ioctl+0x88/0x200 <4>[ 141.165428] sock_ioctl+0x4b0/0x884 <4>[ 141.165868] do_vfs_ioctl+0x6b0/0xcc4 <4>[ 141.166330] __arm64_sys_ioctl+0xc0/0xec <4>[ 141.166825] el0_svc_common+0x130/0x2c0 <4>[ 141.167308] el0_svc_handler+0xd0/0xe0 <4>[ 141.167786] el0_svc+0x8/0xc <6>[ 141.168153] ------------ rtnl_print_btrace end -----------<6>[ 147.321389] rtnl_lock is held by [5546] from[139129481562] to [147321378812]
...
net/core/rtnetlink.c line 85
Quoted 6 lines
net/core/rtnetlink.c +6
-0+static struct rtnl_debug_btrace_t rtnl_instance = { + .task =NULL , + .pid =0 , + .start_time =0 , + .end_time =0 , + .nr_entries =0 ,
static assumes all 0:s, what's the point?
Quoted 1 line
+};
...
net/core/rtnetlink.c line 121
Quoted 11 lines
net/core/rtnetlink.c +10
-0+static void rtnl_print_btrace (struct timer_list *unused) +{ +pr_info ("----------- %s start -----------\n" , __func__); +pr_info ("%s[%d][%c] hold rtnl_lock more than 2 sec, start time: %llu\n" , + rtnl_instance.task->comm, + rtnl_instance.pid, +task_state_to_char (rtnl_instance.task), + rtnl_instance.start_time); +stack_trace_print (rtnl_instance.addrs, rtnl_instance.nr_entries,0 ); +show_stack (rtnl_instance.task,NULL ,KERN_DEBUG );
Unaligned debug level.
Quoted 1 line
+
pr_info("------------ %s end -----------\n", __func__);
Looking into tons of these, perhaps you need to define pr_fmt(). I haven't checked if it's already defined, though.
Quoted 1 line
+}
...
Quoted 1 line
+ if (rtnl_instance.end_time - rtnl_instance.start_time > 2000000000ULL) {
Perhaps you should use one of the defined constants from time64.h ?
Quoted 5 lines
net/core/rtnetlink.c +5
-0+pr_info ("rtnl_lock is held by [%d] from [%llu] to [%llu]\n" , + rtnl_instance.pid, + rtnl_instance.start_time, + rtnl_instance.end_time); + }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 18 lines
Quoted 10 lines
We often encounter system hangs caused by certain processes holding
rtnl_lockfor a long time. Even if there is a lock detection mechanism in Linux, it is a bit troublesome and affects the system performance. We hope to add a lightweight debugging mechanism for detectingrtnl_lock.Up to now, we have discovered and solved some potential bugs through such debug information of this lightweight
rtnl_lock, which is helpful for us.Quoted 5 lines
When you say Y for
RTNL_LOCK_DEBUG, then the kernel will detect if any function holdrtnl_locktoo long and some key information will be printed to help identify the issue point.i.e: from the following logs, we can clear know that the pid=5546
clearly
Quoted 8 lines
Quoted 1 line
RfxSender_4process holdrtnl_lockfor a long time, causing theholds
Quoted 1 line
system hang. And we can also speculate that the delay operation
to hang
Thanks for your review, Andy.
I Will fix them.
Quoted 7 lines
Quoted 4 lines
may be performed in
devinet_ioctl(), resulting inrtnl_lockwas not released in time.<6>[ 141.151364] ----------- rtnl_print_btrace start -----------Can you, please, shrink this to the point?
Will shrink these points.
Quoted 43 lines
Quoted 39 lines
<6>[ 141.152079] RfxSender_4[5546][R] hold rtnl_lock more than 2 sec, start time: 139129481562 <4>[ 141.153114] rtnl_lock+0x88/0xfc <4>[ 141.153523] devinet_ioctl+0x190/0x1268 <4>[ 141.154007] inet_ioctl+0x108/0x1f4 <4>[ 141.154449] sock_do_ioctl+0x88/0x200 <4>[ 141.154911] sock_ioctl+0x4b0/0x884 <4>[ 141.155367] do_vfs_ioctl+0x6b0/0xcc4 <4>[ 141.155830] __arm64_sys_ioctl+0xc0/0xec <4>[ 141.156326] el0_svc_common+0x130/0x2c0 <4>[ 141.156810] el0_svc_handler+0xd0/0xe0 <4>[ 141.157283] el0_svc+0x8/0xc <4>[ 141.157646] Call trace: <4>[ 141.157956] dump_backtrace+0x0/0x240 <4>[ 141.158418] show_stack+0x18/0x24 <4>[ 141.158836] rtnl_print_btrace+0x138/0x1cc <4>[ 141.159362] call_timer_fn+0x120/0x47c <4>[ 141.159834] expire_timers+0x28c/0x420 <4>[ 141.160306] __run_timers+0x3d0/0x494 <4>[ 141.160768] run_timer_softirq+0x24/0x48 <4>[ 141.161262] __do_softirq+0x26c/0x968 <4>[ 141.161725] irq_exit+0x1f8/0x2b4 <4>[ 141.162145] __handle_domain_irq+0xdc/0x15c <4>[ 141.162672] gic_handle_irq+0xe4/0x188 <4>[ 141.163144] el1_irq+0x104/0x200 <4>[ 141.163559] __const_udelay+0x118/0x1b0 <4>[ 141.164044] devinet_ioctl+0x1a0/0x1268 <4>[ 141.164527] inet_ioctl+0x108/0x1f4 <4>[ 141.164968] sock_do_ioctl+0x88/0x200 <4>[ 141.165428] sock_ioctl+0x4b0/0x884 <4>[ 141.165868] do_vfs_ioctl+0x6b0/0xcc4 <4>[ 141.166330] __arm64_sys_ioctl+0xc0/0xec <4>[ 141.166825] el0_svc_common+0x130/0x2c0 <4>[ 141.167308] el0_svc_handler+0xd0/0xe0 <4>[ 141.167786] el0_svc+0x8/0xc <6>[ 141.168153] ------------ rtnl_print_btrace end -----------<6>[ 147.321389] rtnl_lock is held by [5546] from[139129481562] to [147321378812]
...
Quoted 9 lines
net/core/rtnetlink.c line 85
Quoted 6 lines
net/core/rtnetlink.c +6
-0+static struct rtnl_debug_btrace_t rtnl_instance = { + .task =NULL , + .pid =0 , + .start_time =0 , + .end_time =0 , + .nr_entries =0 ,static assumes all 0:s, what's the point?
will fix it in the patch v2.
Quoted 14 lines
Quoted 1 line
+};
...
Quoted 9 lines
net/core/rtnetlink.c +9
-0+static void rtnl_print_btrace (struct timer_list *unused) +{ +pr_info ("----------- %s start -----------\n" , __func__); +pr_info ("%s[%d][%c] hold rtnl_lock more than 2 sec, start time: %llu\n" , + rtnl_instance.task->comm, + rtnl_instance.pid, +task_state_to_char (rtnl_instance.task), + rtnl_instance.start_time); +stack_trace_print (rtnl_instance.addrs, rtnl_instance.nr_entries,0 );
Quoted 4 lines
Quoted 1 line
+
show_stack(rtnl_instance.task, NULL, KERN_DEBUG);Unaligned debug level.
KERN_INFO is expected, I will fix it in patch v2.
Quoted 5 lines
Quoted 1 line
+
pr_info("------------ %s end -----------\n", __func__);Looking into tons of these, perhaps you need to define
pr_fmt(). I haven't checked if it's already defined, though.
In the files related rtnetlink, pr_fmt() is not defined. I am not sure if I can define one since there are other error logs in the rtnetlink.c.
In addition, there is "rtnl_lock" field in the log, I usually use it to retrieve whether rtnl_lock is held for a long time.
If adding pr_fmt() is better, it is ok to me :-)
Quoted 8 lines
Quoted 1 line
+}
...
Quoted 1 line
+ if (rtnl_instance.end_time - rtnl_instance.start_time > 2000000000ULL) {
Perhaps you should use one of the defined constants from
time64.h?
Will have a separate patch for this.
Quoted 6 lines
net/core/rtnetlink.c line 134
Quoted 5 lines
net/core/rtnetlink.c +5
-0+pr_info ("rtnl_lock is held by [%d] from [%llu] to [%llu]\n" , + rtnl_instance.pid, + rtnl_instance.start_time, + rtnl_instance.end_time); + }
Best Regard
Rocco
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Rocco,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on net-next/master]
[also build test ERROR on net/master linus/master v5.12 next-20210429] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Rocco-Yue/rtnetlink-add-rtnl_lock-debug-log/20210429-151958 base: https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 4a52dd8fefb45626dace70a63c0738dbd83b7edb config: m68k-allmodconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/662e06d6ff200b5cee31d3615a7b2a5079cc5c0a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Rocco-Yue/rtnetlink-add-rtnl_lock-debug-log/20210429-151958 git checkout 662e06d6ff200b5cee31d3615a7b2a5079cc5c0a
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross W=1 ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
m68k-linux-ld: kernel/stacktrace.o: in function `stack_trace_save':
>> (.text+0x144): undefined reference to `save_stack_trace'
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for STACKTRACE Depends on STACKTRACE_SUPPORT
Selected by
- RTNL_LOCK_DEBUG
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
net/core/rtnetlink.c line 120
Quoted 9 lines · Rocco Yue
net/core/rtnetlink.c +9
-0+static void rtnl_print_btrace (struct timer_list *unused) +{ +pr_info ("----------- %s start -----------\n" , __func__); +pr_info ("%s[%d][%c] hold rtnl_lock more than 2 sec, start time: %llu\n" , + rtnl_instance.task->comm, + rtnl_instance.pid, +task_state_to_char (rtnl_instance.task), + rtnl_instance.start_time); +stack_trace_print (rtnl_instance.addrs, rtnl_instance.nr_entries,0 );
Do we want to print same traces every 2 seconds?
Since it is possible to stall for e.g. 30 seconds, printing either only upon first call to rtnl_print_btrace() for each stalling duration or only upon end of stalling duration (i.e. from rtnl_relase_btrace()) is better?
net/core/rtnetlink.c line 121
Quoted 1 line
net/core/rtnetlink.c +1
-0+show_stack (rtnl_instance.task,NULL ,KERN_DEBUG );
Why KERN_DEBUG ?
If you retrieve the output via dmesg, KERN_DEBUG would be fine. But for syzkaller (which counts on printk() messages being printed to consoles), KERN_INFO (or default) is expected.
net/core/rtnetlink.c line 128
Quoted 7 lines
net/core/rtnetlink.c +7
-0+pr_info ("------------ %s end -----------\n" , __func__); +} + +static void rtnl_relase_btrace (void ) +{ + rtnl_instance.end_time =sched_clock (); +
You should del_timer_sync() here than
net/core/rtnetlink.c line 136
Quoted 8 lines
net/core/rtnetlink.c +8
-0+if (rtnl_instance.end_time - rtnl_instance.start_time >2000000000ULL ) { +pr_info ("rtnl_lock is held by [%d] from [%llu] to [%llu]\n" , + rtnl_instance.pid, + rtnl_instance.start_time, + rtnl_instance.end_time); + } + +del_timer (&rtnl_chk_timer);
here in order to make sure that end message is printed only after rtnl_print_btrace() messages are printed.
Quoted 3 lines
net/core/rtnetlink.c +3
-0+} +#endif +
Quoted 12 lines
net/core/rtnetlink.c line 120
Quoted 9 lines
net/core/rtnetlink.c +9
-0+static void rtnl_print_btrace (struct timer_list *unused) +{ +pr_info ("----------- %s start -----------\n" , __func__); +pr_info ("%s[%d][%c] hold rtnl_lock more than 2 sec, start time: %llu\n" , + rtnl_instance.task->comm, + rtnl_instance.pid, +task_state_to_char (rtnl_instance.task), + rtnl_instance.start_time); +stack_trace_print (rtnl_instance.addrs, rtnl_instance.nr_entries,0 );Do we want to print same traces every 2 seconds?
Quoted 4 lines
Since it is possible to stall for e.g. 30 seconds, printing either only upon first call to
rtnl_print_btrace()for each stalling duration or only upon end of stalling duration (i.e. fromrtnl_relase_btrace()) is better?
Thanks for your review, Tetsuo.
rtnl_chk_timer is a one-shot timer, I don't rearm the timer after expire, therefore traces are only logged once after rtnl_lock was held for more than 2 seconds, rather than every 2 seconds. In this way, even if this rtnl_lock debug mechanism is enabled, the overhead is also affordable in the user load.
As far as I understand it, there won't be the problem you mentioned.
In my experience, it's more appropriate to print trace when call rtnl_print_btrace(), we can't expect that rtnl_lock will be released before kernel reboot. And after holding the rtnl_lock for more than 2s, we will print these logs, which is more helpful for us.
Quoted 8 lines
net/core/rtnetlink.c line 121
Quoted 1 line
net/core/rtnetlink.c +1
-0+show_stack (rtnl_instance.task,NULL ,KERN_DEBUG );Why
KERN_DEBUG?If you retrieve the output via dmesg,
KERN_DEBUGwould be fine. But for syzkaller (which counts onprintk()messages being printed to consoles),KERN_INFO(or default) is expected.
KERN_INFO is expected, I will fix it in patch v2.
Quoted 10 lines
net/core/rtnetlink.c line 128
Quoted 7 lines
net/core/rtnetlink.c +7
-0+pr_info ("------------ %s end -----------\n" , __func__); +} + +static void rtnl_relase_btrace (void ) +{ + rtnl_instance.end_time =sched_clock (); +You should
del_timer_sync()here than
Quoted 12 lines
net/core/rtnetlink.c line 136
Quoted 8 lines
net/core/rtnetlink.c +8
-0+if (rtnl_instance.end_time - rtnl_instance.start_time >2000000000ULL ) { +pr_info ("rtnl_lock is held by [%d] from [%llu] to [%llu]\n" , + rtnl_instance.pid, + rtnl_instance.start_time, + rtnl_instance.end_time); + } + +del_timer (&rtnl_chk_timer);here in order to make sure that end message is printed only after
rtnl_print_btrace()messages are printed.
Will have a separate patch for this.
Quoted 4 lines
net/core/rtnetlink.c line 139
Quoted 3 lines
net/core/rtnetlink.c +3
-0+} +#endif +
Best Regards
Rocco
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek