From 5385dec724ab4582df5b1fb2184c8b42ea547b3d Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Wed, 13 Aug 2025 15:08:22 +0000 Subject: x86/mm: Unify __phys_addr_symbol() There are two implementations on 64-bit, depending on CONFIG_DEBUG_VIRTUAL, but they differ only regarding the presence of VIRTUAL_BUG_ON, which is already ifdef'd on CONFIG_DEBUG_VIRTUAL. To avoid adding a function call on non-LTO non-DEBUG_VIRTUAL builds, move the function into the header. (Note the function is already only used on 64-bit). Signed-off-by: Brendan Jackman Signed-off-by: Borislav Petkov (AMD) Acked-by: Dave Hansen Link: https://patch.msgid.link/all/20250813-phys-addr-cleanup-v1-1-19e334b1c466@google.com/ --- arch/x86/include/asm/page_64.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'arch/x86/include') diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h index 015d23f3e01f..364c8d618fa7 100644 --- a/arch/x86/include/asm/page_64.h +++ b/arch/x86/include/asm/page_64.h @@ -9,6 +9,7 @@ #include #include +#include /* duplicated to the one in bootmem.h */ extern unsigned long max_pfn; @@ -31,13 +32,20 @@ static __always_inline unsigned long __phys_addr_nodebug(unsigned long x) #ifdef CONFIG_DEBUG_VIRTUAL extern unsigned long __phys_addr(unsigned long); -extern unsigned long __phys_addr_symbol(unsigned long); #else #define __phys_addr(x) __phys_addr_nodebug(x) -#define __phys_addr_symbol(x) \ - ((unsigned long)(x) - __START_KERNEL_map + phys_base) #endif +static inline unsigned long __phys_addr_symbol(unsigned long x) +{ + unsigned long y = x - __START_KERNEL_map; + + /* only check upper bounds since lower bounds will trigger carry */ + VIRTUAL_BUG_ON(y >= KERNEL_IMAGE_SIZE); + + return y + phys_base; +} + #define __phys_reloc_hide(x) (x) void clear_page_orig(void *page); -- cgit v1.2.3