mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4 0/4] locking/lockdep: Disable KASAN instrumentation of lockdep.c
@ 2025-02-13 20:02 Waiman Long
  2025-02-13 20:02 ` [PATCH v4 1/4] locking/lock_events: Add locking events for rtmutex slow paths Waiman Long
                   ` (5 more replies)
  0 siblings, 6 replies; 23+ messages in thread
From: Waiman Long @ 2025-02-13 20:02 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng,
	Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov,
	Dmitry Vyukov, Vincenzo Frascino, Marco Elver
  Cc: linux-kernel, kasan-dev, Waiman Long

 v3: 
  - Add another patch to insert lock events into lockdep.c.
  - Rerun all the tests with the simpler defconfig kernel build and do
    further analysis of the of the performance difference between the
    the RT and non-RT debug kernels.

 v4:
  - Update test results in patch 3 after incorporating CONFIG_KASAN_INLINE
    into the test matrix.
  - Add patch 4 to call kasan_check_byte() in lock_acquire.

It is found that disabling KASAN instrumentation when compiling
lockdep.c can significantly improve the performance of RT debug kernel
while the performance benefit of non-RT debug kernel is relatively
modest.

This series also include patches to add locking events to the rtmutex
slow paths and the lockdep code for better analysis of the different
performance behavior between RT and non-RT debug kernels.

Waiman Long (4):
  locking/lock_events: Add locking events for rtmutex slow paths
  locking/lock_events: Add locking events for lockdep
  locking/lockdep: Disable KASAN instrumentation of lockdep.c
  locking/lockdep: Add kasan_check_byte() check in lock_acquire()

 kernel/locking/Makefile           |  3 ++-
 kernel/locking/lock_events_list.h | 29 +++++++++++++++++++++++++++++
 kernel/locking/lockdep.c          | 22 +++++++++++++++++++++-
 kernel/locking/rtmutex.c          | 29 ++++++++++++++++++++++++-----
 4 files changed, 76 insertions(+), 7 deletions(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 23+ messages in thread
* [PATCH locking 06/11] locking/lockdep: Add kasan_check_byte() check in lock_acquire()
@ 2025-03-07 23:26 Boqun Feng
  2025-03-08  0:08 ` [tip: locking/core] " tip-bot2 for Waiman Long
  0 siblings, 1 reply; 23+ messages in thread
From: Boqun Feng @ 2025-03-07 23:26 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra
  Cc: Will Deacon, Waiman Long, linux-kernel, Marco Elver,
	Andrey Konovalov, Boqun Feng, Ingo Molnar

From: Waiman Long <longman@redhat.com>

KASAN instrumentation of lockdep has been disabled as we don't need
KASAN to check the validity of lockdep internal data structures and
incur unnecessary performance overhead. However, the lockdep_map pointer
passed in externally may not be valid (e.g. use-after-free) and we run
the risk of using garbage data resulting in false lockdep reports.

Add kasan_check_byte() call in lock_acquire() for non kernel core data
object to catch invalid lockdep_map and print out a KASAN report before
any lockdep splat, if any.

Suggested-by: Marco Elver <elver@google.com>
Signed-off-by: Waiman Long <longman@redhat.com>
Reviewed-by: Marco Elver <elver@google.com>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250214195242.2480920-1-longman@redhat.com
---
 kernel/locking/lockdep.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 8436f017c74d..b15757e63626 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -57,6 +57,7 @@
 #include <linux/lockdep.h>
 #include <linux/context_tracking.h>
 #include <linux/console.h>
+#include <linux/kasan.h>
 
 #include <asm/sections.h>
 
@@ -5830,6 +5831,14 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
 	if (!debug_locks)
 		return;
 
+	/*
+	 * As KASAN instrumentation is disabled and lock_acquire() is usually
+	 * the first lockdep call when a task tries to acquire a lock, add
+	 * kasan_check_byte() here to check for use-after-free and other
+	 * memory errors.
+	 */
+	kasan_check_byte(lock);
+
 	if (unlikely(!lockdep_enabled())) {
 		/* XXX allow trylock from NMI ?!? */
 		if (lockdep_nmi() && !trylock) {
-- 
2.47.1


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2025-03-08  0:08 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-13 20:02 [PATCH v4 0/4] locking/lockdep: Disable KASAN instrumentation of lockdep.c Waiman Long
2025-02-13 20:02 ` [PATCH v4 1/4] locking/lock_events: Add locking events for rtmutex slow paths Waiman Long
2025-03-03 18:51   ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-02-13 20:02 ` [PATCH v4 2/4] locking/lock_events: Add locking events for lockdep Waiman Long
2025-03-03 18:51   ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-02-13 20:02 ` [PATCH v4 3/4] locking/lockdep: Disable KASAN instrumentation of lockdep.c Waiman Long
2025-02-17  7:00   ` Marco Elver
2025-02-17 16:53   ` Andrey Konovalov
2025-03-03 18:51   ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-02-13 20:02 ` [PATCH v4 4/4] locking/lockdep: Add kasan_check_byte() check in lock_acquire() Waiman Long
2025-02-14 10:44   ` Marco Elver
2025-02-14 14:09     ` Waiman Long
2025-02-14 14:44       ` Marco Elver
2025-02-14 15:30         ` Waiman Long
2025-02-14 16:18         ` Waiman Long
2025-02-14 16:43           ` Marco Elver
2025-02-14 17:18             ` Waiman Long
2025-02-14 19:52 ` [PATCH v4.1 " Waiman Long
2025-02-17  7:00   ` Marco Elver
2025-02-17 16:51   ` Andrey Konovalov
2025-03-03 18:51   ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-02-24  2:11 ` [PATCH v4 0/4] locking/lockdep: Disable KASAN instrumentation of lockdep.c Boqun Feng
2025-03-07 23:26 [PATCH locking 06/11] locking/lockdep: Add kasan_check_byte() check in lock_acquire() Boqun Feng
2025-03-08  0:08 ` [tip: locking/core] " tip-bot2 for Waiman Long

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®