asm-generic: clean up asm/mman.h
Subsystems (16)
cover asm-generic: clean up asm/mman.h
From: Arnd Bergmann <[email protected]>
While thinking about the changes to linux/mman.h in
https://lore.kernel.org/all/[email protected]/
I ended up trying to clean up the duplicate definitions in order to better see what's in there, and then I found a clash between two MAP_* flags.
Here is my current state, lightly tested. Please have a look at the last patch in particular.
Arnd
Arnd Bergmann (5):
asm-generic: cosmetic updates to uapi/asm/mman.h
asm-generic: move MAP_* flags from mman-common.h to mman.h
asm-generic: use asm-generic/mman-common.h on mips and xtensa
asm-generic: use asm-generic/mman-common.h on parisc and alpha [RFC] mm: Remove MAP_UNINITIALIZED support
Documentation/admin-guide/mm/nommu-mmap.rst | 10 +-- arch/alpha/include/uapi/asm/mman.h | 93 ++++++------------- arch/mips/include/uapi/asm/mman.h | 95 +++----------------- arch/parisc/include/uapi/asm/mman.h | 79 ++++------------- arch/powerpc/include/uapi/asm/mman.h | 11 +++ arch/sh/configs/rsk7264_defconfig | 1 - arch/sparc/include/uapi/asm/mman.h | 12 +++ arch/xtensa/include/uapi/asm/mman.h | 98 +++------------------ fs/binfmt_elf_fdpic.c | 3 +- include/linux/mman.h | 4 - include/uapi/asm-generic/mman-common.h | 31 +++---- include/uapi/asm-generic/mman.h | 17 ++++ include/uapi/linux/mman.h | 5 ++ mm/Kconfig | 22 ----- mm/nommu.c | 4 +- 15 files changed, 125 insertions(+), 360 deletions(-)
Signature · 34 lines
2.39.2 Cc: "Jason A. Donenfeld" <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Andreas Larsson <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Damien Le Moal <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Greg Ungerer <[email protected]> Cc: Helge Deller <[email protected]> Cc: Kees Cook <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Cc: Matt Turner <[email protected]> Cc: Max Filippov <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Nicholas Piggin <[email protected]> Cc: Richard Henderson <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Vladimir Murzin <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected]
PATCH 1/5 asm-generic: cosmetic updates to uapi/asm/mman.h
From: Arnd Bergmann <[email protected]>
All but four architectures use asm-generic/mman-common.h, and the differences between these are mostly accidental. Rearrange them slightly to make it possible to 'vimdiff' them to see the actual relevant differences:
- Move MADV_HWPOISON/MADV_SOFT_OFFLINE to the end of the list and ensure that all architectures include definitions
- Use the exact same amount of whitespace and leading digits in each architecture
- Synchronize comments, replacing historic defines that were never used with appropriate comments
- explicitly point out MAP_SYNC and MAP_UNINITIALIZED as unsupported
--- arch/alpha/include/uapi/asm/mman.h | 53 ++++++++++++------- arch/mips/include/uapi/asm/mman.h | 72 ++++++++++++-------------- arch/parisc/include/uapi/asm/mman.h | 50 +++++++++++------- arch/xtensa/include/uapi/asm/mman.h | 61 ++++++++++------------ include/uapi/asm-generic/mman-common.h | 8 ++- 5 files changed, 129 insertions(+), 115 deletions(-)
arch/alpha/include/uapi/asm/mman.h +33 -20
@@ -6,6 +6,8 @@#define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ #define PROT_SEM 0x8/* page may be used for atomic ops */ +/* 0x10 reserved for arch-specific use */ +/* 0x20 reserved for arch-specific use */ #define PROT_NONE 0x0/* page can not be accessed */ #define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ #define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */
@@ -15,41 +17,49 @@#define MAP_FIXED 0x100/* Interpret addr exactly */ #define MAP_ANONYMOUS 0x10/* don't use a file */ -/* not used by linux, but here to make sure we don't clash with OSF/1 defines */ -#define _MAP_HASSEMAPHORE 0x0200 -#define _MAP_INHERIT 0x0400 -#define _MAP_UNALIGNED 0x0800 - -/* These are linux-specific */ -#define MAP_GROWSDOWN 0x01000/* stack-like segment */ -#define MAP_DENYWRITE 0x02000/* ETXTBSY */ -#define MAP_EXECUTABLE 0x04000/* mark it as an executable */ -#define MAP_LOCKED 0x08000/* lock the mapping */ +/* 0x200 through 0x800 originally for OSF-1 compat */ +#define MAP_GROWSDOWN 0x1000/* stack-like segment */ +#define MAP_DENYWRITE 0x2000/* ETXTBSY */ +#define MAP_EXECUTABLE 0x4000/* mark it as an executable */ +#define MAP_LOCKED 0x8000/* pages are locked */ #define MAP_NORESERVE 0x10000/* don't check for reservations */ -#define MAP_POPULATE 0x20000/* populate (prefault) pagetables */ -#define MAP_NONBLOCK 0x40000/* do not block on IO */ -#define MAP_STACK 0x80000/* give out an address that is best suited for process/thread stacks */ -#define MAP_HUGETLB 0x100000/* create a huge page mapping */ + +#define MAP_POPULATE 0x020000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x040000/* do not block on IO */ +#define MAP_STACK 0x080000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x100000/* create a huge page mapping */ +/* MAP_SYNC not supported */ #define MAP_FIXED_NOREPLACE 0x200000/* MAP_FIXED which doesn't unmap underlying mapping */ -#define MS_ASYNC 1/* sync memory asynchronously */ -#define MS_SYNC 2/* synchronous memory sync */ -#define MS_INVALIDATE 4/* invalidate the caches */ +/* MAP_UNINITIALIZED not supported */ +/* +* Flags for mlockall +*/ #define MCL_CURRENT 8192/* lock all currently mapped pages */ #define MCL_FUTURE 16384/* lock all additions to address space */ #define MCL_ONFAULT 32768/* lock all pages that are faulted in */ +/* +* Flags for mlock +*/ #define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ +/* +* Flags for msync +*/ +#define MS_ASYNC 1/* sync memory asynchronously */ +#define MS_SYNC 2/* synchronous memory sync */ +#define MS_INVALIDATE 4/* invalidate the caches */ +#define MADV_NORMAL 0/* no further special treatment */ #define MADV_RANDOM 1/* expect random page references */ #define MADV_SEQUENTIAL 2/* expect sequential page references */ #define MADV_WILLNEED 3/* will need these pages */ -#define MADV_SPACEAVAIL 5/* ensure resources are available */ #define MADV_DONTNEED 6/* don't need these pages */ +/* originally MADV_SPACEAVAIL 5 */ -/* common/generic parameters */ +/* common parameters: try to keep these consistent across architectures */ #define MADV_FREE 8/* free pages only if memory pressure */ #define MADV_REMOVE 9/* remove these pages & resources */ #define MADV_DONTFORK 10/* don't inherit across fork */
@@ -63,7 +73,7 @@#define MADV_DONTDUMP 16/* Explicity exclude from the core dump, overrides the coredump filter bits */ -#define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ +#define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ #define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ #define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */
@@ -78,6 +88,9 @@#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ +#define MADV_HWPOISON 100/* poison a page for testing */ +#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ +/* compatibility flags */ #define MAP_FILE 0
arch/mips/include/uapi/asm/mman.h +32 -40
116 lines not on this page · raw message
arch/parisc/include/uapi/asm/mman.h +32 -18
86 lines not on this page · raw message
arch/xtensa/include/uapi/asm/mman.h +26 -35
102 lines not on this page · raw message
include/uapi/asm-generic/mman-common.h +6 -2
@@ -38,6 +38,9 @@*/ #define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ +/* +* Flags for msync +*/ #define MS_ASYNC 1/* sync memory asynchronously */ #define MS_INVALIDATE 2/* invalidate the caches */ #define MS_SYNC 4/* synchronous memory sync */
@@ -53,8 +56,6 @@#define MADV_REMOVE 9/* remove these pages & resources */ #define MADV_DONTFORK 10/* don't inherit across fork */ #define MADV_DOFORK 11/* do inherit across fork */ -#define MADV_HWPOISON 100/* poison a page for testing */ -#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ #define MADV_MERGEABLE 12/* KSM may merge identical pages */ #define MADV_UNMERGEABLE 13/* KSM may not merge identical pages */
@@ -79,6 +80,9 @@#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ +#define MADV_HWPOISON 100/* poison a page for testing */ +#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ +/* compatibility flags */ #define MAP_FILE 0
Signature · 1 line
2.39.2
PATCH 2/5 asm-generic: move MAP_* flags from mman-common.h to mman.h
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
powerpc and sparc include asm-generic/mman-common.h to get the MAP_* flags 0x008000 through 0x4000000, but those flags are all different on alpha, mips, parisc and xtensa.
Add duplicate definitions for these along with the MAP_* flags for 0x100 through 0x4000 that are already different on powerpc and sparc, as a preparation for actually sharing mman-common.h with all architectures.
--- arch/powerpc/include/uapi/asm/mman.h | 16 ++++++++++++++++ arch/sparc/include/uapi/asm/mman.h | 15 +++++++++++++++ include/uapi/asm-generic/mman-common.h | 16 ---------------- include/uapi/asm-generic/mman.h | 21 +++++++++++++++++++++ include/uapi/linux/mman.h | 5 +++++ 5 files changed, 57 insertions(+), 16 deletions(-)
arch/powerpc/include/uapi/asm/mman.h +16 -0
@@ -13,6 +13,11 @@#define PROT_SAO 0x10/* Strong Access Ordering */ +/* 0x01 - 0x03 are defined in linux/mman.h */ +#define MAP_TYPE 0x0f/* Mask for type of mapping */ +#define MAP_FIXED 0x10/* Interpret addr exactly */ +#define MAP_ANONYMOUS 0x20/* don't use a file */ +#define MAP_RENAME MAP_ANONYMOUS/* In SunOS terminology */ #define MAP_NORESERVE 0x40/* don't reserve swap pages */ #define MAP_LOCKED 0x80
@@ -21,6 +26,17 @@#define MAP_DENYWRITE 0x0800/* ETXTBSY */ #define MAP_EXECUTABLE 0x1000/* mark it as an executable */ +#define MAP_POPULATE 0x008000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x010000/* do not block on IO */ +#define MAP_STACK 0x020000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x040000/* create a huge page mapping */ +#define MAP_SYNC 0x080000/* perform synchronous page faults for the mapping */ +#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ + +#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be +* uninitialized */ + +#define MCL_CURRENT 0x2000/* lock all currently mapped pages */ #define MCL_FUTURE 0x4000/* lock all additions to address space */
arch/sparc/include/uapi/asm/mman.h +15 -0
@@ -8,6 +8,11 @@#define PROT_ADI 0x10/* ADI enabled */ +/* 0x01 - 0x03 are defined in linux/mman.h */ +#define MAP_TYPE 0x0f/* Mask for type of mapping */ +#define MAP_FIXED 0x10/* Interpret addr exactly */ +#define MAP_ANONYMOUS 0x20/* don't use a file */ +#define MAP_RENAME MAP_ANONYMOUS/* In SunOS terminology */ #define MAP_NORESERVE 0x40/* don't reserve swap pages */ #define MAP_INHERIT 0x80/* SunOS doesn't do this, but... */
@@ -18,6 +23,16 @@#define MAP_DENYWRITE 0x0800/* ETXTBSY */ #define MAP_EXECUTABLE 0x1000/* mark it as an executable */ +#define MAP_POPULATE 0x008000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x010000/* do not block on IO */ +#define MAP_STACK 0x020000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x040000/* create a huge page mapping */ +#define MAP_SYNC 0x080000/* perform synchronous page faults for the mapping */ +#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ + +#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be +* uninitialized */ +#define MCL_CURRENT 0x2000/* lock all currently mapped pages */ #define MCL_FUTURE 0x4000/* lock all additions to address space */ #define MCL_ONFAULT 0x8000/* lock all pages that are faulted in */
include/uapi/asm-generic/mman-common.h +0 -16
@@ -17,22 +17,6 @@#define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ #define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ -/* 0x01 - 0x03 are defined in linux/mman.h */ -#define MAP_TYPE 0x0f/* Mask for type of mapping */ -#define MAP_FIXED 0x10/* Interpret addr exactly */ -#define MAP_ANONYMOUS 0x20/* don't use a file */ - -/* 0x0100 - 0x4000 flags are defined in asm-generic/mman.h */ -#define MAP_POPULATE 0x008000/* populate (prefault) pagetables */ -#define MAP_NONBLOCK 0x010000/* do not block on IO */ -#define MAP_STACK 0x020000/* give out an address that is best suited for process/thread stacks */ -#define MAP_HUGETLB 0x040000/* create a huge page mapping */ -#define MAP_SYNC 0x080000/* perform synchronous page faults for the mapping */ -#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ - -#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be -* uninitialized */ -/* * Flags for mlock */
include/uapi/asm-generic/mman.h +21 -0
@@ -4,12 +4,33 @@#include <asm-generic/mman-common.h> +/* +* 0x01 - 0x03 are defined in linux/mman.h +* 0x04 - 0x200000 are architecture specific +* 0x200000 - 0x2000000 are available for common assignments in linux/mman.h +* 0x4000000 - 0x80000000 are used for hugepage encodings +*/ +#define MAP_TYPE 0x0f/* Mask for type of mapping */ +#define MAP_FIXED 0x10/* Interpret addr exactly */ +#define MAP_ANONYMOUS 0x20/* don't use a file */ +#define MAP_GROWSDOWN 0x0100/* stack-like segment */ #define MAP_DENYWRITE 0x0800/* ETXTBSY */ #define MAP_EXECUTABLE 0x1000/* mark it as an executable */ #define MAP_LOCKED 0x2000/* pages are locked */ #define MAP_NORESERVE 0x4000/* don't check for reservations */ +#define MAP_POPULATE 0x008000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x010000/* do not block on IO */ +#define MAP_STACK 0x020000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x040000/* create a huge page mapping */ +#define MAP_SYNC 0x080000/* perform synchronous page faults for the mapping */ +#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ + +#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be +* uninitialized */ + +/* * Bits [26:31] are reserved, see asm-generic/hugetlb_encode.h * for MAP_HUGETLB usage
include/uapi/linux/mman.h +5 -0
@@ -18,6 +18,11 @@#define MAP_PRIVATE 0x02/* Changes are private */ #define MAP_SHARED_VALIDATE 0x03/* share + validate extension flags */ #define MAP_DROPPABLE 0x08/* Zero memory under memory pressure. */ +/* +* 0x10 through 0x200000 are used for architecture specific definitions +* in asm/mman.h, numbers 0x400000 through 0x2000000 are currently +* available on all architectures. +*/ /* * Huge page size encoding when MAP_HUGETLB is specified, and a huge page
Signature · 1 line
2.39.2
PATCH 3/5 asm-generic: use asm-generic/mman-common.h on mips and xtensa
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
mips and xtensa have almost the same asm/mman.h, aside from an unintentional difference in MAP_UNINITIALIZED that has no effect in practice.
Now that the MAP_* flags are moved out of asm-generic/mman-common.h, the only difference from the its contents and the mips/xtensa version is the PROT_SEM definition that is one bit off from the rest.
Make the generic PROT_SEM definition conditional on it already being defined and then include that header from both architectures, to remove the bulk of the contents.
--- arch/alpha/include/uapi/asm/mman.h | 2 + arch/mips/include/uapi/asm/mman.h | 65 +------------------------ arch/parisc/include/uapi/asm/mman.h | 3 ++ arch/xtensa/include/uapi/asm/mman.h | 66 +------------------------- include/uapi/asm-generic/mman-common.h | 2 + 5 files changed, 9 insertions(+), 129 deletions(-)
arch/alpha/include/uapi/asm/mman.h +2 -0
@@ -5,7 +5,9 @@#define PROT_READ 0x1/* page can be read */ #define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ +#ifndef PROT_SEM /* different on mips and xtensa */ #define PROT_SEM 0x8/* page may be used for atomic ops */ +#endif /* 0x10 reserved for arch-specific use */ /* 0x20 reserved for arch-specific use */ #define PROT_NONE 0x0/* page can not be accessed */
arch/mips/include/uapi/asm/mman.h +1 -64
78 lines not on this page · raw message
arch/parisc/include/uapi/asm/mman.h +3 -0
@@ -2,10 +2,13 @@#ifndef __PARISC_MMAN_H__#define __PARISC_MMAN_H__ +#define PROT_READ 0x1/* page can be read */ #define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ +#ifndef PROT_SEM /* different on mips and xtensa */ #define PROT_SEM 0x8/* page may be used for atomic ops */ +#endif /* 0x10 reserved for arch-specific use */ /* 0x20 reserved for arch-specific use */ #define PROT_NONE 0x0/* page can not be accessed */
arch/xtensa/include/uapi/asm/mman.h +1 -65
82 lines not on this page · raw message
include/uapi/asm-generic/mman-common.h +2 -0
@@ -10,7 +10,9 @@#define PROT_READ 0x1/* page can be read */ #define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ +#ifndef PROT_SEM /* different on mips and xtensa */ #define PROT_SEM 0x8/* page may be used for atomic ops */ +#endif /* 0x10 reserved for arch-specific use */ /* 0x20 reserved for arch-specific use */ #define PROT_NONE 0x0/* page can not be accessed */
Signature · 1 line
2.39.2
PATCH 4/5 asm-generic: use asm-generic/mman-common.h on parisc and alpha
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
These two architectures each have their own set of MAP_* flags, like powerpc, mips and others do. In addition, the msync() flags are also different, here both define the same flags but in a different order. Finally, alpha also has a custom MADV_DONTNEED flag for madvise.
Make the generic MADV_DONTNEED and MS_* definitions conditional on them already being defined and then include the common header header from both architectures, to remove the bulk of the contents.
--- arch/alpha/include/uapi/asm/mman.h | 68 +++----------------------- arch/parisc/include/uapi/asm/mman.h | 66 +------------------------ include/uapi/asm-generic/mman-common.h | 5 ++ 3 files changed, 13 insertions(+), 126 deletions(-)
arch/alpha/include/uapi/asm/mman.h +6 -62
@@ -2,18 +2,6 @@#ifndef __ALPHA_MMAN_H__#define __ALPHA_MMAN_H__ -#define PROT_READ 0x1/* page can be read */ -#define PROT_WRITE 0x2/* page can be written */ -#define PROT_EXEC 0x4/* page can be executed */ -#ifndef PROT_SEM /* different on mips and xtensa */ -#define PROT_SEM 0x8/* page may be used for atomic ops */ -#endif -/* 0x10 reserved for arch-specific use */ -/* 0x20 reserved for arch-specific use */ -#define PROT_NONE 0x0/* page can not be accessed */ -#define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ -#define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ -/* 0x01 - 0x03 are defined in linux/mman.h */ #define MAP_TYPE 0x0f/* Mask for type of mapping (OSF/1 is _wrong_) */ #define MAP_FIXED 0x100/* Interpret addr exactly */
@@ -43,62 +31,18 @@#define MCL_ONFAULT 32768/* lock all pages that are faulted in */ /* -* Flags for mlock -*/ -#define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ - -/* -* Flags for msync +* Flags for msync, order is different from all others */ #define MS_ASYNC 1/* sync memory asynchronously */ #define MS_SYNC 2/* synchronous memory sync */ #define MS_INVALIDATE 4/* invalidate the caches */ -#define MADV_NORMAL 0/* no further special treatment */ -#define MADV_RANDOM 1/* expect random page references */ -#define MADV_SEQUENTIAL 2/* expect sequential page references */ -#define MADV_WILLNEED 3/* will need these pages */ -#define MADV_DONTNEED 6/* don't need these pages */ +/* +* Flags for madvise, 1 through 3 are normal +*/ /* originally MADV_SPACEAVAIL 5 */ +#define MADV_DONTNEED 6/* don't need these pages */ -/* common parameters: try to keep these consistent across architectures */ -#define MADV_FREE 8/* free pages only if memory pressure */ -#define MADV_REMOVE 9/* remove these pages & resources */ -#define MADV_DONTFORK 10/* don't inherit across fork */ -#define MADV_DOFORK 11/* do inherit across fork */ - -#define MADV_MERGEABLE 12/* KSM may merge identical pages */ -#define MADV_UNMERGEABLE 13/* KSM may not merge identical pages */ - -#define MADV_HUGEPAGE 14/* Worth backing with hugepages */ -#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ - -#define MADV_DONTDUMP 16/* Explicity exclude from the core dump, -overrides the coredump filter bits */ -#define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ - -#define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ -#define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ - -#define MADV_COLD 20/* deactivate these pages */ -#define MADV_PAGEOUT 21/* reclaim these pages */ - -#define MADV_POPULATE_READ 22/* populate (prefault) page tables readable */ -#define MADV_POPULATE_WRITE 23/* populate (prefault) page tables writable */ - -#define MADV_DONTNEED_LOCKED 24/* like DONTNEED, but drop locked pages too */ - -#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ - -#define MADV_HWPOISON 100/* poison a page for testing */ -#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ - -/* compatibility flags */ -#define MAP_FILE 0 - -#define PKEY_DISABLE_ACCESS 0x1 -#define PKEY_DISABLE_WRITE 0x2 -#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\ - PKEY_DISABLE_WRITE) +#include <asm-generic/mman-common.h> #endif /* __ALPHA_MMAN_H__ */
arch/parisc/include/uapi/asm/mman.h +2 -64
82 lines not on this page · raw message
include/uapi/asm-generic/mman-common.h +5 -0
@@ -27,15 +27,20 @@/* * Flags for msync */ +#ifndef MS_ASYNC /* different order on alpha and parisc */ #define MS_ASYNC 1/* sync memory asynchronously */ #define MS_INVALIDATE 2/* invalidate the caches */ #define MS_SYNC 4/* synchronous memory sync */ +#endif #define MADV_NORMAL 0/* no further special treatment */ #define MADV_RANDOM 1/* expect random page references */ #define MADV_SEQUENTIAL 2/* expect sequential page references */ #define MADV_WILLNEED 3/* will need these pages */ +/* 4 through 6 are different on alpha */ +#ifndef MADV_DONTNEED #define MADV_DONTNEED 4/* don't need these pages */ +#endif /* common parameters: try to keep these consistent across architectures */ #define MADV_FREE 8/* free pages only if memory pressure */
Signature · 1 line
2.39.2
RFC PATCH 5/5 mm: Remove MAP_UNINITIALIZED support
In reply to Arnd BergmannFrom: Arnd Bergmann <[email protected]>
MAP_UNINITIALIZED was added back in 2009 for NOMMU kernels, specifically for blackfin, which is long gone. MAP_HUGE_SHIFT/MAP_HUGE_MASK were added in 2012 for architectures supporting hugepages, which at the time did not overlap with the ones supporting NOMMU.
Adding the macro under an #ifdef was obviously a mistake, which Christoph Hellwig tried to address by making it unconditionally defined to 0x4000000 as part of the series to support RISC-V NOMMU kernels. At this point linux/mman.h contained two conflicting definitions for bit 26, though the two are still mutually exclusive at runtime in all supported configurations.
According to the commit 854e9ed09ded ("mm: support madvise(MADV_FREE)") description, it was previously used internally by facebook, which would have resulted in MAP_HUGE_1MB turning into MAP_HUGE_2MB with MAP_UNINITIALIZED enabled, and every other page size implying MAP_UNINITIALIZED. I assume there are no remaining out of tree users on MMU-enabled kernels today.
I do not see any sensible way to redefine the macros for the ABI in a way avoids breaking something. The only ideas so far are:
- do nothing, try to document the bug, hope for the best
- remove the kernel implementation and redefine MAP_UNINITIALIZED to zero in the header to silently turn it off for everyone. There are few NOMMU users left, and the ones that do use NOMMU usually turn off MMAP_ALLOW_UNINITIALIZED, as it still has the potential to cause bugs and even security issues on systems with a memory protection unit.
- remove both the implementation and the macro to force a build failure for anyone trying to use the feature. This way we can see who complains and whether we need to put it back in some form or change the userspace sources to no longer pass the flag.
Implement the third option here for the sake of discussion.
--- Documentation/admin-guide/mm/nommu-mmap.rst | 10 ++-------- arch/alpha/include/uapi/asm/mman.h | 2 -- arch/mips/include/uapi/asm/mman.h | 2 -- arch/parisc/include/uapi/asm/mman.h | 2 -- arch/powerpc/include/uapi/asm/mman.h | 5 ----- arch/sh/configs/rsk7264_defconfig | 1 - arch/sparc/include/uapi/asm/mman.h | 3 --- arch/xtensa/include/uapi/asm/mman.h | 3 --- fs/binfmt_elf_fdpic.c | 3 +-- include/linux/mman.h | 4 ---- include/uapi/asm-generic/mman.h | 4 ---- mm/Kconfig | 22 --------------------- mm/nommu.c | 4 +--- 13 files changed, 4 insertions(+), 61 deletions(-)
Documentation/admin-guide/mm/nommu-mmap.rst +2 -8
@@ -135,14 +135,8 @@ Further notes on no-MMU MMAP significant delays during a userspace malloc() as the C library does an anonymous mapping and the kernel then does a memset for the entire map. - However, for memory that isn't required to be precleared - such as that - returned by malloc() - mmap() can take a MAP_UNINITIALIZED flag to - indicate to the kernel that it shouldn't bother clearing the memory before - returning it. Note that CONFIG_MMAP_ALLOW_UNINITIALIZED must be enabled - to permit this, otherwise the flag will be ignored. - - uClibc uses this to speed up malloc(), and the ELF-FDPIC binfmt uses this - to allocate the brk and stack region. + Previously, Linux also supported a MAP_UNINITIALIZED flag to allocate + memory without clearing it, this is no longer support. (#) A list of all the private copy and anonymous mappings on the system is visible through /proc/maps in no-MMU mode.
arch/alpha/include/uapi/asm/mman.h +0 -2
@@ -21,8 +21,6 @@/* MAP_SYNC not supported */ #define MAP_FIXED_NOREPLACE 0x200000/* MAP_FIXED which doesn't unmap underlying mapping */ -/* MAP_UNINITIALIZED not supported */ -/* * Flags for mlockall */
arch/mips/include/uapi/asm/mman.h +0 -2
@@ -31,8 +31,6 @@/* MAP_SYNC not supported */ #define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ -/* MAP_UNINITIALIZED not supported */ -/* * Flags for mlockall */
arch/parisc/include/uapi/asm/mman.h +0 -2
@@ -20,8 +20,6 @@/* MAP_SYNC not supported */ #define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ -/* MAP_UNINITIALIZED not supported */ -/* * Flags for mlockall */
arch/powerpc/include/uapi/asm/mman.h +0 -5
@@ -33,11 +33,6 @@#define MAP_SYNC 0x080000/* perform synchronous page faults for the mapping */ #define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ -#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be -* uninitialized */ - - -#define MCL_CURRENT 0x2000/* lock all currently mapped pages */ #define MCL_FUTURE 0x4000/* lock all additions to address space */ #define MCL_ONFAULT 0x8000/* lock all pages that are faulted in */
arch/sh/configs/rsk7264_defconfig +0 -1
@@ -12,7 +12,6 @@ CONFIG_KALLSYMS_ALL=y CONFIG_EXPERT=y CONFIG_PERF_COUNTERS=y # CONFIG_VM_EVENT_COUNTERS is not set -CONFIG_MMAP_ALLOW_UNINITIALIZED=y CONFIG_PROFILING=y # CONFIG_BLK_DEV_BSG is not set CONFIG_PARTITION_ADVANCED=y
arch/sparc/include/uapi/asm/mman.h +0 -3
@@ -30,9 +30,6 @@#define MAP_SYNC 0x080000/* perform synchronous page faults for the mapping */ #define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ -#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be -* uninitialized */ -#define MCL_CURRENT 0x2000/* lock all currently mapped pages */ #define MCL_FUTURE 0x4000/* lock all additions to address space */ #define MCL_ONFAULT 0x8000/* lock all pages that are faulted in */
arch/xtensa/include/uapi/asm/mman.h +0 -3
@@ -36,9 +36,6 @@/* MAP_SYNC not supported */ #define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ -#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be -* uninitialized */ -/* * Flags for mlockall */
fs/binfmt_elf_fdpic.c +1 -2
@@ -418,8 +418,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) current->mm->start_brk =vm_mmap (NULL ,0 , stack_size, stack_prot,MAP_PRIVATE |MAP_ANONYMOUS | -MAP_UNINITIALIZED |MAP_GROWSDOWN , -0 ); +MAP_GROWSDOWN ,0 );if (IS_ERR_VALUE (current->mm->start_brk)) { retval = current->mm->start_brk;
include/linux/mman.h +0 -4
@@ -24,9 +24,6 @@#ifndef MAP_HUGE_1GB #define MAP_HUGE_1GB 0#endif -#ifndef MAP_UNINITIALIZED -#define MAP_UNINITIALIZED 0 -#endif #ifndef MAP_SYNC #define MAP_SYNC 0#endif
@@ -44,7 +41,6 @@ | MAP_ANONYMOUS \ |MAP_DENYWRITE \ |MAP_EXECUTABLE \ - |MAP_UNINITIALIZED \ |MAP_GROWSDOWN \ |MAP_LOCKED \ |MAP_NORESERVE \
include/uapi/asm-generic/mman.h +0 -4
@@ -27,10 +27,6 @@#define MAP_SYNC 0x080000/* perform synchronous page faults for the mapping */ #define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ -#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be -* uninitialized */ - -/* * Bits [26:31] are reserved, see asm-generic/hugetlb_encode.h * for MAP_HUGETLB usage
mm/Kconfig +0 -22
@@ -381,28 +381,6 @@ config COMPAT_BRK On non-ancient distros (post-2000 ones) N is usually a safe choice. -config MMAP_ALLOW_UNINITIALIZED - bool "Allow mmapped anonymous memory to be uninitialized" - depends on EXPERT && !MMU - default n - help - Normally, and according to the Linux spec, anonymous memory obtained - from mmap() has its contents cleared before it is passed to - userspace. Enabling this config option allows you to request that - mmap() skip that if it is given an MAP_UNINITIALIZED flag, thus - providing a huge performance boost. If this option is not enabled, - then the flag will be ignored. - - This is taken advantage of by uClibc's malloc(), and also by - ELF-FDPIC binfmt's brk and stack allocator. - - Because of the obvious security issues, this option should only be - enabled on embedded devices where you control what is run in - userspace. Since that isn't generally a problem on no-MMU systems, - it is normally safe to say Y here. - - See Documentation/admin-guide/mm/nommu-mmap.rst for more information. - config SELECT_MEMORY_MODEL def_bool y depends on ARCH_SELECT_MEMORY_MODEL
mm/nommu.c +1 -3
@@ -1172,9 +1172,7 @@ unsigned long do_mmap(struct file *file,add_nommu_region (region);/* clear anonymous mappings that don't ask for uninitialized data */ -if (!vma->vm_file && - (!IS_ENABLED (CONFIG_MMAP_ALLOW_UNINITIALIZED ) || - !(flags &MAP_UNINITIALIZED ))) +if (!vma->vm_file)memset ((void *)region->vm_start,0 , region->vm_end - region->vm_start);
Signature · 1 line
2.39.2
Re: [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support
Quoted 33 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
MAP_UNINITIALIZEDwas added back in 2009 for NOMMU kernels, specifically for blackfin, which is long gone. MAP_HUGE_SHIFT/MAP_HUGE_MASK were added in 2012 for architectures supporting hugepages, which at the time did not overlap with the ones supporting NOMMU.Adding the macro under an #ifdef was obviously a mistake, which Christoph Hellwig tried to address by making it unconditionally defined to
0x4000000as part of the series to support RISC-V NOMMU kernels. At this pointlinux/mman.hcontained two conflicting definitions for bit 26, though the two are still mutually exclusive at runtime in all supported configurations.According to the commit
854e9ed09ded("mm: supportmadvise(MADV_FREE)") description, it was previously used internally by facebook, which would have resulted inMAP_HUGE_1MBturning intoMAP_HUGE_2MBwithMAP_UNINITIALIZEDenabled, and every other page size implyingMAP_UNINITIALIZED. I assume there are no remaining out of tree users on MMU-enabled kernels today.I do not see any sensible way to redefine the macros for the ABI in a way avoids breaking something. The only ideas so far are:
- do nothing, try to document the bug, hope for the best
- remove the kernel implementation and redefine
MAP_UNINITIALIZEDto zero in the header to silently turn it off for everyone. There are few NOMMU users left, and the ones that do use NOMMU usually turn offMMAP_ALLOW_UNINITIALIZED, as it still has the potential to cause bugs and even security issues on systems with a memory protection unit.
Quoted 5 lines
- remove both the implementation and the macro to force a build failure for anyone trying to use the feature. This way we can see who complains and whether we need to put it back in some form or change the userspace sources to no longer pass the flag.
The first, uncontroversial step could indeed be to make MAP_UNINITIALIZED a nop, but still leave the definitions in mman.h etc around.
This is the same we did with MAP_DENYWRITE. There might be some weird user out there, and carelessly reusing the bit could result in trouble. (people might argue that they are not using it with MAP_HUGETLB, so it would work)
Going forward and removing MAP_UNINITIALIZED is a bit more controversial, but maybe there really isn't any other user around. Software that is not getting recompiled cannot be really identified by letting it rest in -next only.
My take would be to leave MAP_UNINITIALIZED in the headers in some form for documentation purposes.
Signature · 3 lines
Cheers, David / dhildenb
Helge Deller
maintainerRe: [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support
In reply to Arnd BergmannQuoted 33 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
MAP_UNINITIALIZEDwas added back in 2009 for NOMMU kernels, specifically for blackfin, which is long gone. MAP_HUGE_SHIFT/MAP_HUGE_MASK were added in 2012 for architectures supporting hugepages, which at the time did not overlap with the ones supporting NOMMU.Adding the macro under an #ifdef was obviously a mistake, which Christoph Hellwig tried to address by making it unconditionally defined to
0x4000000as part of the series to support RISC-V NOMMU kernels. At this pointlinux/mman.hcontained two conflicting definitions for bit 26, though the two are still mutually exclusive at runtime in all supported configurations.According to the commit
854e9ed09ded("mm: supportmadvise(MADV_FREE)") description, it was previously used internally by facebook, which would have resulted inMAP_HUGE_1MBturning intoMAP_HUGE_2MBwithMAP_UNINITIALIZEDenabled, and every other page size implyingMAP_UNINITIALIZED. I assume there are no remaining out of tree users on MMU-enabled kernels today.I do not see any sensible way to redefine the macros for the ABI in a way avoids breaking something. The only ideas so far are:
- do nothing, try to document the bug, hope for the best
- remove the kernel implementation and redefine
MAP_UNINITIALIZEDto zero in the header to silently turn it off for everyone. There are few NOMMU users left, and the ones that do use NOMMU usually turn offMMAP_ALLOW_UNINITIALIZED, as it still has the potential to cause bugs and even security issues on systems with a memory protection unit.
Quoted 6 lines
- remove both the implementation and the macro to force a build failure for anyone trying to use the feature. This way we can see who complains and whether we need to put it back in some form or change the userspace sources to no longer pass the flag.
Implement the third option here for the sake of discussion.
Usually I'd vote for option #2, which means remove the kernel implementation and redefine MAP_UNINITIALIZED to zero in the header.
A few years back this turned out to be the "most compatible" solution.
But today, and specifically regarding MAP_UNINITIALIZED, I think we should get rid of it now. This flag is useless and build issues will force people to drop it.
Helge
Helge Deller
maintainerRe: [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h
In reply to Arnd BergmannQuoted 42 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
All but four architectures use
asm-generic/mman-common.h, and the differences between these are mostly accidental. Rearrange them slightly to make it possible to 'vimdiff' them to see the actual relevant differences:- Move MADV_HWPOISON/MADV_SOFT_OFFLINE to the end of the list and ensure that all architectures include definitions
- Use the exact same amount of whitespace and leading digits in each architecture
- Synchronize comments, replacing historic defines that were never used with appropriate comments
- explicitly point out
MAP_SYNCandMAP_UNINITIALIZEDas unsupportedSigned-off-by Arnd Bergmann <[email protected]>--- arch/alpha/include/uapi/asm/mman.h | 53 ++++++++++++------- arch/mips/include/uapi/asm/mman.h | 72 ++++++++++++-------------- arch/parisc/include/uapi/asm/mman.h | 50 +++++++++++------- arch/xtensa/include/uapi/asm/mman.h | 61 ++++++++++------------ include/uapi/asm-generic/mman-common.h | 8 ++- 5 files changed, 129 insertions(+), 115 deletions(-)arch/alpha/include/uapi/asm/mman.h +2
-0@@ -6,6 +6,8 @@#define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ #define PROT_SEM 0x8/* page may be used for atomic ops */ +/* 0x10 reserved for arch-specific use */ +/* 0x20 reserved for arch-specific use */ #define PROT_NONE 0x0/* page can not be accessed */ #define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ #define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */
arch/alpha/include/uapi/asm/mman.h line 21
Quoted 7 lines
arch/alpha/include/uapi/asm/mman.h +0
-4@@ -15,41 +17,49 @@#define MAP_FIXED 0x100/* Interpret addr exactly */ #define MAP_ANONYMOUS 0x10/* don't use a file */ -/* not used by linux, but here to make sure we don't clash with OSF/1 defines */ -#define _MAP_HASSEMAPHORE 0x0200 -#define _MAP_INHERIT 0x0400 -#define _MAP_UNALIGNED 0x0800
I suggest to keep ^^ those. It's useful information which isn't easily visible otherwise.
Quoted 112 lines
arch/alpha/include/uapi/asm/mman.h +31
-15-/* These are linux-specific */ -#define MAP_GROWSDOWN 0x01000/* stack-like segment */ -#define MAP_DENYWRITE 0x02000/* ETXTBSY */ -#define MAP_EXECUTABLE 0x04000/* mark it as an executable */ -#define MAP_LOCKED 0x08000/* lock the mapping */ +/* 0x200 through 0x800 originally for OSF-1 compat */ +#define MAP_GROWSDOWN 0x1000/* stack-like segment */ +#define MAP_DENYWRITE 0x2000/* ETXTBSY */ +#define MAP_EXECUTABLE 0x4000/* mark it as an executable */ +#define MAP_LOCKED 0x8000/* pages are locked */ #define MAP_NORESERVE 0x10000/* don't check for reservations */ -#define MAP_POPULATE 0x20000/* populate (prefault) pagetables */ -#define MAP_NONBLOCK 0x40000/* do not block on IO */ -#define MAP_STACK 0x80000/* give out an address that is best suited for process/thread stacks */ -#define MAP_HUGETLB 0x100000/* create a huge page mapping */ + +#define MAP_POPULATE 0x020000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x040000/* do not block on IO */ +#define MAP_STACK 0x080000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x100000/* create a huge page mapping */ +/* MAP_SYNC not supported */ #define MAP_FIXED_NOREPLACE 0x200000/* MAP_FIXED which doesn't unmap underlying mapping */ -#define MS_ASYNC 1/* sync memory asynchronously */ -#define MS_SYNC 2/* synchronous memory sync */ -#define MS_INVALIDATE 4/* invalidate the caches */ +/* MAP_UNINITIALIZED not supported */ +/* +* Flags for mlockall +*/ #define MCL_CURRENT 8192/* lock all currently mapped pages */ #define MCL_FUTURE 16384/* lock all additions to address space */ #define MCL_ONFAULT 32768/* lock all pages that are faulted in */ +/* +* Flags for mlock +*/ #define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ +/* +* Flags for msync +*/ +#define MS_ASYNC 1/* sync memory asynchronously */ +#define MS_SYNC 2/* synchronous memory sync */ +#define MS_INVALIDATE 4/* invalidate the caches */ +#define MADV_NORMAL 0/* no further special treatment */ #define MADV_RANDOM 1/* expect random page references */ #define MADV_SEQUENTIAL 2/* expect sequential page references */ #define MADV_WILLNEED 3/* will need these pages */ -#define MADV_SPACEAVAIL 5/* ensure resources are available */ #define MADV_DONTNEED 6/* don't need these pages */ +/* originally MADV_SPACEAVAIL 5 */ -/* common/generic parameters */ +/* common parameters: try to keep these consistent across architectures */ #define MADV_FREE 8/* free pages only if memory pressure */ #define MADV_REMOVE 9/* remove these pages & resources */ #define MADV_DONTFORK 10/* don't inherit across fork */ @@ -63,7 +73,7 @@#define MADV_DONTDUMP 16/* Explicity exclude from the core dump, overrides the coredump filter bits */ -#define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ +#define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ #define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ #define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ @@ -78,6 +88,9 @@#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ +#define MADV_HWPOISON 100/* poison a page for testing */ +#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ +/* compatibility flags */ #define MAP_FILE 0arch/mips/include/uapi/asm/mman.h +6
-14@@ -9,53 +9,36 @@#ifndef _ASM_MMAN_H#define _ASM_MMAN_H -/* -* Protections are chosen from these bits, OR'd together. The -* implementation does not necessarily support PROT_EXEC or PROT_WRITE -* without PROT_READ. The only guarantees are that no writing will be -* allowed without PROT_WRITE and no access will be allowed for PROT_NONE. -*/ -#define PROT_NONE 0x00/* page can not be accessed */ -#define PROT_READ 0x01/* page can be read */ -#define PROT_WRITE 0x02/* page can be written */ -#define PROT_EXEC 0x04/* page can be executed */ -/* 0x08 reserved for PROT_EXEC_NOFLUSH */ +#define PROT_READ 0x1/* page can be read */ +#define PROT_WRITE 0x2/* page can be written */ +#define PROT_EXEC 0x4/* page can be executed */ +/* 0x8 reserved for PROT_EXEC_NOFLUSH */ #define PROT_SEM 0x10/* page may be used for atomic ops */ +/* 0x20 reserved for arch-specific use */ +#define PROT_NONE 0x0/* page can not be accessed */ #define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ #define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ -/* -* Flags for mmap -*/ /* 0x01 - 0x03 are defined in linux/mman.h */
arch/mips/include/uapi/asm/mman.h line 38
Quoted 10 lines
arch/mips/include/uapi/asm/mman.h +2
-7-#define MAP_TYPE 0x00f/* Mask for type of mapping */ -#define MAP_FIXED 0x010/* Interpret addr exactly */ +#define MAP_TYPE 0x0f/* Mask for type of mapping */ +#define MAP_FIXED 0x10/* Interpret addr exactly */ -/* not used by linux, but here to make sure we don't clash with ABI defines */ -#define MAP_RENAME 0x020/* Assign page to file */ -#define MAP_AUTOGROW 0x040/* File may grow by writing */ -#define MAP_LOCAL 0x080/* Copy on fork/sproc */ -#define MAP_AUTORSRV 0x100/* Logical swap reserved on demand */
same here. I think they should be preserved.
Quoted 207 lines
arch/mips/include/uapi/asm/mman.h +24
-19- -/* These are linux-specific */ +/* 0x20 through 0x100 originally reserved for other unix compat */ #define MAP_NORESERVE 0x0400/* don't check for reservations */ #define MAP_ANONYMOUS 0x0800/* don't use a file */ #define MAP_GROWSDOWN 0x1000/* stack-like segment */ #define MAP_DENYWRITE 0x2000/* ETXTBSY */ #define MAP_EXECUTABLE 0x4000/* mark it as an executable */ #define MAP_LOCKED 0x8000/* pages are locked */ -#define MAP_POPULATE 0x10000/* populate (prefault) pagetables */ -#define MAP_NONBLOCK 0x20000/* do not block on IO */ -#define MAP_STACK 0x40000/* give out an address that is best suited for process/thread stacks */ -#define MAP_HUGETLB 0x80000/* create a huge page mapping */ -#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ -/* -* Flags for msync -*/ -#define MS_ASYNC 0x0001/* sync memory asynchronously */ -#define MS_INVALIDATE 0x0002/* invalidate mappings & caches */ -#define MS_SYNC 0x0004/* synchronous memory sync */ +#define MAP_POPULATE 0x010000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x020000/* do not block on IO */ +#define MAP_STACK 0x040000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x080000/* create a huge page mapping */ +/* MAP_SYNC not supported */ +#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ + +/* MAP_UNINITIALIZED not supported */ /* * Flags for mlockall @@ -69,9 +52,16 @@*/ #define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ +/* +* Flags for msync +*/ +#define MS_ASYNC 1/* sync memory asynchronously */ +#define MS_INVALIDATE 2/* invalidate the caches */ +#define MS_SYNC 4/* synchronous memory sync */ +#define MADV_NORMAL 0/* no further special treatment */ #define MADV_RANDOM 1/* expect random page references */ -#define MADV_SEQUENTIAL 2/* expect sequential page references */ +#define MADV_SEQUENTIAL 2/* expect sequential page references */ #define MADV_WILLNEED 3/* will need these pages */ #define MADV_DONTNEED 4/* don't need these pages */ @@ -81,16 +71,15 @@#define MADV_DONTFORK 10/* don't inherit across fork */ #define MADV_DOFORK 11/* do inherit across fork */ -#define MADV_MERGEABLE 12/* KSM may merge identical pages */ +#define MADV_MERGEABLE 12/* KSM may merge identical pages */ #define MADV_UNMERGEABLE 13/* KSM may not merge identical pages */ -#define MADV_HWPOISON 100/* poison a page for testing */ #define MADV_HUGEPAGE 14/* Worth backing with hugepages */ -#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ +#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ -#define MADV_DONTDUMP 16/* Explicitly exclude from core dump, +#define MADV_DONTDUMP 16/* Explicity exclude from the core dump, overrides the coredump filter bits */ -#define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ +#define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ #define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ #define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ @@ -105,6 +94,9 @@#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ +#define MADV_HWPOISON 100/* poison a page for testing */ +#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ +/* compatibility flags */ #define MAP_FILE 0arch/parisc/include/uapi/asm/mman.h +32
-18@@ -6,6 +6,8 @@#define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ #define PROT_SEM 0x8/* page may be used for atomic ops */ +/* 0x10 reserved for arch-specific use */ +/* 0x20 reserved for arch-specific use */ #define PROT_NONE 0x0/* page can not be accessed */ #define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ #define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ @@ -20,30 +22,42 @@#define MAP_LOCKED 0x2000/* pages are locked */ #define MAP_NORESERVE 0x4000/* don't check for reservations */ #define MAP_GROWSDOWN 0x8000/* stack-like segment */ -#define MAP_POPULATE 0x10000/* populate (prefault) pagetables */ -#define MAP_NONBLOCK 0x20000/* do not block on IO */ -#define MAP_STACK 0x40000/* give out an address that is best suited for process/thread stacks */ -#define MAP_HUGETLB 0x80000/* create a huge page mapping */ -#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ -#define MAP_UNINITIALIZED 0/* uninitialized anonymous mmap */ -#define MS_SYNC 1/* synchronous memory sync */ -#define MS_ASYNC 2/* sync memory asynchronously */ -#define MS_INVALIDATE 4/* invalidate the caches */ +#define MAP_POPULATE 0x010000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x020000/* do not block on IO */ +#define MAP_STACK 0x040000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x080000/* create a huge page mapping */ +/* MAP_SYNC not supported */ +#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ + +/* MAP_UNINITIALIZED not supported */ +/* +* Flags for mlockall +*/ #define MCL_CURRENT 1/* lock all current mappings */ #define MCL_FUTURE 2/* lock all future mappings */ #define MCL_ONFAULT 4/* lock all pages that are faulted in */ +/* +* Flags for mlock +*/ #define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ -#define MADV_NORMAL 0/* no further special treatment */ -#define MADV_RANDOM 1/* expect random page references */ -#define MADV_SEQUENTIAL 2/* expect sequential page references */ -#define MADV_WILLNEED 3/* will need these pages */ -#define MADV_DONTNEED 4/* don't need these pages */ +/* +* Flags for msync +*/ +#define MS_SYNC 1/* synchronous memory sync */ +#define MS_ASYNC 2/* sync memory asynchronously */ +#define MS_INVALIDATE 4/* invalidate the caches */ + +#define MADV_NORMAL 0/* no further special treatment */ +#define MADV_RANDOM 1/* expect random page references */ +#define MADV_SEQUENTIAL 2/* expect sequential page references */ +#define MADV_WILLNEED 3/* will need these pages */ +#define MADV_DONTNEED 4/* don't need these pages */ -/* common/generic parameters */ +/* common parameters: try to keep these consistent across architectures */ #define MADV_FREE 8/* free pages only if memory pressure */ #define MADV_REMOVE 9/* remove these pages & resources */ #define MADV_DONTFORK 10/* don't inherit across fork */ @@ -53,11 +67,11 @@#define MADV_UNMERGEABLE 13/* KSM may not merge identical pages */ #define MADV_HUGEPAGE 14/* Worth backing with hugepages */ -#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ +#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ #define MADV_DONTDUMP 16/* Explicity exclude from the core dump, overrides the coredump filter bits */ -#define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ +#define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ #define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ #define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ @@ -72,7 +86,7 @@#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ -#define MADV_HWPOISON 100/* poison a page for testing */ +#define MADV_HWPOISON 100/* poison a page for testing */ #define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ /* compatibility flags */ arch/xtensa/include/uapi/asm/mman.h +4
-13@@ -15,57 +15,38 @@#ifndef _XTENSA_MMAN_H#define _XTENSA_MMAN_H -/* -* Protections are chosen from these bits, OR'd together. The -* implementation does not necessarily support PROT_EXEC or PROT_WRITE -* without PROT_READ. The only guarantees are that no writing will be -* allowed without PROT_WRITE and no access will be allowed for PROT_NONE. -*/ - -#define PROT_NONE 0x0/* page can not be accessed */ #define PROT_READ 0x1/* page can be read */ #define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ - +/* 0x8 reserved for arch-specific use */ #define PROT_SEM 0x10/* page may be used for atomic ops */ +/* 0x20 reserved for arch-specific use */ +#define PROT_NONE 0x0/* page can not be accessed */ #define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ -#define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end fo growsup vma */ +#define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ -/* -* Flags for mmap -*/ /* 0x01 - 0x03 are defined in linux/mman.h */
arch/xtensa/include/uapi/asm/mman.h line 45
Quoted 10 lines
arch/xtensa/include/uapi/asm/mman.h +2
-7-#define MAP_TYPE 0x00f/* Mask for type of mapping */ -#define MAP_FIXED 0x010/* Interpret addr exactly */ +#define MAP_TYPE 0x0f/* Mask for type of mapping */ +#define MAP_FIXED 0x10/* Interpret addr exactly */ -/* not used by linux, but here to make sure we don't clash with ABI defines */ -#define MAP_RENAME 0x020/* Assign page to file */ -#define MAP_AUTOGROW 0x040/* File may grow by writing */ -#define MAP_LOCAL 0x080/* Copy on fork/sproc */ -#define MAP_AUTORSRV 0x100/* Logical swap reserved on demand */
If xtensa had those, those should be kept as well IMHO.
Looks good otherwise.
Helge
Arnd Bergmann
maintainerRe: [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h
Quoted 9 lines · Helge Deller
arch/alpha/include/uapi/asm/mman.h line 21
Quoted 4 lines · Arnd Bergmann
arch/alpha/include/uapi/asm/mman.h +0
-4-/* not used by linux, but here to make sure we don't clash with OSF/1 defines */ -#define _MAP_HASSEMAPHORE 0x0200 -#define _MAP_INHERIT 0x0400 -#define _MAP_UNALIGNED 0x0800I suggest to keep ^^ those. It's useful information which isn't easily visible otherwise.
Fair enough. I removed them in order to bring the differences between files to an absolute minimum, but since at the end of the series the files only contain the map values, there is no real harm in keeping them, and they may help.
Quoted 7 lines
arch/mips/include/uapi/asm/mman.h line 38
Quoted 5 lines
arch/mips/include/uapi/asm/mman.h +0
-5-/* not used by linux, but here to make sure we don't clash with ABI defines */ -#define MAP_RENAME 0x020/* Assign page to file */ -#define MAP_AUTOGROW 0x040/* File may grow by writing */ -#define MAP_LOCAL 0x080/* Copy on fork/sproc */ -#define MAP_AUTORSRV 0x100/* Logical swap reserved on demand */ same here. I think they should be preserved.
Right.
Quoted 6 lines
Quoted 6 lines
/*
0x01-0x03are defined inlinux/mman.h*/arch/mips/include/uapi/asm/mman.h +2
-2-#define MAP_TYPE 0x00f/* Mask for type of mapping */ -#define MAP_FIXED 0x010/* Interpret addr exactly */ +#define MAP_TYPE 0x0f/* Mask for type of mapping */ +#define MAP_FIXED 0x10/* Interpret addr exactly */
Quoted 7 lines
arch/mips/include/uapi/asm/mman.h line 38
Quoted 5 lines
arch/mips/include/uapi/asm/mman.h +0
-5-/* not used by linux, but here to make sure we don't clash with ABI defines */ -#define MAP_RENAME 0x020/* Assign page to file */ -#define MAP_AUTOGROW 0x040/* File may grow by writing */ -#define MAP_LOCAL 0x080/* Copy on fork/sproc */ -#define MAP_AUTORSRV 0x100/* Logical swap reserved on demand */ If xtensa had those, those should be kept as well IMHO.
The thing with xtensa is that the file was blindly copied from mips, so I'm sure it never had these, but there may be value in keeping the two files in sync anyway. The only difference at the moment is MAP_UNINITIALIZED, which is potentially used on xtensa-nommu.
Let's see if Max Filippov has an opinion on this, otherwise I'd keep it the same as mips.
Arnd
Arnd Bergmann
maintainerRe: [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support
In reply to David HildenbrandQuoted 11 lines · David Hildenbrand
On 25.09.24 23:06, Arnd Bergmann wrote:
The first, uncontroversial step could indeed be to make
MAP_UNINITIALIZEDa nop, but still leave the definitions inmman.hetc around.This is the same we did with
MAP_DENYWRITE. There might be some weird user out there, and carelessly reusing the bit could result in trouble. (people might argue that they are not using it withMAP_HUGETLB, so it would work)
Quoted 7 lines
Going forward and removing
MAP_UNINITIALIZEDis a bit more controversial, but maybe there really isn't any other user around. Software that is not getting recompiled cannot be really identified by letting it rest in -next only.My take would be to leave
MAP_UNINITIALIZEDin the headers in some form for documentation purposes.
I don't think there is much point in doing this in multiple steps, either we want to break it at compile time or leave it silently doing nothing. There is also very little difference in practice because applications almost always use sys/mman.h instead of linux/mman.h.
FWIW, the main user appears to be the uClibc and uclibc-ng malloc() implementation for NOMMU targets:
https://git.uclibc.org/uClibc/commit/libc/stdlib/malloc/malloc.c?id=00673f93826bf1f
Both of these also define this constant itself as 0x4000000 for all architectures.
There are a few others that I could find with Debian codesearch:
https://sources.debian.org/src/monado/21.0.0+git2905.e26a272c1~dfsg1-2/src/external/tracy/client/tracy_rpmalloc.cpp/?hl=890#L889
https://sources.debian.org/src/systemtap/5.1-4/testsuite/systemtap.syscall/mmap.c/?hl=224#L224
https://sources.debian.org/src/fuzzel/1.11.1+ds-1/shm.c/?hl=488#L488
https://sources.debian.org/src/notcurses/3.0.7+dfsg.1-1/src/lib/fbuf.h/?hl=35#L35
https://sources.debian.org/src/lmms/1.2.2+dfsg1-6/src/3rdparty/rpmalloc/rpmalloc/rpmalloc/rpmalloc.c/?hl=1753#L1753
All of these will fall back to not passing MAP_UNINITIALIZED if it's not defined, which is what happens on glibc and musl.
Arnd
Richard Henderson
maintainerRe: [PATCH 3/5] asm-generic: use asm-generic/mman-common.h on mips and xtensa
In reply to Arnd BergmannQuoted 28 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
mips and xtensa have almost the same
asm/mman.h, aside from an unintentional difference inMAP_UNINITIALIZEDthat has no effect in practice.Now that the MAP_* flags are moved out of
asm-generic/mman-common.h, the only difference from the its contents and the mips/xtensa version is thePROT_SEMdefinition that is one bit off from the rest.Make the generic
PROT_SEMdefinition conditional on it already being defined and then include that header from both architectures, to remove the bulk of the contents.Signed-off-by Arnd Bergmann <[email protected]>--- arch/alpha/include/uapi/asm/mman.h | 2 + arch/mips/include/uapi/asm/mman.h | 65 +------------------------ arch/parisc/include/uapi/asm/mman.h | 3 ++ arch/xtensa/include/uapi/asm/mman.h | 66 +------------------------- include/uapi/asm-generic/mman-common.h | 2 + 5 files changed, 9 insertions(+), 129 deletions(-)arch/alpha/include/uapi/asm/mman.h +0
-0
arch/alpha/include/uapi/asm/mman.h line 10
Quoted 6 lines
arch/alpha/include/uapi/asm/mman.h +2
-0@@ -5,7 +5,9 @@#define PROT_READ 0x1/* page can be read */ #define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ +#ifndef PROT_SEM /* different on mips and xtensa */ #define PROT_SEM 0x8/* page may be used for atomic ops */ +#endif
Surely not conditional within arch/alpha/...
include/uapi/asm-generic/mman-common.h line 15
Quoted 9 lines
include/uapi/asm-generic/mman-common.h +2
-0@@ -10,7 +10,9 @@#define PROT_READ 0x1/* page can be read */ #define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ +#ifndef PROT_SEM /* different on mips and xtensa */ #define PROT_SEM 0x8/* page may be used for atomic ops */ +#endif
... only conditional here in asm-generic.
r~
Re: [PATCH 4/5] asm-generic: use asm-generic/mman-common.h on parisc and alpha
In reply to Arnd BergmannQuoted 11 lines · Arnd Bergmann
From: Arnd Bergmann<[email protected]>
These two architectures each have their own set of MAP_* flags, like powerpc, mips and others do. In addition, the
msync()flags are also different, here both define the same flags but in a different order. Finally, alpha also has a customMADV_DONTNEEDflag for madvise.Make the generic
MADV_DONTNEEDand MS_* definitions conditional on them already being defined and then include the common header header from both architectures, to remove the bulk of the contents.
Quoted 6 lines
Signed-off-by Arnd Bergmann<[email protected]>--- arch/alpha/include/uapi/asm/mman.h | 68 +++----------------------- arch/parisc/include/uapi/asm/mman.h | 66 +------------------------ include/uapi/asm-generic/mman-common.h | 5 ++ 3 files changed, 13 insertions(+), 126 deletions(-)
r~
Re: [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h
In reply to Arnd BergmannQuoted 13 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
All but four architectures use
asm-generic/mman-common.h, and the differences between these are mostly accidental. Rearrange them slightly to make it possible to 'vimdiff' them to see the actual relevant differences:- Move MADV_HWPOISON/MADV_SOFT_OFFLINE to the end of the list and ensure that all architectures include definitions
- Use the exact same amount of whitespace and leading digits in each architecture
Quoted 7 lines
- Synchronize comments, replacing historic defines that were never used with appropriate comments
- explicitly point out
MAP_SYNCandMAP_UNINITIALIZEDas unsupportedSigned-off-by Arnd Bergmann <[email protected]>
(Apologies for delay in response!)
Notwithstanding Helge's comments, this looks good to me - thanks very much for taking a look at this!)
Quoted 473 lines
--- arch/alpha/include/uapi/asm/mman.h | 53 ++++++++++++------- arch/mips/include/uapi/asm/mman.h | 72 ++++++++++++-------------- arch/parisc/include/uapi/asm/mman.h | 50 +++++++++++------- arch/xtensa/include/uapi/asm/mman.h | 61 ++++++++++------------ include/uapi/asm-generic/mman-common.h | 8 ++- 5 files changed, 129 insertions(+), 115 deletions(-)arch/alpha/include/uapi/asm/mman.h +33
-20@@ -6,6 +6,8 @@#define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ #define PROT_SEM 0x8/* page may be used for atomic ops */ +/* 0x10 reserved for arch-specific use */ +/* 0x20 reserved for arch-specific use */ #define PROT_NONE 0x0/* page can not be accessed */ #define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ #define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ @@ -15,41 +17,49 @@#define MAP_FIXED 0x100/* Interpret addr exactly */ #define MAP_ANONYMOUS 0x10/* don't use a file */ -/* not used by linux, but here to make sure we don't clash with OSF/1 defines */ -#define _MAP_HASSEMAPHORE 0x0200 -#define _MAP_INHERIT 0x0400 -#define _MAP_UNALIGNED 0x0800 - -/* These are linux-specific */ -#define MAP_GROWSDOWN 0x01000/* stack-like segment */ -#define MAP_DENYWRITE 0x02000/* ETXTBSY */ -#define MAP_EXECUTABLE 0x04000/* mark it as an executable */ -#define MAP_LOCKED 0x08000/* lock the mapping */ +/* 0x200 through 0x800 originally for OSF-1 compat */ +#define MAP_GROWSDOWN 0x1000/* stack-like segment */ +#define MAP_DENYWRITE 0x2000/* ETXTBSY */ +#define MAP_EXECUTABLE 0x4000/* mark it as an executable */ +#define MAP_LOCKED 0x8000/* pages are locked */ #define MAP_NORESERVE 0x10000/* don't check for reservations */ -#define MAP_POPULATE 0x20000/* populate (prefault) pagetables */ -#define MAP_NONBLOCK 0x40000/* do not block on IO */ -#define MAP_STACK 0x80000/* give out an address that is best suited for process/thread stacks */ -#define MAP_HUGETLB 0x100000/* create a huge page mapping */ + +#define MAP_POPULATE 0x020000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x040000/* do not block on IO */ +#define MAP_STACK 0x080000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x100000/* create a huge page mapping */ +/* MAP_SYNC not supported */ #define MAP_FIXED_NOREPLACE 0x200000/* MAP_FIXED which doesn't unmap underlying mapping */ -#define MS_ASYNC 1/* sync memory asynchronously */ -#define MS_SYNC 2/* synchronous memory sync */ -#define MS_INVALIDATE 4/* invalidate the caches */ +/* MAP_UNINITIALIZED not supported */ +/* +* Flags for mlockall +*/ #define MCL_CURRENT 8192/* lock all currently mapped pages */ #define MCL_FUTURE 16384/* lock all additions to address space */ #define MCL_ONFAULT 32768/* lock all pages that are faulted in */ +/* +* Flags for mlock +*/ #define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ +/* +* Flags for msync +*/ +#define MS_ASYNC 1/* sync memory asynchronously */ +#define MS_SYNC 2/* synchronous memory sync */ +#define MS_INVALIDATE 4/* invalidate the caches */ +#define MADV_NORMAL 0/* no further special treatment */ #define MADV_RANDOM 1/* expect random page references */ #define MADV_SEQUENTIAL 2/* expect sequential page references */ #define MADV_WILLNEED 3/* will need these pages */ -#define MADV_SPACEAVAIL 5/* ensure resources are available */ #define MADV_DONTNEED 6/* don't need these pages */ +/* originally MADV_SPACEAVAIL 5 */ -/* common/generic parameters */ +/* common parameters: try to keep these consistent across architectures */ #define MADV_FREE 8/* free pages only if memory pressure */ #define MADV_REMOVE 9/* remove these pages & resources */ #define MADV_DONTFORK 10/* don't inherit across fork */ @@ -63,7 +73,7 @@#define MADV_DONTDUMP 16/* Explicity exclude from the core dump, overrides the coredump filter bits */ -#define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ +#define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ #define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ #define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ @@ -78,6 +88,9 @@#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ +#define MADV_HWPOISON 100/* poison a page for testing */ +#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ +/* compatibility flags */ #define MAP_FILE 0arch/mips/include/uapi/asm/mman.h +32
-40@@ -9,53 +9,36 @@#ifndef _ASM_MMAN_H#define _ASM_MMAN_H -/* -* Protections are chosen from these bits, OR'd together. The -* implementation does not necessarily support PROT_EXEC or PROT_WRITE -* without PROT_READ. The only guarantees are that no writing will be -* allowed without PROT_WRITE and no access will be allowed for PROT_NONE. -*/ -#define PROT_NONE 0x00/* page can not be accessed */ -#define PROT_READ 0x01/* page can be read */ -#define PROT_WRITE 0x02/* page can be written */ -#define PROT_EXEC 0x04/* page can be executed */ -/* 0x08 reserved for PROT_EXEC_NOFLUSH */ +#define PROT_READ 0x1/* page can be read */ +#define PROT_WRITE 0x2/* page can be written */ +#define PROT_EXEC 0x4/* page can be executed */ +/* 0x8 reserved for PROT_EXEC_NOFLUSH */ #define PROT_SEM 0x10/* page may be used for atomic ops */ +/* 0x20 reserved for arch-specific use */ +#define PROT_NONE 0x0/* page can not be accessed */ #define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ #define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ -/* -* Flags for mmap -*/ /* 0x01 - 0x03 are defined in linux/mman.h */ -#define MAP_TYPE 0x00f/* Mask for type of mapping */ -#define MAP_FIXED 0x010/* Interpret addr exactly */ +#define MAP_TYPE 0x0f/* Mask for type of mapping */ +#define MAP_FIXED 0x10/* Interpret addr exactly */ -/* not used by linux, but here to make sure we don't clash with ABI defines */ -#define MAP_RENAME 0x020/* Assign page to file */ -#define MAP_AUTOGROW 0x040/* File may grow by writing */ -#define MAP_LOCAL 0x080/* Copy on fork/sproc */ -#define MAP_AUTORSRV 0x100/* Logical swap reserved on demand */ - -/* These are linux-specific */ +/* 0x20 through 0x100 originally reserved for other unix compat */ #define MAP_NORESERVE 0x0400/* don't check for reservations */ #define MAP_ANONYMOUS 0x0800/* don't use a file */ #define MAP_GROWSDOWN 0x1000/* stack-like segment */ #define MAP_DENYWRITE 0x2000/* ETXTBSY */ #define MAP_EXECUTABLE 0x4000/* mark it as an executable */ #define MAP_LOCKED 0x8000/* pages are locked */ -#define MAP_POPULATE 0x10000/* populate (prefault) pagetables */ -#define MAP_NONBLOCK 0x20000/* do not block on IO */ -#define MAP_STACK 0x40000/* give out an address that is best suited for process/thread stacks */ -#define MAP_HUGETLB 0x80000/* create a huge page mapping */ -#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ -/* -* Flags for msync -*/ -#define MS_ASYNC 0x0001/* sync memory asynchronously */ -#define MS_INVALIDATE 0x0002/* invalidate mappings & caches */ -#define MS_SYNC 0x0004/* synchronous memory sync */ +#define MAP_POPULATE 0x010000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x020000/* do not block on IO */ +#define MAP_STACK 0x040000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x080000/* create a huge page mapping */ +/* MAP_SYNC not supported */ +#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ + +/* MAP_UNINITIALIZED not supported */ /* * Flags for mlockall @@ -69,9 +52,16 @@*/ #define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ +/* +* Flags for msync +*/ +#define MS_ASYNC 1/* sync memory asynchronously */ +#define MS_INVALIDATE 2/* invalidate the caches */ +#define MS_SYNC 4/* synchronous memory sync */ +#define MADV_NORMAL 0/* no further special treatment */ #define MADV_RANDOM 1/* expect random page references */ -#define MADV_SEQUENTIAL 2/* expect sequential page references */ +#define MADV_SEQUENTIAL 2/* expect sequential page references */ #define MADV_WILLNEED 3/* will need these pages */ #define MADV_DONTNEED 4/* don't need these pages */ @@ -81,16 +71,15 @@#define MADV_DONTFORK 10/* don't inherit across fork */ #define MADV_DOFORK 11/* do inherit across fork */ -#define MADV_MERGEABLE 12/* KSM may merge identical pages */ +#define MADV_MERGEABLE 12/* KSM may merge identical pages */ #define MADV_UNMERGEABLE 13/* KSM may not merge identical pages */ -#define MADV_HWPOISON 100/* poison a page for testing */ #define MADV_HUGEPAGE 14/* Worth backing with hugepages */ -#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ +#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ -#define MADV_DONTDUMP 16/* Explicitly exclude from core dump, +#define MADV_DONTDUMP 16/* Explicity exclude from the core dump, overrides the coredump filter bits */ -#define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ +#define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ #define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ #define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ @@ -105,6 +94,9 @@#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ +#define MADV_HWPOISON 100/* poison a page for testing */ +#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ +/* compatibility flags */ #define MAP_FILE 0arch/parisc/include/uapi/asm/mman.h +32
-18@@ -6,6 +6,8 @@#define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ #define PROT_SEM 0x8/* page may be used for atomic ops */ +/* 0x10 reserved for arch-specific use */ +/* 0x20 reserved for arch-specific use */ #define PROT_NONE 0x0/* page can not be accessed */ #define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ #define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ @@ -20,30 +22,42 @@#define MAP_LOCKED 0x2000/* pages are locked */ #define MAP_NORESERVE 0x4000/* don't check for reservations */ #define MAP_GROWSDOWN 0x8000/* stack-like segment */ -#define MAP_POPULATE 0x10000/* populate (prefault) pagetables */ -#define MAP_NONBLOCK 0x20000/* do not block on IO */ -#define MAP_STACK 0x40000/* give out an address that is best suited for process/thread stacks */ -#define MAP_HUGETLB 0x80000/* create a huge page mapping */ -#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ -#define MAP_UNINITIALIZED 0/* uninitialized anonymous mmap */ -#define MS_SYNC 1/* synchronous memory sync */ -#define MS_ASYNC 2/* sync memory asynchronously */ -#define MS_INVALIDATE 4/* invalidate the caches */ +#define MAP_POPULATE 0x010000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x020000/* do not block on IO */ +#define MAP_STACK 0x040000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x080000/* create a huge page mapping */ +/* MAP_SYNC not supported */ +#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ + +/* MAP_UNINITIALIZED not supported */ +/* +* Flags for mlockall +*/ #define MCL_CURRENT 1/* lock all current mappings */ #define MCL_FUTURE 2/* lock all future mappings */ #define MCL_ONFAULT 4/* lock all pages that are faulted in */ +/* +* Flags for mlock +*/ #define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ -#define MADV_NORMAL 0/* no further special treatment */ -#define MADV_RANDOM 1/* expect random page references */ -#define MADV_SEQUENTIAL 2/* expect sequential page references */ -#define MADV_WILLNEED 3/* will need these pages */ -#define MADV_DONTNEED 4/* don't need these pages */ +/* +* Flags for msync +*/ +#define MS_SYNC 1/* synchronous memory sync */ +#define MS_ASYNC 2/* sync memory asynchronously */ +#define MS_INVALIDATE 4/* invalidate the caches */ + +#define MADV_NORMAL 0/* no further special treatment */ +#define MADV_RANDOM 1/* expect random page references */ +#define MADV_SEQUENTIAL 2/* expect sequential page references */ +#define MADV_WILLNEED 3/* will need these pages */ +#define MADV_DONTNEED 4/* don't need these pages */ -/* common/generic parameters */ +/* common parameters: try to keep these consistent across architectures */ #define MADV_FREE 8/* free pages only if memory pressure */ #define MADV_REMOVE 9/* remove these pages & resources */ #define MADV_DONTFORK 10/* don't inherit across fork */ @@ -53,11 +67,11 @@#define MADV_UNMERGEABLE 13/* KSM may not merge identical pages */ #define MADV_HUGEPAGE 14/* Worth backing with hugepages */ -#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ +#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ #define MADV_DONTDUMP 16/* Explicity exclude from the core dump, overrides the coredump filter bits */ -#define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ +#define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ #define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ #define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ @@ -72,7 +86,7 @@#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ -#define MADV_HWPOISON 100/* poison a page for testing */ +#define MADV_HWPOISON 100/* poison a page for testing */ #define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ /* compatibility flags */ arch/xtensa/include/uapi/asm/mman.h +26
-35@@ -15,57 +15,38 @@#ifndef _XTENSA_MMAN_H#define _XTENSA_MMAN_H -/* -* Protections are chosen from these bits, OR'd together. The -* implementation does not necessarily support PROT_EXEC or PROT_WRITE -* without PROT_READ. The only guarantees are that no writing will be -* allowed without PROT_WRITE and no access will be allowed for PROT_NONE. -*/ - -#define PROT_NONE 0x0/* page can not be accessed */ #define PROT_READ 0x1/* page can be read */ #define PROT_WRITE 0x2/* page can be written */ #define PROT_EXEC 0x4/* page can be executed */ - +/* 0x8 reserved for arch-specific use */ #define PROT_SEM 0x10/* page may be used for atomic ops */ +/* 0x20 reserved for arch-specific use */ +#define PROT_NONE 0x0/* page can not be accessed */ #define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ -#define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end fo growsup vma */ +#define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ -/* -* Flags for mmap -*/ /* 0x01 - 0x03 are defined in linux/mman.h */ -#define MAP_TYPE 0x00f/* Mask for type of mapping */ -#define MAP_FIXED 0x010/* Interpret addr exactly */ +#define MAP_TYPE 0x0f/* Mask for type of mapping */ +#define MAP_FIXED 0x10/* Interpret addr exactly */ -/* not used by linux, but here to make sure we don't clash with ABI defines */ -#define MAP_RENAME 0x020/* Assign page to file */ -#define MAP_AUTOGROW 0x040/* File may grow by writing */ -#define MAP_LOCAL 0x080/* Copy on fork/sproc */ -#define MAP_AUTORSRV 0x100/* Logical swap reserved on demand */ - -/* These are linux-specific */ +/* 0x20 through 0x100 originally reserved for other unix compat */ #define MAP_NORESERVE 0x0400/* don't check for reservations */ #define MAP_ANONYMOUS 0x0800/* don't use a file */ #define MAP_GROWSDOWN 0x1000/* stack-like segment */ #define MAP_DENYWRITE 0x2000/* ETXTBSY */ #define MAP_EXECUTABLE 0x4000/* mark it as an executable */ #define MAP_LOCKED 0x8000/* pages are locked */ -#define MAP_POPULATE 0x10000/* populate (prefault) pagetables */ -#define MAP_NONBLOCK 0x20000/* do not block on IO */ -#define MAP_STACK 0x40000/* give out an address that is best suited for process/thread stacks */ -#define MAP_HUGETLB 0x80000/* create a huge page mapping */ -#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ + +#define MAP_POPULATE 0x010000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x020000/* do not block on IO */ +#define MAP_STACK 0x040000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x080000/* create a huge page mapping */ +/* MAP_SYNC not supported */ +#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ +#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be * uninitialized */ -/* -* Flags for msync -*/ -#define MS_ASYNC 0x0001/* sync memory asynchronously */ -#define MS_INVALIDATE 0x0002/* invalidate mappings & caches */ -#define MS_SYNC 0x0004/* synchronous memory sync */ -/* * Flags for mlockall */ @@ -78,6 +59,13 @@*/ #define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ +/* +* Flags for msync +*/ +#define MS_ASYNC 1/* sync memory asynchronously */ +#define MS_INVALIDATE 2/* invalidate the caches */ +#define MS_SYNC 4/* synchronous memory sync */ +#define MADV_NORMAL 0/* no further special treatment */ #define MADV_RANDOM 1/* expect random page references */ #define MADV_SEQUENTIAL 2/* expect sequential page references */ @@ -98,7 +86,7 @@#define MADV_DONTDUMP 16/* Explicity exclude from the core dump, overrides the coredump filter bits */ -#define MADV_DODUMP 17/* Clear the MADV_NODUMP flag */ +#define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ #define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ #define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ @@ -113,6 +101,9 @@#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ +#define MADV_HWPOISON 100/* poison a page for testing */ +#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ +/* compatibility flags */ #define MAP_FILE 0include/uapi/asm-generic/mman-common.h +6
-3@@ -38,6 +38,9 @@*/ #define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ +/* +* Flags for msync +*/ #define MS_ASYNC 1/* sync memory asynchronously */ #define MS_INVALIDATE 2/* invalidate the caches */ #define MS_SYNC 4/* synchronous memory sync */ @@ -53,8 +56,6 @@#define MADV_REMOVE 9/* remove these pages & resources */ #define MADV_DONTFORK 10/* don't inherit across fork */ #define MADV_DOFORK 11/* do inherit across fork */ -#define MADV_HWPOISON 100/* poison a page for testing */ -#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ #define MADV_MERGEABLE 12/* KSM may merge identical pages */ #define MADV_UNMERGEABLE 13/* KSM may not merge identical pages */ @@ -79,6 +80,9 @@#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ +#define MADV_HWPOISON 100/* poison a page for testing */ +#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ +/* compatibility flags */ #define MAP_FILE 0 --2.39.2
Re: [PATCH 2/5] asm-generic: move MAP_* flags from mman-common.h to mman.h
In reply to Arnd BergmannQuoted 91 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
powerpc and sparc include
asm-generic/mman-common.hto get the MAP_* flags0x008000through0x4000000, but those flags are all different on alpha, mips, parisc and xtensa.Add duplicate definitions for these along with the MAP_* flags for
0x100through0x4000that are already different on powerpc and sparc, as a preparation for actually sharingmman-common.hwith all architectures.Signed-off-by Arnd Bergmann <[email protected]>--- arch/powerpc/include/uapi/asm/mman.h | 16 ++++++++++++++++ arch/sparc/include/uapi/asm/mman.h | 15 +++++++++++++++ include/uapi/asm-generic/mman-common.h | 16 ---------------- include/uapi/asm-generic/mman.h | 21 +++++++++++++++++++++ include/uapi/linux/mman.h | 5 +++++ 5 files changed, 57 insertions(+), 16 deletions(-)arch/powerpc/include/uapi/asm/mman.h +16
-0@@ -13,6 +13,11 @@#define PROT_SAO 0x10/* Strong Access Ordering */ +/* 0x01 - 0x03 are defined in linux/mman.h */ +#define MAP_TYPE 0x0f/* Mask for type of mapping */ +#define MAP_FIXED 0x10/* Interpret addr exactly */ +#define MAP_ANONYMOUS 0x20/* don't use a file */ +#define MAP_RENAME MAP_ANONYMOUS/* In SunOS terminology */ #define MAP_NORESERVE 0x40/* don't reserve swap pages */ #define MAP_LOCKED 0x80@@ -21,6 +26,17 @@#define MAP_DENYWRITE 0x0800/* ETXTBSY */ #define MAP_EXECUTABLE 0x1000/* mark it as an executable */ +#define MAP_POPULATE 0x008000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x010000/* do not block on IO */ +#define MAP_STACK 0x020000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x040000/* create a huge page mapping */ +#define MAP_SYNC 0x080000/* perform synchronous page faults for the mapping */ +#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ + +#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be +* uninitialized */ + +#define MCL_CURRENT 0x2000/* lock all currently mapped pages */ #define MCL_FUTURE 0x4000/* lock all additions to address space */ arch/sparc/include/uapi/asm/mman.h +15
-0@@ -8,6 +8,11 @@#define PROT_ADI 0x10/* ADI enabled */ +/* 0x01 - 0x03 are defined in linux/mman.h */ +#define MAP_TYPE 0x0f/* Mask for type of mapping */ +#define MAP_FIXED 0x10/* Interpret addr exactly */ +#define MAP_ANONYMOUS 0x20/* don't use a file */ +#define MAP_RENAME MAP_ANONYMOUS/* In SunOS terminology */ #define MAP_NORESERVE 0x40/* don't reserve swap pages */ #define MAP_INHERIT 0x80/* SunOS doesn't do this, but... */ @@ -18,6 +23,16 @@#define MAP_DENYWRITE 0x0800/* ETXTBSY */ #define MAP_EXECUTABLE 0x1000/* mark it as an executable */ +#define MAP_POPULATE 0x008000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x010000/* do not block on IO */ +#define MAP_STACK 0x020000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x040000/* create a huge page mapping */ +#define MAP_SYNC 0x080000/* perform synchronous page faults for the mapping */ +#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ + +#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be +* uninitialized */ +#define MCL_CURRENT 0x2000/* lock all currently mapped pages */ #define MCL_FUTURE 0x4000/* lock all additions to address space */ #define MCL_ONFAULT 0x8000/* lock all pages that are faulted in */ include/uapi/asm-generic/mman-common.h +0
-0
include/uapi/asm-generic/mman-common.h line 24
Quoted 8 lines
include/uapi/asm-generic/mman-common.h +0
-5@@ -17,22 +17,6 @@#define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ #define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ -/* 0x01 - 0x03 are defined in linux/mman.h */ -#define MAP_TYPE 0x0f/* Mask for type of mapping */ -#define MAP_FIXED 0x10/* Interpret addr exactly */ -#define MAP_ANONYMOUS 0x20/* don't use a file */ -
Hm, maybe I'm missing something, but why are we duplicating these?
Quoted 57 lines
include/uapi/asm-generic/mman-common.h +0
-11-/* 0x0100 - 0x4000 flags are defined in asm-generic/mman.h */ -#define MAP_POPULATE 0x008000/* populate (prefault) pagetables */ -#define MAP_NONBLOCK 0x010000/* do not block on IO */ -#define MAP_STACK 0x020000/* give out an address that is best suited for process/thread stacks */ -#define MAP_HUGETLB 0x040000/* create a huge page mapping */ -#define MAP_SYNC 0x080000/* perform synchronous page faults for the mapping */ -#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ - -#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be -* uninitialized */ -/* * Flags for mlock */ include/uapi/asm-generic/mman.h +21
-0@@ -4,12 +4,33 @@#include <asm-generic/mman-common.h> +/* +* 0x01 - 0x03 are defined in linux/mman.h +* 0x04 - 0x200000 are architecture specific +* 0x200000 - 0x2000000 are available for common assignments in linux/mman.h +* 0x4000000 - 0x80000000 are used for hugepage encodings +*/ +#define MAP_TYPE 0x0f/* Mask for type of mapping */ +#define MAP_FIXED 0x10/* Interpret addr exactly */ +#define MAP_ANONYMOUS 0x20/* don't use a file */ +#define MAP_GROWSDOWN 0x0100/* stack-like segment */ #define MAP_DENYWRITE 0x0800/* ETXTBSY */ #define MAP_EXECUTABLE 0x1000/* mark it as an executable */ #define MAP_LOCKED 0x2000/* pages are locked */ #define MAP_NORESERVE 0x4000/* don't check for reservations */ +#define MAP_POPULATE 0x008000/* populate (prefault) pagetables */ +#define MAP_NONBLOCK 0x010000/* do not block on IO */ +#define MAP_STACK 0x020000/* give out an address that is best suited for process/thread stacks */ +#define MAP_HUGETLB 0x040000/* create a huge page mapping */ +#define MAP_SYNC 0x080000/* perform synchronous page faults for the mapping */ +#define MAP_FIXED_NOREPLACE 0x100000/* MAP_FIXED which doesn't unmap underlying mapping */ + +#define MAP_UNINITIALIZED 0x4000000/* For anonymous mmap, memory could be +* uninitialized */ + +/* * Bits [26:31] are reserved, see asm-generic/hugetlb_encode.h * for MAP_HUGETLB usage include/uapi/linux/mman.h +0
-0
include/uapi/linux/mman.h line 25
Quoted 8 lines
include/uapi/linux/mman.h +5
-0@@ -18,6 +18,11 @@#define MAP_PRIVATE 0x02/* Changes are private */ #define MAP_SHARED_VALIDATE 0x03/* share + validate extension flags */ #define MAP_DROPPABLE 0x08/* Zero memory under memory pressure. */ +/* +* 0x10 through 0x200000 are used for architecture specific definitions +* in asm/mman.h, numbers 0x400000 through 0x2000000 are currently +* available on all architectures. +*/
Nice to add this documentation!
Quoted 6 lines
include/uapi/linux/mman.h +0
-1/* * Huge page size encoding when MAP_HUGETLB is specified, and a huge page -- 2.39.2
Re: [PATCH 4/5] asm-generic: use asm-generic/mman-common.h on parisc and alpha
In reply to Arnd BergmannQuoted 7 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
These two architectures each have their own set of MAP_* flags, like powerpc, mips and others do. In addition, the
msync()flags are also different, here both define the same flags but in a different order. Finally, alpha also has a customMADV_DONTNEEDflag for madvise.
Quoted 5 lines
Make the generic
MADV_DONTNEEDand MS_* definitions conditional on them already being defined and then include the common header header from both architectures, to remove the bulk of the contents.Signed-off-by Arnd Bergmann <[email protected]>
Lovely! Look at all that red :) Great work!
Quoted 198 lines
--- arch/alpha/include/uapi/asm/mman.h | 68 +++----------------------- arch/parisc/include/uapi/asm/mman.h | 66 +------------------------ include/uapi/asm-generic/mman-common.h | 5 ++ 3 files changed, 13 insertions(+), 126 deletions(-)arch/alpha/include/uapi/asm/mman.h +6
-62@@ -2,18 +2,6 @@#ifndef __ALPHA_MMAN_H__#define __ALPHA_MMAN_H__ -#define PROT_READ 0x1/* page can be read */ -#define PROT_WRITE 0x2/* page can be written */ -#define PROT_EXEC 0x4/* page can be executed */ -#ifndef PROT_SEM /* different on mips and xtensa */ -#define PROT_SEM 0x8/* page may be used for atomic ops */ -#endif -/* 0x10 reserved for arch-specific use */ -/* 0x20 reserved for arch-specific use */ -#define PROT_NONE 0x0/* page can not be accessed */ -#define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ -#define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ -/* 0x01 - 0x03 are defined in linux/mman.h */ #define MAP_TYPE 0x0f/* Mask for type of mapping (OSF/1 is _wrong_) */ #define MAP_FIXED 0x100/* Interpret addr exactly */ @@ -43,62 +31,18 @@#define MCL_ONFAULT 32768/* lock all pages that are faulted in */ /* -* Flags for mlock -*/ -#define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ - -/* -* Flags for msync +* Flags for msync, order is different from all others */ #define MS_ASYNC 1/* sync memory asynchronously */ #define MS_SYNC 2/* synchronous memory sync */ #define MS_INVALIDATE 4/* invalidate the caches */ -#define MADV_NORMAL 0/* no further special treatment */ -#define MADV_RANDOM 1/* expect random page references */ -#define MADV_SEQUENTIAL 2/* expect sequential page references */ -#define MADV_WILLNEED 3/* will need these pages */ -#define MADV_DONTNEED 6/* don't need these pages */ +/* +* Flags for madvise, 1 through 3 are normal +*/ /* originally MADV_SPACEAVAIL 5 */ +#define MADV_DONTNEED 6/* don't need these pages */ -/* common parameters: try to keep these consistent across architectures */ -#define MADV_FREE 8/* free pages only if memory pressure */ -#define MADV_REMOVE 9/* remove these pages & resources */ -#define MADV_DONTFORK 10/* don't inherit across fork */ -#define MADV_DOFORK 11/* do inherit across fork */ - -#define MADV_MERGEABLE 12/* KSM may merge identical pages */ -#define MADV_UNMERGEABLE 13/* KSM may not merge identical pages */ - -#define MADV_HUGEPAGE 14/* Worth backing with hugepages */ -#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ - -#define MADV_DONTDUMP 16/* Explicity exclude from the core dump, -overrides the coredump filter bits */ -#define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ - -#define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ -#define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ - -#define MADV_COLD 20/* deactivate these pages */ -#define MADV_PAGEOUT 21/* reclaim these pages */ - -#define MADV_POPULATE_READ 22/* populate (prefault) page tables readable */ -#define MADV_POPULATE_WRITE 23/* populate (prefault) page tables writable */ - -#define MADV_DONTNEED_LOCKED 24/* like DONTNEED, but drop locked pages too */ - -#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ - -#define MADV_HWPOISON 100/* poison a page for testing */ -#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ - -/* compatibility flags */ -#define MAP_FILE 0 - -#define PKEY_DISABLE_ACCESS 0x1 -#define PKEY_DISABLE_WRITE 0x2 -#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\ - PKEY_DISABLE_WRITE) +#include <asm-generic/mman-common.h> #endif /* __ALPHA_MMAN_H__ */ arch/parisc/include/uapi/asm/mman.h +2
-64@@ -2,19 +2,6 @@#ifndef __PARISC_MMAN_H__#define __PARISC_MMAN_H__ - -#define PROT_READ 0x1/* page can be read */ -#define PROT_WRITE 0x2/* page can be written */ -#define PROT_EXEC 0x4/* page can be executed */ -#ifndef PROT_SEM /* different on mips and xtensa */ -#define PROT_SEM 0x8/* page may be used for atomic ops */ -#endif -/* 0x10 reserved for arch-specific use */ -/* 0x20 reserved for arch-specific use */ -#define PROT_NONE 0x0/* page can not be accessed */ -#define PROT_GROWSDOWN 0x01000000/* mprotect flag: extend change to start of growsdown vma */ -#define PROT_GROWSUP 0x02000000/* mprotect flag: extend change to end of growsup vma */ -/* 0x01 - 0x03 are defined in linux/mman.h */ #define MAP_TYPE 0x2b/* Mask for type of mapping, includes bits 0x08 and 0x20 */ #define MAP_FIXED 0x04/* Interpret addr exactly */ @@ -43,61 +30,12 @@#define MCL_ONFAULT 4/* lock all pages that are faulted in */ /* -* Flags for mlock -*/ -#define MLOCK_ONFAULT 0x01/* Lock pages in range after they are faulted in, do not prefault */ - -/* -* Flags for msync +* Flags for msync, order is different from all others */ #define MS_SYNC 1/* synchronous memory sync */ #define MS_ASYNC 2/* sync memory asynchronously */ #define MS_INVALIDATE 4/* invalidate the caches */ -#define MADV_NORMAL 0/* no further special treatment */ -#define MADV_RANDOM 1/* expect random page references */ -#define MADV_SEQUENTIAL 2/* expect sequential page references */ -#define MADV_WILLNEED 3/* will need these pages */ -#define MADV_DONTNEED 4/* don't need these pages */ - -/* common parameters: try to keep these consistent across architectures */ -#define MADV_FREE 8/* free pages only if memory pressure */ -#define MADV_REMOVE 9/* remove these pages & resources */ -#define MADV_DONTFORK 10/* don't inherit across fork */ -#define MADV_DOFORK 11/* do inherit across fork */ - -#define MADV_MERGEABLE 12/* KSM may merge identical pages */ -#define MADV_UNMERGEABLE 13/* KSM may not merge identical pages */ - -#define MADV_HUGEPAGE 14/* Worth backing with hugepages */ -#define MADV_NOHUGEPAGE 15/* Not worth backing with hugepages */ - -#define MADV_DONTDUMP 16/* Explicity exclude from the core dump, -overrides the coredump filter bits */ -#define MADV_DODUMP 17/* Clear the MADV_DONTDUMP flag */ - -#define MADV_WIPEONFORK 18/* Zero memory on fork, child only */ -#define MADV_KEEPONFORK 19/* Undo MADV_WIPEONFORK */ - -#define MADV_COLD 20/* deactivate these pages */ -#define MADV_PAGEOUT 21/* reclaim these pages */ - -#define MADV_POPULATE_READ 22/* populate (prefault) page tables readable */ -#define MADV_POPULATE_WRITE 23/* populate (prefault) page tables writable */ - -#define MADV_DONTNEED_LOCKED 24/* like DONTNEED, but drop locked pages too */ - -#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ - -#define MADV_HWPOISON 100/* poison a page for testing */ -#define MADV_SOFT_OFFLINE 101/* soft offline page for testing */ - -/* compatibility flags */ -#define MAP_FILE 0 - -#define PKEY_DISABLE_ACCESS 0x1 -#define PKEY_DISABLE_WRITE 0x2 -#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\ - PKEY_DISABLE_WRITE) +#include <asm-generic/mman-common.h> #endif /* __PARISC_MMAN_H__ */ include/uapi/asm-generic/mman-common.h +1
-0@@ -27,15 +27,20 @@/* * Flags for msync */ +#ifndef MS_ASYNC /* different order on alpha and parisc */ #define MS_ASYNC 1/* sync memory asynchronously */ #define MS_INVALIDATE 2/* invalidate the caches */ #define MS_SYNC 4/* synchronous memory sync */
include/uapi/asm-generic/mman-common.h line 43
Quoted 10 lines
include/uapi/asm-generic/mman-common.h +4
-0+#endif #define MADV_NORMAL 0/* no further special treatment */ #define MADV_RANDOM 1/* expect random page references */ #define MADV_SEQUENTIAL 2/* expect sequential page references */ #define MADV_WILLNEED 3/* will need these pages */ +/* 4 through 6 are different on alpha */ +#ifndef MADV_DONTNEED #define MADV_DONTNEED 4/* don't need these pages */ +#endif
Rather nice to have these differences both de-duplicated and documented here...
Quoted 6 lines
include/uapi/asm-generic/mman-common.h +0
-1/* common parameters: try to keep these consistent across architectures */ #define MADV_FREE 8/* free pages only if memory pressure */ --2.39.2
Re: [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support
In reply to Arnd BergmannQuoted 42 lines · Arnd Bergmann
Quoted 11 lines · David Hildenbrand
On 25.09.24 23:06, Arnd Bergmann wrote:
The first, uncontroversial step could indeed be to make
MAP_UNINITIALIZEDa nop, but still leave the definitions inmman.hetc around.This is the same we did with
MAP_DENYWRITE. There might be some weird user out there, and carelessly reusing the bit could result in trouble. (people might argue that they are not using it withMAP_HUGETLB, so it would work)Quoted 7 lines
Going forward and removing
MAP_UNINITIALIZEDis a bit more controversial, but maybe there really isn't any other user around. Software that is not getting recompiled cannot be really identified by letting it rest in -next only.My take would be to leave
MAP_UNINITIALIZEDin the headers in some form for documentation purposes.I don't think there is much point in doing this in multiple steps, either we want to break it at compile time or leave it silently doing nothing. There is also very little difference in practice because applications almost always use
sys/mman.hinstead oflinux/mman.h.FWIW, the main user appears to be the uClibc and uclibc-ng
malloc()implementation for NOMMU targets:https://git.uclibc.org/uClibc/commit/libc/stdlib/malloc/malloc.c?id=00673f93826bf1f
Both of these also define this constant itself as
0x4000000for all architectures.There are a few others that I could find with Debian codesearch:
https://sources.debian.org/src/monado/21.0.0+git2905.e26a272c1~dfsg1-2/src/external/tracy/client/tracy_rpmalloc.cpp/?hl=890#L889
https://sources.debian.org/src/systemtap/5.1-4/testsuite/systemtap.syscall/mmap.c/?hl=224#L224
https://sources.debian.org/src/fuzzel/1.11.1+ds-1/shm.c/?hl=488#L488
https://sources.debian.org/src/notcurses/3.0.7+dfsg.1-1/src/lib/fbuf.h/?hl=35#L35
https://sources.debian.org/src/lmms/1.2.2+dfsg1-6/src/3rdparty/rpmalloc/rpmalloc/rpmalloc/rpmalloc.c/?hl=1753#L1753
Quoted 4 lines
All of these will fall back to not passing
MAP_UNINITIALIZEDif it's not defined, which is what happens on glibc and musl.Arnd
My point of view on this basis is to rip the bandaid off and get rid. Agree with DavidH it's worth keeping some kind of documentation that these existed around so somebody grepping and confused can see what happened...