Skip to content

Commit c7eba51

Browse files
committed
Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking updates from Ingo Molnar: - improve rwsem scalability - add uninitialized rwsem debugging check - reduce lockdep's stacktrace memory usage and add diagnostics - misc cleanups, code consolidation and constification * 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: mutex: Fix up mutex_waiter usage locking/mutex: Use mutex flags macro instead of hard code locking/mutex: Make __mutex_owner static to mutex.c locking/qspinlock,x86: Clarify virt_spin_lock_key locking/rwsem: Check for operations on an uninitialized rwsem locking/rwsem: Make handoff writer optimistically spin on owner locking/lockdep: Report more stack trace statistics locking/lockdep: Reduce space occupied by stack traces stacktrace: Constify 'entries' arguments locking/lockdep: Make it clear that what lock_class::key points at is not modified
2 parents cc9b499 + e57d143 commit c7eba51

11 files changed

Lines changed: 241 additions & 84 deletions

File tree

‎arch/x86/include/asm/qspinlock.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,25 @@ static inline bool vcpu_is_preempted(long cpu)
6363
#endif
6464

6565
#ifdef CONFIG_PARAVIRT
66+
/*
67+
* virt_spin_lock_key - enables (by default) the virt_spin_lock() hijack.
68+
*
69+
* Native (and PV wanting native due to vCPU pinning) should disable this key.
70+
* It is done in this backwards fashion to only have a single direction change,
71+
* which removes ordering between native_pv_spin_init() and HV setup.
72+
*/
6673
DECLARE_STATIC_KEY_TRUE(virt_spin_lock_key);
6774

6875
void native_pv_lock_init(void) __init;
6976

77+
/*
78+
* Shortcut for the queued_spin_lock_slowpath() function that allows
79+
* virt to hijack it.
80+
*
81+
* Returns:
82+
* true - lock has been negotiated, all done;
83+
* false - queued_spin_lock_slowpath() will do its thing.
84+
*/
7085
#define virt_spin_lock virt_spin_lock
7186
static inline bool virt_spin_lock(struct qspinlock *lock)
7287
{

‎include/linux/lockdep.h‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ struct lock_class_key {
6666

6767
extern struct lock_class_key __lockdep_no_validate__;
6868

69-
struct lock_trace {
70-
unsigned int nr_entries;
71-
unsigned int offset;
72-
};
69+
struct lock_trace;
7370

7471
#define LOCKSTAT_POINTS 4
7572

@@ -97,15 +94,15 @@ struct lock_class {
9794
*/
9895
struct list_head locks_after, locks_before;
9996

100-
struct lockdep_subclass_key *key;
97+
const struct lockdep_subclass_key *key;
10198
unsigned int subclass;
10299
unsigned int dep_gen_id;
103100

104101
/*
105102
* IRQ/softirq usage tracking bits:
106103
*/
107104
unsigned long usage_mask;
108-
struct lock_trace usage_traces[XXX_LOCK_USAGE_STATES];
105+
const struct lock_trace *usage_traces[XXX_LOCK_USAGE_STATES];
109106

110107
/*
111108
* Generation counter, when doing certain classes of graph walking,
@@ -193,7 +190,7 @@ struct lock_list {
193190
struct list_head entry;
194191
struct lock_class *class;
195192
struct lock_class *links_to;
196-
struct lock_trace trace;
193+
const struct lock_trace *trace;
197194
int distance;
198195

199196
/*

‎include/linux/mutex.h‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@ struct mutex {
6565
#endif
6666
};
6767

68-
/*
69-
* Internal helper function; C doesn't allow us to hide it :/
70-
*
71-
* DO NOT USE (outside of mutex code).
72-
*/
73-
static inline struct task_struct *__mutex_owner(struct mutex *lock)
74-
{
75-
return (struct task_struct *)(atomic_long_read(&lock->owner) & ~0x07);
76-
}
77-
7868
/*
7969
* This is the control structure for tasks blocked on mutex,
8070
* which resides on the blocked task's kernel stack:
@@ -144,10 +134,7 @@ extern void __mutex_init(struct mutex *lock, const char *name,
144134
*
145135
* Returns true if the mutex is locked, false if unlocked.
146136
*/
147-
static inline bool mutex_is_locked(struct mutex *lock)
148-
{
149-
return __mutex_owner(lock) != NULL;
150-
}
137+
extern bool mutex_is_locked(struct mutex *lock);
151138

152139
/*
153140
* See kernel/locking/mutex.c for detailed documentation of these APIs.
@@ -220,13 +207,7 @@ enum mutex_trylock_recursive_enum {
220207
* - MUTEX_TRYLOCK_SUCCESS - lock acquired,
221208
* - MUTEX_TRYLOCK_RECURSIVE - we already owned the lock.
222209
*/
223-
static inline /* __deprecated */ __must_check enum mutex_trylock_recursive_enum
224-
mutex_trylock_recursive(struct mutex *lock)
225-
{
226-
if (unlikely(__mutex_owner(lock) == current))
227-
return MUTEX_TRYLOCK_RECURSIVE;
228-
229-
return mutex_trylock(lock);
230-
}
210+
extern /* __deprecated */ __must_check enum mutex_trylock_recursive_enum
211+
mutex_trylock_recursive(struct mutex *lock);
231212

232213
#endif /* __LINUX_MUTEX_H */

‎include/linux/rwsem.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ struct rw_semaphore {
4545
#endif
4646
raw_spinlock_t wait_lock;
4747
struct list_head wait_list;
48+
#ifdef CONFIG_DEBUG_RWSEMS
49+
void *magic;
50+
#endif
4851
#ifdef CONFIG_DEBUG_LOCK_ALLOC
4952
struct lockdep_map dep_map;
5053
#endif
@@ -73,6 +76,12 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem)
7376
# define __RWSEM_DEP_MAP_INIT(lockname)
7477
#endif
7578

79+
#ifdef CONFIG_DEBUG_RWSEMS
80+
# define __DEBUG_RWSEM_INITIALIZER(lockname) , .magic = &lockname
81+
#else
82+
# define __DEBUG_RWSEM_INITIALIZER(lockname)
83+
#endif
84+
7685
#ifdef CONFIG_RWSEM_SPIN_ON_OWNER
7786
#define __RWSEM_OPT_INIT(lockname) , .osq = OSQ_LOCK_UNLOCKED
7887
#else
@@ -85,6 +94,7 @@ static inline int rwsem_is_locked(struct rw_semaphore *sem)
8594
.wait_list = LIST_HEAD_INIT((name).wait_list), \
8695
.wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock) \
8796
__RWSEM_OPT_INIT(name) \
97+
__DEBUG_RWSEM_INITIALIZER(name) \
8898
__RWSEM_DEP_MAP_INIT(name) }
8999

90100
#define DECLARE_RWSEM(name) \

‎include/linux/stacktrace.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ struct task_struct;
99
struct pt_regs;
1010

1111
#ifdef CONFIG_STACKTRACE
12-
void stack_trace_print(unsigned long *trace, unsigned int nr_entries,
12+
void stack_trace_print(const unsigned long *trace, unsigned int nr_entries,
1313
int spaces);
14-
int stack_trace_snprint(char *buf, size_t size, unsigned long *entries,
14+
int stack_trace_snprint(char *buf, size_t size, const unsigned long *entries,
1515
unsigned int nr_entries, int spaces);
1616
unsigned int stack_trace_save(unsigned long *store, unsigned int size,
1717
unsigned int skipnr);

0 commit comments

Comments
 (0)