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

Configure Feed

Select the types of activity you want to include in your feed.

powerpc/mm: Convert to default topdown mmap layout

Select CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT and
remove arch/powerpc/mm/mmap.c

This change reuses the generic framework added by
commit 67f3977f805b ("arm64, mm: move generic mmap layout
functions to mm") without any functional change.

Comparison between powerpc implementation and the generic one:
- mmap_is_legacy() is identical.
- arch_mmap_rnd() does exactly the same allthough it's written
slightly differently.
- MIN_GAP and MAX_GAP are identical.
- mmap_base() does the same but uses STACK_RND_MASK which provides
the same values as stack_maxrandom_size().
- arch_pick_mmap_layout() is identical.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/518f9def87d3c889d5958103e7463cf45a2f673d.1649523076.git.christophe.leroy@csgroup.eu

authored by

Christophe Leroy and committed by
Michael Ellerman
36e5f9ee 5cf7f9a0

+2 -109
+1 -1
arch/powerpc/Kconfig
··· 118 118 select ARCH_HAS_DEBUG_WX if STRICT_KERNEL_RWX 119 119 select ARCH_HAS_DEVMEM_IS_ALLOWED 120 120 select ARCH_HAS_DMA_MAP_DIRECT if PPC_PSERIES 121 - select ARCH_HAS_ELF_RANDOMIZE 122 121 select ARCH_HAS_FORTIFY_SOURCE 123 122 select ARCH_HAS_GCOV_PROFILE_ALL 124 123 select ARCH_HAS_HUGEPD if HUGETLB_PAGE ··· 153 154 select ARCH_USE_MEMTEST 154 155 select ARCH_USE_QUEUED_RWLOCKS if PPC_QUEUED_SPINLOCKS 155 156 select ARCH_USE_QUEUED_SPINLOCKS if PPC_QUEUED_SPINLOCKS 157 + select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT 156 158 select ARCH_WANT_IPC_PARSE_VERSION 157 159 select ARCH_WANT_IRQS_OFF_ACTIVATE_MM 158 160 select ARCH_WANT_LD_ORPHAN_WARN
-2
arch/powerpc/include/asm/processor.h
··· 392 392 393 393 #define spin_lock_prefetch(x) prefetchw(x) 394 394 395 - #define HAVE_ARCH_PICK_MMAP_LAYOUT 396 - 397 395 /* asm stubs */ 398 396 extern unsigned long isa300_idle_stop_noloss(unsigned long psscr_val); 399 397 extern unsigned long isa300_idle_stop_mayloss(unsigned long psscr_val);
+1 -1
arch/powerpc/mm/Makefile
··· 5 5 6 6 ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC) 7 7 8 - obj-y := fault.o mem.o pgtable.o mmap.o maccess.o pageattr.o \ 8 + obj-y := fault.o mem.o pgtable.o maccess.o pageattr.o \ 9 9 init_$(BITS).o pgtable_$(BITS).o \ 10 10 pgtable-frag.o ioremap.o ioremap_$(BITS).o \ 11 11 init-common.o mmu_context.o drmem.o \
-105
arch/powerpc/mm/mmap.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * flexible mmap layout support 4 - * 5 - * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina. 6 - * All Rights Reserved. 7 - * 8 - * Started by Ingo Molnar <mingo@elte.hu> 9 - */ 10 - 11 - #include <linux/personality.h> 12 - #include <linux/mm.h> 13 - #include <linux/random.h> 14 - #include <linux/sched/signal.h> 15 - #include <linux/sched/mm.h> 16 - #include <linux/elf-randomize.h> 17 - #include <linux/security.h> 18 - #include <linux/mman.h> 19 - 20 - /* 21 - * Top of mmap area (just below the process stack). 22 - * 23 - * Leave at least a ~128 MB hole. 24 - */ 25 - #define MIN_GAP (128*1024*1024) 26 - #define MAX_GAP (TASK_SIZE/6*5) 27 - 28 - static inline int mmap_is_legacy(struct rlimit *rlim_stack) 29 - { 30 - if (current->personality & ADDR_COMPAT_LAYOUT) 31 - return 1; 32 - 33 - if (rlim_stack->rlim_cur == RLIM_INFINITY) 34 - return 1; 35 - 36 - return sysctl_legacy_va_layout; 37 - } 38 - 39 - unsigned long arch_mmap_rnd(void) 40 - { 41 - unsigned long shift, rnd; 42 - 43 - shift = mmap_rnd_bits; 44 - #ifdef CONFIG_COMPAT 45 - if (is_32bit_task()) 46 - shift = mmap_rnd_compat_bits; 47 - #endif 48 - rnd = get_random_long() % (1ul << shift); 49 - 50 - return rnd << PAGE_SHIFT; 51 - } 52 - 53 - static inline unsigned long stack_maxrandom_size(void) 54 - { 55 - if (!(current->flags & PF_RANDOMIZE)) 56 - return 0; 57 - 58 - /* 8MB for 32bit, 1GB for 64bit */ 59 - if (is_32bit_task()) 60 - return (1<<23); 61 - else 62 - return (1<<30); 63 - } 64 - 65 - static inline unsigned long mmap_base(unsigned long rnd, 66 - struct rlimit *rlim_stack) 67 - { 68 - unsigned long gap = rlim_stack->rlim_cur; 69 - unsigned long pad = stack_maxrandom_size() + stack_guard_gap; 70 - 71 - /* Values close to RLIM_INFINITY can overflow. */ 72 - if (gap + pad > gap) 73 - gap += pad; 74 - 75 - if (gap < MIN_GAP) 76 - gap = MIN_GAP; 77 - else if (gap > MAX_GAP) 78 - gap = MAX_GAP; 79 - 80 - return PAGE_ALIGN(DEFAULT_MAP_WINDOW - gap - rnd); 81 - } 82 - 83 - /* 84 - * This function, called very early during the creation of a new 85 - * process VM image, sets up which VM layout function to use: 86 - */ 87 - void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) 88 - { 89 - unsigned long random_factor = 0UL; 90 - 91 - if (current->flags & PF_RANDOMIZE) 92 - random_factor = arch_mmap_rnd(); 93 - 94 - /* 95 - * Fall back to the standard layout if the personality 96 - * bit is set, or if the expected stack growth is unlimited: 97 - */ 98 - if (mmap_is_legacy(rlim_stack)) { 99 - mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; 100 - mm->get_unmapped_area = arch_get_unmapped_area; 101 - } else { 102 - mm->mmap_base = mmap_base(random_factor, rlim_stack); 103 - mm->get_unmapped_area = arch_get_unmapped_area_topdown; 104 - } 105 - }