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

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 <kirill.shutemov@linux.intel.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250304153342.2016569-1-kirill.shutemov@linux.intel.com

authored by

Kirill A. Shutemov and committed by
Ingo Molnar
bd72baff fadb6f56

+15 -5
+13
arch/x86/include/asm/runtime-const.h
··· 2 2 #ifndef _ASM_RUNTIME_CONST_H 3 3 #define _ASM_RUNTIME_CONST_H 4 4 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 + 5 17 #define runtime_const_ptr(sym) ({ \ 6 18 typeof(sym) __ret; \ 7 19 asm_inline("mov %1,%0\n1:\n" \ ··· 70 58 } 71 59 } 72 60 61 + #endif /* __ASSEMBLY__ */ 73 62 #endif
+2 -5
arch/x86/lib/getuser.S
··· 35 35 #include <asm/thread_info.h> 36 36 #include <asm/asm.h> 37 37 #include <asm/smap.h> 38 + #include <asm/runtime-const.h> 38 39 39 40 #define ASM_BARRIER_NOSPEC ALTERNATIVE "", "lfence", X86_FEATURE_LFENCE_RDTSC 40 41 41 42 .macro check_range size:req 42 43 .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 48 45 cmp %rdx, %rax 49 46 cmova %rdx, %rax 50 47 .else