Skip to content

Commit 28c5099

Browse files
committed
Merge tag 'locking-urgent-2025-03-14' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull misc locking fixes from Ingo Molnar: - 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 * tag 'locking-urgent-2025-03-14' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: locking/semaphore: Use wake_q to wake up processes outside lock critical section locking/rtmutex: Use the 'struct' keyword in kernel-doc comment rust: lockdep: Remove support for dynamically allocated LockClassKeys
2 parents 70e23dd + 85b2b9c commit 28c5099

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

kernel/locking/rtmutex_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ struct rt_mutex_waiter {
5959
};
6060

6161
/**
62-
* rt_wake_q_head - Wrapper around regular wake_q_head to support
63-
* "sleeping" spinlocks on RT
62+
* struct rt_wake_q_head - Wrapper around regular wake_q_head to support
63+
* "sleeping" spinlocks on RT
6464
* @head: The regular wake_q_head for sleeping lock variants
6565
* @rtlock_task: Task pointer for RT lock (spin/rwlock) wakeups
6666
*/

kernel/locking/semaphore.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/export.h>
3030
#include <linux/sched.h>
3131
#include <linux/sched/debug.h>
32+
#include <linux/sched/wake_q.h>
3233
#include <linux/semaphore.h>
3334
#include <linux/spinlock.h>
3435
#include <linux/ftrace.h>
@@ -38,7 +39,7 @@ static noinline void __down(struct semaphore *sem);
3839
static noinline int __down_interruptible(struct semaphore *sem);
3940
static noinline int __down_killable(struct semaphore *sem);
4041
static noinline int __down_timeout(struct semaphore *sem, long timeout);
41-
static noinline void __up(struct semaphore *sem);
42+
static noinline void __up(struct semaphore *sem, struct wake_q_head *wake_q);
4243

4344
/**
4445
* down - acquire the semaphore
@@ -183,13 +184,16 @@ EXPORT_SYMBOL(down_timeout);
183184
void __sched up(struct semaphore *sem)
184185
{
185186
unsigned long flags;
187+
DEFINE_WAKE_Q(wake_q);
186188

187189
raw_spin_lock_irqsave(&sem->lock, flags);
188190
if (likely(list_empty(&sem->wait_list)))
189191
sem->count++;
190192
else
191-
__up(sem);
193+
__up(sem, &wake_q);
192194
raw_spin_unlock_irqrestore(&sem->lock, flags);
195+
if (!wake_q_empty(&wake_q))
196+
wake_up_q(&wake_q);
193197
}
194198
EXPORT_SYMBOL(up);
195199

@@ -269,11 +273,12 @@ static noinline int __sched __down_timeout(struct semaphore *sem, long timeout)
269273
return __down_common(sem, TASK_UNINTERRUPTIBLE, timeout);
270274
}
271275

272-
static noinline void __sched __up(struct semaphore *sem)
276+
static noinline void __sched __up(struct semaphore *sem,
277+
struct wake_q_head *wake_q)
273278
{
274279
struct semaphore_waiter *waiter = list_first_entry(&sem->wait_list,
275280
struct semaphore_waiter, list);
276281
list_del(&waiter->list);
277282
waiter->up = true;
278-
wake_up_process(waiter->task);
283+
wake_q_add(wake_q, waiter->task);
279284
}

rust/kernel/sync.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,20 @@ pub struct LockClassKey(Opaque<bindings::lock_class_key>);
3030
unsafe impl Sync for LockClassKey {}
3131

3232
impl LockClassKey {
33-
/// Creates a new lock class key.
34-
pub const fn new() -> Self {
35-
Self(Opaque::uninit())
36-
}
37-
3833
pub(crate) fn as_ptr(&self) -> *mut bindings::lock_class_key {
3934
self.0.get()
4035
}
4136
}
4237

43-
impl Default for LockClassKey {
44-
fn default() -> Self {
45-
Self::new()
46-
}
47-
}
48-
4938
/// Defines a new static lock class and returns a pointer to it.
5039
#[doc(hidden)]
5140
#[macro_export]
5241
macro_rules! static_lock_class {
5342
() => {{
54-
static CLASS: $crate::sync::LockClassKey = $crate::sync::LockClassKey::new();
43+
static CLASS: $crate::sync::LockClassKey =
44+
// SAFETY: lockdep expects uninitialized memory when it's handed a statically allocated
45+
// lock_class_key
46+
unsafe { ::core::mem::MaybeUninit::uninit().assume_init() };
5547
&CLASS
5648
}};
5749
}

0 commit comments

Comments
 (0)