Skip to content

Commit

Permalink
mm/vma: define a default value for VM_DATA_DEFAULT_FLAGS
Browse files Browse the repository at this point in the history
There are many platforms with exact same value for VM_DATA_DEFAULT_FLAGS
This creates a default value for VM_DATA_DEFAULT_FLAGS in line with the
existing VM_STACK_DEFAULT_FLAGS.  While here, also define some more
macros with standard VMA access flag combinations that are used
frequently across many platforms.  Apart from simplification, this
reduces code duplication as well.

Signed-off-by: Anshuman Khandual <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: Vlastimil Babka <[email protected]>
Acked-by: Geert Uytterhoeven <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Vineet Gupta <[email protected]>
Cc: Russell King <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Mark Salter <[email protected]>
Cc: Guo Ren <[email protected]>
Cc: Yoshinori Sato <[email protected]>
Cc: Brian Cain <[email protected]>
Cc: Tony Luck <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Ralf Baechle <[email protected]>
Cc: Paul Burton <[email protected]>
Cc: Nick Hu <[email protected]>
Cc: Ley Foon Tan <[email protected]>
Cc: Jonas Bonn <[email protected]>
Cc: "James E.J. Bottomley" <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Paul Walmsley <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Rich Felker <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Guan Xuetao <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Jeff Dike <[email protected]>
Cc: Chris Zankel <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Anshuman Khandual authored and torvalds committed Apr 10, 2020
1 parent 8cd3984 commit c62da0c
Show file tree
Hide file tree
Showing 28 changed files with 31 additions and 89 deletions.
3 changes: 0 additions & 3 deletions arch/alpha/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ typedef struct page *pgtable_t;
#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
#endif /* CONFIG_DISCONTIGMEM */

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

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

Expand Down
2 changes: 1 addition & 1 deletion arch/arc/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ typedef pte_t * pgtable_t;
#define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr))

/* Default Permissions for stack/heaps pages (Non Executable) */
#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC

#define WANT_PAGE_VIRTUAL 1

Expand Down
4 changes: 1 addition & 3 deletions arch/arm/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ extern int pfn_valid(unsigned long);

#endif /* !__ASSEMBLY__ */

#define VM_DATA_DEFAULT_FLAGS \
(((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC

#include <asm-generic/getorder.h>

Expand Down
4 changes: 1 addition & 3 deletions arch/arm64/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ extern int pfn_valid(unsigned long);

#endif /* !__ASSEMBLY__ */

#define VM_DATA_DEFAULT_FLAGS \
(((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC

#include <asm-generic/getorder.h>

Expand Down
5 changes: 1 addition & 4 deletions arch/c6x/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
#ifndef _ASM_C6X_PAGE_H
#define _ASM_C6X_PAGE_H

#define VM_DATA_DEFAULT_FLAGS \
(VM_READ | VM_WRITE | \
((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC

#include <asm-generic/page.h>

Expand Down
3 changes: 0 additions & 3 deletions arch/csky/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ extern unsigned long va_pa_offset;
PHYS_OFFSET_OFFSET)
#define virt_to_page(x) (mem_map + MAP_NR(x))

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#define pfn_to_kaddr(x) __va(PFN_PHYS(x))

#include <asm-generic/memory_model.h>
Expand Down
2 changes: 0 additions & 2 deletions arch/h8300/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <linux/types.h>

#define MAP_NR(addr) (((uintptr_t)(addr)-PAGE_OFFSET) >> PAGE_SHIFT)
#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#ifndef __ASSEMBLY__
extern unsigned long rom_length;
Expand Down
3 changes: 1 addition & 2 deletions arch/hexagon/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ struct page;
#define virt_to_page(kaddr) pfn_to_page(PFN_DOWN(__pa(kaddr)))

/* Default vm area behavior is non-executable. */
#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC

#define pfn_valid(pfn) ((pfn) < max_mapnr)
#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
Expand Down
5 changes: 1 addition & 4 deletions arch/ia64/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,7 @@ get_order (unsigned long size)

#define PAGE_OFFSET RGN_BASE(RGN_KERNEL)

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC | \
(((current->personality & READ_IMPLIES_EXEC) != 0) \
? VM_EXEC : 0))
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC

#define GATE_ADDR RGN_BASE(RGN_GATE)

Expand Down
3 changes: 0 additions & 3 deletions arch/m68k/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ extern unsigned long _ramend;
#define __phys_to_pfn(paddr) ((unsigned long)((paddr) >> PAGE_SHIFT))
#define __pfn_to_phys(pfn) PFN_PHYS(pfn)

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#include <asm-generic/getorder.h>

#endif /* _M68K_PAGE_H */
2 changes: 0 additions & 2 deletions arch/microblaze/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ extern int page_is_ram(unsigned long pfn);

#ifdef CONFIG_MMU

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#endif /* CONFIG_MMU */

#endif /* __KERNEL__ */
Expand Down
5 changes: 1 addition & 4 deletions arch/mips/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,7 @@ extern bool __virt_addr_valid(const volatile void *kaddr);
#define virt_addr_valid(kaddr) \
__virt_addr_valid((const volatile void *) (kaddr))

#define VM_DATA_DEFAULT_FLAGS \
(VM_READ | VM_WRITE | \
((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC

#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
Expand Down
3 changes: 0 additions & 3 deletions arch/nds32/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ typedef struct page *pgtable_t;

#endif /* !__ASSEMBLY__ */

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#endif /* __KERNEL__ */

#endif
3 changes: 1 addition & 2 deletions arch/nios2/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ static inline bool pfn_valid(unsigned long pfn)
# define virt_to_page(vaddr) pfn_to_page(PFN_DOWN(virt_to_phys(vaddr)))
# define virt_addr_valid(vaddr) pfn_valid(PFN_DOWN(virt_to_phys(vaddr)))

# define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
# define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC

#include <asm-generic/memory_model.h>

Expand Down
5 changes: 0 additions & 5 deletions arch/openrisc/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ typedef struct page *pgtable_t;

#endif /* __ASSEMBLY__ */


#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)


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

Expand Down
3 changes: 0 additions & 3 deletions arch/parisc/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ extern int npmem_ranges;
#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
#include <asm/pdc.h>
Expand Down
9 changes: 2 additions & 7 deletions arch/powerpc/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,8 @@ static inline bool pfn_valid(unsigned long pfn)
* and needs to be executable. This means the whole heap ends
* up being executable.
*/
#define VM_DATA_DEFAULT_FLAGS32 \
(((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
VM_READ | VM_WRITE | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_DEFAULT_FLAGS32 VM_DATA_FLAGS_TSK_EXEC
#define VM_DATA_DEFAULT_FLAGS64 VM_DATA_FLAGS_NON_EXEC

#ifdef __powerpc64__
#include <asm/page_64.h>
Expand Down
7 changes: 2 additions & 5 deletions arch/powerpc/include/asm/page_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ extern u64 ppc64_pft_size;
* stack by default, so in the absence of a PT_GNU_STACK program header
* we turn execute permission off.
*/
#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_STACK_DEFAULT_FLAGS32 VM_DATA_FLAGS_EXEC
#define VM_STACK_DEFAULT_FLAGS64 VM_DATA_FLAGS_NON_EXEC

#define VM_STACK_DEFAULT_FLAGS \
(is_32bit_task() ? \
Expand Down
3 changes: 1 addition & 2 deletions arch/riscv/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ extern phys_addr_t __phys_addr_symbol(unsigned long x);

#define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr)))

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC

#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
Expand Down
3 changes: 1 addition & 2 deletions arch/s390/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ int arch_make_page_accessible(struct page *page);

#define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr))

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_NON_EXEC

#include <asm-generic/memory_model.h>
#include <asm-generic/getorder.h>
Expand Down
3 changes: 0 additions & 3 deletions arch/sh/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ typedef struct page *pgtable_t;
#endif
#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

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

Expand Down
3 changes: 0 additions & 3 deletions arch/sparc/include/asm/page_32.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ extern unsigned long pfn_base;
#define pfn_valid(pfn) (((pfn) >= (pfn_base)) && (((pfn)-(pfn_base)) < max_mapnr))
#define virt_addr_valid(kaddr) ((((unsigned long)(kaddr)-PAGE_OFFSET)>>PAGE_SHIFT) < max_mapnr)

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

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

Expand Down
3 changes: 0 additions & 3 deletions arch/sparc/include/asm/page_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ extern unsigned long PAGE_OFFSET;

#endif /* !(__ASSEMBLY__) */

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#include <asm-generic/getorder.h>

#endif /* _SPARC64_PAGE_H */
3 changes: 0 additions & 3 deletions arch/unicore32/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ extern int pfn_valid(unsigned long);

#endif /* !__ASSEMBLY__ */

#define VM_DATA_DEFAULT_FLAGS \
(VM_READ | VM_WRITE | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#include <asm-generic/getorder.h>

#endif
4 changes: 1 addition & 3 deletions arch/x86/include/asm/page_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@

#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)

#define VM_DATA_DEFAULT_FLAGS \
(((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC

#define __PHYSICAL_START ALIGN(CONFIG_PHYSICAL_START, \
CONFIG_PHYSICAL_ALIGN)
Expand Down
10 changes: 2 additions & 8 deletions arch/x86/um/asm/vm-flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@

#ifdef CONFIG_X86_32

#define VM_DATA_DEFAULT_FLAGS \
(VM_READ | VM_WRITE | \
((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC

#else

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_STACK_DEFAULT_FLAGS (VM_GROWSDOWN | VM_READ | VM_WRITE | \
VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_STACK_DEFAULT_FLAGS (VM_GROWSDOWN | VM_DATA_FLAGS_EXEC)

#endif
#endif
3 changes: 0 additions & 3 deletions arch/xtensa/include/asm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,5 @@ static inline unsigned long ___pa(unsigned long va)

#endif /* __ASSEMBLY__ */

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#include <asm-generic/memory_model.h>
#endif /* _XTENSA_PAGE_H */
14 changes: 14 additions & 0 deletions include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,20 @@ extern unsigned int kobjsize(const void *objp);
/* Bits set in the VMA until the stack is in its final location */
#define VM_STACK_INCOMPLETE_SETUP (VM_RAND_READ | VM_SEQ_READ)

#define TASK_EXEC ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0)

/* Common data flag combinations */
#define VM_DATA_FLAGS_TSK_EXEC (VM_READ | VM_WRITE | TASK_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_FLAGS_NON_EXEC (VM_READ | VM_WRITE | VM_MAYREAD | \
VM_MAYWRITE | VM_MAYEXEC)
#define VM_DATA_FLAGS_EXEC (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#ifndef VM_DATA_DEFAULT_FLAGS /* arch can override this */
#define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_EXEC
#endif

#ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */
#define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
#endif
Expand Down

0 comments on commit c62da0c

Please sign in to comment.