From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753978AbcBPF6x (ORCPT ); Tue, 16 Feb 2016 00:58:53 -0500 Received: from mail-pa0-f50.google.com ([209.85.220.50]:34020 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753920AbcBPF6t (ORCPT ); Tue, 16 Feb 2016 00:58:49 -0500 From: Boqun Feng To: linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , "Paul E. McKenney" , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , sasha.levin@oracle.com, Boqun Feng Subject: [RFC v2 3/6] lockdep: LOCKED_ACCESS: Maintain the keys of acqchains Date: Tue, 16 Feb 2016 13:57:42 +0800 Message-Id: <1455602265-16490-4-git-send-email-boqun.feng@gmail.com> X-Mailer: git-send-email 2.7.1 In-Reply-To: <1455602265-16490-1-git-send-email-boqun.feng@gmail.com> References: <1455602265-16490-1-git-send-email-boqun.feng@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add held_lock::prev_acqchain_key and task_struct::curr_acqchain_key to maintain the keys of acqchains as the same as what lockdep does for keys of lock classes. Signed-off-by: Boqun Feng --- include/linux/lockdep.h | 3 +++ include/linux/sched.h | 3 +++ kernel/fork.c | 3 +++ kernel/locking/lockdep.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 140c1c3..2ffe6c3 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -244,6 +244,9 @@ struct held_lock { * with zero), here we store the previous hash value: */ u64 prev_chain_key; +#ifdef CONFIG_LOCKED_ACCESS + u64 prev_acqchain_key; +#endif unsigned long acquire_ip; struct lockdep_map *instance; struct lockdep_map *nest_lock; diff --git a/include/linux/sched.h b/include/linux/sched.h index a10494a..c24348e 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1643,6 +1643,9 @@ struct task_struct { unsigned int lockdep_recursion; struct held_lock held_locks[MAX_LOCK_DEPTH]; gfp_t lockdep_reclaim_gfp; +#ifdef CONFIG_LOCKED_ACCESS + u64 curr_acqchain_key; +#endif #endif #ifdef CONFIG_UBSAN unsigned int in_ubsan; diff --git a/kernel/fork.c b/kernel/fork.c index 2e391c7..d9fc51b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1404,6 +1404,9 @@ static struct task_struct *copy_process(unsigned long clone_flags, p->lockdep_depth = 0; /* no locks held yet */ p->curr_chain_key = 0; p->lockdep_recursion = 0; +# ifdef CONFIG_LOCKED_ACCESS + p->curr_acqchain_key = 0; +# endif #endif #ifdef CONFIG_DEBUG_MUTEXES diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index fdb1b8c..3ebd00d 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -3089,6 +3089,9 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, int chain_head = 0; int class_idx; u64 chain_key; +#ifdef CONFIG_LOCKED_ACCESS + u64 acqchain_key; +#endif if (unlikely(!debug_locks)) return 0; @@ -3196,6 +3199,9 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, return 0; chain_key = curr->curr_chain_key; +#ifdef CONFIG_LOCKED_ACCESS + acqchain_key = curr->curr_acqchain_key; +#endif if (!depth) { /* * How can we have a chain hash when we ain't got no keys?! @@ -3206,12 +3212,23 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, } hlock->prev_chain_key = chain_key; +#ifdef CONFIG_LOCKED_ACCESS + hlock->prev_acqchain_key = acqchain_key; +#endif if (separate_irq_context(curr, hlock)) { chain_key = 0; + +#ifdef CONFIG_LOCKED_ACCESS + acqchain_key = 0; +#endif + chain_head = 1; } chain_key = iterate_chain_key(chain_key, id); +#ifdef CONFIG_LOCKED_ACCESS + acqchain_key = iterate_acqchain_key(acqchain_key, ip); +#endif if (nest_lock && !__lock_is_held(nest_lock)) return print_lock_nested_lock_not_held(curr, hlock, ip); @@ -3219,6 +3236,9 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, return 0; curr->curr_chain_key = chain_key; +#ifdef CONFIG_LOCKED_ACCESS + curr->curr_acqchain_key = acqchain_key; +#endif curr->lockdep_depth++; check_chain_key(curr); #ifdef CONFIG_DEBUG_LOCKDEP @@ -3348,6 +3368,9 @@ found_it: curr->lockdep_depth = i; curr->curr_chain_key = hlock->prev_chain_key; +#ifdef CONFIG_LOCKED_ACCESS + curr->curr_acqchain_key = hlock->prev_acqchain_key; +#endif for (; i < depth; i++) { hlock = curr->held_locks + i; @@ -3438,6 +3461,9 @@ found_it: curr->lockdep_depth = i; curr->curr_chain_key = hlock->prev_chain_key; +#ifdef CONFIG_LOCKED_ACCESS + curr->curr_acqchain_key = hlock->prev_acqchain_key; +#endif for (i++; i < depth; i++) { hlock = curr->held_locks + i; @@ -3879,6 +3905,11 @@ void lockdep_reset(void) raw_local_irq_save(flags); current->curr_chain_key = 0; + +#ifdef CONFIG_LOCKED_ACCESS + current->curr_acqchain_key = 0; +#endif + current->lockdep_depth = 0; current->lockdep_recursion = 0; memset(current->held_locks, 0, MAX_LOCK_DEPTH*sizeof(struct held_lock)); -- 2.7.1