From: Byungchul Park <byungchul.park@lge.com>
To: peterz@infradead.org, mingo@kernel.org
Cc: linux-kernel@vger.kernel.org, npiggin@suse.de, walken@google.com,
ak@suse.de, tglx@inhelltoy.tec.linutronix.de
Subject: [RFC 02/12] lockdep: Add a function building a chain between two hlocks
Date: Mon, 20 Jun 2016 13:55:17 +0900 [thread overview]
Message-ID: <1466398527-1122-3-git-send-email-byungchul.park@lge.com> (raw)
In-Reply-To: <1466398527-1122-1-git-send-email-byungchul.park@lge.com>
add_chain_cache() can only be used by current context since it
depends on a task's held_locks which is not protected by lock.
However, it would be useful if a dependency chain can be built
in any context. This patch makes the chain building not depend
on its context.
Especially, crossrelease feature wants to do this. Crossrelease
feature introduces a additional dependency chain consisting of 2
lock classes using 2 hlock instances, to connect dependency
between different contexts.
Signed-off-by: Byungchul Park <byungchul.park@lge.com>
---
kernel/locking/lockdep.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index efd001c..4d51208 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -2010,6 +2010,63 @@ struct lock_class *lock_chain_get_class(struct lock_chain *chain, int i)
return lock_classes + chain_hlocks[chain->base + i];
}
+/*
+ * This can make it possible to build a chain between just two
+ * specified hlocks rather than between already held locks of
+ * the current task and newly held lock, which can be done by
+ * add_chain_cache().
+ *
+ * add_chain_cache() must be done within the lock owner's context,
+ * however this can be called in any context if two racy-less hlock
+ * instances were already taken by caller. Thus this can be useful
+ * when building a chain between two hlocks regardless of context.
+ */
+static inline int add_chain_cache_2hlocks(struct held_lock *prev,
+ struct held_lock *next,
+ u64 chain_key)
+{
+ struct hlist_head *hash_head = chainhashentry(chain_key);
+ struct lock_chain *chain;
+
+ /*
+ * Allocate a new chain entry from the static array, and add
+ * it to the hash:
+ */
+
+ /*
+ * We might need to take the graph lock, ensure we've got IRQs
+ * disabled to make this an IRQ-safe lock.. for recursion reasons
+ * lockdep won't complain about its own locking errors.
+ */
+ if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
+ return 0;
+
+ if (unlikely(nr_lock_chains >= MAX_LOCKDEP_CHAINS)) {
+ if (!debug_locks_off_graph_unlock())
+ return 0;
+
+ print_lockdep_off("BUG: MAX_LOCKDEP_CHAINS too low!");
+ dump_stack();
+ return 0;
+ }
+
+ chain = lock_chains + nr_lock_chains++;
+ chain->chain_key = chain_key;
+ chain->irq_context = next->irq_context;
+ chain->depth = 2;
+ if (likely(nr_chain_hlocks + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS)) {
+ chain->base = nr_chain_hlocks;
+ nr_chain_hlocks += chain->depth;
+ chain_hlocks[chain->base] = prev->class_idx - 1;
+ chain_hlocks[chain->base + 1] = next->class_idx -1;
+ }
+ hlist_add_head_rcu(&chain->entry, hash_head);
+ debug_atomic_inc(chain_lookup_misses);
+ inc_chains();
+
+ return 1;
+}
+
static inline int add_chain_cache(struct task_struct *curr,
struct held_lock *hlock,
u64 chain_key)
--
1.9.1
next prev parent reply other threads:[~2016-06-20 5:12 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-20 4:55 [RFC 00/12] lockdep: Implement crossrelease feature Byungchul Park
2016-06-20 4:55 ` [RFC 01/12] lockdep: Refactor lookup_chain_cache() Byungchul Park
2016-06-20 4:55 ` Byungchul Park [this message]
2016-06-20 4:55 ` [RFC 03/12] lockdep: Make check_prev_add can use a stack_trace of other context Byungchul Park
2016-06-20 4:55 ` [RFC 04/12] lockdep: Make save_trace can copy from other stack_trace Byungchul Park
2016-06-20 4:55 ` [RFC 05/12] lockdep: Implement crossrelease feature Byungchul Park
2016-06-30 13:03 ` Peter Zijlstra
2016-06-30 23:28 ` Byungchul Park
2016-06-20 4:55 ` [RFC 06/12] lockdep: Apply crossrelease to completion Byungchul Park
2016-06-20 4:55 ` [RFC 07/12] pagemap.h: Remove trailing white space Byungchul Park
2016-06-20 4:55 ` [RFC 08/12] lockdep: Apply crossrelease to PG_locked lock Byungchul Park
2016-06-30 13:04 ` Peter Zijlstra
2016-06-30 23:21 ` Byungchul Park
2016-07-01 8:10 ` Peter Zijlstra
2016-07-01 11:18 ` Kirill A. Shutemov
2016-07-04 4:30 ` Byungchul Park
2016-06-20 4:55 ` [RFC 09/12] cifs/file.c: Remove trailing white space Byungchul Park
2016-06-20 4:55 ` [RFC 10/12] mm/swap_state.c: " Byungchul Park
2016-06-20 4:55 ` [RFC 11/12] lockdep: Call lock_acquire(release) when accessing PG_locked manually Byungchul Park
2016-06-20 4:55 ` [RFC 12/12] x86/dumpstack: Optimize save_stack_trace Byungchul Park
2016-06-20 7:29 ` xinhui
2016-06-20 7:50 ` byungchul.park
2016-06-29 12:43 ` Byungchul Park
2016-06-30 10:38 ` xinhui
2016-06-30 23:06 ` Byungchul Park
2016-06-23 23:37 ` [RFC 00/12] lockdep: Implement crossrelease feature Byungchul Park
2016-06-24 7:08 ` Peter Zijlstra
2016-06-24 11:13 ` Byungchul Park
2016-06-24 11:26 ` Nikolay Borisov
2016-06-27 1:34 ` Byungchul Park
2016-07-01 4:15 ` [PATCH] lockdep: Add a document describing " Byungchul Park
2016-07-01 10:45 ` Peter Zijlstra
2016-07-04 6:42 ` Byungchul Park
2016-07-06 0:49 ` Boqun Feng
2016-07-06 2:17 ` Byungchul Park
2016-07-06 5:33 ` Byungchul Park
2016-07-06 7:56 ` Peter Zijlstra
2016-07-06 8:12 ` Byungchul Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1466398527-1122-3-git-send-email-byungchul.park@lge.com \
--to=byungchul.park@lge.com \
--cc=ak@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=npiggin@suse.de \
--cc=peterz@infradead.org \
--cc=tglx@inhelltoy.tec.linutronix.de \
--cc=walken@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®