Skip to content

Commit

Permalink
locking/lockdep: Make it easy to detect whether or not inside a selftest
Browse files Browse the repository at this point in the history
The patch that frees unused lock classes will modify the behavior of
lockdep_free_key_range() and lockdep_reset_lock() depending on whether
or not these functions are called from the context of the lockdep
selftests. Hence make it easy to detect whether or not lockdep code
is called from the context of a lockdep selftest.

Signed-off-by: Bart Van Assche <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Johannes Berg <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Paul E. McKenney <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Waiman Long <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: [email protected]
Cc: [email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
bvanassche authored and Ingo Molnar committed Feb 28, 2019
1 parent 956f356 commit cdc84d7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/linux/lockdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ extern void lockdep_reset(void);
extern void lockdep_reset_lock(struct lockdep_map *lock);
extern void lockdep_free_key_range(void *start, unsigned long size);
extern asmlinkage void lockdep_sys_exit(void);
extern void lockdep_set_selftest_task(struct task_struct *task);

extern void lockdep_off(void);
extern void lockdep_on(void);
Expand Down Expand Up @@ -395,6 +396,10 @@ static inline void lockdep_on(void)
{
}

static inline void lockdep_set_selftest_task(struct task_struct *task)
{
}

# define lock_acquire(l, s, t, r, c, n, i) do { } while (0)
# define lock_release(l, n, i) do { } while (0)
# define lock_downgrade(l, i) do { } while (0)
Expand Down
6 changes: 6 additions & 0 deletions kernel/locking/lockdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module_param(lock_stat, int, 0644);
* code to recurse back into the lockdep code...
*/
static arch_spinlock_t lockdep_lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
static struct task_struct *lockdep_selftest_task_struct;

static int graph_lock(void)
{
Expand Down Expand Up @@ -331,6 +332,11 @@ void lockdep_on(void)
}
EXPORT_SYMBOL(lockdep_on);

void lockdep_set_selftest_task(struct task_struct *task)
{
lockdep_selftest_task_struct = task;
}

/*
* Debugging switches:
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/locking-selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,7 @@ void locking_selftest(void)

init_shared_classes();
debug_locks_silent = !debug_locks_verbose;
lockdep_set_selftest_task(current);

DO_TESTCASE_6R("A-A deadlock", AA);
DO_TESTCASE_6R("A-B-B-A deadlock", ABBA);
Expand Down Expand Up @@ -2097,5 +2098,6 @@ void locking_selftest(void)
printk("---------------------------------\n");
debug_locks = 1;
}
lockdep_set_selftest_task(NULL);
debug_locks_silent = 0;
}

0 comments on commit cdc84d7

Please sign in to comment.