ARM: mm: Make virt_to_pfn() a static inline

Making virt_to_pfn() a static inline taking a strongly typed
(const void *) makes the contract of a passing a pointer of that
type to the function explicit and exposes any misuse of the
macro virt_to_pfn() acting polymorphic and accepting many types
such as (void *), (unitptr_t) or (unsigned long) as arguments
without warnings.

Doing this is a bit intrusive: virt_to_pfn() requires
PHYS_PFN_OFFSET and PAGE_SHIFT to be defined, and this is defined in
<asm/page.h>, so this must be included *before* <asm/memory.h>.

The use of macros were obscuring the unclear inclusion order here,
as the macros would eventually be resolved, but a static inline
like this cannot be compiled with unresolved macros.

The naive solution to include <asm/page.h> at the top of
<asm/memory.h> does not work, because <asm/memory.h> sometimes
includes <asm/page.h> at the end of itself, which would create a
confusing inclusion loop. So instead, take the approach to always
unconditionally include <asm/page.h> at the end of <asm/memory.h>

arch/arm uses <asm/memory.h> explicitly in a lot of places,
however it turns out that if we just unconditionally include
<asm/memory.h> into <asm/page.h> and switch all inclusions of
<asm/memory.h> to <asm/page.h> instead, we enforce the right
order and <asm/memory.h> will always have access to the
definitions.

Put an inclusion guard in place making it impossible to include
<asm/memory.h> explicitly.

Link: https://lore.kernel.org/linux-mm/20220701160004.2ffff4e5ab59a55499f4c736@linux-foundation.org/
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
Linus Walleij 2022-06-02 10:18:32 +02:00
parent 2d78057f0d
commit a9ff696160
46 changed files with 54 additions and 55 deletions

View File

@ -11,7 +11,7 @@
#include <linux/module.h>
#include <linux/string.h>
#include <asm/mach/sharpsl_param.h>
#include <asm/memory.h>
#include <asm/page.h>
/*
* Certain hardware parameters determined at the time of device manufacture,

View File

@ -7,7 +7,7 @@
#ifndef __ASM_ARM_DELAY_H
#define __ASM_ARM_DELAY_H
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/param.h> /* HZ */
/*

View File

@ -23,7 +23,7 @@
#include <linux/string.h>
#include <linux/types.h>
#include <asm/byteorder.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm-generic/pci_iomap.h>
/*

View File

@ -5,11 +5,16 @@
* Copyright (C) 2000-2002 Russell King
* modification for nommu, Hyok S. Choi, 2004
*
* Note: this file should not be included by non-asm/.h files
* Note: this file should not be included explicitly, include <asm/page.h>
* to get access to these definitions.
*/
#ifndef __ASM_ARM_MEMORY_H
#define __ASM_ARM_MEMORY_H
#ifndef _ASMARM_PAGE_H
#error "Do not include <asm/memory.h> directly"
#endif
#include <linux/compiler.h>
#include <linux/const.h>
#include <linux/types.h>
@ -288,10 +293,12 @@ static inline unsigned long __phys_to_virt(phys_addr_t x)
#endif
#define virt_to_pfn(kaddr) \
((((unsigned long)(kaddr) - PAGE_OFFSET) >> PAGE_SHIFT) + \
PHYS_PFN_OFFSET)
static inline unsigned long virt_to_pfn(const void *p)
{
unsigned long kaddr = (unsigned long)p;
return (((kaddr - PAGE_OFFSET) >> PAGE_SHIFT) +
PHYS_PFN_OFFSET);
}
#define __pa_symbol_nodebug(x) __virt_to_phys_nodebug((x))
#ifdef CONFIG_DEBUG_VIRTUAL

View File

@ -161,10 +161,10 @@ extern int pfn_valid(unsigned long);
#define pfn_valid pfn_valid
#endif
#include <asm/memory.h>
#endif /* !__ASSEMBLY__ */
#include <asm/memory.h>
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC
#include <asm-generic/getorder.h>

View File

@ -27,7 +27,7 @@ extern struct page *empty_zero_page;
#else
#include <asm-generic/pgtable-nopud.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/pgtable-hwdef.h>

View File

@ -147,8 +147,6 @@ static inline void init_proc_vtable(const struct processor *p)
extern void cpu_resume(void);
#include <asm/memory.h>
#ifdef CONFIG_MMU
#define cpu_switch_mm(pgd,mm) cpu_do_switch_mm(virt_to_phys(pgd),mm)

View File

@ -2,7 +2,7 @@
#ifndef ASMARM_SPARSEMEM_H
#define ASMARM_SPARSEMEM_H
#include <asm/memory.h>
#include <asm/page.h>
/*
* Two definitions are required for sparsemem:

View File

@ -5,7 +5,7 @@
#include <asm/asm-offsets.h>
#include <asm/domain.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/thread_info.h>
.macro csdb

View File

@ -9,7 +9,7 @@
* User space memory access functions
*/
#include <linux/string.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/domain.h>
#include <asm/unaligned.h>
#include <asm/unified.h>

View File

@ -17,7 +17,7 @@
#include <asm/glue-pf.h>
#include <asm/mach/arch.h>
#include <asm/thread_info.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/mpu.h>
#include <asm/procinfo.h>
#include <asm/suspend.h>

View File

@ -15,7 +15,7 @@
#include <linux/init.h>
#include <asm/assembler.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/glue-df.h>
#include <asm/glue-pf.h>
#include <asm/vfpmacros.h>

View File

@ -9,7 +9,7 @@
#include <asm/unistd.h>
#include <asm/ftrace.h>
#include <asm/unwind.h>
#include <asm/memory.h>
#include <asm/page.h>
#ifdef CONFIG_AEABI
#include <asm/unistd-oabi.h>
#endif

View File

@ -6,7 +6,7 @@
*
* Low-level vector interface routines for the ARMv7-M architecture
*/
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/glue.h>
#include <asm/thread_notify.h>
#include <asm/v7m.h>

View File

@ -14,12 +14,11 @@
#include <asm/assembler.h>
#include <asm/ptrace.h>
#include <asm/asm-offsets.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/cp15.h>
#include <asm/thread_info.h>
#include <asm/v7m.h>
#include <asm/mpu.h>
#include <asm/page.h>
/*
* Kernel startup entry point.

View File

@ -17,7 +17,7 @@
#include <asm/domain.h>
#include <asm/ptrace.h>
#include <asm/asm-offsets.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/thread_info.h>
#if defined(CONFIG_DEBUG_LL) && !defined(CONFIG_DEBUG_SEMIHOSTING)

View File

@ -19,7 +19,7 @@
#include <asm/system_misc.h>
#include <asm/idmap.h>
#include <asm/suspend.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/sections.h>
#include "reboot.h"

View File

@ -8,7 +8,7 @@
#include <asm/bugs.h>
#include <asm/cacheflush.h>
#include <asm/idmap.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/smp_plat.h>
#include <asm/suspend.h>
#include <asm/tlbflush.h>

View File

@ -15,7 +15,7 @@
#include <linux/string.h> /* memcpy */
#include <asm/cputype.h>
#include <asm/mach/map.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/system_info.h>
#include <asm/traps.h>
#include <asm/tcm.h>

View File

@ -12,9 +12,8 @@
#include <asm/vmlinux.lds.h>
#include <asm/cache.h>
#include <asm/thread_info.h>
#include <asm/memory.h>
#include <asm/mpu.h>
#include <asm/page.h>
#include <asm/mpu.h>
OUTPUT_ARCH(arm)
ENTRY(stext)

View File

@ -12,9 +12,8 @@
#include <asm/vmlinux.lds.h>
#include <asm/cache.h>
#include <asm/thread_info.h>
#include <asm/memory.h>
#include <asm/mpu.h>
#include <asm/page.h>
#include <asm/mpu.h>
OUTPUT_ARCH(arm)
ENTRY(stext)

View File

@ -12,7 +12,7 @@
#include <asm/cacheflush.h>
#include <asm/cp15.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/smp_plat.h>
#include <asm/smp_scu.h>

View File

@ -18,7 +18,7 @@
#include <asm/mach/map.h>
#include <asm/mach/arch.h>
#include <asm/mach/time.h>
#include <asm/memory.h>
#include <asm/page.h>
#include "memory.h"

View File

@ -10,7 +10,7 @@
#include <linux/platform_data/pm33xx.h>
#include <linux/ti-emif-sram.h>
#include <asm/assembler.h>
#include <asm/memory.h>
#include <asm/page.h>
#include "iomap.h"
#include "cm33xx.h"

View File

@ -11,7 +11,7 @@
#include <linux/platform_data/pm33xx.h>
#include <asm/assembler.h>
#include <asm/hardware/cache-l2x0.h>
#include <asm/memory.h>
#include <asm/page.h>
#include "cm33xx.h"
#include "common.h"

View File

@ -9,7 +9,7 @@
#include <linux/linkage.h>
#include <asm/assembler.h>
#include <asm/smp_scu.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/hardware/cache-l2x0.h>
#include "omap-secure.h"

View File

@ -26,7 +26,7 @@
#include <linux/clk.h>
#include <asm/setup.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/mach-types.h>
#include <asm/irq.h>
#include <linux/sizes.h>

View File

@ -6,7 +6,7 @@
#include <linux/linkage.h>
#include <asm/assembler.h>
#include <asm/memory.h>
#include <asm/page.h>
.data
/*

View File

@ -29,7 +29,7 @@
#include <linux/time.h>
#include <mach/hardware.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/suspend.h>
#include <asm/mach/time.h>

View File

@ -7,7 +7,7 @@
#include <linux/linkage.h>
#include <linux/init.h>
#include <asm/memory.h>
#include <asm/page.h>
/*
* Boot code for secondary CPUs.

View File

@ -11,7 +11,7 @@
#include <linux/linkage.h>
#include <linux/threads.h>
#include <asm/assembler.h>
#include <asm/memory.h>
#include <asm/page.h>
#define SCTLR_MMU 0x01
#define BOOTROM_ADDRESS 0xE6340000

View File

@ -6,7 +6,7 @@
*/
#include <linux/linkage.h>
#include <linux/init.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/assembler.h>
.arch armv7-a

View File

@ -10,7 +10,7 @@
#ifndef __MACH_SPEAR_H
#define __MACH_SPEAR_H
#include <asm/memory.h>
#include <asm/page.h>
#if defined(CONFIG_ARCH_SPEAR3XX) || defined (CONFIG_ARCH_SPEAR6XX)

View File

@ -13,7 +13,6 @@
#include <linux/linkage.h>
#include <linux/init.h>
#include <asm/assembler.h>
#include <asm/memory.h>
#include <asm/page.h>
#include "proc-macros.S"

View File

@ -7,7 +7,6 @@
#include <linux/linkage.h>
#include <linux/init.h>
#include <asm/assembler.h>
#include <asm/memory.h>
#include <asm/page.h>
#include "proc-macros.S"

View File

@ -25,7 +25,7 @@
#include <linux/sizes.h>
#include <linux/cma.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/highmem.h>
#include <asm/cacheflush.h>
#include <asm/tlbflush.h>

View File

@ -15,7 +15,7 @@
#include <asm/domain.h>
#include <asm/fixmap.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/ptdump.h>
static struct addr_marker address_markers[] = {

View File

@ -26,7 +26,7 @@
#include <asm/cp15.h>
#include <asm/mach-types.h>
#include <asm/memblock.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/prom.h>
#include <asm/sections.h>
#include <asm/setup.h>

View File

@ -17,7 +17,6 @@
#include <asm/cputype.h>
#include <asm/highmem.h>
#include <asm/mach/map.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/pgalloc.h>
#include <asm/procinfo.h>

View File

@ -26,7 +26,7 @@
#include <asm/system_info.h>
#include <asm/traps.h>
#include <asm/procinfo.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/pgalloc.h>
#include <asm/kasan_def.h>

View File

@ -6,7 +6,7 @@
#include <linux/mm.h>
#include <asm/sections.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/fixmap.h>
#include <asm/dma.h>

View File

@ -11,7 +11,7 @@
#include <asm/cputype.h>
#include <asm/mpu.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/sections.h>
#include "mm.h"

View File

@ -14,7 +14,7 @@
#include <asm/asm-offsets.h>
#include <asm/hwcap.h>
#include <asm/pgtable-hwdef.h>
#include <asm/memory.h>
#include <asm/page.h>
#include "proc-macros.S"

View File

@ -9,7 +9,7 @@
*/
#include <linux/linkage.h>
#include <asm/assembler.h>
#include <asm/memory.h>
#include <asm/page.h>
#include <asm/v7m.h>
#include "proc-macros.S"

View File

@ -9,7 +9,7 @@
#include <linux/pgtable.h>
#include <asm/asm-offsets.h>
#include <asm/cp15.h>
#include <asm/memory.h>
#include <asm/page.h>
.section ".idmap.text", "ax"

View File

@ -8,7 +8,7 @@
#include <linux/linkage.h>
#include <asm/assembler.h>
#include <asm/memory.h>
#include <asm/page.h>
#include "emif.h"
#include "ti-emif-asm-offsets.h"