locking fixes
Subsystems (3)
Linus,
Please pull the latest locking/urgent Git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking-urgent-2025-03-14
# HEAD: 85b2b9c16d053364e2004883140538e73b333cdb locking/semaphore: Use wake_q to wake up processes outside lock critical section
Miscellaneous fixes:
- Restrict the Rust runtime from unintended access to dynamically allocated LockClassKeys
- KernelDoc annotation fix
- Fix a lock ordering bug in semaphore::up(), related to trying to printk() and wake up the console within critical sections
Thanks,
Ingo
------------------>
Mitchell Levy (1):
rust: lockdep: Remove support for dynamically allocated LockClassKeys
Randy Dunlap (1):
locking/rtmutex: Use the 'struct' keyword in kernel-doc comment
Waiman Long (1):
locking/semaphore: Use wake_q to wake up processes outside lock critical section
kernel/locking/rtmutex_common.h | 4 ++-- kernel/locking/semaphore.c | 13 +++++++++---- rust/kernel/sync.rs | 16 ++++------------ 3 files changed, 15 insertions(+), 18 deletions(-)
kernel/locking/rtmutex_common.h +2 -2
@@ -59,8 +59,8 @@ struct rt_mutex_waiter { };/** -* rt_wake_q_head - Wrapper around regular wake_q_head to support -* "sleeping" spinlocks on RT +* struct rt_wake_q_head - Wrapper around regular wake_q_head to support +* "sleeping" spinlocks on RT * @head: The regular wake_q_head for sleeping lock variants * @rtlock_task: Task pointer for RT lock (spin/rwlock) wakeups */
kernel/locking/semaphore.c +9 -4
@@ -29,6 +29,7 @@#include <linux/export.h> #include <linux/sched.h> #include <linux/sched/debug.h> +#include <linux/sched/wake_q.h> #include <linux/semaphore.h> #include <linux/spinlock.h> #include <linux/ftrace.h>
@@ -38,7 +39,7 @@ static noinline void __down(struct semaphore *sem); static noinline int __down_interruptible(struct semaphore *sem); static noinline int __down_killable(struct semaphore *sem); static noinline int __down_timeout(struct semaphore *sem, long timeout); -static noinline void __up(struct semaphore *sem); +static noinline void __up(struct semaphore *sem, struct wake_q_head *wake_q);/** * down - acquire the semaphore
@@ -183,13 +184,16 @@ EXPORT_SYMBOL(down_timeout); void __sched up(struct semaphore *sem) {unsigned long flags; +DEFINE_WAKE_Q (wake_q);raw_spin_lock_irqsave (&sem->lock, flags);if (likely (list_empty (&sem->wait_list))) sem->count++;else -__up (sem); +__up (sem, &wake_q);raw_spin_unlock_irqrestore (&sem->lock, flags); +if (!wake_q_empty (&wake_q)) +wake_up_q (&wake_q); }EXPORT_SYMBOL (up);
@@ -269,11 +273,12 @@ static noinline int __sched __down_timeout(struct semaphore *sem, long timeout)return __down_common (sem,TASK_UNINTERRUPTIBLE , timeout); } -static noinline void __sched __up(struct semaphore *sem) +static noinline void __sched __up(struct semaphore *sem, +struct wake_q_head *wake_q) {struct semaphore_waiter *waiter =list_first_entry (&sem->wait_list, struct semaphore_waiter, list);list_del (&waiter->list); waiter->up = true; -wake_up_process (waiter->task); +wake_q_add (wake_q, waiter->task); }
rust/kernel/sync.rs +4 -12
@@ -30,28 +30,20 @@unsafe impl Sync for LockClassKey {}impl LockClassKey { -/// Creates a new lock class key. -pub const fn new () ->Self { -Self (Opaque ::uninit ()) - } -pub (crate )fn as_ptr (&self) -> *mut bindings::lock_class_key { self.0 .get () } } -impl Default for LockClassKey { -fn default () ->Self { -Self ::new () - } -} -/// Defines a new static lock class and returns a pointer to it. #[doc(hidden)] #[macro_export] macro_rules! static_lock_class { () => {{ -static CLASS : $crate::sync::LockClassKey = $crate::sync::LockClassKey ::new (); +static CLASS : $crate::sync::LockClassKey = +// SAFETY: lockdep expects uninitialized memory when it's handed a statically allocated +// lock_class_key +unsafe { ::core::mem::MaybeUninit ::uninit ().assume_init () }; &CLASS }}; }
The pull request you sent on Fri, 14 Mar 2025 10:06:31 +0100:
The pull request you sent on Fri, 14 Mar 2025 10:06:31 +0100:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitlocking-urgent-2025-03-14
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/28c50999c977fc60ecbadfee4359a93116163d4f
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html