lkml.org 
[lkml]   [2018]   [Sep]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC 12/60] locking/lockdep: Make cookie generator accessible
Date
If a dynamic amount of locks needs to be pinned in the same context,
it is impractical to have a cookie per lock. Make the cookie generator
accessible, so that such a group of locks can be (re-)pinned with
just one (shared) cookie.

Signed-off-by: Jan H. Schönherr <jschoenh@amazon.de>
---
include/linux/lockdep.h | 2 ++
kernel/locking/lockdep.c | 21 +++++++++++++++------
2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index d93a5ec3077f..06aee3386071 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -363,6 +363,7 @@ struct pin_cookie { unsigned int val; };

#define NIL_COOKIE (struct pin_cookie){ .val = 0U, }

+struct pin_cookie lockdep_cookie(void);
extern struct pin_cookie lock_pin_lock(struct lockdep_map *lock);
extern void lock_repin_lock(struct lockdep_map *lock, struct pin_cookie);
extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie);
@@ -452,6 +453,7 @@ struct pin_cookie { };

#define NIL_COOKIE (struct pin_cookie){ }

+#define lockdep_cookie() (NIL_COOKIE)
#define lockdep_pin_lock(l) ({ struct pin_cookie cookie; cookie; })
#define lockdep_repin_lock(l, c) do { (void)(l); (void)(c); } while (0)
#define lockdep_unpin_lock(l, c) do { (void)(l); (void)(c); } while (0)
diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index e406c5fdb41e..76aae27e1736 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -3729,6 +3729,20 @@ static int __lock_is_held(const struct lockdep_map *lock, int read)
return 0;
}

+struct pin_cookie lockdep_cookie(void)
+{
+ struct pin_cookie cookie;
+
+ /*
+ * Grab 16bits of randomness; this is sufficient to not
+ * be guessable and still allows some pin nesting in
+ * our u32 pin_count.
+ */
+ cookie.val = 1 + (prandom_u32() >> 16);
+
+ return cookie;
+}
+
static struct pin_cookie __lock_pin_lock(struct lockdep_map *lock)
{
struct pin_cookie cookie = NIL_COOKIE;
@@ -3742,12 +3756,7 @@ static struct pin_cookie __lock_pin_lock(struct lockdep_map *lock)
struct held_lock *hlock = curr->held_locks + i;

if (match_held_lock(hlock, lock)) {
- /*
- * Grab 16bits of randomness; this is sufficient to not
- * be guessable and still allows some pin nesting in
- * our u32 pin_count.
- */
- cookie.val = 1 + (prandom_u32() >> 16);
+ cookie = lockdep_cookie();
hlock->pin_count += cookie.val;
return cookie;
}
--
2.9.3.1.gcba166c.dirty
\
 
 \ /
  Last update: 2018-09-07 23:47    [W:3.930 / U:0.080 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site