[RFC/RFT PATCH 12/19] x86/sync_core: Use RIP-relative addressing

Ard Biesheuvel posted 19 patches 1 month ago
[RFC/RFT PATCH 12/19] x86/sync_core: Use RIP-relative addressing
Posted by Ard Biesheuvel 1 month ago
Use RIP-relative accesses for sync_core(). This removes a 32-bit
absolute reference that requires fixing up at runtime when KASLR is
enabled. This is a prerequisite for PIE linking, which only permits
64-bit wide loader-visible absolute references.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/x86/include/asm/sync_core.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/sync_core.h b/arch/x86/include/asm/sync_core.h
index 96bda43538ee..547fdc690ecc 100644
--- a/arch/x86/include/asm/sync_core.h
+++ b/arch/x86/include/asm/sync_core.h
@@ -31,7 +31,8 @@ static __always_inline void iret_to_self(void)
 		"pushfq\n\t"
 		"mov %%cs, %0\n\t"
 		"pushq %q0\n\t"
-		"pushq $1f\n\t"
+		"leaq 1f(%%rip), %q0\n\t"
+		"pushq %q0\n\t"
 		"iretq\n\t"
 		"1:"
 		: "=&r" (tmp), ASM_CALL_CONSTRAINT : : "cc", "memory");
-- 
2.47.3