rtnetlink: add rtnl_lock debug log
Subsystems (4)
PATCH v3 1/1 rtnetlink: add rtnl_lock debug log
From: Rocco Yue <[email protected]>
We often encounter system hangs caused by certain process 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 this lightweight rtnl_lock debugging mechanism, 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 out to help locate the problem.
i.e: from the following logs, we can clearly know that the pid=2206 RfxSender_4 process holds rtnl_lock for a long time, causing the system to 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.
[ 40.191481] rtnetlink: -- rtnl_print_btrace start -- [ 40.191494] rtnetlink: RfxSender_4[2206][R] hold rtnl_lock more than 2 sec, start time: 38181400013 [ 40.191571] Call trace: [ 40.191586] rtnl_print_btrace+0xf0/0x124 [ 40.191656] __delay+0xc0/0x180 [ 40.191663] devinet_ioctl+0x21c/0x75c [ 40.191668] inet_ioctl+0xb8/0x1f8 [ 40.191675] sock_do_ioctl+0x70/0x2ac [ 40.191682] sock_ioctl+0x5dc/0xa74 [ 40.191715] rtnetlink: -- rtnl_print_btrace end --
[ 42.181879] rtnetlink: rtnl_lock is held by [2206] from
[38181400013] to [42181875177]
--- lib/Kconfig.debug | 10 ++++++ net/core/rtnetlink.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+)
lib/Kconfig.debug +10 -0
@@ -2027,6 +2027,16 @@ 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" + depends on STACKTRACE_SUPPORT + select STACKTRACE + help + If you say Y here then the kernel will detect whether any function + hold rtnl_lock too long and some key information will be printed + out to help locate the problem. + If unsure, say N. + menuconfig RUNTIME_TESTING_MENU bool "Runtime Testing" def_bool y
net/core/rtnetlink.c +85 -0
109 lines not on this page · raw message
Signature · 1 line
2.18.0
Quoted 8 lines · Rocco yue
From: Rocco Yue <[email protected]>
We often encounter system hangs caused by certain process 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.
Any reason why this is specific to RTNL lock? To me holding a mutex lock for a long time is problematic for any mutex. I have seen some fs mutex being held for a long time caused many hung tasks in the system.
Thanks.
Quoted 10 lines · Cong Wang
Quoted 8 lines · Rocco yue
From: Rocco Yue <[email protected]>
We often encounter system hangs caused by certain process 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.
Quoted 6 lines
Any reason why this is specific to RTNL lock? To me holding a mutex lock for a long time is problematic for any mutex. I have seen some fs mutex being held for a long time caused many hung tasks in the system.
Thanks.
Thank you for a good question.
It's a problem to hold rtnl_lock for a long time, and other locks are no exception.
the reason for adding rtnl_lock debug log:
1.rtnl_lock is a widely used lock:
In my view, for some other mutex locks, such as "f2fs_stat_mutex" in the fs/f2fs/debug.c , there are not many codes that use this lock, and the module involved is relatively single.
But when we search for rtnl_lock in the entire Linux kernel, we will get a lot of matching results. Obviously this lock is a widely used lock, which makes it difficult for us to locate the problem. If we do not enable CONFIG_DEBUG_LOCKDEP and CONFIG_PROVE_LOCKING, it is often difficult for us to find out where went wrong.
2.codes that use rtnl_lock include some basic functions of networking:
There are many networking modules that use rtnl_lock, and some functions that use rtnl_lock are infrastructure part, such as unregister_netdev(), dev_ioctl(). Perhaps this can also explain to a certain extent the importance of adding a lightweight debug mechanism for rtnl_lock. And mediatek and our customer have benefited a lot from such log.
Hope above contents can answer your question.
Best Regards
Rocco
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Quoted 17 lines · Rocco.Yue
Quoted 15 lines · Cong Wang
Quoted 8 lines · Rocco yue
From: Rocco Yue <[email protected]>
We often encounter system hangs caused by certain process 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.Any reason why this is specific to RTNL lock? To me holding a mutex lock for a long time is problematic for any mutex. I have seen some fs mutex being held for a long time caused many hung tasks in the system.
Quoted 6 lines
Quoted 1 line
Thanks.
Thank you for a good question.
It's a problem to hold
rtnl_lockfor a long time, and other locks are no exception.
Then please try to make it generic so that other mutex locks will benefit too.
Thanks.
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Jakub Kicinski
maintainerQuoted 14 lines · On Tue, 11 May 2021 19:32:57 +0800 Rocco yue wrote:
We often encounter system hangs caused by certain process 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 this lightweight
rtnl_lockdebugging mechanism, which is helpful for us.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 out to help locate the problem.
Quoted 5 lines
i.e: from the following logs, we can clearly know that the pid=2206
RfxSender_4process holdsrtnl_lockfor a long time, causing the system to hang. And we can also speculate that the delay operation may be performed indevinet_ioctl(), resulting inrtnl_lockwas not released in time.
You can achieve that with a pair of fexit/fentry hooks or kprobes, and maybe a bit of BPF. No need for config options, and hardcoded parameters..
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek