Skip to content

Commit

Permalink
locking/lockdep: Define INITIAL_CHAIN_KEY for chain keys to start with
Browse files Browse the repository at this point in the history
Chain keys are computed using Jenkins hash function, which needs an initial
hash to start with. Dedicate a macro to make this clear and configurable. A
later patch changes this initial chain key.

Signed-off-by: Yuyang Du <duyuyang@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: bvanassche@acm.org
Cc: frederic@kernel.org
Cc: ming.lei@redhat.com
Cc: will.deacon@arm.com
Link: https://lkml.kernel.org/r/20190506081939.74287-9-duyuyang@gmail.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Yuyang Du authored and Ingo Molnar committed Jun 3, 2019
1 parent e196e47 commit f6ec882
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions include/linux/lockdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ struct lock_chain {
* bitfield and hitting the BUG in hlock_class().
*/
#define MAX_LOCKDEP_KEYS ((1UL << MAX_LOCKDEP_KEYS_BITS) - 1)
#define INITIAL_CHAIN_KEY 0

struct held_lock {
/*
Expand Down
2 changes: 1 addition & 1 deletion init/init_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ struct task_struct init_task
#endif
#ifdef CONFIG_LOCKDEP
.lockdep_depth = 0, /* no locks held yet */
.curr_chain_key = 0,
.curr_chain_key = INITIAL_CHAIN_KEY,
.lockdep_recursion = 0,
#endif
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Expand Down
18 changes: 9 additions & 9 deletions kernel/locking/lockdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static inline u64 iterate_chain_key(u64 key, u32 idx)
void lockdep_init_task(struct task_struct *task)
{
task->lockdep_depth = 0; /* no locks held yet */
task->curr_chain_key = 0;
task->curr_chain_key = INITIAL_CHAIN_KEY;
task->lockdep_recursion = 0;
}

Expand Down Expand Up @@ -857,7 +857,7 @@ static u16 chain_hlocks[MAX_LOCKDEP_CHAIN_HLOCKS];
static bool check_lock_chain_key(struct lock_chain *chain)
{
#ifdef CONFIG_PROVE_LOCKING
u64 chain_key = 0;
u64 chain_key = INITIAL_CHAIN_KEY;
int i;

for (i = chain->base; i < chain->base + chain->depth; i++)
Expand Down Expand Up @@ -2524,7 +2524,7 @@ static void
print_chain_keys_held_locks(struct task_struct *curr, struct held_lock *hlock_next)
{
struct held_lock *hlock;
u64 chain_key = 0;
u64 chain_key = INITIAL_CHAIN_KEY;
int depth = curr->lockdep_depth;
int i = get_first_held_lock(curr, hlock_next);

Expand All @@ -2544,7 +2544,7 @@ print_chain_keys_held_locks(struct task_struct *curr, struct held_lock *hlock_ne
static void print_chain_keys_chain(struct lock_chain *chain)
{
int i;
u64 chain_key = 0;
u64 chain_key = INITIAL_CHAIN_KEY;
int class_id;

printk("depth: %u\n", chain->depth);
Expand Down Expand Up @@ -2848,7 +2848,7 @@ static void check_chain_key(struct task_struct *curr)
#ifdef CONFIG_DEBUG_LOCKDEP
struct held_lock *hlock, *prev_hlock = NULL;
unsigned int i;
u64 chain_key = 0;
u64 chain_key = INITIAL_CHAIN_KEY;

for (i = 0; i < curr->lockdep_depth; i++) {
hlock = curr->held_locks + i;
Expand All @@ -2872,7 +2872,7 @@ static void check_chain_key(struct task_struct *curr)

if (prev_hlock && (prev_hlock->irq_context !=
hlock->irq_context))
chain_key = 0;
chain_key = INITIAL_CHAIN_KEY;
chain_key = iterate_chain_key(chain_key, hlock->class_idx);
prev_hlock = hlock;
}
Expand Down Expand Up @@ -3787,14 +3787,14 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
/*
* How can we have a chain hash when we ain't got no keys?!
*/
if (DEBUG_LOCKS_WARN_ON(chain_key != 0))
if (DEBUG_LOCKS_WARN_ON(chain_key != INITIAL_CHAIN_KEY))
return 0;
chain_head = 1;
}

hlock->prev_chain_key = chain_key;
if (separate_irq_context(curr, hlock)) {
chain_key = 0;
chain_key = INITIAL_CHAIN_KEY;
chain_head = 1;
}
chain_key = iterate_chain_key(chain_key, class_idx);
Expand Down Expand Up @@ -4636,7 +4636,7 @@ static void remove_class_from_lock_chain(struct pending_free *pf,
return;

recalc:
chain_key = 0;
chain_key = INITIAL_CHAIN_KEY;
for (i = chain->base; i < chain->base + chain->depth; i++)
chain_key = iterate_chain_key(chain_key, chain_hlocks[i] + 1);
if (chain->depth && chain->chain_key == chain_key)
Expand Down

0 comments on commit f6ec882

Please sign in to comment.