Skip to content

Commit 9eef023

Browse files
committed
Merge tag 'locking-core-2021-02-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking updates from Ingo Molnar: "Core locking primitives updates: - Remove mutex_trylock_recursive() from the API - no users left - Simplify + constify the futex code a bit Lockdep updates: - Teach lockdep about local_lock_t - Add CONFIG_DEBUG_IRQFLAGS=y debug config option to check for potentially unsafe IRQ mask restoration patterns. (I.e. calling raw_local_irq_restore() with IRQs enabled.) - Add wait context self-tests - Fix graph lock corner case corrupting internal data structures - Fix noinstr annotations LKMM updates: - Simplify the litmus tests - Documentation fixes KCSAN updates: - Re-enable KCSAN instrumentation in lib/random32.c Misc fixes: - Don't branch-trace static label APIs - DocBook fix - Remove stale leftover empty file" * tag 'locking-core-2021-02-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (24 commits) checkpatch: Don't check for mutex_trylock_recursive() locking/mutex: Kill mutex_trylock_recursive() s390: Use arch_local_irq_{save,restore}() in early boot code lockdep: Noinstr annotate warn_bogus_irq_restore() locking/lockdep: Avoid unmatched unlock locking/rwsem: Remove empty rwsem.h locking/rtmutex: Add missing kernel-doc markup futex: Remove unneeded gotos futex: Change utime parameter to be 'const ... *' lockdep: report broken irq restoration jump_label: Do not profile branch annotations locking: Add Reviewers locking/selftests: Add local_lock inversion tests locking/lockdep: Exclude local_lock_t from IRQ inversions locking/lockdep: Clean up check_redundant() a bit locking/lockdep: Add a skip() function to __bfs() locking/lockdep: Mark local_lock_t locking/selftests: More granular debug_locks_verbose lockdep/selftest: Add wait context selftests tools/memory-model: Fix typo in klitmus7 compatibility table ...
2 parents d089f48 + 3765d01 commit 9eef023

File tree

57 files changed

+617
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+617
-294
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -802,13 +802,14 @@
802802
insecure, please do not use on production kernels.
803803

804804
debug_locks_verbose=
805-
[KNL] verbose self-tests
806-
Format=<0|1>
805+
[KNL] verbose locking self-tests
806+
Format: <int>
807807
Print debugging info while doing the locking API
808808
self-tests.
809-
We default to 0 (no extra messages), setting it to
810-
1 will print _a lot_ more information - normally
811-
only useful to kernel developers.
809+
Bitmask for the various LOCKTYPE_ tests. Defaults to 0
810+
(no extra messages), setting it to -1 (all bits set)
811+
will print _a_lot_ more information - normally only
812+
useful to lockdep developers.
812813

813814
debug_objects [KNL] Enable object debugging
814815

MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10342,6 +10342,8 @@ LOCKING PRIMITIVES
1034210342
M: Peter Zijlstra <peterz@infradead.org>
1034310343
M: Ingo Molnar <mingo@redhat.com>
1034410344
M: Will Deacon <will@kernel.org>
10345+
R: Waiman Long <longman@redhat.com>
10346+
R: Boqun Feng <boqun.feng@gmail.com> (LOCKDEP)
1034510347
L: linux-kernel@vger.kernel.org
1034610348
S: Maintained
1034710349
T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git locking/core

drivers/s390/char/sclp_early_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ int sclp_early_cmd(sclp_cmdw_t cmd, void *sccb)
6666
unsigned long flags;
6767
int rc;
6868

69-
raw_local_irq_save(flags);
69+
flags = arch_local_irq_save();
7070
rc = sclp_service_call(cmd, sccb);
7171
if (rc)
7272
goto out;
7373
sclp_early_wait_irq();
7474
out:
75-
raw_local_irq_restore(flags);
75+
arch_local_irq_restore(flags);
7676
return rc;
7777
}
7878

include/linux/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
7676
#else
7777
# define likely(x) __builtin_expect(!!(x), 1)
7878
# define unlikely(x) __builtin_expect(!!(x), 0)
79+
# define likely_notrace(x) likely(x)
80+
# define unlikely_notrace(x) unlikely(x)
7981
#endif
8082

8183
/* Optimization barrier */

include/linux/irqflags.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ do { \
149149
# define start_critical_timings() do { } while (0)
150150
#endif
151151

152+
#ifdef CONFIG_DEBUG_IRQFLAGS
153+
extern void warn_bogus_irq_restore(void);
154+
#define raw_check_bogus_irq_restore() \
155+
do { \
156+
if (unlikely(!arch_irqs_disabled())) \
157+
warn_bogus_irq_restore(); \
158+
} while (0)
159+
#else
160+
#define raw_check_bogus_irq_restore() do { } while (0)
161+
#endif
162+
152163
/*
153164
* Wrap the arch provided IRQ routines to provide appropriate checks.
154165
*/
@@ -162,6 +173,7 @@ do { \
162173
#define raw_local_irq_restore(flags) \
163174
do { \
164175
typecheck(unsigned long, flags); \
176+
raw_check_bogus_irq_restore(); \
165177
arch_local_irq_restore(flags); \
166178
} while (0)
167179
#define raw_local_save_flags(flags) \

include/linux/jump_label.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ static __always_inline void jump_label_init(void)
261261

262262
static __always_inline bool static_key_false(struct static_key *key)
263263
{
264-
if (unlikely(static_key_count(key) > 0))
264+
if (unlikely_notrace(static_key_count(key) > 0))
265265
return true;
266266
return false;
267267
}
268268

269269
static __always_inline bool static_key_true(struct static_key *key)
270270
{
271-
if (likely(static_key_count(key) > 0))
271+
if (likely_notrace(static_key_count(key) > 0))
272272
return true;
273273
return false;
274274
}
@@ -460,7 +460,7 @@ extern bool ____wrong_branch_error(void);
460460
branch = !arch_static_branch_jump(&(x)->key, true); \
461461
else \
462462
branch = ____wrong_branch_error(); \
463-
likely(branch); \
463+
likely_notrace(branch); \
464464
})
465465

466466
#define static_branch_unlikely(x) \
@@ -472,13 +472,13 @@ extern bool ____wrong_branch_error(void);
472472
branch = arch_static_branch(&(x)->key, false); \
473473
else \
474474
branch = ____wrong_branch_error(); \
475-
unlikely(branch); \
475+
unlikely_notrace(branch); \
476476
})
477477

478478
#else /* !CONFIG_JUMP_LABEL */
479479

480-
#define static_branch_likely(x) likely(static_key_enabled(&(x)->key))
481-
#define static_branch_unlikely(x) unlikely(static_key_enabled(&(x)->key))
480+
#define static_branch_likely(x) likely_notrace(static_key_enabled(&(x)->key))
481+
#define static_branch_unlikely(x) unlikely_notrace(static_key_enabled(&(x)->key))
482482

483483
#endif /* CONFIG_JUMP_LABEL */
484484

include/linux/local_lock_internal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ typedef struct {
1818
.dep_map = { \
1919
.name = #lockname, \
2020
.wait_type_inner = LD_WAIT_CONFIG, \
21+
.lock_type = LD_LOCK_PERCPU, \
2122
}
2223
#else
2324
# define LL_DEP_MAP_INIT(lockname)
@@ -30,7 +31,9 @@ do { \
3031
static struct lock_class_key __key; \
3132
\
3233
debug_check_no_locks_freed((void *)lock, sizeof(*lock));\
33-
lockdep_init_map_wait(&(lock)->dep_map, #lock, &__key, 0, LD_WAIT_CONFIG);\
34+
lockdep_init_map_type(&(lock)->dep_map, #lock, &__key, 0, \
35+
LD_WAIT_CONFIG, LD_WAIT_INV, \
36+
LD_LOCK_PERCPU); \
3437
} while (0)
3538

3639
#ifdef CONFIG_DEBUG_LOCK_ALLOC

include/linux/lockdep.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,19 @@ extern void lockdep_unregister_key(struct lock_class_key *key);
185185
* to lockdep:
186186
*/
187187

188-
extern void lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
189-
struct lock_class_key *key, int subclass, short inner, short outer);
188+
extern void lockdep_init_map_type(struct lockdep_map *lock, const char *name,
189+
struct lock_class_key *key, int subclass, u8 inner, u8 outer, u8 lock_type);
190+
191+
static inline void
192+
lockdep_init_map_waits(struct lockdep_map *lock, const char *name,
193+
struct lock_class_key *key, int subclass, u8 inner, u8 outer)
194+
{
195+
lockdep_init_map_type(lock, name, key, subclass, inner, LD_WAIT_INV, LD_LOCK_NORMAL);
196+
}
190197

191198
static inline void
192199
lockdep_init_map_wait(struct lockdep_map *lock, const char *name,
193-
struct lock_class_key *key, int subclass, short inner)
200+
struct lock_class_key *key, int subclass, u8 inner)
194201
{
195202
lockdep_init_map_waits(lock, name, key, subclass, inner, LD_WAIT_INV);
196203
}
@@ -340,6 +347,8 @@ static inline void lockdep_set_selftest_task(struct task_struct *task)
340347
# define lock_set_class(l, n, k, s, i) do { } while (0)
341348
# define lock_set_subclass(l, s, i) do { } while (0)
342349
# define lockdep_init() do { } while (0)
350+
# define lockdep_init_map_type(lock, name, key, sub, inner, outer, type) \
351+
do { (void)(name); (void)(key); } while (0)
343352
# define lockdep_init_map_waits(lock, name, key, sub, inner, outer) \
344353
do { (void)(name); (void)(key); } while (0)
345354
# define lockdep_init_map_wait(lock, name, key, sub, inner) \

include/linux/lockdep_types.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ enum lockdep_wait_type {
3030
LD_WAIT_MAX, /* must be last */
3131
};
3232

33+
enum lockdep_lock_type {
34+
LD_LOCK_NORMAL = 0, /* normal, catch all */
35+
LD_LOCK_PERCPU, /* percpu */
36+
LD_LOCK_MAX,
37+
};
38+
3339
#ifdef CONFIG_LOCKDEP
3440

3541
/*
@@ -119,8 +125,10 @@ struct lock_class {
119125
int name_version;
120126
const char *name;
121127

122-
short wait_type_inner;
123-
short wait_type_outer;
128+
u8 wait_type_inner;
129+
u8 wait_type_outer;
130+
u8 lock_type;
131+
/* u8 hole; */
124132

125133
#ifdef CONFIG_LOCK_STAT
126134
unsigned long contention_point[LOCKSTAT_POINTS];
@@ -169,8 +177,10 @@ struct lockdep_map {
169177
struct lock_class_key *key;
170178
struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES];
171179
const char *name;
172-
short wait_type_outer; /* can be taken in this context */
173-
short wait_type_inner; /* presents this context */
180+
u8 wait_type_outer; /* can be taken in this context */
181+
u8 wait_type_inner; /* presents this context */
182+
u8 lock_type;
183+
/* u8 hole; */
174184
#ifdef CONFIG_LOCK_STAT
175185
int cpu;
176186
unsigned long ip;

include/linux/mutex.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -199,29 +199,4 @@ extern void mutex_unlock(struct mutex *lock);
199199

200200
extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
201201

202-
/*
203-
* These values are chosen such that FAIL and SUCCESS match the
204-
* values of the regular mutex_trylock().
205-
*/
206-
enum mutex_trylock_recursive_enum {
207-
MUTEX_TRYLOCK_FAILED = 0,
208-
MUTEX_TRYLOCK_SUCCESS = 1,
209-
MUTEX_TRYLOCK_RECURSIVE,
210-
};
211-
212-
/**
213-
* mutex_trylock_recursive - trylock variant that allows recursive locking
214-
* @lock: mutex to be locked
215-
*
216-
* This function should not be used, _ever_. It is purely for hysterical GEM
217-
* raisins, and once those are gone this will be removed.
218-
*
219-
* Returns:
220-
* - MUTEX_TRYLOCK_FAILED - trylock failed,
221-
* - MUTEX_TRYLOCK_SUCCESS - lock acquired,
222-
* - MUTEX_TRYLOCK_RECURSIVE - we already owned the lock.
223-
*/
224-
extern /* __deprecated */ __must_check enum mutex_trylock_recursive_enum
225-
mutex_trylock_recursive(struct mutex *lock);
226-
227202
#endif /* __LINUX_MUTEX_H */

0 commit comments

Comments
 (0)