26 Commits

Author SHA1 Message Date
Kobe Wu
907fce2338 [ALPS05081866] lockdep: fix build error
Include the correct header file to fix build error.

MTK-Commit-Id: ebf39a326a9bc2b53294b904dbb82d5d6477865d

Change-Id: Ibaee0ddc1f91211cfee8d48819ac4813894d0cad
CR-Id: ALPS05081866
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
2020-04-16 17:06:03 +08:00
skylake.huang
2f9c776ac2 [ALPS05077885] [Do NOT Sync]Merge branch android-4.14 into alps-trunk-r0.basic
[Detail]
	Parent: 234de92896
		Merge 4.14.150 into android-4.14
	Start: 7d642373db
		ANDROID: refactor build.config files to remove duplication
	Target: 32bc956bc2
		Merge 4.14.174 into android-4.14

MTK-Commit-Id: 73aee9b6172d4865b3b10bd396f7cfa40e7207b1

Feature: Others
Change-Id: Id09b858cd9f7f12db63cdb0bea42254d233a9fbd
CR-Id: ALPS05077885
Signed-off-by: Breeze.Li <breeze.li@mediatek.com>
2020-04-16 17:06:03 +08:00
Kobe Wu
3d3f72d7bb [ALPS04994668] lockdep: adjust the dependency of lock debugging
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
2020-04-16 16:31:21 +08:00
Kobe Wu
2334f7dd85 [ALPS04994668] lockdep: improve lockdep debugging
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>
2020-04-09 10:02:39 +08:00
Kobe Wu
23e7aae629 [ALPS04993096] sched_mon: implement schedule monitor v2
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>
2020-03-22 19:33:11 +08:00
Kobe Wu
02beb0ad8c [ALPS04810076] locking: fix KE at spinlock_debug
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>
2020-03-03 04:11:28 +08:00
Kobe Wu
832453cb58 [ALPS04680210] lockdep: fix build error
Fix build error when aee feature is not enabled.

MTK-Commit-Id: 7d416e62fab9593e2277dc8a2faf09a8e31f6ef2

Change-Id: I4aad1d80ea10f55e5a065e8ef614f35b2b4cf504
CR-Id: ALPS04680210
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
2020-03-03 04:05:25 +08:00
Kobe Wu
1cf50eb7ae [ALPS04683647] lockdep: fix Coverity Scanned Code Defect:8255793
Fix potential integer overflow.

MTK-Commit-Id: a71bad14a38c3aa6392fda1d036fa92d76c4278a

Change-Id: I109b9c5f943dcd0b88c3696f4c960aa2655e1f70
CR-Id: ALPS04683647
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
2020-03-03 04:05:20 +08:00
Kobe Wu
0298776480 [ALPS04677019] lockdep: introduce spinlock debugger v2
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>
2020-03-03 04:05:03 +08:00
Kobe Wu
b373b2d100 [ALPS04670617] lockdep: disable spin time warning
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>
2020-03-03 04:04:54 +08:00
Kobe Wu
3b003d22ac [ALPS04659845] lockdep: reduce warning messages
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>
2020-03-03 04:04:39 +08:00
Kobe Wu
08a13191bb [ALPS04657041] lockdep: enhance spinlock debugger on warning message
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>
2020-03-03 04:04:18 +08:00
Kobe Wu
93acc1b4e7 [ALPS04655435] lockdep: Fix Coverity Scanned Code Defect: 5470961
check null return from kmalloc

MTK-Commit-Id: 8c7d32162963286d0134e57970be4b10648d366c

Change-Id: I6b9f7284c08b5284bfe28e6251b64bd72a0d7aa8
CR-Id: ALPS04655435
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
2020-03-03 04:04:17 +08:00
Kobe Wu
5ff521c846 [ALPS04503017] lockdep: fix KE when checking lock->owner
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>
2020-03-03 04:04:10 +08:00
Kobe Wu
52b3bf2d24 [ALPS04644130] lockdep: enhance spinlock debugger
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>
2020-03-03 04:03:51 +08:00
Kobe Wu
ed493de65b [ALPS04379940] lockdep: fix deadlock condition on pool->lock
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)
2020-03-03 02:10:09 +08:00
Kobe Wu
d31acb9fcc [ALPS04355347] lockdep: enhance lock debugging function
1. verify lockdep lifetime
2. dump held locks when rcu stalls on CPU/task
3. adjust aee_dump position
4. improve lockdep selftest cases
5. print warning message to trace when printk is unusable
6. skip UBSAN checking in lockdep.c
7. add false alarm cases to filter

MTK-Commit-Id: a610ff8aa5a0d25a119898ceb69aae4cbb1213f6

Change-Id: Ieb7054ef94676f3b4d77c3c00706671d4e238826
CR-Id: ALPS04355347
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
2020-03-03 02:10:06 +08:00
Kobe Wu
c6d9d71ce8 [ALPS04182361] lockdep: prevent deadlock and improve spinlock log
1. prevent deadlock in aee_kernel_warning_api
2. prevent deadlock in smp_call_function_single
3. improve debug log in __spin_lock_debug

MTK-Commit-Id: b8563cc91f1bb81e7a03d31a0d2d8827fd572ea4

Change-Id: Ieb9f6536a6a1cd24b3999e32494f00baac478f8d
CR-Id: ALPS04182361
Feature: [Module]Lockdep
Signed-off-by: Kobe Wu <kobe-cp.wu@mediatek.com>
(cherry-pick from 650b2dad47e95d51b190afa1d3e1b8c04698b846)
2020-03-03 02:02:40 +08:00
Kobe Wu
b32821219a [ALPS04105356] lockdep: implement lock monitor
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)
2020-03-03 02:00:05 +08:00
Kobe Wu
4fa8447bc7 [ALPS04107248] spinlock: fix logbuf_lock/console_sem deadlock
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)
2020-03-03 00:30:20 +08:00
Seiya Wang
7ac76c5ec7 [ALPS03934967] arm: fix build error
Fix build error of 32bit project

MTK-Commit-Id: 57c17d57d86b3d74fdd1b4dce6d252205fd23ca5

Change-Id: I61ce002c7f1ae44b1b9d6c50577a0d7430f5e734
Feature: [Module]Kernel Maintenance
CR-Id: ALPS03934967
Signed-off-by: Seiya Wang <seiya.wang@mediatek.com>
(cherry-pick from d129eb47d72d084f28a5427a4260b8a028c718af)
2020-03-03 00:23:07 +08:00
Kobe Wu
03dc5c6283 [ALPS04082523] lockdep: implement debugging and self-test function
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)
2020-03-03 00:14:43 +08:00
Kobe Wu
f313224102 [ALPS04062204] sched_mon: monitor irq/preempt, signal, and boot time
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)
2020-03-03 00:12:51 +08:00
Marco Elver
09226e5c38 locking/spinlock/debug: Fix various data races
[ 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>
2020-01-12 12:11:49 +01:00
Waiman Long
bc88c10d7e locking/spinlock/debug: Remove spinlock lockup detection code
The current spinlock lockup detection code can sometimes produce false
positives because of the unfairness of the locking algorithm itself.

So the lockup detection code is now removed. Instead, we are relying
on the NMI watchdog to detect potential lockup. We won't have lockup
detection if the watchdog isn't running.

The commented-out read-write lock lockup detection code are also
removed.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1486583208-11038-1-git-send-email-longman@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-02-10 09:09:49 +01:00
Peter Zijlstra
60fc28746a locking: Move the spinlock code to kernel/locking/
Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/n/tip-b81ol0z3mon45m51o131yc9j@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2013-11-06 07:55:21 +01:00