Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Waiman Long <longman@redhat.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/all/20250630075138.3448715-2-bigeasy@linutronix.de

authored by

Sebastian Andrzej Siewior and committed by
Thomas Gleixner
7ff495e2 19272b37

+25 -25
+10 -10
include/linux/local_lock.h
··· 13 13 * local_lock - Acquire a per CPU local lock 14 14 * @lock: The lock variable 15 15 */ 16 - #define local_lock(lock) __local_lock(lock) 16 + #define local_lock(lock) __local_lock(this_cpu_ptr(lock)) 17 17 18 18 /** 19 19 * local_lock_irq - Acquire a per CPU local lock and disable interrupts 20 20 * @lock: The lock variable 21 21 */ 22 - #define local_lock_irq(lock) __local_lock_irq(lock) 22 + #define local_lock_irq(lock) __local_lock_irq(this_cpu_ptr(lock)) 23 23 24 24 /** 25 25 * local_lock_irqsave - Acquire a per CPU local lock, save and disable ··· 28 28 * @flags: Storage for interrupt flags 29 29 */ 30 30 #define local_lock_irqsave(lock, flags) \ 31 - __local_lock_irqsave(lock, flags) 31 + __local_lock_irqsave(this_cpu_ptr(lock), flags) 32 32 33 33 /** 34 34 * local_unlock - Release a per CPU local lock 35 35 * @lock: The lock variable 36 36 */ 37 - #define local_unlock(lock) __local_unlock(lock) 37 + #define local_unlock(lock) __local_unlock(this_cpu_ptr(lock)) 38 38 39 39 /** 40 40 * local_unlock_irq - Release a per CPU local lock and enable interrupts 41 41 * @lock: The lock variable 42 42 */ 43 - #define local_unlock_irq(lock) __local_unlock_irq(lock) 43 + #define local_unlock_irq(lock) __local_unlock_irq(this_cpu_ptr(lock)) 44 44 45 45 /** 46 46 * local_unlock_irqrestore - Release a per CPU local lock and restore ··· 49 49 * @flags: Interrupt flags to restore 50 50 */ 51 51 #define local_unlock_irqrestore(lock, flags) \ 52 - __local_unlock_irqrestore(lock, flags) 52 + __local_unlock_irqrestore(this_cpu_ptr(lock), flags) 53 53 54 54 /** 55 55 * local_lock_init - Runtime initialize a lock instance ··· 64 64 * locking constrains it will _always_ fail to acquire the lock in NMI or 65 65 * HARDIRQ context on PREEMPT_RT. 66 66 */ 67 - #define local_trylock(lock) __local_trylock(lock) 67 + #define local_trylock(lock) __local_trylock(this_cpu_ptr(lock)) 68 68 69 69 /** 70 70 * local_trylock_irqsave - Try to acquire a per CPU local lock, save and disable ··· 77 77 * HARDIRQ context on PREEMPT_RT. 78 78 */ 79 79 #define local_trylock_irqsave(lock, flags) \ 80 - __local_trylock_irqsave(lock, flags) 80 + __local_trylock_irqsave(this_cpu_ptr(lock), flags) 81 81 82 82 DEFINE_GUARD(local_lock, local_lock_t __percpu*, 83 83 local_lock(_T), ··· 91 91 unsigned long flags) 92 92 93 93 #define local_lock_nested_bh(_lock) \ 94 - __local_lock_nested_bh(_lock) 94 + __local_lock_nested_bh(this_cpu_ptr(_lock)) 95 95 96 96 #define local_unlock_nested_bh(_lock) \ 97 - __local_unlock_nested_bh(_lock) 97 + __local_unlock_nested_bh(this_cpu_ptr(_lock)) 98 98 99 99 DEFINE_GUARD(local_lock_nested_bh, local_lock_t __percpu*, 100 100 local_lock_nested_bh(_T),
+15 -15
include/linux/local_lock_internal.h
··· 99 99 local_trylock_t *tl; \ 100 100 local_lock_t *l; \ 101 101 \ 102 - l = (local_lock_t *)this_cpu_ptr(lock); \ 102 + l = (local_lock_t *)(lock); \ 103 103 tl = (local_trylock_t *)l; \ 104 104 _Generic((lock), \ 105 - __percpu local_trylock_t *: ({ \ 105 + local_trylock_t *: ({ \ 106 106 lockdep_assert(tl->acquired == 0); \ 107 107 WRITE_ONCE(tl->acquired, 1); \ 108 108 }), \ 109 - __percpu local_lock_t *: (void)0); \ 109 + local_lock_t *: (void)0); \ 110 110 local_lock_acquire(l); \ 111 111 } while (0) 112 112 ··· 133 133 local_trylock_t *tl; \ 134 134 \ 135 135 preempt_disable(); \ 136 - tl = this_cpu_ptr(lock); \ 136 + tl = (lock); \ 137 137 if (READ_ONCE(tl->acquired)) { \ 138 138 preempt_enable(); \ 139 139 tl = NULL; \ ··· 150 150 local_trylock_t *tl; \ 151 151 \ 152 152 local_irq_save(flags); \ 153 - tl = this_cpu_ptr(lock); \ 153 + tl = (lock); \ 154 154 if (READ_ONCE(tl->acquired)) { \ 155 155 local_irq_restore(flags); \ 156 156 tl = NULL; \ ··· 167 167 local_trylock_t *tl; \ 168 168 local_lock_t *l; \ 169 169 \ 170 - l = (local_lock_t *)this_cpu_ptr(lock); \ 170 + l = (local_lock_t *)(lock); \ 171 171 tl = (local_trylock_t *)l; \ 172 172 local_lock_release(l); \ 173 173 _Generic((lock), \ 174 - __percpu local_trylock_t *: ({ \ 174 + local_trylock_t *: ({ \ 175 175 lockdep_assert(tl->acquired == 1); \ 176 176 WRITE_ONCE(tl->acquired, 0); \ 177 177 }), \ 178 - __percpu local_lock_t *: (void)0); \ 178 + local_lock_t *: (void)0); \ 179 179 } while (0) 180 180 181 181 #define __local_unlock(lock) \ ··· 199 199 #define __local_lock_nested_bh(lock) \ 200 200 do { \ 201 201 lockdep_assert_in_softirq(); \ 202 - local_lock_acquire(this_cpu_ptr(lock)); \ 202 + local_lock_acquire((lock)); \ 203 203 } while (0) 204 204 205 205 #define __local_unlock_nested_bh(lock) \ 206 - local_lock_release(this_cpu_ptr(lock)) 206 + local_lock_release((lock)) 207 207 208 208 #else /* !CONFIG_PREEMPT_RT */ 209 209 ··· 227 227 #define __local_lock(__lock) \ 228 228 do { \ 229 229 migrate_disable(); \ 230 - spin_lock(this_cpu_ptr((__lock))); \ 230 + spin_lock((__lock)); \ 231 231 } while (0) 232 232 233 233 #define __local_lock_irq(lock) __local_lock(lock) ··· 241 241 242 242 #define __local_unlock(__lock) \ 243 243 do { \ 244 - spin_unlock(this_cpu_ptr((__lock))); \ 244 + spin_unlock((__lock)); \ 245 245 migrate_enable(); \ 246 246 } while (0) 247 247 ··· 252 252 #define __local_lock_nested_bh(lock) \ 253 253 do { \ 254 254 lockdep_assert_in_softirq_func(); \ 255 - spin_lock(this_cpu_ptr(lock)); \ 255 + spin_lock((lock)); \ 256 256 } while (0) 257 257 258 258 #define __local_unlock_nested_bh(lock) \ 259 259 do { \ 260 - spin_unlock(this_cpu_ptr((lock))); \ 260 + spin_unlock((lock)); \ 261 261 } while (0) 262 262 263 263 #define __local_trylock(lock) \ ··· 268 268 __locked = 0; \ 269 269 } else { \ 270 270 migrate_disable(); \ 271 - __locked = spin_trylock(this_cpu_ptr((lock))); \ 271 + __locked = spin_trylock((lock)); \ 272 272 if (!__locked) \ 273 273 migrate_enable(); \ 274 274 } \