All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] locking/lockdep: Use sched_clock() for random numbers.
@ 2022-05-17  9:16 Sebastian Andrzej Siewior
  2022-05-17  9:53 ` Jason A. Donenfeld
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-05-17  9:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long, Boqun Feng,
	Jason A. Donenfeld, Theodore Ts'o, Thomas Gleixner

Since the rewrote of prandom_u32(), in the commit mentioned below, the
function uses sleeping locks which extracing random numbers and filling
the batch.
This breaks lockdep on PREEMPT_RT because lock_pin_lock() disables
interrupts while calling __lock_pin_lock(). This can't be moved earlier
because the main user of the function (rq_pin_lock()) invokes that
function after disabling interrupts in order to acquire the lock.

The cookie does not require random numbers as its goal is to provide a
random value in order to notice unexpected "unlock + lock" sites.

Use sched_clock() to provide random numbers.

Fixes: a0103f4d86f88 ("random32: use real rng for non-deterministic randomness")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---

So if the architecture does not provide sched_clock() and does not
enabled GENERIC_SCHED_CLOCK then we use jiffies here. Most of them do
one or the other except for alpha, csky, hexagon, ... but I don't worry
here since arm*, power*, x86* do provide it.

 kernel/locking/lockdep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
index 81e87280513ea..f06b91ca6482d 100644
--- a/kernel/locking/lockdep.c
+++ b/kernel/locking/lockdep.c
@@ -5432,7 +5432,7 @@ static struct pin_cookie __lock_pin_lock(struct lockdep_map *lock)
 			 * be guessable and still allows some pin nesting in
 			 * our u32 pin_count.
 			 */
-			cookie.val = 1 + (prandom_u32() >> 16);
+			cookie.val = 1 + (sched_clock() & 0xffff);
 			hlock->pin_count += cookie.val;
 			return cookie;
 		}
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-06-13  8:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-17  9:16 [PATCH] locking/lockdep: Use sched_clock() for random numbers Sebastian Andrzej Siewior
2022-05-17  9:53 ` Jason A. Donenfeld
2022-05-17  9:59   ` Jason A. Donenfeld
2022-05-17 12:08     ` Sebastian Andrzej Siewior
2022-06-13  8:11       ` Peter Zijlstra
2022-06-13  8:05   ` Peter Zijlstra
2022-06-13  8:16     ` Jason A. Donenfeld
2022-06-07 16:51 ` Sebastian Andrzej Siewior
2022-06-12 15:43 ` Sasha Levin
2022-06-13  8:36 ` [tip: locking/urgent] " tip-bot2 for Sebastian Andrzej Siewior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.