linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] asm-generic: clean up asm/mman.h
@ 2024-09-25 21:06 Arnd Bergmann
  2024-09-25 21:06 ` [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h Arnd Bergmann
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: Arnd Bergmann @ 2024-09-25 21:06 UTC (permalink / raw)
  To: linux-mm
  Cc: Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R . Howlett, Lorenzo Stoakes, Matt Turner,
	Max Filippov, Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

From: Arnd Bergmann <arnd@arndb.de>

While thinking about the changes to linux/mman.h in
https://lore.kernel.org/all/20240923141943.133551-1-vincenzo.frascino@arm.com/
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(-)

-- 
2.39.2

Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Damien Le Moal <dlemoal@kernel.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Greg Ungerer <gerg@linux-m68k.org>
Cc: Helge Deller <deller@gmx.de>
Cc: Kees Cook <kees@kernel.org>
Cc: Liam R. Howlett <Liam.Howlett@oracle.com> 
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Vladimir Murzin <vladimir.murzin@arm.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@vger.kernel.org
Cc: linux-parisc@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-mm@kvack.org
Cc: linux-arch@vger.kernel.org


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h
  2024-09-25 21:06 [PATCH 0/5] asm-generic: clean up asm/mman.h Arnd Bergmann
@ 2024-09-25 21:06 ` Arnd Bergmann
  2024-09-26  9:21   ` Helge Deller
  2024-10-09 14:16   ` Lorenzo Stoakes
  2024-09-25 21:06 ` [PATCH 2/5] asm-generic: move MAP_* flags from mman-common.h to mman.h Arnd Bergmann
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 17+ messages in thread
From: Arnd Bergmann @ 2024-09-25 21:06 UTC (permalink / raw)
  To: linux-mm
  Cc: Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R . Howlett, Lorenzo Stoakes, Matt Turner,
	Max Filippov, Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

From: Arnd Bergmann <arnd@arndb.de>

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

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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(-)

diff --git a/arch/alpha/include/uapi/asm/mman.h b/arch/alpha/include/uapi/asm/mman.h
index 763929e814e9..8946a13ce858 100644
--- a/arch/alpha/include/uapi/asm/mman.h
+++ b/arch/alpha/include/uapi/asm/mman.h
@@ -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
 
diff --git a/arch/mips/include/uapi/asm/mman.h b/arch/mips/include/uapi/asm/mman.h
index 9c48d9a21aa0..399937cefaa6 100644
--- a/arch/mips/include/uapi/asm/mman.h
+++ b/arch/mips/include/uapi/asm/mman.h
@@ -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	0
 
diff --git a/arch/parisc/include/uapi/asm/mman.h b/arch/parisc/include/uapi/asm/mman.h
index 68c44f99bc93..80f4a55763a0 100644
--- a/arch/parisc/include/uapi/asm/mman.h
+++ b/arch/parisc/include/uapi/asm/mman.h
@@ -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 */
diff --git a/arch/xtensa/include/uapi/asm/mman.h b/arch/xtensa/include/uapi/asm/mman.h
index 1ff0c858544f..ad6bc56a7aef 100644
--- a/arch/xtensa/include/uapi/asm/mman.h
+++ b/arch/xtensa/include/uapi/asm/mman.h
@@ -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	0
 
diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h
index 6ce1f1ceb432..792ad5599d9c 100644
--- a/include/uapi/asm-generic/mman-common.h
+++ b/include/uapi/asm-generic/mman-common.h
@@ -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


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/5] asm-generic: move MAP_* flags from mman-common.h to mman.h
  2024-09-25 21:06 [PATCH 0/5] asm-generic: clean up asm/mman.h Arnd Bergmann
  2024-09-25 21:06 ` [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h Arnd Bergmann
@ 2024-09-25 21:06 ` Arnd Bergmann
  2024-10-09 14:25   ` Lorenzo Stoakes
  2024-09-25 21:06 ` [PATCH 3/5] asm-generic: use asm-generic/mman-common.h on mips and xtensa Arnd Bergmann
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 17+ messages in thread
From: Arnd Bergmann @ 2024-09-25 21:06 UTC (permalink / raw)
  To: linux-mm
  Cc: Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R . Howlett, Lorenzo Stoakes, Matt Turner,
	Max Filippov, Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

From: Arnd Bergmann <arnd@arndb.de>

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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(-)

diff --git a/arch/powerpc/include/uapi/asm/mman.h b/arch/powerpc/include/uapi/asm/mman.h
index c0c737215b00..d57b347c37fe 100644
--- a/arch/powerpc/include/uapi/asm/mman.h
+++ b/arch/powerpc/include/uapi/asm/mman.h
@@ -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 */
diff --git a/arch/sparc/include/uapi/asm/mman.h b/arch/sparc/include/uapi/asm/mman.h
index cec9f4109687..afb86698cdb1 100644
--- a/arch/sparc/include/uapi/asm/mman.h
+++ b/arch/sparc/include/uapi/asm/mman.h
@@ -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 */
diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h
index 792ad5599d9c..8d66d2dabaa8 100644
--- a/include/uapi/asm-generic/mman-common.h
+++ b/include/uapi/asm-generic/mman-common.h
@@ -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
  */
diff --git a/include/uapi/asm-generic/mman.h b/include/uapi/asm-generic/mman.h
index 57e8195d0b53..f26f9b4c03e1 100644
--- a/include/uapi/asm-generic/mman.h
+++ b/include/uapi/asm-generic/mman.h
@@ -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
diff --git a/include/uapi/linux/mman.h b/include/uapi/linux/mman.h
index e89d00528f2f..b70cb06dd7ef 100644
--- a/include/uapi/linux/mman.h
+++ b/include/uapi/linux/mman.h
@@ -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
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/5] asm-generic: use asm-generic/mman-common.h on mips and xtensa
  2024-09-25 21:06 [PATCH 0/5] asm-generic: clean up asm/mman.h Arnd Bergmann
  2024-09-25 21:06 ` [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h Arnd Bergmann
  2024-09-25 21:06 ` [PATCH 2/5] asm-generic: move MAP_* flags from mman-common.h to mman.h Arnd Bergmann
@ 2024-09-25 21:06 ` Arnd Bergmann
  2024-10-05 17:13   ` Richard Henderson
  2024-09-25 21:06 ` [PATCH 4/5] asm-generic: use asm-generic/mman-common.h on parisc and alpha Arnd Bergmann
  2024-09-25 21:06 ` [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support Arnd Bergmann
  4 siblings, 1 reply; 17+ messages in thread
From: Arnd Bergmann @ 2024-09-25 21:06 UTC (permalink / raw)
  To: linux-mm
  Cc: Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R . Howlett, Lorenzo Stoakes, Matt Turner,
	Max Filippov, Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

From: Arnd Bergmann <arnd@arndb.de>

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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(-)

diff --git a/arch/alpha/include/uapi/asm/mman.h b/arch/alpha/include/uapi/asm/mman.h
index 8946a13ce858..1f1c03c047ce 100644
--- a/arch/alpha/include/uapi/asm/mman.h
+++ b/arch/alpha/include/uapi/asm/mman.h
@@ -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 */
diff --git a/arch/mips/include/uapi/asm/mman.h b/arch/mips/include/uapi/asm/mman.h
index 399937cefaa6..6deb62db90de 100644
--- a/arch/mips/include/uapi/asm/mman.h
+++ b/arch/mips/include/uapi/asm/mman.h
@@ -9,15 +9,8 @@
 #ifndef _ASM_MMAN_H
 #define _ASM_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 */
 /*			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 */
 
 /* 0x01 - 0x03 are defined in linux/mman.h */
 #define MAP_TYPE	0x0f		/* Mask for type of mapping */
@@ -47,62 +40,6 @@
 #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 */
-
-/*
- * 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_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 /* _ASM_MMAN_H */
diff --git a/arch/parisc/include/uapi/asm/mman.h b/arch/parisc/include/uapi/asm/mman.h
index 80f4a55763a0..1cd5d816d4cf 100644
--- a/arch/parisc/include/uapi/asm/mman.h
+++ b/arch/parisc/include/uapi/asm/mman.h
@@ -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 */
diff --git a/arch/xtensa/include/uapi/asm/mman.h b/arch/xtensa/include/uapi/asm/mman.h
index ad6bc56a7aef..e713b8dc8587 100644
--- a/arch/xtensa/include/uapi/asm/mman.h
+++ b/arch/xtensa/include/uapi/asm/mman.h
@@ -11,19 +11,11 @@
  * Copyright (C) 1995 by Ralf Baechle
  * Copyright (C) 2001 - 2005 Tensilica Inc.
  */
-
 #ifndef _XTENSA_MMAN_H
 #define _XTENSA_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 */
 /*			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 of growsup vma */
 
 /* 0x01 - 0x03 are defined in linux/mman.h */
 #define MAP_TYPE	0x0f		/* Mask for type of mapping */
@@ -54,62 +46,6 @@
 #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 */
-
-/*
- * 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_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 /* _XTENSA_MMAN_H */
diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h
index 8d66d2dabaa8..2911dd14ef2a 100644
--- a/include/uapi/asm-generic/mman-common.h
+++ b/include/uapi/asm-generic/mman-common.h
@@ -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 */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 4/5] asm-generic: use asm-generic/mman-common.h on parisc and alpha
  2024-09-25 21:06 [PATCH 0/5] asm-generic: clean up asm/mman.h Arnd Bergmann
                   ` (2 preceding siblings ...)
  2024-09-25 21:06 ` [PATCH 3/5] asm-generic: use asm-generic/mman-common.h on mips and xtensa Arnd Bergmann
@ 2024-09-25 21:06 ` Arnd Bergmann
  2024-10-05 17:15   ` Richard Henderson
  2024-10-09 14:31   ` Lorenzo Stoakes
  2024-09-25 21:06 ` [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support Arnd Bergmann
  4 siblings, 2 replies; 17+ messages in thread
From: Arnd Bergmann @ 2024-09-25 21:06 UTC (permalink / raw)
  To: linux-mm
  Cc: Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R . Howlett, Lorenzo Stoakes, Matt Turner,
	Max Filippov, Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

From: Arnd Bergmann <arnd@arndb.de>

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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(-)

diff --git a/arch/alpha/include/uapi/asm/mman.h b/arch/alpha/include/uapi/asm/mman.h
index 1f1c03c047ce..fc8b74aa3f89 100644
--- a/arch/alpha/include/uapi/asm/mman.h
+++ b/arch/alpha/include/uapi/asm/mman.h
@@ -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__ */
diff --git a/arch/parisc/include/uapi/asm/mman.h b/arch/parisc/include/uapi/asm/mman.h
index 1cd5d816d4cf..3732950a5cd8 100644
--- a/arch/parisc/include/uapi/asm/mman.h
+++ b/arch/parisc/include/uapi/asm/mman.h
@@ -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__ */
diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h
index 2911dd14ef2a..81a14ed99197 100644
--- a/include/uapi/asm-generic/mman-common.h
+++ b/include/uapi/asm-generic/mman-common.h
@@ -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 */
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support
  2024-09-25 21:06 [PATCH 0/5] asm-generic: clean up asm/mman.h Arnd Bergmann
                   ` (3 preceding siblings ...)
  2024-09-25 21:06 ` [PATCH 4/5] asm-generic: use asm-generic/mman-common.h on parisc and alpha Arnd Bergmann
@ 2024-09-25 21:06 ` Arnd Bergmann
  2024-09-26  8:46   ` David Hildenbrand
  2024-09-26  9:18   ` Helge Deller
  4 siblings, 2 replies; 17+ messages in thread
From: Arnd Bergmann @ 2024-09-25 21:06 UTC (permalink / raw)
  To: linux-mm
  Cc: Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R . Howlett, Lorenzo Stoakes, Matt Turner,
	Max Filippov, Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

From: Arnd Bergmann <arnd@arndb.de>

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.

Link: https://git.uclibc.org/uClibc/commit/libc/stdlib/malloc/malloc.c?id=00673f93826bf1f
Link: https://lore.kernel.org/lkml/20190610221621.10938-4-hch@lst.de/
Link: https://lore.kernel.org/lkml/1352157848-29473-1-git-send-email-andi@firstfloor.org/
Link: https://lore.kernel.org/lkml/1448865583-2446-2-git-send-email-minchan@kernel.org/
Cc: Christoph Hellwig <hch@lst.de>
Cc: Damien Le Moal <dlemoal@kernel.org>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: linux-stm32@st-md-mailman.stormreply.com
Cc: Greg Ungerer <gerg@linux-m68k.org>
Cc: Vladimir Murzin <vladimir.murzin@arm.com>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 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(-)

diff --git a/Documentation/admin-guide/mm/nommu-mmap.rst b/Documentation/admin-guide/mm/nommu-mmap.rst
index 530fed08de2c..9434c2fa99ae 100644
--- a/Documentation/admin-guide/mm/nommu-mmap.rst
+++ b/Documentation/admin-guide/mm/nommu-mmap.rst
@@ -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.
diff --git a/arch/alpha/include/uapi/asm/mman.h b/arch/alpha/include/uapi/asm/mman.h
index fc8b74aa3f89..1099b17a4003 100644
--- a/arch/alpha/include/uapi/asm/mman.h
+++ b/arch/alpha/include/uapi/asm/mman.h
@@ -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
  */
diff --git a/arch/mips/include/uapi/asm/mman.h b/arch/mips/include/uapi/asm/mman.h
index 6deb62db90de..9463c9071268 100644
--- a/arch/mips/include/uapi/asm/mman.h
+++ b/arch/mips/include/uapi/asm/mman.h
@@ -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
  */
diff --git a/arch/parisc/include/uapi/asm/mman.h b/arch/parisc/include/uapi/asm/mman.h
index 3732950a5cd8..8d7f3a8912b3 100644
--- a/arch/parisc/include/uapi/asm/mman.h
+++ b/arch/parisc/include/uapi/asm/mman.h
@@ -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
  */
diff --git a/arch/powerpc/include/uapi/asm/mman.h b/arch/powerpc/include/uapi/asm/mman.h
index d57b347c37fe..48c734b4d201 100644
--- a/arch/powerpc/include/uapi/asm/mman.h
+++ b/arch/powerpc/include/uapi/asm/mman.h
@@ -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 */
diff --git a/arch/sh/configs/rsk7264_defconfig b/arch/sh/configs/rsk7264_defconfig
index e4ef259425c4..86421e2fec10 100644
--- a/arch/sh/configs/rsk7264_defconfig
+++ b/arch/sh/configs/rsk7264_defconfig
@@ -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
diff --git a/arch/sparc/include/uapi/asm/mman.h b/arch/sparc/include/uapi/asm/mman.h
index afb86698cdb1..e05ac492f9a8 100644
--- a/arch/sparc/include/uapi/asm/mman.h
+++ b/arch/sparc/include/uapi/asm/mman.h
@@ -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 */
diff --git a/arch/xtensa/include/uapi/asm/mman.h b/arch/xtensa/include/uapi/asm/mman.h
index e713b8dc8587..6fdf9f3e587a 100644
--- a/arch/xtensa/include/uapi/asm/mman.h
+++ b/arch/xtensa/include/uapi/asm/mman.h
@@ -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
  */
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 4fe5bb9f1b1f..82ba92d28ddf 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -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;
diff --git a/include/linux/mman.h b/include/linux/mman.h
index bcb201ab7a41..f606b2264cc0 100644
--- a/include/linux/mman.h
+++ b/include/linux/mman.h
@@ -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 \
diff --git a/include/uapi/asm-generic/mman.h b/include/uapi/asm-generic/mman.h
index f26f9b4c03e1..541be26ad947 100644
--- a/include/uapi/asm-generic/mman.h
+++ b/include/uapi/asm-generic/mman.h
@@ -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
diff --git a/mm/Kconfig b/mm/Kconfig
index 09aebca1cae3..7326820ba200 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -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
diff --git a/mm/nommu.c b/mm/nommu.c
index 385b0c15add8..793fa7303065 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -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);
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support
  2024-09-25 21:06 ` [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support Arnd Bergmann
@ 2024-09-26  8:46   ` David Hildenbrand
  2024-09-26 13:54     ` Arnd Bergmann
  2024-09-26  9:18   ` Helge Deller
  1 sibling, 1 reply; 17+ messages in thread
From: David Hildenbrand @ 2024-09-26  8:46 UTC (permalink / raw)
  To: Arnd Bergmann, linux-mm
  Cc: Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, Greg Ungerer, Helge Deller, Kees Cook,
	Liam R . Howlett, Lorenzo Stoakes, Matt Turner, Max Filippov,
	Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

On 25.09.24 23:06, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> 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.
> 

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.

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support
  2024-09-25 21:06 ` [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support Arnd Bergmann
  2024-09-26  8:46   ` David Hildenbrand
@ 2024-09-26  9:18   ` Helge Deller
  1 sibling, 0 replies; 17+ messages in thread
From: Helge Deller @ 2024-09-26  9:18 UTC (permalink / raw)
  To: Arnd Bergmann, linux-mm
  Cc: Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Kees Cook,
	Liam R . Howlett, Lorenzo Stoakes, Matt Turner, Max Filippov,
	Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

On 9/25/24 23:06, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> 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.

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h
  2024-09-25 21:06 ` [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h Arnd Bergmann
@ 2024-09-26  9:21   ` Helge Deller
  2024-09-26  9:41     ` Arnd Bergmann
  2024-10-09 14:16   ` Lorenzo Stoakes
  1 sibling, 1 reply; 17+ messages in thread
From: Helge Deller @ 2024-09-26  9:21 UTC (permalink / raw)
  To: Arnd Bergmann, linux-mm
  Cc: Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Kees Cook,
	Liam R . Howlett, Lorenzo Stoakes, Matt Turner, Max Filippov,
	Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

On 9/25/24 23:06, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> 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
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>   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(-)
>
> diff --git a/arch/alpha/include/uapi/asm/mman.h b/arch/alpha/include/uapi/asm/mman.h
> index 763929e814e9..8946a13ce858 100644
> --- a/arch/alpha/include/uapi/asm/mman.h
> +++ b/arch/alpha/include/uapi/asm/mman.h
> @@ -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

I suggest to keep ^^ those. It's useful information which isn't
easily visible otherwise.


> -/* 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
>
> diff --git a/arch/mips/include/uapi/asm/mman.h b/arch/mips/include/uapi/asm/mman.h
> index 9c48d9a21aa0..399937cefaa6 100644
> --- a/arch/mips/include/uapi/asm/mman.h
> +++ b/arch/mips/include/uapi/asm/mman.h
> @@ -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 */

same here. I think they should be preserved.


> -
> -/* 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	0
>
> diff --git a/arch/parisc/include/uapi/asm/mman.h b/arch/parisc/include/uapi/asm/mman.h
> index 68c44f99bc93..80f4a55763a0 100644
> --- a/arch/parisc/include/uapi/asm/mman.h
> +++ b/arch/parisc/include/uapi/asm/mman.h
> @@ -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 */
> diff --git a/arch/xtensa/include/uapi/asm/mman.h b/arch/xtensa/include/uapi/asm/mman.h
> index 1ff0c858544f..ad6bc56a7aef 100644
> --- a/arch/xtensa/include/uapi/asm/mman.h
> +++ b/arch/xtensa/include/uapi/asm/mman.h
> @@ -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 */

If xtensa had those, those should be kept as well IMHO.

Looks good otherwise.

Helge

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h
  2024-09-26  9:21   ` Helge Deller
@ 2024-09-26  9:41     ` Arnd Bergmann
  0 siblings, 0 replies; 17+ messages in thread
From: Arnd Bergmann @ 2024-09-26  9:41 UTC (permalink / raw)
  To: Helge Deller, Arnd Bergmann, linux-mm
  Cc: Jason A . Donenfeld, Alexander Viro, Alexandre Torgue,
	Andreas Larsson, Andrew Morton, Ard Biesheuvel, Christian Brauner,
	Christoph Hellwig, Christophe Leroy, Damien Le Moal,
	David Hildenbrand, Greg Ungerer, Kees Cook, Liam R. Howlett,
	Lorenzo Stoakes, Matt Turner, Max Filippov, Michael Ellerman,
	Michal Hocko, Nicholas Piggin, Richard Henderson,
	Thomas Bogendoerfer, Vladimir Murzin, Vlastimil Babka,
	linux-stm32, linux-kernel, linux-mips, linux-parisc, linuxppc-dev,
	Linux-Arch

On Thu, Sep 26, 2024, at 09:21, Helge Deller wrote:
> On 9/25/24 23:06, Arnd Bergmann wrote:

>> -/* 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.

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.

>> -/* 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.

>>   /* 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 */
>
> 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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support
  2024-09-26  8:46   ` David Hildenbrand
@ 2024-09-26 13:54     ` Arnd Bergmann
  2024-10-09 14:32       ` Lorenzo Stoakes
  0 siblings, 1 reply; 17+ messages in thread
From: Arnd Bergmann @ 2024-09-26 13:54 UTC (permalink / raw)
  To: David Hildenbrand, Arnd Bergmann, linux-mm
  Cc: Jason A . Donenfeld, Alexander Viro, Alexandre Torgue,
	Andreas Larsson, Andrew Morton, Ard Biesheuvel, Christian Brauner,
	Christoph Hellwig, Christophe Leroy, Damien Le Moal, Greg Ungerer,
	Helge Deller, Kees Cook, Liam R. Howlett, Lorenzo Stoakes,
	Matt Turner, Max Filippov, Michael Ellerman, Michal Hocko,
	Nicholas Piggin, Richard Henderson, Thomas Bogendoerfer,
	Vladimir Murzin, Vlastimil Babka, linux-stm32, linux-kernel,
	linux-mips, linux-parisc, linuxppc-dev, Linux-Arch

On Thu, Sep 26, 2024, at 08:46, David Hildenbrand wrote:
> On 25.09.24 23:06, Arnd Bergmann wrote:
>
> 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.

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

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/5] asm-generic: use asm-generic/mman-common.h on mips and xtensa
  2024-09-25 21:06 ` [PATCH 3/5] asm-generic: use asm-generic/mman-common.h on mips and xtensa Arnd Bergmann
@ 2024-10-05 17:13   ` Richard Henderson
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Henderson @ 2024-10-05 17:13 UTC (permalink / raw)
  To: Arnd Bergmann, linux-mm
  Cc: Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R . Howlett, Lorenzo Stoakes, Matt Turner,
	Max Filippov, Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Thomas Bogendoerfer, Vladimir Murzin, Vlastimil Babka,
	linux-stm32, linux-kernel, linux-mips, linux-parisc, linuxppc-dev,
	linux-arch

On 9/25/24 14:06, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> 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.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>   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(-)
> 
> diff --git a/arch/alpha/include/uapi/asm/mman.h b/arch/alpha/include/uapi/asm/mman.h
> index 8946a13ce858..1f1c03c047ce 100644
> --- a/arch/alpha/include/uapi/asm/mman.h
> +++ b/arch/alpha/include/uapi/asm/mman.h
> @@ -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/...

> --- a/include/uapi/asm-generic/mman-common.h
> +++ b/include/uapi/asm-generic/mman-common.h
> @@ -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~

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/5] asm-generic: use asm-generic/mman-common.h on parisc and alpha
  2024-09-25 21:06 ` [PATCH 4/5] asm-generic: use asm-generic/mman-common.h on parisc and alpha Arnd Bergmann
@ 2024-10-05 17:15   ` Richard Henderson
  2024-10-09 14:31   ` Lorenzo Stoakes
  1 sibling, 0 replies; 17+ messages in thread
From: Richard Henderson @ 2024-10-05 17:15 UTC (permalink / raw)
  To: Arnd Bergmann, linux-mm
  Cc: Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R . Howlett, Lorenzo Stoakes, Matt Turner,
	Max Filippov, Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Thomas Bogendoerfer, Vladimir Murzin, Vlastimil Babka,
	linux-stm32, linux-kernel, linux-mips, linux-parisc, linuxppc-dev,
	linux-arch

On 9/25/24 14:06, Arnd Bergmann wrote:
> From: Arnd Bergmann<arnd@arndb.de>
> 
> 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.
> 
> Signed-off-by: Arnd Bergmann<arnd@arndb.de>
> ---
>   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(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h
  2024-09-25 21:06 ` [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h Arnd Bergmann
  2024-09-26  9:21   ` Helge Deller
@ 2024-10-09 14:16   ` Lorenzo Stoakes
  1 sibling, 0 replies; 17+ messages in thread
From: Lorenzo Stoakes @ 2024-10-09 14:16 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-mm, Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R . Howlett, Matt Turner, Max Filippov,
	Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

On Wed, Sep 25, 2024 at 09:06:11PM +0000, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> 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
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

(Apologies for delay in response!)

Notwithstanding Helge's comments, this looks good to me - thanks very much
for taking a look at this!)

Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
>  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(-)
>
> diff --git a/arch/alpha/include/uapi/asm/mman.h b/arch/alpha/include/uapi/asm/mman.h
> index 763929e814e9..8946a13ce858 100644
> --- a/arch/alpha/include/uapi/asm/mman.h
> +++ b/arch/alpha/include/uapi/asm/mman.h
> @@ -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
>
> diff --git a/arch/mips/include/uapi/asm/mman.h b/arch/mips/include/uapi/asm/mman.h
> index 9c48d9a21aa0..399937cefaa6 100644
> --- a/arch/mips/include/uapi/asm/mman.h
> +++ b/arch/mips/include/uapi/asm/mman.h
> @@ -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	0
>
> diff --git a/arch/parisc/include/uapi/asm/mman.h b/arch/parisc/include/uapi/asm/mman.h
> index 68c44f99bc93..80f4a55763a0 100644
> --- a/arch/parisc/include/uapi/asm/mman.h
> +++ b/arch/parisc/include/uapi/asm/mman.h
> @@ -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 */
> diff --git a/arch/xtensa/include/uapi/asm/mman.h b/arch/xtensa/include/uapi/asm/mman.h
> index 1ff0c858544f..ad6bc56a7aef 100644
> --- a/arch/xtensa/include/uapi/asm/mman.h
> +++ b/arch/xtensa/include/uapi/asm/mman.h
> @@ -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	0
>
> diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h
> index 6ce1f1ceb432..792ad5599d9c 100644
> --- a/include/uapi/asm-generic/mman-common.h
> +++ b/include/uapi/asm-generic/mman-common.h
> @@ -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
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/5] asm-generic: move MAP_* flags from mman-common.h to mman.h
  2024-09-25 21:06 ` [PATCH 2/5] asm-generic: move MAP_* flags from mman-common.h to mman.h Arnd Bergmann
@ 2024-10-09 14:25   ` Lorenzo Stoakes
  0 siblings, 0 replies; 17+ messages in thread
From: Lorenzo Stoakes @ 2024-10-09 14:25 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-mm, Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R . Howlett, Matt Turner, Max Filippov,
	Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

On Wed, Sep 25, 2024 at 09:06:12PM +0000, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> 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.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  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(-)
>
> diff --git a/arch/powerpc/include/uapi/asm/mman.h b/arch/powerpc/include/uapi/asm/mman.h
> index c0c737215b00..d57b347c37fe 100644
> --- a/arch/powerpc/include/uapi/asm/mman.h
> +++ b/arch/powerpc/include/uapi/asm/mman.h
> @@ -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 */
> diff --git a/arch/sparc/include/uapi/asm/mman.h b/arch/sparc/include/uapi/asm/mman.h
> index cec9f4109687..afb86698cdb1 100644
> --- a/arch/sparc/include/uapi/asm/mman.h
> +++ b/arch/sparc/include/uapi/asm/mman.h
> @@ -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 */
> diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h
> index 792ad5599d9c..8d66d2dabaa8 100644
> --- a/include/uapi/asm-generic/mman-common.h
> +++ b/include/uapi/asm-generic/mman-common.h
> @@ -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?

> -/* 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
>   */
> diff --git a/include/uapi/asm-generic/mman.h b/include/uapi/asm-generic/mman.h
> index 57e8195d0b53..f26f9b4c03e1 100644
> --- a/include/uapi/asm-generic/mman.h
> +++ b/include/uapi/asm-generic/mman.h
> @@ -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
> diff --git a/include/uapi/linux/mman.h b/include/uapi/linux/mman.h
> index e89d00528f2f..b70cb06dd7ef 100644
> --- a/include/uapi/linux/mman.h
> +++ b/include/uapi/linux/mman.h
> @@ -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!

>
>  /*
>   * Huge page size encoding when MAP_HUGETLB is specified, and a huge page
> --
> 2.39.2
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 4/5] asm-generic: use asm-generic/mman-common.h on parisc and alpha
  2024-09-25 21:06 ` [PATCH 4/5] asm-generic: use asm-generic/mman-common.h on parisc and alpha Arnd Bergmann
  2024-10-05 17:15   ` Richard Henderson
@ 2024-10-09 14:31   ` Lorenzo Stoakes
  1 sibling, 0 replies; 17+ messages in thread
From: Lorenzo Stoakes @ 2024-10-09 14:31 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: linux-mm, Arnd Bergmann, Jason A. Donenfeld, Alexander Viro,
	Alexandre Torgue, Andreas Larsson, Andrew Morton, Ard Biesheuvel,
	Christian Brauner, Christoph Hellwig, Christophe Leroy,
	Damien Le Moal, David Hildenbrand, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R . Howlett, Matt Turner, Max Filippov,
	Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, linux-arch

On Wed, Sep 25, 2024 at 09:06:14PM +0000, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> 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.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Lovely! Look at all that red :) Great work!

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
>  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(-)
>
> diff --git a/arch/alpha/include/uapi/asm/mman.h b/arch/alpha/include/uapi/asm/mman.h
> index 1f1c03c047ce..fc8b74aa3f89 100644
> --- a/arch/alpha/include/uapi/asm/mman.h
> +++ b/arch/alpha/include/uapi/asm/mman.h
> @@ -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__ */
> diff --git a/arch/parisc/include/uapi/asm/mman.h b/arch/parisc/include/uapi/asm/mman.h
> index 1cd5d816d4cf..3732950a5cd8 100644
> --- a/arch/parisc/include/uapi/asm/mman.h
> +++ b/arch/parisc/include/uapi/asm/mman.h
> @@ -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__ */
> diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h
> index 2911dd14ef2a..81a14ed99197 100644
> --- a/include/uapi/asm-generic/mman-common.h
> +++ b/include/uapi/asm-generic/mman-common.h
> @@ -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

Rather nice to have these differences both de-duplicated and documented
here...

>
>  /* common parameters: try to keep these consistent across architectures */
>  #define MADV_FREE	8		/* free pages only if memory pressure */
> --
> 2.39.2
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support
  2024-09-26 13:54     ` Arnd Bergmann
@ 2024-10-09 14:32       ` Lorenzo Stoakes
  0 siblings, 0 replies; 17+ messages in thread
From: Lorenzo Stoakes @ 2024-10-09 14:32 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: David Hildenbrand, Arnd Bergmann, linux-mm, Jason A . Donenfeld,
	Alexander Viro, Alexandre Torgue, Andreas Larsson, Andrew Morton,
	Ard Biesheuvel, Christian Brauner, Christoph Hellwig,
	Christophe Leroy, Damien Le Moal, Greg Ungerer, Helge Deller,
	Kees Cook, Liam R. Howlett, Matt Turner, Max Filippov,
	Michael Ellerman, Michal Hocko, Nicholas Piggin,
	Richard Henderson, Thomas Bogendoerfer, Vladimir Murzin,
	Vlastimil Babka, linux-stm32, linux-kernel, linux-mips,
	linux-parisc, linuxppc-dev, Linux-Arch

On Thu, Sep 26, 2024 at 01:54:09PM +0000, Arnd Bergmann wrote:
> On Thu, Sep 26, 2024, at 08:46, David Hildenbrand wrote:
> > On 25.09.24 23:06, Arnd Bergmann wrote:
> >
> > 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.
>
> 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

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...

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-10-09 14:33 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-25 21:06 [PATCH 0/5] asm-generic: clean up asm/mman.h Arnd Bergmann
2024-09-25 21:06 ` [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h Arnd Bergmann
2024-09-26  9:21   ` Helge Deller
2024-09-26  9:41     ` Arnd Bergmann
2024-10-09 14:16   ` Lorenzo Stoakes
2024-09-25 21:06 ` [PATCH 2/5] asm-generic: move MAP_* flags from mman-common.h to mman.h Arnd Bergmann
2024-10-09 14:25   ` Lorenzo Stoakes
2024-09-25 21:06 ` [PATCH 3/5] asm-generic: use asm-generic/mman-common.h on mips and xtensa Arnd Bergmann
2024-10-05 17:13   ` Richard Henderson
2024-09-25 21:06 ` [PATCH 4/5] asm-generic: use asm-generic/mman-common.h on parisc and alpha Arnd Bergmann
2024-10-05 17:15   ` Richard Henderson
2024-10-09 14:31   ` Lorenzo Stoakes
2024-09-25 21:06 ` [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support Arnd Bergmann
2024-09-26  8:46   ` David Hildenbrand
2024-09-26 13:54     ` Arnd Bergmann
2024-10-09 14:32       ` Lorenzo Stoakes
2024-09-26  9:18   ` Helge Deller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).