Skip to content

Commit 50c94de

Browse files
committed
Merge tag 'locking_urgent_for_v5.18_rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull locking fixes from Borislav Petkov: - Allow the compiler to optimize away unused percpu accesses and change the local_lock_* macros back to inline functions - A couple of fixes to static call insn patching * tag 'locking_urgent_for_v5.18_rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: Revert "mm/page_alloc: mark pagesets as __maybe_unused" Revert "locking/local_lock: Make the empty local_lock_*() function a macro." x86/percpu: Remove volatile from arch_raw_cpu_ptr(). static_call: Remove __DEFINE_STATIC_CALL macro static_call: Properly initialise DEFINE_STATIC_CALL_RET0() static_call: Don't make __static_call_return0 static x86,static_call: Fix __static_call_return0 for i386
2 parents 7136849 + 273ba85 commit 50c94de

File tree

10 files changed

+585
-572
lines changed

10 files changed

+585
-572
lines changed

arch/powerpc/include/asm/static_call.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424

2525
#define ARCH_DEFINE_STATIC_CALL_TRAMP(name, func) __PPC_SCT(name, "b " #func)
2626
#define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) __PPC_SCT(name, "blr")
27+
#define ARCH_DEFINE_STATIC_CALL_RET0_TRAMP(name) __PPC_SCT(name, "b .+20")
2728

2829
#endif /* _ASM_POWERPC_STATIC_CALL_H */

arch/x86/include/asm/percpu.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
#define arch_raw_cpu_ptr(ptr) \
3939
({ \
4040
unsigned long tcp_ptr__; \
41-
asm volatile("add " __percpu_arg(1) ", %0" \
42-
: "=r" (tcp_ptr__) \
43-
: "m" (this_cpu_off), "0" (ptr)); \
41+
asm ("add " __percpu_arg(1) ", %0" \
42+
: "=r" (tcp_ptr__) \
43+
: "m" (this_cpu_off), "0" (ptr)); \
4444
(typeof(*(ptr)) __kernel __force *)tcp_ptr__; \
4545
})
4646
#else

arch/x86/include/asm/static_call.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) \
3939
__ARCH_DEFINE_STATIC_CALL_TRAMP(name, "ret; int3; nop; nop; nop")
4040

41+
#define ARCH_DEFINE_STATIC_CALL_RET0_TRAMP(name) \
42+
ARCH_DEFINE_STATIC_CALL_TRAMP(name, __static_call_return0)
4143

4244
#define ARCH_ADD_TRAMP_KEY(name) \
4345
asm(".pushsection .static_call_tramp_key, \"a\" \n" \

arch/x86/kernel/static_call.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ enum insn_type {
1212
};
1313

1414
/*
15-
* data16 data16 xorq %rax, %rax - a single 5 byte instruction that clears %rax
16-
* The REX.W cancels the effect of any data16.
15+
* cs cs cs xorl %eax, %eax - a single 5 byte instruction that clears %[er]ax
1716
*/
18-
static const u8 xor5rax[] = { 0x66, 0x66, 0x48, 0x31, 0xc0 };
17+
static const u8 xor5rax[] = { 0x2e, 0x2e, 0x2e, 0x31, 0xc0 };
1918

2019
static const u8 retinsn[] = { RET_INSN_OPCODE, 0xcc, 0xcc, 0xcc, 0xcc };
2120

include/linux/local_lock_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ static inline void local_lock_debug_init(local_lock_t *l)
4444
}
4545
#else /* CONFIG_DEBUG_LOCK_ALLOC */
4646
# define LOCAL_LOCK_DEBUG_INIT(lockname)
47-
# define local_lock_acquire(__ll) do { typecheck(local_lock_t *, __ll); } while (0)
48-
# define local_lock_release(__ll) do { typecheck(local_lock_t *, __ll); } while (0)
49-
# define local_lock_debug_init(__ll) do { typecheck(local_lock_t *, __ll); } while (0)
47+
static inline void local_lock_acquire(local_lock_t *l) { }
48+
static inline void local_lock_release(local_lock_t *l) { }
49+
static inline void local_lock_debug_init(local_lock_t *l) { }
5050
#endif /* !CONFIG_DEBUG_LOCK_ALLOC */
5151

5252
#define INIT_LOCAL_LOCK(lockname) { LOCAL_LOCK_DEBUG_INIT(lockname) }

include/linux/static_call.h

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ extern int static_call_text_reserved(void *start, void *end);
180180

181181
extern long __static_call_return0(void);
182182

183-
#define __DEFINE_STATIC_CALL(name, _func, _func_init) \
183+
#define DEFINE_STATIC_CALL(name, _func) \
184184
DECLARE_STATIC_CALL(name, _func); \
185185
struct static_call_key STATIC_CALL_KEY(name) = { \
186-
.func = _func_init, \
186+
.func = _func, \
187187
.type = 1, \
188188
}; \
189-
ARCH_DEFINE_STATIC_CALL_TRAMP(name, _func_init)
189+
ARCH_DEFINE_STATIC_CALL_TRAMP(name, _func)
190190

191191
#define DEFINE_STATIC_CALL_NULL(name, _func) \
192192
DECLARE_STATIC_CALL(name, _func); \
@@ -196,6 +196,14 @@ extern long __static_call_return0(void);
196196
}; \
197197
ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name)
198198

199+
#define DEFINE_STATIC_CALL_RET0(name, _func) \
200+
DECLARE_STATIC_CALL(name, _func); \
201+
struct static_call_key STATIC_CALL_KEY(name) = { \
202+
.func = __static_call_return0, \
203+
.type = 1, \
204+
}; \
205+
ARCH_DEFINE_STATIC_CALL_RET0_TRAMP(name)
206+
199207
#define static_call_cond(name) (void)__static_call(name)
200208

201209
#define EXPORT_STATIC_CALL(name) \
@@ -217,12 +225,12 @@ extern long __static_call_return0(void);
217225

218226
static inline int static_call_init(void) { return 0; }
219227

220-
#define __DEFINE_STATIC_CALL(name, _func, _func_init) \
228+
#define DEFINE_STATIC_CALL(name, _func) \
221229
DECLARE_STATIC_CALL(name, _func); \
222230
struct static_call_key STATIC_CALL_KEY(name) = { \
223-
.func = _func_init, \
231+
.func = _func, \
224232
}; \
225-
ARCH_DEFINE_STATIC_CALL_TRAMP(name, _func_init)
233+
ARCH_DEFINE_STATIC_CALL_TRAMP(name, _func)
226234

227235
#define DEFINE_STATIC_CALL_NULL(name, _func) \
228236
DECLARE_STATIC_CALL(name, _func); \
@@ -231,6 +239,12 @@ static inline int static_call_init(void) { return 0; }
231239
}; \
232240
ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name)
233241

242+
#define DEFINE_STATIC_CALL_RET0(name, _func) \
243+
DECLARE_STATIC_CALL(name, _func); \
244+
struct static_call_key STATIC_CALL_KEY(name) = { \
245+
.func = __static_call_return0, \
246+
}; \
247+
ARCH_DEFINE_STATIC_CALL_RET0_TRAMP(name)
234248

235249
#define static_call_cond(name) (void)__static_call(name)
236250

@@ -248,10 +262,7 @@ static inline int static_call_text_reserved(void *start, void *end)
248262
return 0;
249263
}
250264

251-
static inline long __static_call_return0(void)
252-
{
253-
return 0;
254-
}
265+
extern long __static_call_return0(void);
255266

256267
#define EXPORT_STATIC_CALL(name) \
257268
EXPORT_SYMBOL(STATIC_CALL_KEY(name)); \
@@ -281,11 +292,14 @@ static inline long __static_call_return0(void)
281292
.func = _func_init, \
282293
}
283294

295+
#define DEFINE_STATIC_CALL(name, _func) \
296+
__DEFINE_STATIC_CALL(name, _func, _func)
297+
284298
#define DEFINE_STATIC_CALL_NULL(name, _func) \
285-
DECLARE_STATIC_CALL(name, _func); \
286-
struct static_call_key STATIC_CALL_KEY(name) = { \
287-
.func = NULL, \
288-
}
299+
__DEFINE_STATIC_CALL(name, _func, NULL)
300+
301+
#define DEFINE_STATIC_CALL_RET0(name, _func) \
302+
__DEFINE_STATIC_CALL(name, _func, __static_call_return0)
289303

290304
static inline void __static_call_nop(void) { }
291305

@@ -327,10 +341,4 @@ static inline int static_call_text_reserved(void *start, void *end)
327341

328342
#endif /* CONFIG_HAVE_STATIC_CALL */
329343

330-
#define DEFINE_STATIC_CALL(name, _func) \
331-
__DEFINE_STATIC_CALL(name, _func, _func)
332-
333-
#define DEFINE_STATIC_CALL_RET0(name, _func) \
334-
__DEFINE_STATIC_CALL(name, _func, __static_call_return0)
335-
336344
#endif /* _LINUX_STATIC_CALL_H */

kernel/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ obj-$(CONFIG_CPU_PM) += cpu_pm.o
114114
obj-$(CONFIG_BPF) += bpf/
115115
obj-$(CONFIG_KCSAN) += kcsan/
116116
obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o
117-
obj-$(CONFIG_HAVE_STATIC_CALL_INLINE) += static_call.o
117+
obj-$(CONFIG_HAVE_STATIC_CALL) += static_call.o
118+
obj-$(CONFIG_HAVE_STATIC_CALL_INLINE) += static_call_inline.o
118119
obj-$(CONFIG_CFI_CLANG) += cfi.o
119120

120121
obj-$(CONFIG_PERF_EVENTS) += events/

0 commit comments

Comments
 (0)