Skip to content

Commit 7ff495e

Browse files
Sebastian Andrzej SiewiorKAGA-KOKO
authored andcommitted
local_lock: Move this_cpu_ptr() notation from internal to main header
local_lock.h is the main header for the local_lock_t type and provides wrappers around internal functions prefixed with __ in local_lock_internal.h. Move the this_cpu_ptr() dereference of the variable from the internal to the main header. Since it is all macro implemented, this_cpu_ptr() will still happen within the preempt/ IRQ disabled section. This frees the internal implementation (__) to be used on local_lock_t types which are local variables and must not be accessed via this_cpu_ptr(). Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Waiman Long <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent 19272b3 commit 7ff495e

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

include/linux/local_lock.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
* local_lock - Acquire a per CPU local lock
1414
* @lock: The lock variable
1515
*/
16-
#define local_lock(lock) __local_lock(lock)
16+
#define local_lock(lock) __local_lock(this_cpu_ptr(lock))
1717

1818
/**
1919
* local_lock_irq - Acquire a per CPU local lock and disable interrupts
2020
* @lock: The lock variable
2121
*/
22-
#define local_lock_irq(lock) __local_lock_irq(lock)
22+
#define local_lock_irq(lock) __local_lock_irq(this_cpu_ptr(lock))
2323

2424
/**
2525
* local_lock_irqsave - Acquire a per CPU local lock, save and disable
@@ -28,19 +28,19 @@
2828
* @flags: Storage for interrupt flags
2929
*/
3030
#define local_lock_irqsave(lock, flags) \
31-
__local_lock_irqsave(lock, flags)
31+
__local_lock_irqsave(this_cpu_ptr(lock), flags)
3232

3333
/**
3434
* local_unlock - Release a per CPU local lock
3535
* @lock: The lock variable
3636
*/
37-
#define local_unlock(lock) __local_unlock(lock)
37+
#define local_unlock(lock) __local_unlock(this_cpu_ptr(lock))
3838

3939
/**
4040
* local_unlock_irq - Release a per CPU local lock and enable interrupts
4141
* @lock: The lock variable
4242
*/
43-
#define local_unlock_irq(lock) __local_unlock_irq(lock)
43+
#define local_unlock_irq(lock) __local_unlock_irq(this_cpu_ptr(lock))
4444

4545
/**
4646
* local_unlock_irqrestore - Release a per CPU local lock and restore
@@ -49,7 +49,7 @@
4949
* @flags: Interrupt flags to restore
5050
*/
5151
#define local_unlock_irqrestore(lock, flags) \
52-
__local_unlock_irqrestore(lock, flags)
52+
__local_unlock_irqrestore(this_cpu_ptr(lock), flags)
5353

5454
/**
5555
* local_lock_init - Runtime initialize a lock instance
@@ -64,7 +64,7 @@
6464
* locking constrains it will _always_ fail to acquire the lock in NMI or
6565
* HARDIRQ context on PREEMPT_RT.
6666
*/
67-
#define local_trylock(lock) __local_trylock(lock)
67+
#define local_trylock(lock) __local_trylock(this_cpu_ptr(lock))
6868

6969
/**
7070
* local_trylock_irqsave - Try to acquire a per CPU local lock, save and disable
@@ -77,7 +77,7 @@
7777
* HARDIRQ context on PREEMPT_RT.
7878
*/
7979
#define local_trylock_irqsave(lock, flags) \
80-
__local_trylock_irqsave(lock, flags)
80+
__local_trylock_irqsave(this_cpu_ptr(lock), flags)
8181

8282
DEFINE_GUARD(local_lock, local_lock_t __percpu*,
8383
local_lock(_T),
@@ -91,10 +91,10 @@ DEFINE_LOCK_GUARD_1(local_lock_irqsave, local_lock_t __percpu,
9191
unsigned long flags)
9292

9393
#define local_lock_nested_bh(_lock) \
94-
__local_lock_nested_bh(_lock)
94+
__local_lock_nested_bh(this_cpu_ptr(_lock))
9595

9696
#define local_unlock_nested_bh(_lock) \
97-
__local_unlock_nested_bh(_lock)
97+
__local_unlock_nested_bh(this_cpu_ptr(_lock))
9898

9999
DEFINE_GUARD(local_lock_nested_bh, local_lock_t __percpu*,
100100
local_lock_nested_bh(_T),

include/linux/local_lock_internal.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ do { \
9999
local_trylock_t *tl; \
100100
local_lock_t *l; \
101101
\
102-
l = (local_lock_t *)this_cpu_ptr(lock); \
102+
l = (local_lock_t *)(lock); \
103103
tl = (local_trylock_t *)l; \
104104
_Generic((lock), \
105-
__percpu local_trylock_t *: ({ \
105+
local_trylock_t *: ({ \
106106
lockdep_assert(tl->acquired == 0); \
107107
WRITE_ONCE(tl->acquired, 1); \
108108
}), \
109-
__percpu local_lock_t *: (void)0); \
109+
local_lock_t *: (void)0); \
110110
local_lock_acquire(l); \
111111
} while (0)
112112

@@ -133,7 +133,7 @@ do { \
133133
local_trylock_t *tl; \
134134
\
135135
preempt_disable(); \
136-
tl = this_cpu_ptr(lock); \
136+
tl = (lock); \
137137
if (READ_ONCE(tl->acquired)) { \
138138
preempt_enable(); \
139139
tl = NULL; \
@@ -150,7 +150,7 @@ do { \
150150
local_trylock_t *tl; \
151151
\
152152
local_irq_save(flags); \
153-
tl = this_cpu_ptr(lock); \
153+
tl = (lock); \
154154
if (READ_ONCE(tl->acquired)) { \
155155
local_irq_restore(flags); \
156156
tl = NULL; \
@@ -167,15 +167,15 @@ do { \
167167
local_trylock_t *tl; \
168168
local_lock_t *l; \
169169
\
170-
l = (local_lock_t *)this_cpu_ptr(lock); \
170+
l = (local_lock_t *)(lock); \
171171
tl = (local_trylock_t *)l; \
172172
local_lock_release(l); \
173173
_Generic((lock), \
174-
__percpu local_trylock_t *: ({ \
174+
local_trylock_t *: ({ \
175175
lockdep_assert(tl->acquired == 1); \
176176
WRITE_ONCE(tl->acquired, 0); \
177177
}), \
178-
__percpu local_lock_t *: (void)0); \
178+
local_lock_t *: (void)0); \
179179
} while (0)
180180

181181
#define __local_unlock(lock) \
@@ -199,11 +199,11 @@ do { \
199199
#define __local_lock_nested_bh(lock) \
200200
do { \
201201
lockdep_assert_in_softirq(); \
202-
local_lock_acquire(this_cpu_ptr(lock)); \
202+
local_lock_acquire((lock)); \
203203
} while (0)
204204

205205
#define __local_unlock_nested_bh(lock) \
206-
local_lock_release(this_cpu_ptr(lock))
206+
local_lock_release((lock))
207207

208208
#else /* !CONFIG_PREEMPT_RT */
209209

@@ -227,7 +227,7 @@ typedef spinlock_t local_trylock_t;
227227
#define __local_lock(__lock) \
228228
do { \
229229
migrate_disable(); \
230-
spin_lock(this_cpu_ptr((__lock))); \
230+
spin_lock((__lock)); \
231231
} while (0)
232232

233233
#define __local_lock_irq(lock) __local_lock(lock)
@@ -241,7 +241,7 @@ typedef spinlock_t local_trylock_t;
241241

242242
#define __local_unlock(__lock) \
243243
do { \
244-
spin_unlock(this_cpu_ptr((__lock))); \
244+
spin_unlock((__lock)); \
245245
migrate_enable(); \
246246
} while (0)
247247

@@ -252,12 +252,12 @@ typedef spinlock_t local_trylock_t;
252252
#define __local_lock_nested_bh(lock) \
253253
do { \
254254
lockdep_assert_in_softirq_func(); \
255-
spin_lock(this_cpu_ptr(lock)); \
255+
spin_lock((lock)); \
256256
} while (0)
257257

258258
#define __local_unlock_nested_bh(lock) \
259259
do { \
260-
spin_unlock(this_cpu_ptr((lock))); \
260+
spin_unlock((lock)); \
261261
} while (0)
262262

263263
#define __local_trylock(lock) \
@@ -268,7 +268,7 @@ do { \
268268
__locked = 0; \
269269
} else { \
270270
migrate_disable(); \
271-
__locked = spin_trylock(this_cpu_ptr((lock))); \
271+
__locked = spin_trylock((lock)); \
272272
if (!__locked) \
273273
migrate_enable(); \
274274
} \

0 commit comments

Comments
 (0)