Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: define default value for FIRST_USER_ADDRESS

Currently most platforms define FIRST_USER_ADDRESS as 0UL duplication the
same code all over. Instead just define a generic default value (i.e 0UL)
for FIRST_USER_ADDRESS and let the platforms override when required. This
makes it much cleaner with reduced code.

The default FIRST_USER_ADDRESS here would be skipped in <linux/pgtable.h>
when the given platform overrides its value via <asm/pgtable.h>.

Link: https://lkml.kernel.org/r/1620615725-24623-1-git-send-email-anshuman.khandual@arm.com
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> [m68k]
Acked-by: Guo Ren <guoren@kernel.org> [csky]
Acked-by: Stafford Horne <shorne@gmail.com> [openrisc]
Acked-by: Catalin Marinas <catalin.marinas@arm.com> [arm64]
Acked-by: Mike Rapoport <rppt@linux.ibm.com>
Acked-by: Palmer Dabbelt <palmerdabbelt@google.com> [RISC-V]
Cc: Richard Henderson <rth@twiddle.net>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Brian Cain <bcain@codeaurora.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Ley Foon Tan <ley.foon.tan@intel.com>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
Cc: Stafford Horne <shorne@gmail.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Chris Zankel <chris@zankel.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Anshuman Khandual and committed by
Linus Torvalds
fac7757e c4ffefd1

+9 -43
-1
arch/alpha/include/asm/pgtable.h
··· 46 46 #define PTRS_PER_PMD (1UL << (PAGE_SHIFT-3)) 47 47 #define PTRS_PER_PGD (1UL << (PAGE_SHIFT-3)) 48 48 #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) 49 - #define FIRST_USER_ADDRESS 0UL 50 49 51 50 /* Number of pointers that fit on a page: this will go away. */ 52 51 #define PTRS_PER_PAGE (1UL << (PAGE_SHIFT-3))
-6
arch/arc/include/asm/pgtable.h
··· 222 222 */ 223 223 #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) 224 224 225 - /* 226 - * No special requirements for lowest virtual address we permit any user space 227 - * mapping to be mapped at. 228 - */ 229 - #define FIRST_USER_ADDRESS 0UL 230 - 231 225 232 226 /**************************************************************** 233 227 * Bucket load of VM Helpers
-2
arch/arm64/include/asm/pgtable.h
··· 26 26 27 27 #define vmemmap ((struct page *)VMEMMAP_START - (memstart_addr >> PAGE_SHIFT)) 28 28 29 - #define FIRST_USER_ADDRESS 0UL 30 - 31 29 #ifndef __ASSEMBLY__ 32 30 33 31 #include <asm/cmpxchg.h>
-1
arch/csky/include/asm/pgtable.h
··· 14 14 #define PGDIR_MASK (~(PGDIR_SIZE-1)) 15 15 16 16 #define USER_PTRS_PER_PGD (PAGE_OFFSET/PGDIR_SIZE) 17 - #define FIRST_USER_ADDRESS 0UL 18 17 19 18 /* 20 19 * C-SKY is two-level paging structure:
-3
arch/hexagon/include/asm/pgtable.h
··· 155 155 156 156 extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; /* located in head.S */ 157 157 158 - /* Seems to be zero even in architectures where the zero page is firewalled? */ 159 - #define FIRST_USER_ADDRESS 0UL 160 - 161 158 /* HUGETLB not working currently */ 162 159 #ifdef CONFIG_HUGETLB_PAGE 163 160 #define pte_mkhuge(pte) __pte((pte_val(pte) & ~0x3) | HVM_HUGEPAGE_SIZE)
-1
arch/ia64/include/asm/pgtable.h
··· 128 128 #define PTRS_PER_PGD_SHIFT PTRS_PER_PTD_SHIFT 129 129 #define PTRS_PER_PGD (1UL << PTRS_PER_PGD_SHIFT) 130 130 #define USER_PTRS_PER_PGD (5*PTRS_PER_PGD/8) /* regions 0-4 are user regions */ 131 - #define FIRST_USER_ADDRESS 0UL 132 131 133 132 /* 134 133 * All the normal masks have the "page accessed" bits on, as any time
-1
arch/m68k/include/asm/pgtable_mm.h
··· 72 72 #define PTRS_PER_PGD 128 73 73 #endif 74 74 #define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE) 75 - #define FIRST_USER_ADDRESS 0UL 76 75 77 76 /* Virtual address region for use by kernel_map() */ 78 77 #ifdef CONFIG_SUN3
-2
arch/microblaze/include/asm/pgtable.h
··· 25 25 #include <asm/mmu.h> 26 26 #include <asm/page.h> 27 27 28 - #define FIRST_USER_ADDRESS 0UL 29 - 30 28 extern unsigned long va_to_phys(unsigned long address); 31 29 extern pte_t *va_to_pte(unsigned long address); 32 30
-1
arch/mips/include/asm/pgtable-32.h
··· 93 93 #endif 94 94 95 95 #define USER_PTRS_PER_PGD (0x80000000UL/PGDIR_SIZE) 96 - #define FIRST_USER_ADDRESS 0UL 97 96 98 97 #define VMALLOC_START MAP_BASE 99 98
-1
arch/mips/include/asm/pgtable-64.h
··· 137 137 #define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t)) 138 138 139 139 #define USER_PTRS_PER_PGD ((TASK_SIZE64 / PGDIR_SIZE)?(TASK_SIZE64 / PGDIR_SIZE):1) 140 - #define FIRST_USER_ADDRESS 0UL 141 140 142 141 /* 143 142 * TLB refill handlers also map the vmalloc area into xuseg. Avoid
-2
arch/nios2/include/asm/pgtable.h
··· 24 24 #include <asm/pgtable-bits.h> 25 25 #include <asm-generic/pgtable-nopmd.h> 26 26 27 - #define FIRST_USER_ADDRESS 0UL 28 - 29 27 #define VMALLOC_START CONFIG_NIOS2_KERNEL_MMU_REGION_BASE 30 28 #define VMALLOC_END (CONFIG_NIOS2_KERNEL_REGION_BASE - 1) 31 29
-1
arch/openrisc/include/asm/pgtable.h
··· 73 73 */ 74 74 75 75 #define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE) 76 - #define FIRST_USER_ADDRESS 0UL 77 76 78 77 /* 79 78 * Kernels own virtual memory area.
-2
arch/parisc/include/asm/pgtable.h
··· 171 171 * pgd entries used up by user/kernel: 172 172 */ 173 173 174 - #define FIRST_USER_ADDRESS 0UL 175 - 176 174 /* NB: The tlb miss handlers make certain assumptions about the order */ 177 175 /* of the following bits, so be careful (One example, bits 25-31 */ 178 176 /* are moved together in one instruction). */
-1
arch/powerpc/include/asm/book3s/pgtable.h
··· 8 8 #include <asm/book3s/32/pgtable.h> 9 9 #endif 10 10 11 - #define FIRST_USER_ADDRESS 0UL 12 11 #ifndef __ASSEMBLY__ 13 12 /* Insert a PTE, top-level function is out of line. It uses an inline 14 13 * low level function in the respective pgtable-* files
-1
arch/powerpc/include/asm/nohash/32/pgtable.h
··· 54 54 #define PGD_MASKED_BITS 0 55 55 56 56 #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) 57 - #define FIRST_USER_ADDRESS 0UL 58 57 59 58 #define pte_ERROR(e) \ 60 59 pr_err("%s:%d: bad pte %llx.\n", __FILE__, __LINE__, \
-2
arch/powerpc/include/asm/nohash/64/pgtable.h
··· 12 12 #include <asm/barrier.h> 13 13 #include <asm/asm-const.h> 14 14 15 - #define FIRST_USER_ADDRESS 0UL 16 - 17 15 /* 18 16 * Size of EA range mapped by our pagetables. 19 17 */
-2
arch/riscv/include/asm/pgtable.h
··· 536 536 void paging_init(void); 537 537 void misc_mem_init(void); 538 538 539 - #define FIRST_USER_ADDRESS 0 540 - 541 539 /* 542 540 * ZERO_PAGE is a global shared page that is always zero, 543 541 * used for zero-mapped memory areas, etc.
-2
arch/s390/include/asm/pgtable.h
··· 65 65 66 66 /* TODO: s390 cannot support io_remap_pfn_range... */ 67 67 68 - #define FIRST_USER_ADDRESS 0UL 69 - 70 68 #define pte_ERROR(e) \ 71 69 printk("%s:%d: bad pte %p.\n", __FILE__, __LINE__, (void *) pte_val(e)) 72 70 #define pmd_ERROR(e) \
-2
arch/sh/include/asm/pgtable.h
··· 59 59 /* Entries per level */ 60 60 #define PTRS_PER_PTE (PAGE_SIZE / (1 << PTE_MAGNITUDE)) 61 61 62 - #define FIRST_USER_ADDRESS 0UL 63 - 64 62 #define PHYS_ADDR_MASK29 0x1fffffff 65 63 #define PHYS_ADDR_MASK32 0xffffffff 66 64
-1
arch/sparc/include/asm/pgtable_32.h
··· 48 48 #define PTRS_PER_PMD 64 49 49 #define PTRS_PER_PGD 256 50 50 #define USER_PTRS_PER_PGD PAGE_OFFSET / PGDIR_SIZE 51 - #define FIRST_USER_ADDRESS 0UL 52 51 #define PTE_SIZE (PTRS_PER_PTE*4) 53 52 54 53 #define PAGE_NONE SRMMU_PAGE_NONE
-3
arch/sparc/include/asm/pgtable_64.h
··· 95 95 #define PTRS_PER_PUD (1UL << PUD_BITS) 96 96 #define PTRS_PER_PGD (1UL << PGDIR_BITS) 97 97 98 - /* Kernel has a separate 44bit address space. */ 99 - #define FIRST_USER_ADDRESS 0UL 100 - 101 98 #define pmd_ERROR(e) \ 102 99 pr_err("%s:%d: bad pmd %p(%016lx) seen at (%pS)\n", \ 103 100 __FILE__, __LINE__, &(e), pmd_val(e), __builtin_return_address(0))
-1
arch/um/include/asm/pgtable-2level.h
··· 23 23 #define PTRS_PER_PTE 1024 24 24 #define USER_PTRS_PER_PGD ((TASK_SIZE + (PGDIR_SIZE - 1)) / PGDIR_SIZE) 25 25 #define PTRS_PER_PGD 1024 26 - #define FIRST_USER_ADDRESS 0UL 27 26 28 27 #define pte_ERROR(e) \ 29 28 printk("%s:%d: bad pte %p(%08lx).\n", __FILE__, __LINE__, &(e), \
-1
arch/um/include/asm/pgtable-3level.h
··· 41 41 #endif 42 42 43 43 #define USER_PTRS_PER_PGD ((TASK_SIZE + (PGDIR_SIZE - 1)) / PGDIR_SIZE) 44 - #define FIRST_USER_ADDRESS 0UL 45 44 46 45 #define pte_ERROR(e) \ 47 46 printk("%s:%d: bad pte %p(%016lx).\n", __FILE__, __LINE__, &(e), \
-2
arch/x86/include/asm/pgtable_types.h
··· 7 7 8 8 #include <asm/page_types.h> 9 9 10 - #define FIRST_USER_ADDRESS 0UL 11 - 12 10 #define _PAGE_BIT_PRESENT 0 /* is present */ 13 11 #define _PAGE_BIT_RW 1 /* writeable */ 14 12 #define _PAGE_BIT_USER 2 /* userspace addressable */
-1
arch/xtensa/include/asm/pgtable.h
··· 59 59 #define PTRS_PER_PGD 1024 60 60 #define PGD_ORDER 0 61 61 #define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE) 62 - #define FIRST_USER_ADDRESS 0UL 63 62 #define FIRST_USER_PGD_NR (FIRST_USER_ADDRESS >> PGDIR_SHIFT) 64 63 65 64 #ifdef CONFIG_MMU
+9
include/linux/pgtable.h
··· 29 29 #endif 30 30 31 31 /* 32 + * This defines the first usable user address. Platforms 33 + * can override its value with custom FIRST_USER_ADDRESS 34 + * defined in their respective <asm/pgtable.h>. 35 + */ 36 + #ifndef FIRST_USER_ADDRESS 37 + #define FIRST_USER_ADDRESS 0UL 38 + #endif 39 + 40 + /* 32 41 * A page table page can be thought of an array like this: pXd_t[PTRS_PER_PxD] 33 42 * 34 43 * The pXx_index() functions return the index of the entry in the page