From: Bart Van Assche <bvanassche@acm.org>
To: mingo@redhat.com
Cc: linux-kernel@vger.kernel.org,
Bart Van Assche <bvanassche@acm.org>,
Peter Zijlstra <peterz@infradead.org>,
Will Deacon <will.deacon@arm.com>, Tejun Heo <tj@kernel.org>,
Johannes Berg <johannes.berg@intel.com>
Subject: [PATCH 1/2] locking/lockdep: Add support for dynamic depmaps and keys
Date: Fri, 9 Nov 2018 15:46:44 -0800 [thread overview]
Message-ID: <20181109234645.10530-2-bvanassche@acm.org> (raw)
In-Reply-To: <20181109234645.10530-1-bvanassche@acm.org>
The lock validator forces to categorize multiple instances of a lock object
as the same lock class because it requires that struct lockdep_map and struct
lock_class_key instances are static objects. This can result in false
positive lockdep reports that are hard to suppress in an elegant way. Hence
add support for allocating instances of these objects dynamically.
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
include/linux/lockdep.h | 2 ++
kernel/locking/lockdep.c | 16 +++++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index 1fd82ff99c65..a10a131ccc9a 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -56,6 +56,7 @@ struct lockdep_subclass_key {
struct lock_class_key {
struct lockdep_subclass_key subkeys[MAX_LOCKDEP_SUBCLASSES];
+ bool dynamic:1;
};
extern struct lock_class_key __lockdep_no_validate__;
@@ -153,6 +154,7 @@ struct lockdep_map {
int cpu;
unsigned long ip;
#endif
+ bool dynamic:1;
};
static inline void lockdep_copy_map(struct lockdep_map *to,
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 1efada2dd9dd..8a3d3f0b6d8d 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -624,6 +624,16 @@ static int static_obj(void *obj)
}
#endif
+static bool is_valid_lockdep_map(struct lockdep_map *lock)
+{
+ return static_obj(lock) || lock->dynamic;
+}
+
+static bool is_valid_key(struct lock_class_key *key)
+{
+ return static_obj(key) || key->dynamic;
+}
+
/*
* To make lock name printouts unique, we calculate a unique
* class->name_version generation counter:
@@ -716,7 +726,7 @@ static bool assign_lock_key(struct lockdep_map *lock)
lock->key = (void *)can_addr;
else if (__is_module_percpu_address(addr, &can_addr))
lock->key = (void *)can_addr;
- else if (static_obj(lock))
+ else if (is_valid_lockdep_map(lock))
lock->key = (void *)lock;
else {
/* Debug-check: all keys must be persistent! */
@@ -752,7 +762,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
if (!lock->key) {
if (!assign_lock_key(lock))
return NULL;
- } else if (!static_obj(lock->key)) {
+ } else if (!is_valid_key(lock->key)) {
return NULL;
}
@@ -3118,7 +3128,7 @@ static void __lockdep_init_map(struct lockdep_map *lock, const char *name,
/*
* Sanity check, the lock-class key must be persistent:
*/
- if (!static_obj(key)) {
+ if (!is_valid_key(key)) {
printk("BUG: key %px not in .data!\n", key);
/*
* What it says above ^^^^^, I suggest you read it.
--
2.19.1.930.g4563a0d9d0-goog
next prev parent reply other threads:[~2018-11-09 23:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-09 23:46 [PATCH 0/2] locking/lockdep: Support dynamic lockdep keys Bart Van Assche
2018-11-09 23:46 ` Bart Van Assche [this message]
2018-11-10 13:55 ` [PATCH 1/2] locking/lockdep: Add support for dynamic depmaps and keys Peter Zijlstra
2018-11-19 21:55 ` Bart Van Assche
2018-11-09 23:46 ` [PATCH 2/2] kernel/workqueue: Use dynamic lockdep keys for workqueues Bart Van Assche
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=20181109234645.10530-2-bvanassche@acm.org \
--to=bvanassche@acm.org \
--cc=johannes.berg@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tj@kernel.org \
--cc=will.deacon@arm.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;
as well as URLs for NNTP newsgroup(s).