Skip to content

Commit 785a242

Browse files
committed
Merge: locking/lockdep: Disable KASAN instrumentation of lockdep.c
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6507 JIRA: https://issues.redhat.com/browse/RHEL-81997 MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/6507 KASAN and LOCKDEP are the two major performance hitters in the debug kernel. Disabling KASAN instrumentation in the LOCKDEP code can regain some of the lost performance back. A targeted KASAN memory check is still done in the lock_acquire() function to catch memory error, if any. Signed-off-by: Waiman Long <longman@redhat.com> Approved-by: Phil Auld <pauld@redhat.com> Approved-by: Wander Lairson Costa <wander@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Augusto Caringi <acaringi@redhat.com>
2 parents 53d1084 + 4314ae6 commit 785a242

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

kernel/locking/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ KCOV_INSTRUMENT := n
55

66
obj-y += mutex.o semaphore.o rwsem.o percpu-rwsem.o
77

8-
# Avoid recursion lockdep -> sanitizer -> ... -> lockdep.
8+
# Avoid recursion lockdep -> sanitizer -> ... -> lockdep & improve performance.
9+
KASAN_SANITIZE_lockdep.o := n
910
KCSAN_SANITIZE_lockdep.o := n
1011

1112
ifdef CONFIG_FUNCTION_TRACER

kernel/locking/lockdep.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <linux/lockdep.h>
5858
#include <linux/context_tracking.h>
5959
#include <linux/console.h>
60+
#include <linux/kasan.h>
6061

6162
#include <asm/sections.h>
6263

@@ -5738,6 +5739,14 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
57385739
if (!debug_locks)
57395740
return;
57405741

5742+
/*
5743+
* As KASAN instrumentation is disabled and lock_acquire() is usually
5744+
* the first lockdep call when a task tries to acquire a lock, add
5745+
* kasan_check_byte() here to check for use-after-free and other
5746+
* memory errors.
5747+
*/
5748+
kasan_check_byte(lock);
5749+
57415750
if (unlikely(!lockdep_enabled())) {
57425751
/* XXX allow trylock from NMI ?!? */
57435752
if (lockdep_nmi() && !trylock) {

0 commit comments

Comments
 (0)