x86/mm: Unify __phys_addr_symbol()
PATCH 1/1 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).
---
Note: I started to unify __phys_addr() too since at first glance it also seems to have the same unnecessary duplication. But actually for that one there's code that needs to skip the VIRTUAL_BUG_ON() even when CONFIG_DEBUG_VIRTUAL (via __pa_nodebug()).
I've run KUnit on x86_64 with DEBUG_VIRTUAL on and off.
--- arch/x86/include/asm/page_64.h | 14 +++++++++++--- arch/x86/mm/physaddr.c | 11 ----------- 2 files changed, 11 insertions(+), 14 deletions(-)
arch/x86/include/asm/page_64.h +11 -3
@@ -9,6 +9,7 @@#include <asm/alternative.h> #include <linux/kmsan-checks.h> +#include <linux/mmdebug.h> /* 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);
arch/x86/mm/physaddr.c +0 -11
@@ -31,17 +31,6 @@ unsigned long __phys_addr(unsigned long x) return x; }EXPORT_SYMBOL (__phys_addr); - -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; -} -EXPORT_SYMBOL (__phys_addr_symbol);#endif bool __virt_addr_valid (unsigned long x)
---
base-commit: 8742b2d8935f476449ef37e263bc4da3295c7b58
change-id: 20250813-phys-addr-cleanup-d85f181534e7
Best regards,
Signature · 1 line
Brendan Jackman <[email protected]>
Quoted 7 lines · Brendan Jackman
There are two implementations on 64-bit, depending on
CONFIG_DEBUG_VIRTUAL, but they differ only regarding the presence ofVIRTUAL_BUG_ON, which is already ifdef'd onCONFIG_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).
... and just for the record CONFIG_DEBUG_VIRTUAL really is a debug-build-only thing. I don't see it set in any normal distro kernels. This shouldn't bloat any normal builds, although it will probably make CONFIG_DEBUG_VIRTUAL=y build bigger. But I don't think we care about that.