Spinlock debugging is bundled to CONFIG_DEBUG_SPINLOCK.
Lock monitor is bundled to CONFIG_LOCKDEP.
CONFIG_DEBUG_LOCK_ALLOC is the basic option to enable
CONFIG_LOCKDEP (Lock monitor). The other choices are
CONFIG_LOCK_STAT and CONFIG_PROVE_LOCKING.
MTK-Commit-Id: 58b4cd9af33bdfd797320eb147d8bb7b726667ee
Change-Id: Ie50a28a379b4174e75c018a7d0481255c7d30231
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
CR-Id: ALPS04994668
Feature: [Module]Lockdep
1. set a limitation to prevent from log too much
2. add aee dump on held lock too much
3. ignore performance warning on KASAN/UBSAN load
4. increase size of lockdep chain buffer
5. refine function to dump task stack
6. refine mt_aee_dump_held_locks
MTK-Commit-Id: 5d2ddb79008c3919483973c2e5459e1405f70a30
Change-Id: I8c5d6c467873cdb9be896089cd2d8100b16f11c1
CR-Id: ALPS04994668
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
refactor schedule monitor functions into four domains
- irq processing time tracer (CONFIG_MTK_SCHED_MONITOR)
- irq count status tracer (CONFIG_MTK_IRQ_COUNT_TRACER)
- irq off tracer (CONFIG_MTK_IRQ_OFF_TRACER)
- preempt off tracer (CONFIG_MTK_PREEMPT_TRACER)
The major changes
- support debug in user load
- support preempt off detection
- support default setting in device tree
- refactor /proc/mtmon architecture
- refactor debug information for aee dump
- move mtk_sched_mon.h to drivers/misc/mediatek/include/mt-plat
MTK-Commit-Id: 16ecf23a9a75a442c612422b5e7648fd5fa04394
Change-Id: Id506d0c76efc99c78ef854c3b54d83650c060a22
CR-Id: ALPS04993096
Feature: [Module]Schedule Monitor
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
sdi = per_cpu_ptr(&sp_dbg, owner_cpu);
sdi->detector_cpu = -1;
If the lock is already released, owner_cpu would be -1 and
result in kernel exception when access sdi pointer.
MTK-Commit-Id: 58a071c37566f21de74559ec28a94b6e32c011ca
Change-Id: Ic126afcbbfa267ecaffb61b7a5a93717336cd03e
CR-Id: ALPS04810076
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
Because the old spinlock debugger might result in rq->lock
lockup in schedule flow. (only occurred on mt6771 Android Q)
We introduce the spinlock debugger v2 to avoid this problem.
The new version wouldnt show warnings when a task is spinning
for a spinlock. It only shows the holding time, spinning time,
and stack trace when a lock is released by the owner and above
the threshold. It wouldnt show magic number and raw_lock value.
MTK-Commit-Id: 1ef4259a053b21af07a6d33d66d629994d90c79e
Change-Id: Ib89b0b9456daa3188c8b8f05a5697849ef5db3ce
CR-Id: ALPS04677019
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
This is a temporary patch to disable spinlock debugger
warning on spin time. The root cause of spin time warning
on rq->lock is still under tracking.
MTK-Commit-Id: 1fa36bd2112a6ee68ebf1d0e95054a0d5c42857d
Change-Id: I375b27c2c46883eb0760c5dff532f9c6d8b7e87c
CR-Id: ALPS04670617
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
Reduce warning messages of spinlock debugger and lock monitor.
Only trigger aee dump once while more than one task are spinning
for the same spinlock. Remove backtrace of spinning tasks.
MTK-Commit-Id: 732bcd60d3237229bbc614c53f511284dfbe83ac
Change-Id: I25769faede5f49203e5232dd441e1123904dfa3f
CR-Id: ALPS04659845
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
Because a spinlock could be held by a task and other tasks are
waiting for it. If each task waiting for the spinlock triggers
an aee dump. It will make system very busy and many similar
warning messages will be shown in kernel log. This patch make
sure that aee dump will be triggered once under some conditions.
MTK-Commit-Id: 5d2505a40d384124ffd53f20b4ff3e3da5e62a27
Change-Id: I0bc3cb6416767758292c6ce63138fed15f89ab69
CR-Id: ALPS04657041
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
Because locks are acquired and released anytime. If we reserve
lock->owner information without using atomic operation. The
information could be invalid at that moment and results in
kernel exception when reading the information.
We will check the lock->owner information after reserving it
to a local variable. To see the information is valid or not.
MTK-Commit-Id: a314923a1dd34a4da86c1bfc4b9f03065929dbf2
Change-Id: I7150ab58bce45d68505e286e5179a04dc0c26638
CR-Id: ALPS04503017
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
Before we trigger aee dump in the call flow of spinning task.
Now we trigger aee dump in the call flow of lock owner.
This is helpful to find correct owner directly.
MTK-Commit-Id: ab41c7d331a3f19fd99ec4f4a81721b15f98e682
Change-Id: I8190ffc7e434774409bb3ca0597a367452b396f3
CR-Id: ALPS04644130
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
When a possible circular locking dependency detected, lockdep
have to invoke kernel API dump to keep warning message. But kernel
API dump works based on workqueue and pool->lock is needed by
workqueue. If pool->lock is already held by current task, invoking
kernel API dump will result in deadlock on pool->lock.
The solution is to check if pool->lock is held by current task and
dont invoke kernel API dump to avoid deadlock.
MTK-Commit-Id: d6645694f271119aa2019b0407109850ec22ced6
Change-Id: I680dceed71e0e8d0677c2c42fea3c7657e5d72a7
CR-Id: ALPS04379940
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
(cherry picked from commit 1fd08092895a71a2972f92bdd7ae78c7738a4a54)
1. implement lock monitor to check held locks on each task
2. add lock/unlock timestamps on spinlock
3. add checking on usage of uninitialized spinlock
4. remove debug_show_all_locks from spin time messages
5. add "lock_monitor" and "uninitialized" tests to lockdep_test
MTK-Commit-Id: f7fddeb812669f8a00a9e247775c7e781a94cd81
Change-Id: I57dfe0edb89cb76d23df4fae1d3886f2496875de
CR-Id: ALPS04105356
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
(cherry-pick from d65debc2bdb3f5d343233a1d267ac54b2ef286b3)
Use is_logbuf_lock() to check the held lock waiting by the
spinning tasks is logbuf_lock/console_sem or not. If yes,
spinlock_debug will not print any debug messages. Otherwise
deadlock will happen on logbuf_lock/console_sem.
MTK-Commit-Id: 9721e9de6995cd13e48bfbdf03ca68b40eec99f5
Change-Id: I62579d31a46fc838a8140fdbecdac5570570ccb7
CR-Id: ALPS04107248
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
(cherry-pick from 1daa74683e2c10b32c1afaf334761f934f14328e)
1. add try lock function for spinlock and monitor spin time
2. add aee function to lockdep and spin_bug warnings
3. enhance /proc/lockdep debugging information
4. record call trace of held locks for debugging
5. implement function to catch a new lock dependency
6. implement self-test commands to verify lockdep function
MTK-Commit-Id: b22752cc0c156db6adb1e633201c17ef3573da11
Change-Id: I85ca99808eba3bda894c35c0ccd8c15d3e2e9f3f
CR-Id: ALPS04082523
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
(cherry-pick from ab0d43fe483b8679a469a8a86e15f950308ccb55)
schedule monitor monitors the following items to help debugging.
1. processing time of irq handler
2. duration between irq enabled and disabled
3. preempt count
4. boot time
5. signal
MTK-Commit-Id: 27a823857268df65d87ab633adfedbe57013e228
Change-Id: I45f6fa20e034a0967d950e3b5691d404a99f7e14
CR-Id: ALPS04062204
Feature: [Module]Schedule Monitor
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
(cherry-pick from d9c9710719770a0e74c2a8adc24f68470580b613)
[ Upstream commit 1a365e822372ba24c9da0822bc583894f6f3d821 ]
This fixes various data races in spinlock_debug. By testing with KCSAN,
it is observable that the console gets spammed with data races reports,
suggesting these are extremely frequent.
Example data race report:
read to 0xffff8ab24f403c48 of 4 bytes by task 221 on cpu 2:
debug_spin_lock_before kernel/locking/spinlock_debug.c:85 [inline]
do_raw_spin_lock+0x9b/0x210 kernel/locking/spinlock_debug.c:112
__raw_spin_lock include/linux/spinlock_api_smp.h:143 [inline]
_raw_spin_lock+0x39/0x40 kernel/locking/spinlock.c:151
spin_lock include/linux/spinlock.h:338 [inline]
get_partial_node.isra.0.part.0+0x32/0x2f0 mm/slub.c:1873
get_partial_node mm/slub.c:1870 [inline]
<snip>
write to 0xffff8ab24f403c48 of 4 bytes by task 167 on cpu 3:
debug_spin_unlock kernel/locking/spinlock_debug.c:103 [inline]
do_raw_spin_unlock+0xc9/0x1a0 kernel/locking/spinlock_debug.c:138
__raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:159 [inline]
_raw_spin_unlock_irqrestore+0x2d/0x50 kernel/locking/spinlock.c:191
spin_unlock_irqrestore include/linux/spinlock.h:393 [inline]
free_debug_processing+0x1b3/0x210 mm/slub.c:1214
__slab_free+0x292/0x400 mm/slub.c:2864
<snip>
As a side-effect, with KCSAN, this eventually locks up the console, most
likely due to deadlock, e.g. .. -> printk lock -> spinlock_debug ->
KCSAN detects data race -> kcsan_print_report() -> printk lock ->
deadlock.
This fix will 1) avoid the data races, and 2) allow using lock debugging
together with KCSAN.
Reported-by: Qian Cai <cai@lca.pw>
Signed-off-by: Marco Elver <elver@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will.deacon@arm.com>
Link: https://lkml.kernel.org/r/20191120155715.28089-1-elver@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>