mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [GIT PULL] LOCKDEP and Rust locking changes for v6.15
@ 2025-02-26  4:12 Boqun Feng
  2025-02-28 18:57 ` Boqun Feng
                   ` (2 more replies)
  0 siblings, 3 replies; 32+ messages in thread
From: Boqun Feng @ 2025-02-26  4:12 UTC (permalink / raw)
  To: Peter Zijlstra, mingo
  Cc: Will Deacon, Waiman Long, linux-kernel, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, rust-for-linux

Hi Peter & Ingo,

Please pull the changes of lockdep and Rust locking for v6.15 into tip.

The following changes since commit 337369f8ce9e20226402cf139c4f0d3ada7d1705:

  locking/mutex: Add MUTEX_WARN_ON() into fast path (2025-02-21 20:19:12 +0100)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git tags/lockdep-for-tip.2025.02.25

for you to fetch changes up to 3b5b307cf84ca3a73abe797df31e0efe897411a9:

  rust: lockdep: Use Pin for all LockClassKey usages (2025-02-25 08:53:08 -0800)


Regards,
Boqun

----------------------------------------------------------------
Lockdep changes for v6.15:

- Fix kernel-doc for rtmutex.
- Fix lock wait context check on softirq for PREEMPT_RT.
- Disable KASAN for lockdep to improve debug kernel performance.

Miscellaneous locking changes for v6.15:

- Use wake_q for semaphore to avoid wake-up in lock critical sections.

Rust locking changes for v6.15:

- Fix the soundness issue around dynamically allocated lock class keys.
- Add CondVar::wait_interruptible_freezable() to allow freezable waits.
- Add Guard::lock_ref() to access the lock reference behind a lock
  guard.

----------------------------------------------------------------
Alice Ryhl (2):
      rust: sync: Add accessor for the lock behind a given guard
      rust: sync: condvar: Add wait_interruptible_freezable()

Boqun Feng (1):
      rust: sync: lock: Add an example for Guard::lock_ref()

Mitchell Levy (2):
      rust: lockdep: Remove support for dynamically allocated LockClassKeys
      rust: lockdep: Use Pin for all LockClassKey usages

Randy Dunlap (1):
      locking/rtmutex: Use struct keyword in kernel-doc comment

Ryo Takakura (1):
      lockdep: Fix wait context check on softirq for PREEMPT_RT

Waiman Long (5):
      locking/semaphore: Use wake_q to wake up processes outside lock critical section
      locking/lock_events: Add locking events for rtmutex slow paths
      locking/lock_events: Add locking events for lockdep
      locking/lockdep: Disable KASAN instrumentation of lockdep.c
      locking/lockdep: Add kasan_check_byte() check in lock_acquire()

 include/linux/bottom_half.h       |  8 +++++
 kernel/locking/Makefile           |  3 +-
 kernel/locking/lock_events_list.h | 28 +++++++++++++++++
 kernel/locking/lockdep.c          | 17 ++++++++++-
 kernel/locking/rtmutex.c          | 29 ++++++++++++++----
 kernel/locking/rtmutex_common.h   |  4 +--
 kernel/locking/semaphore.c        | 13 +++++---
 kernel/softirq.c                  | 12 ++++++++
 rust/helpers/helpers.c            |  1 +
 rust/helpers/sync.c               | 13 ++++++++
 rust/kernel/sync.rs               | 63 ++++++++++++++++++++++++++++++++-------
 rust/kernel/sync/condvar.rs       | 28 ++++++++++++++---
 rust/kernel/sync/lock.rs          | 35 ++++++++++++++++++++--
 rust/kernel/sync/lock/global.rs   |  5 ++--
 rust/kernel/sync/poll.rs          |  2 +-
 rust/kernel/task.rs               |  2 ++
 rust/kernel/workqueue.rs          |  2 +-
 17 files changed, 231 insertions(+), 34 deletions(-)
 create mode 100644 rust/helpers/sync.c

^ permalink raw reply	[flat|nested] 32+ messages in thread
* [PATCH v4 1/4] locking/lock_events: Add locking events for rtmutex slow paths
@ 2025-02-13 20:02 Waiman Long
  2025-03-03 18:51 ` [tip: locking/core] " tip-bot2 for Waiman Long
  0 siblings, 1 reply; 32+ messages in thread
From: Waiman Long @ 2025-02-13 20:02 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng,
	Andrey Ryabinin, Alexander Potapenko, Andrey Konovalov,
	Dmitry Vyukov, Vincenzo Frascino, Marco Elver
  Cc: linux-kernel, kasan-dev, Waiman Long

Add locking events for rtlock_slowlock() and rt_mutex_slowlock() for
profiling the slow path behavior of rt_spin_lock() and rt_mutex_lock().

Signed-off-by: Waiman Long <longman@redhat.com>
---
 kernel/locking/lock_events_list.h | 21 +++++++++++++++++++++
 kernel/locking/rtmutex.c          | 29 ++++++++++++++++++++++++-----
 2 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/kernel/locking/lock_events_list.h b/kernel/locking/lock_events_list.h
index 97fb6f3f840a..80b11f194c9f 100644
--- a/kernel/locking/lock_events_list.h
+++ b/kernel/locking/lock_events_list.h
@@ -67,3 +67,24 @@ LOCK_EVENT(rwsem_rlock_handoff)	/* # of read lock handoffs		*/
 LOCK_EVENT(rwsem_wlock)		/* # of write locks acquired		*/
 LOCK_EVENT(rwsem_wlock_fail)	/* # of failed write lock acquisitions	*/
 LOCK_EVENT(rwsem_wlock_handoff)	/* # of write lock handoffs		*/
+
+/*
+ * Locking events for rtlock_slowlock()
+ */
+LOCK_EVENT(rtlock_slowlock)	/* # of rtlock_slowlock() calls		*/
+LOCK_EVENT(rtlock_slow_acq1)	/* # of locks acquired after wait_lock	*/
+LOCK_EVENT(rtlock_slow_acq2)	/* # of locks acquired in for loop	*/
+LOCK_EVENT(rtlock_slow_sleep)	/* # of sleeps				*/
+LOCK_EVENT(rtlock_slow_wake)	/* # of wakeup's			*/
+
+/*
+ * Locking events for rt_mutex_slowlock()
+ */
+LOCK_EVENT(rtmutex_slowlock)	/* # of rt_mutex_slowlock() calls	*/
+LOCK_EVENT(rtmutex_slow_block)	/* # of rt_mutex_slowlock_block() calls	*/
+LOCK_EVENT(rtmutex_slow_acq1)	/* # of locks acquired after wait_lock	*/
+LOCK_EVENT(rtmutex_slow_acq2)	/* # of locks acquired at the end	*/
+LOCK_EVENT(rtmutex_slow_acq3)	/* # of locks acquired in *block()	*/
+LOCK_EVENT(rtmutex_slow_sleep)	/* # of sleeps				*/
+LOCK_EVENT(rtmutex_slow_wake)	/* # of wakeup's			*/
+LOCK_EVENT(rtmutex_deadlock)	/* # of rt_mutex_handle_deadlock()'s	*/
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 4a8df1800cbb..c80902eacd79 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -27,6 +27,7 @@
 #include <trace/events/lock.h>
 
 #include "rtmutex_common.h"
+#include "lock_events.h"
 
 #ifndef WW_RT
 # define build_ww_mutex()	(false)
@@ -1612,10 +1613,13 @@ static int __sched rt_mutex_slowlock_block(struct rt_mutex_base *lock,
 	struct task_struct *owner;
 	int ret = 0;
 
+	lockevent_inc(rtmutex_slow_block);
 	for (;;) {
 		/* Try to acquire the lock: */
-		if (try_to_take_rt_mutex(lock, current, waiter))
+		if (try_to_take_rt_mutex(lock, current, waiter)) {
+			lockevent_inc(rtmutex_slow_acq3);
 			break;
+		}
 
 		if (timeout && !timeout->task) {
 			ret = -ETIMEDOUT;
@@ -1638,8 +1642,10 @@ static int __sched rt_mutex_slowlock_block(struct rt_mutex_base *lock,
 			owner = NULL;
 		raw_spin_unlock_irq_wake(&lock->wait_lock, wake_q);
 
-		if (!owner || !rtmutex_spin_on_owner(lock, waiter, owner))
+		if (!owner || !rtmutex_spin_on_owner(lock, waiter, owner)) {
+			lockevent_inc(rtmutex_slow_sleep);
 			rt_mutex_schedule();
+		}
 
 		raw_spin_lock_irq(&lock->wait_lock);
 		set_current_state(state);
@@ -1694,6 +1700,7 @@ static int __sched __rt_mutex_slowlock(struct rt_mutex_base *lock,
 	int ret;
 
 	lockdep_assert_held(&lock->wait_lock);
+	lockevent_inc(rtmutex_slowlock);
 
 	/* Try to acquire the lock again: */
 	if (try_to_take_rt_mutex(lock, current, NULL)) {
@@ -1701,6 +1708,7 @@ static int __sched __rt_mutex_slowlock(struct rt_mutex_base *lock,
 			__ww_mutex_check_waiters(rtm, ww_ctx, wake_q);
 			ww_mutex_lock_acquired(ww, ww_ctx);
 		}
+		lockevent_inc(rtmutex_slow_acq1);
 		return 0;
 	}
 
@@ -1719,10 +1727,12 @@ static int __sched __rt_mutex_slowlock(struct rt_mutex_base *lock,
 				__ww_mutex_check_waiters(rtm, ww_ctx, wake_q);
 			ww_mutex_lock_acquired(ww, ww_ctx);
 		}
+		lockevent_inc(rtmutex_slow_acq2);
 	} else {
 		__set_current_state(TASK_RUNNING);
 		remove_waiter(lock, waiter);
 		rt_mutex_handle_deadlock(ret, chwalk, lock, waiter);
+		lockevent_inc(rtmutex_deadlock);
 	}
 
 	/*
@@ -1751,6 +1761,7 @@ static inline int __rt_mutex_slowlock_locked(struct rt_mutex_base *lock,
 				  &waiter, wake_q);
 
 	debug_rt_mutex_free_waiter(&waiter);
+	lockevent_cond_inc(rtmutex_slow_wake, !wake_q_empty(wake_q));
 	return ret;
 }
 
@@ -1823,9 +1834,12 @@ static void __sched rtlock_slowlock_locked(struct rt_mutex_base *lock,
 	struct task_struct *owner;
 
 	lockdep_assert_held(&lock->wait_lock);
+	lockevent_inc(rtlock_slowlock);
 
-	if (try_to_take_rt_mutex(lock, current, NULL))
+	if (try_to_take_rt_mutex(lock, current, NULL)) {
+		lockevent_inc(rtlock_slow_acq1);
 		return;
+	}
 
 	rt_mutex_init_rtlock_waiter(&waiter);
 
@@ -1838,8 +1852,10 @@ static void __sched rtlock_slowlock_locked(struct rt_mutex_base *lock,
 
 	for (;;) {
 		/* Try to acquire the lock again */
-		if (try_to_take_rt_mutex(lock, current, &waiter))
+		if (try_to_take_rt_mutex(lock, current, &waiter)) {
+			lockevent_inc(rtlock_slow_acq2);
 			break;
+		}
 
 		if (&waiter == rt_mutex_top_waiter(lock))
 			owner = rt_mutex_owner(lock);
@@ -1847,8 +1863,10 @@ static void __sched rtlock_slowlock_locked(struct rt_mutex_base *lock,
 			owner = NULL;
 		raw_spin_unlock_irq_wake(&lock->wait_lock, wake_q);
 
-		if (!owner || !rtmutex_spin_on_owner(lock, &waiter, owner))
+		if (!owner || !rtmutex_spin_on_owner(lock, &waiter, owner)) {
+			lockevent_inc(rtlock_slow_sleep);
 			schedule_rtlock();
+		}
 
 		raw_spin_lock_irq(&lock->wait_lock);
 		set_current_state(TASK_RTLOCK_WAIT);
@@ -1865,6 +1883,7 @@ static void __sched rtlock_slowlock_locked(struct rt_mutex_base *lock,
 	debug_rt_mutex_free_waiter(&waiter);
 
 	trace_contention_end(lock, 0);
+	lockevent_cond_inc(rtlock_slow_wake, !wake_q_empty(wake_q));
 }
 
 static __always_inline void __sched rtlock_slowlock(struct rt_mutex_base *lock)
-- 
2.48.1


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

end of thread, other threads:[~2025-03-08  0:12 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-26  4:12 [GIT PULL] LOCKDEP and Rust locking changes for v6.15 Boqun Feng
2025-02-28 18:57 ` Boqun Feng
2025-03-03 16:52   ` Waiman Long
2025-03-03 18:42 ` Peter Zijlstra
2025-03-07 23:26 ` [PATCH locking 00/11] " Boqun Feng
2025-03-07 23:26   ` [PATCH locking 01/11] locking/rtmutex: Use struct keyword in kernel-doc comment Boqun Feng
2025-03-08  0:08     ` [tip: locking/core] locking/rtmutex: Use the 'struct' " tip-bot2 for Randy Dunlap
2025-03-07 23:26   ` [PATCH locking 02/11] locking/semaphore: Use wake_q to wake up processes outside lock critical section Boqun Feng
2025-03-08  0:08     ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-03-07 23:26   ` [PATCH locking 03/11] locking/lock_events: Add locking events for rtmutex slow paths Boqun Feng
2025-03-08  0:08     ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-03-07 23:26   ` [PATCH locking 04/11] locking/lock_events: Add locking events for lockdep Boqun Feng
2025-03-08  0:08     ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-03-07 23:26   ` [PATCH locking 05/11] locking/lockdep: Disable KASAN instrumentation of lockdep.c Boqun Feng
2025-03-08  0:08     ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-03-07 23:26   ` [PATCH locking 06/11] locking/lockdep: Add kasan_check_byte() check in lock_acquire() Boqun Feng
2025-03-08  0:08     ` [tip: locking/core] " tip-bot2 for Waiman Long
2025-03-07 23:26   ` [PATCH locking 07/11] rust: sync: Add accessor for the lock behind a given guard Boqun Feng
2025-03-08  0:08     ` [tip: locking/core] " tip-bot2 for Alice Ryhl
2025-03-07 23:26   ` [PATCH locking 08/11] rust: sync: lock: Add an example for Guard::lock_ref() Boqun Feng
2025-03-08  0:08     ` [tip: locking/core] rust: sync: lock: Add an example for Guard:: Lock_ref() tip-bot2 for Boqun Feng
2025-03-07 23:26   ` [PATCH locking 09/11] rust: sync: condvar: Add wait_interruptible_freezable() Boqun Feng
2025-03-08  0:08     ` [tip: locking/core] " tip-bot2 for Alice Ryhl
2025-03-07 23:27   ` [PATCH locking 10/11] rust: lockdep: Remove support for dynamically allocated LockClassKeys Boqun Feng
2025-03-08  0:08     ` [tip: locking/core] " tip-bot2 for Mitchell Levy
2025-03-07 23:27   ` [PATCH locking 11/11] rust: lockdep: Use Pin for all LockClassKey usages Boqun Feng
2025-03-08  0:08     ` [tip: locking/core] " tip-bot2 for Mitchell Levy
2025-03-08  0:01   ` [PATCH locking 00/11] LOCKDEP and Rust locking changes for v6.15 Ingo Molnar
2025-03-08  0:04     ` Boqun Feng
2025-03-08  0:11       ` Ingo Molnar
2025-03-08  0:11         ` Boqun Feng
  -- strict thread matches above, loose matches on Subject: below --
2025-02-13 20:02 [PATCH v4 1/4] locking/lock_events: Add locking events for rtmutex slow paths Waiman Long
2025-03-03 18:51 ` [tip: locking/core] " tip-bot2 for Waiman Long

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®