Skip to content

Commit 3b1ddbb

Browse files
committed
Merge tag 'virt-to-pfn-for-arch-v6.5-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator into asm-generic
This is an attempt to harden the typing on virt_to_pfn() and pfn_to_virt(). 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. For symmetry, we do the same with pfn_to_virt(). The problem with this inconsistent typing was pointed out by Russell King: https://lore.kernel.org/linux-arm-kernel/YoJDKJXc0MJ2QZTb@shell.armlinux.org.uk/ And confirmed by Andrew Morton: https://lore.kernel.org/linux-mm/20220701160004.2ffff4e5ab59a55499f4c736@linux-foundation.org/ So the recognition of the problem is widespread. These platforms have been chosen as initial conversion targets: - ARM - ARM64/Aarch64 - asm-generic (including for example x86) - m68k The idea is that if this goes in, it will block further misuse of the function signatures due to the large compile coverage, and then I can go in and fix the remaining architectures on a one-by-one basis. Some of the patches have been circulated before but were not picked up by subsystem maintainers, so now the arch tree is target for this series. It has passed zeroday builds after a lot of iterations in my personal tree, but there could be some randconfig outliers. New added or deeply hidden problems appear all the time so some minor fallout can be expected. * tag 'virt-to-pfn-for-arch-v6.5-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-integrator: m68k/mm: Make pfn accessors static inlines arm64: memory: Make virt_to_pfn() a static inline ARM: mm: Make virt_to_pfn() a static inline asm-generic/page.h: Make pfn accessors static inlines xen/netback: Pass (void *) to virt_to_page() netfs: Pass a pointer to virt_to_page() cifs: Pass a pointer to virt_to_page() in cifsglob cifs: Pass a pointer to virt_to_page() riscv: mm: init: Pass a pointer to virt_to_page() ARC: init: Pass a pointer to virt_to_pfn() in init m68k: Pass a pointer to virt_to_pfn() virt_to_page() fs/proc/kcore.c: Pass a pointer to virt_addr_valid()
2 parents 7877cb9 + ef7d0f5 commit 3b1ddbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+108
-80
lines changed

arch/arc/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void __init setup_arch_memory(void)
8787
setup_initial_init_mm(_text, _etext, _edata, _end);
8888

8989
/* first page of system - kernel .vector starts here */
90-
min_low_pfn = virt_to_pfn(CONFIG_LINUX_RAM_BASE);
90+
min_low_pfn = virt_to_pfn((void *)CONFIG_LINUX_RAM_BASE);
9191

9292
/* Last usable page of low mem */
9393
max_low_pfn = max_pfn = PFN_DOWN(low_mem_start + low_mem_sz);

arch/arm/common/sharpsl_param.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <linux/module.h>
1212
#include <linux/string.h>
1313
#include <asm/mach/sharpsl_param.h>
14-
#include <asm/memory.h>
14+
#include <asm/page.h>
1515

1616
/*
1717
* Certain hardware parameters determined at the time of device manufacture,

arch/arm/include/asm/delay.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#ifndef __ASM_ARM_DELAY_H
88
#define __ASM_ARM_DELAY_H
99

10-
#include <asm/memory.h>
10+
#include <asm/page.h>
1111
#include <asm/param.h> /* HZ */
1212

1313
/*

arch/arm/include/asm/io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <linux/string.h>
2424
#include <linux/types.h>
2525
#include <asm/byteorder.h>
26-
#include <asm/memory.h>
26+
#include <asm/page.h>
2727
#include <asm-generic/pci_iomap.h>
2828

2929
/*

arch/arm/include/asm/memory.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
* Copyright (C) 2000-2002 Russell King
66
* modification for nommu, Hyok S. Choi, 2004
77
*
8-
* Note: this file should not be included by non-asm/.h files
8+
* Note: this file should not be included explicitly, include <asm/page.h>
9+
* to get access to these definitions.
910
*/
1011
#ifndef __ASM_ARM_MEMORY_H
1112
#define __ASM_ARM_MEMORY_H
1213

14+
#ifndef _ASMARM_PAGE_H
15+
#error "Do not include <asm/memory.h> directly"
16+
#endif
17+
1318
#include <linux/compiler.h>
1419
#include <linux/const.h>
1520
#include <linux/types.h>
@@ -288,10 +293,12 @@ static inline unsigned long __phys_to_virt(phys_addr_t x)
288293

289294
#endif
290295

291-
#define virt_to_pfn(kaddr) \
292-
((((unsigned long)(kaddr) - PAGE_OFFSET) >> PAGE_SHIFT) + \
293-
PHYS_PFN_OFFSET)
294-
296+
static inline unsigned long virt_to_pfn(const void *p)
297+
{
298+
unsigned long kaddr = (unsigned long)p;
299+
return (((kaddr - PAGE_OFFSET) >> PAGE_SHIFT) +
300+
PHYS_PFN_OFFSET);
301+
}
295302
#define __pa_symbol_nodebug(x) __virt_to_phys_nodebug((x))
296303

297304
#ifdef CONFIG_DEBUG_VIRTUAL

arch/arm/include/asm/page.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ extern int pfn_valid(unsigned long);
161161
#define pfn_valid pfn_valid
162162
#endif
163163

164-
#include <asm/memory.h>
165-
166164
#endif /* !__ASSEMBLY__ */
167165

166+
#include <asm/memory.h>
167+
168168
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC
169169

170170
#include <asm-generic/getorder.h>

arch/arm/include/asm/pgtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern struct page *empty_zero_page;
2727
#else
2828

2929
#include <asm-generic/pgtable-nopud.h>
30-
#include <asm/memory.h>
30+
#include <asm/page.h>
3131
#include <asm/pgtable-hwdef.h>
3232

3333

arch/arm/include/asm/proc-fns.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ static inline void init_proc_vtable(const struct processor *p)
147147

148148
extern void cpu_resume(void);
149149

150-
#include <asm/memory.h>
151-
152150
#ifdef CONFIG_MMU
153151

154152
#define cpu_switch_mm(pgd,mm) cpu_do_switch_mm(virt_to_phys(pgd),mm)

arch/arm/include/asm/sparsemem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef ASMARM_SPARSEMEM_H
33
#define ASMARM_SPARSEMEM_H
44

5-
#include <asm/memory.h>
5+
#include <asm/page.h>
66

77
/*
88
* Two definitions are required for sparsemem:

arch/arm/include/asm/uaccess-asm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include <asm/asm-offsets.h>
77
#include <asm/domain.h>
8-
#include <asm/memory.h>
8+
#include <asm/page.h>
99
#include <asm/thread_info.h>
1010

1111
.macro csdb

0 commit comments

Comments
 (0)