Skip to content

Commit bd72baf

Browse files
kirylIngo Molnar
authored andcommitted
x86/runtime-const: Add the RUNTIME_CONST_PTR assembly macro
Add an assembly macro to refer runtime cost. It hides linker magic and makes assembly more readable. Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Brian Gerst <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Linus Torvalds <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fadb6f5 commit bd72baf

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

arch/x86/include/asm/runtime-const.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
#ifndef _ASM_RUNTIME_CONST_H
33
#define _ASM_RUNTIME_CONST_H
44

5+
#ifdef __ASSEMBLY__
6+
7+
.macro RUNTIME_CONST_PTR sym reg
8+
movq $0x0123456789abcdef, %\reg
9+
1:
10+
.pushsection runtime_ptr_\sym, "a"
11+
.long 1b - 8 - .
12+
.popsection
13+
.endm
14+
15+
#else /* __ASSEMBLY__ */
16+
517
#define runtime_const_ptr(sym) ({ \
618
typeof(sym) __ret; \
719
asm_inline("mov %1,%0\n1:\n" \
@@ -58,4 +70,5 @@ static inline void runtime_const_fixup(void (*fn)(void *, unsigned long),
5870
}
5971
}
6072

73+
#endif /* __ASSEMBLY__ */
6174
#endif

arch/x86/lib/getuser.S

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,13 @@
3535
#include <asm/thread_info.h>
3636
#include <asm/asm.h>
3737
#include <asm/smap.h>
38+
#include <asm/runtime-const.h>
3839

3940
#define ASM_BARRIER_NOSPEC ALTERNATIVE "", "lfence", X86_FEATURE_LFENCE_RDTSC
4041

4142
.macro check_range size:req
4243
.if IS_ENABLED(CONFIG_X86_64)
43-
movq $0x0123456789abcdef,%rdx
44-
1:
45-
.pushsection runtime_ptr_USER_PTR_MAX,"a"
46-
.long 1b - 8 - .
47-
.popsection
44+
RUNTIME_CONST_PTR USER_PTR_MAX, rdx
4845
cmp %rdx, %rax
4946
cmova %rdx, %rax
5047
.else

0 commit comments

Comments
 (0)