Skip to content

Commit 3e71f01

Browse files
committed
Merge tag 'locking-core-2022-10-07' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking updates from Ingo Molnar: - Disable preemption in rwsem_write_trylock()'s attempt to take the rwsem, to avoid RT tasks hogging the CPU, which managed to preempt this function after the owner has been cleared but before a new owner is set. Also add debug checks to enforce this. - Add __lockfunc to more slow path functions and add __sched to semaphore functions. - Mark spinlock APIs noinline when the respective CONFIG_INLINE_SPIN_* toggles are disabled, to reduce LTO text size. - Print more debug information when lockdep gets confused in look_up_lock_class(). - Improve header file abuse checks. - Misc cleanups * tag 'locking-core-2022-10-07' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: locking/lockdep: Print more debug information - report name and key when look_up_lock_class() got confused locking: Add __sched to semaphore functions locking/rwsem: Disable preemption while trying for rwsem lock locking: Detect includes rwlock.h outside of spinlock.h locking: Add __lockfunc to slow path functions locking/spinlocks: Mark spinlocks noinline when inline spinlocks are disabled selftests: futex: Fix 'the the' typo in comment
2 parents 3871d93 + 76e64c7 commit 3e71f01

File tree

15 files changed

+70
-55
lines changed

15 files changed

+70
-55
lines changed

arch/x86/include/asm/qspinlock_paravirt.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
*/
1313
#ifdef CONFIG_64BIT
1414

15-
PV_CALLEE_SAVE_REGS_THUNK(__pv_queued_spin_unlock_slowpath);
15+
__PV_CALLEE_SAVE_REGS_THUNK(__pv_queued_spin_unlock_slowpath, ".spinlock.text");
1616
#define __pv_queued_spin_unlock __pv_queued_spin_unlock
1717
#define PV_UNLOCK "__raw_callee_save___pv_queued_spin_unlock"
1818
#define PV_UNLOCK_SLOWPATH "__raw_callee_save___pv_queued_spin_unlock_slowpath"
1919

2020
/*
2121
* Optimized assembly version of __raw_callee_save___pv_queued_spin_unlock
2222
* which combines the registers saving trunk and the body of the following
23-
* C code:
23+
* C code. Note that it puts the code in the .spinlock.text section which
24+
* is equivalent to adding __lockfunc in the C code:
2425
*
25-
* void __pv_queued_spin_unlock(struct qspinlock *lock)
26+
* void __lockfunc __pv_queued_spin_unlock(struct qspinlock *lock)
2627
* {
2728
* u8 lockval = cmpxchg(&lock->locked, _Q_LOCKED_VAL, 0);
2829
*
@@ -36,7 +37,7 @@ PV_CALLEE_SAVE_REGS_THUNK(__pv_queued_spin_unlock_slowpath);
3637
* rsi = lockval (second argument)
3738
* rdx = internal variable (set to 0)
3839
*/
39-
asm (".pushsection .text;"
40+
asm (".pushsection .spinlock.text;"
4041
".globl " PV_UNLOCK ";"
4142
".type " PV_UNLOCK ", @function;"
4243
".align 4,0x90;"
@@ -65,8 +66,8 @@ asm (".pushsection .text;"
6566

6667
#else /* CONFIG_64BIT */
6768

68-
extern void __pv_queued_spin_unlock(struct qspinlock *lock);
69-
PV_CALLEE_SAVE_REGS_THUNK(__pv_queued_spin_unlock);
69+
extern void __lockfunc __pv_queued_spin_unlock(struct qspinlock *lock);
70+
__PV_CALLEE_SAVE_REGS_THUNK(__pv_queued_spin_unlock, ".spinlock.text");
7071

7172
#endif /* CONFIG_64BIT */
7273
#endif

include/linux/rwlock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __LINUX_RWLOCK_H
22
#define __LINUX_RWLOCK_H
33

4-
#ifndef __LINUX_SPINLOCK_H
4+
#ifndef __LINUX_INSIDE_SPINLOCK_H
55
# error "please don't include this file directly"
66
#endif
77

include/linux/spinlock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#ifndef __LINUX_SPINLOCK_H
33
#define __LINUX_SPINLOCK_H
4+
#define __LINUX_INSIDE_SPINLOCK_H
45

56
/*
67
* include/linux/spinlock.h - generic spinlock/rwlock declarations
@@ -492,4 +493,5 @@ int __alloc_bucket_spinlocks(spinlock_t **locks, unsigned int *lock_mask,
492493

493494
void free_bucket_spinlocks(spinlock_t *locks);
494495

496+
#undef __LINUX_INSIDE_SPINLOCK_H
495497
#endif /* __LINUX_SPINLOCK_H */

include/linux/spinlock_api_smp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __LINUX_SPINLOCK_API_SMP_H
22
#define __LINUX_SPINLOCK_API_SMP_H
33

4-
#ifndef __LINUX_SPINLOCK_H
4+
#ifndef __LINUX_INSIDE_SPINLOCK_H
55
# error "please don't include this file directly"
66
#endif
77

include/linux/spinlock_api_up.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __LINUX_SPINLOCK_API_UP_H
22
#define __LINUX_SPINLOCK_API_UP_H
33

4-
#ifndef __LINUX_SPINLOCK_H
4+
#ifndef __LINUX_INSIDE_SPINLOCK_H
55
# error "please don't include this file directly"
66
#endif
77

include/linux/spinlock_rt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef __LINUX_SPINLOCK_RT_H
33
#define __LINUX_SPINLOCK_RT_H
44

5-
#ifndef __LINUX_SPINLOCK_H
5+
#ifndef __LINUX_INSIDE_SPINLOCK_H
66
#error Do not include directly. Use spinlock.h
77
#endif
88

include/linux/spinlock_up.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __LINUX_SPINLOCK_UP_H
22
#define __LINUX_SPINLOCK_UP_H
33

4-
#ifndef __LINUX_SPINLOCK_H
4+
#ifndef __LINUX_INSIDE_SPINLOCK_H
55
# error "please don't include this file directly"
66
#endif
77

kernel/locking/lockdep.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,10 @@ look_up_lock_class(const struct lockdep_map *lock, unsigned int subclass)
934934
* Huh! same key, different name? Did someone trample
935935
* on some memory? We're most confused.
936936
*/
937-
WARN_ON_ONCE(class->name != lock->name &&
938-
lock->key != &__lockdep_no_validate__);
937+
WARN_ONCE(class->name != lock->name &&
938+
lock->key != &__lockdep_no_validate__,
939+
"Looking for class \"%s\" with key %ps, but found a different class \"%s\" with the same key\n",
940+
lock->name, lock->key, class->name);
939941
return class;
940942
}
941943
}

kernel/locking/qrwlock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* queued_read_lock_slowpath - acquire read lock of a queued rwlock
1919
* @lock: Pointer to queued rwlock structure
2020
*/
21-
void queued_read_lock_slowpath(struct qrwlock *lock)
21+
void __lockfunc queued_read_lock_slowpath(struct qrwlock *lock)
2222
{
2323
/*
2424
* Readers come here when they cannot get the lock without waiting
@@ -63,7 +63,7 @@ EXPORT_SYMBOL(queued_read_lock_slowpath);
6363
* queued_write_lock_slowpath - acquire write lock of a queued rwlock
6464
* @lock : Pointer to queued rwlock structure
6565
*/
66-
void queued_write_lock_slowpath(struct qrwlock *lock)
66+
void __lockfunc queued_write_lock_slowpath(struct qrwlock *lock)
6767
{
6868
int cnts;
6969

kernel/locking/qspinlock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ static __always_inline u32 __pv_wait_head_or_lock(struct qspinlock *lock,
313313
* contended : (*,x,y) +--> (*,0,0) ---> (*,0,1) -' :
314314
* queue : ^--' :
315315
*/
316-
void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
316+
void __lockfunc queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
317317
{
318318
struct mcs_spinlock *prev, *next, *node;
319319
u32 old, tail;

0 commit comments

Comments
 (0)