From patchwork Wed Sep 25 21:06:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13812420 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37C2213E02E; Wed, 25 Sep 2024 21:06:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727298410; cv=none; b=mkZobM3pZ3FMkHWcURyYf3YkMiClQB8mMOc8LahYGP0slnGGXTlkLJ23kavBOgNXcyRzh2x+ogQ6ljCGBvWmv4PzMrco/7Zvlgqm1bFNY9JT6inBeBImeo076kcY36Om5r0Mha0Q9tm4l5lFbsLrrC/tCRPjJsAANeJX8/Uaa+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727298410; c=relaxed/simple; bh=0XCZZU73KUaPUGV94b5Y4vfVQ2GPZcPS56YVImT6S6k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RYVVtLq9DBfEwbAEnDyNLIgssxqvmZaR75wcNXJIlWnMeHY2uYWDwGnkpY5F5pISoPzJScGiqMeswMwDS/1pD2NkDOtr2bCXt0AccUrb4M7cc9ywkk3keWOfWosHsQ69B4gKi5RHvZ3bDdgg1Os3ilJWESYqGFtrapQ3d7leGnE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rrw0/11n; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Rrw0/11n" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED5E0C4CECE; Wed, 25 Sep 2024 21:06:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727298409; bh=0XCZZU73KUaPUGV94b5Y4vfVQ2GPZcPS56YVImT6S6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rrw0/11nMatKUr+PrDMd2vXb6R6+ZP+SaYtT6WuW/O6kxUVYeGItzda7ucqqy4+Sf wzTLmbEmZXG/73xtdPH/+gbaOxnorCRudP/1NSYNczPmeNahK26MpnP5VeZ0/1VGjl GFtTRedXkgSlu8Gh5pGFFrawX8+jFjtLfbs7zCFyE3iZAXtK8waEB5iYZHsmW7Rwdz HCXA+nUZa0C1DU48dx1g0bySQzc8Rt73RZgCgzPj8BfKteKKN2U/EG53aBcAPbDDv9 V1rZ1EEV8fZI3K4fS2WzlFPirFalsFTj0FFK1nhoyn2PEFNB/ljapvfYoBwpaXaPHA p1BgYSRlQPtKw== From: Arnd Bergmann To: linux-mm@kvack.org 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@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org Subject: [PATCH 1/5] asm-generic: cosmetic updates to uapi/asm/mman.h Date: Wed, 25 Sep 2024 21:06:11 +0000 Message-Id: <20240925210615.2572360-2-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240925210615.2572360-1-arnd@kernel.org> References: <20240925210615.2572360-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnd Bergmann 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 Acked-by: Lorenzo Stoakes --- 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 From patchwork Wed Sep 25 21:06:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13812421 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 186F6158524; Wed, 25 Sep 2024 21:06:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727298417; cv=none; b=r5xNDCl0apffiCV8rGgGDik9WB9f0AUov2iq4tGFgLWgVXqD6t4aF8XLXN7OTv11M5RHHij5QoXm04upzfj4LAZjcfoFIsYWwcTCwf997A+uduNVp4BSZa+XrRhnpOllChubWZD+qDhWMJq99pwHG0FoepH9hNirLXV1HFN6tYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727298417; c=relaxed/simple; bh=aDTBkkmG/d5Qp4dQ7xLc1aEeqRGIp1tx3y3paI2l9us=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QzaJvpR2rCBicsNG/o+W81j21xgCcqk0Ia9pKgde0TsdVGAgetaq8CIBY6K/1g5dFP/KDeGUIyGw1k44/ss9qZlzDjGrzNS1dD0C9l2tcV2cfp1PkQeRrInNQ1PGqZ1Bb0b3mQR3ggP+/liZ15RBY6IHh8Hp0OUC8xCi4td4VcE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CRpxihM2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CRpxihM2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E531C4CED0; Wed, 25 Sep 2024 21:06:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727298417; bh=aDTBkkmG/d5Qp4dQ7xLc1aEeqRGIp1tx3y3paI2l9us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CRpxihM2e75tM0Bh7zwLgE2iWB1Q2C6WpoDxjva8iJOMC6oBQya5HroXk55JEfyL6 LhjXW/qeEZjcui5rJxrOXW/tJdtmU5D2uxIw05LxKdH12WAJXUQPIdWZx6zFsptgmp 9joJA1ZZdNbpONn+zIm4gbqFyJdy0QZIFDugku4mPLkjRJ25aOdb+/1/nuVpPb4jSK AGPijvaPFQ2Md/TDhVdXCRs4LeLobDmZpuYYLQsHtn19s+mGW9Dy41pZhjWzY8BlhR TOovGap+DgQ3DclxvFnyhOOd29bwhFogwsWqcvNyjLBk8WZgYvncO9pF0QaPo4U+On 6ud7LUq7AR7ZA== From: Arnd Bergmann To: linux-mm@kvack.org 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@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org Subject: [PATCH 2/5] asm-generic: move MAP_* flags from mman-common.h to mman.h Date: Wed, 25 Sep 2024 21:06:12 +0000 Message-Id: <20240925210615.2572360-3-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240925210615.2572360-1-arnd@kernel.org> References: <20240925210615.2572360-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnd Bergmann 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 --- 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 +/* + * 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 From patchwork Wed Sep 25 21:06:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13812422 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90C3C165F1A; Wed, 25 Sep 2024 21:07:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727298424; cv=none; b=NEKuajR9Jj8IZj3pakFuJ9RausKPhSRVuAaha0cYb0lK2EOx9pnHBk3AD004uNcFJPgu9I1v6kcy/u0tIRiRfsEJ3n17gmh0tYjRHjbPq2ZFHwAej5bZi6STy6KOqIS+JblmHP2XC0hvMA0dJfSz8J8c1o/lqMOdyVrdLK8HkWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727298424; c=relaxed/simple; bh=0EXzYHjw9wueOmuWN8Ox5HAuCn8dFHsgBxy03Mw7iZk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IqYzmXsg0ezffpidOui+9vNRDEfVOnogILTRz+uBjSSxOPdJ8gCWvvLwCjvmQEK/uO60C5kZYna4bUWohBW/9N63gtyTrC86LByyOjNARJU8RsRqxKmvFhlQKo2tXVwPKvPqTG4yq1GdKV5xcy8RYHqS/QVqvjs6N6VjbgZCcHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kdrlaTqv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kdrlaTqv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7032FC4CEC7; Wed, 25 Sep 2024 21:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727298424; bh=0EXzYHjw9wueOmuWN8Ox5HAuCn8dFHsgBxy03Mw7iZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kdrlaTqvjNbs0lqNwZ1flSvr94VKx4Bff0mmaUe3SciSLDp7ecrYBocKzzLehfzYA hiEVi+rpMBlv5UNrh+PU7Di6s6tuQr5oMZytGo359lRnjcKbC3W8p8cnP/PjapqluX tT/MmOaT+h19VX2kZOzYP3guT3kfRosV6TVYLBXVAB97k7eIQkFfwU3dH1rBs2Mtmf 9iy6hiPNIP63o1kJFvI6b1f40YmdGDguMypPdXeumMIMpgiLA+flbGo5FsdGxj13Xz /WjeFlSScH1pl11mv71fOFMfyJNspQIz96REsaHXkxt3MflXMa0hul4Gw4vqfNv6YY TEe1ufNgcfMOQ== From: Arnd Bergmann To: linux-mm@kvack.org 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@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org Subject: [PATCH 3/5] asm-generic: use asm-generic/mman-common.h on mips and xtensa Date: Wed, 25 Sep 2024 21:06:13 +0000 Message-Id: <20240925210615.2572360-4-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240925210615.2572360-1-arnd@kernel.org> References: <20240925210615.2572360-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnd Bergmann 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 --- 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 #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 #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 */ From patchwork Wed Sep 25 21:06:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13812423 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1FA715B992; Wed, 25 Sep 2024 21:07:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727298431; cv=none; b=V8qF3xvD0vs/pVH3sALoxXBCDgYAAEVjS5FtWHswKG7SZ6Ckg588AW3eJZCqiSwNanG/qaMPUPgDNGhSFX+evAP0FbQPyTmvCDi/SnGmm9E1wAnvbHGoup5SFytMGJY/ZWyQbc+98tEg+A7Azfjo/E50LQ0oxdL0OfKfVghxDKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727298431; c=relaxed/simple; bh=9WWq9eu7cuIVH7faIexy4b1QmBlJqq/TWxw3ZIHVjt4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b0l00+G3IW9+qfZLkTKZQi4ptSZAGPUzp/OjbSQ7dpzN4dKD3rQutyIld+0du3wslfnReujCddSNB8fplRvLG4QCM5pysRaA9of7Iea3io0HAQovTVaKkrkaffO4DDeXS6M510PgiI5YX591VUPWLna/p1VIuNScv2DUnN4qa5E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RFMABg80; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RFMABg80" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A44A1C4CECF; Wed, 25 Sep 2024 21:07:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727298431; bh=9WWq9eu7cuIVH7faIexy4b1QmBlJqq/TWxw3ZIHVjt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RFMABg80UAzlZRGWyrqfIVrpC9pf+KZ7ccnvBYINSdZOE0vEoxMWceBAliZEcMTDW RCpJv2VfcSBLoHeF7E0VDAWsrUKkSgwBOV+P/dVgyITQ122pl5kO5UEOgqjNQZdVfO h4SNxxhIeb2DH76DzE4IlhLrg0T8UQo/j9VkVlXW+oUFymIn6rtT8GPYYlUEcZu7uZ wqHhouBebch/JiLDf7+51e9ufJfgMu3DNhow/hM/VsMPDaC6oAMSQo6eXKF+wHEHKy BbipYo1sQUC+mbsQHvc97qE69iXeCHgMwZE4eDvGEVZFYu6lq2naZhA8bXu43iX0nU OKOKG0CyQpcrg== From: Arnd Bergmann To: linux-mm@kvack.org 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@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org Subject: [PATCH 4/5] asm-generic: use asm-generic/mman-common.h on parisc and alpha Date: Wed, 25 Sep 2024 21:06:14 +0000 Message-Id: <20240925210615.2572360-5-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240925210615.2572360-1-arnd@kernel.org> References: <20240925210615.2572360-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnd Bergmann 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 Reviewed-by: Richard Henderson Reviewed-by: Lorenzo Stoakes --- 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 #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 #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 */ From patchwork Wed Sep 25 21:06:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13812424 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1953117CA19; Wed, 25 Sep 2024 21:07:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727298439; cv=none; b=nBS/nO/X89/aU1Ko5lX+biC/big0sRQPycnYQ2NUrPgfNmEnbSp/DjX2M1+bxtaYJ8Kj9LKmTSGVhxgcfatBvhCiT8ndhSmAH4QVa2pEFusBjkpnQQ/8sMTQDj9f/vqGRcmRA1p1Uf9yvR1Pumg4AMbmHxHQti5WibGlrFXSGoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727298439; c=relaxed/simple; bh=ODTKCHXxIZE3eYSHvfpmzYWSeBfhCgyCnxo8sL2fUHU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YEQ+D/HCZCKPiLT1yFnug4ix259hkY/FR9TiTnuel0p213KxE2YvA22sJf/NfFi05AlX/xOSoHh9tmwybIQZScWaMHMjJFvMCoQXC6jn3GkrQ2n1myfPgWE1GN1a7+bLEVdRZXqyf9he81ESY48R/7xI7dd+Xjy4R9dwz/0S9Ro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UqUeN44x; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UqUeN44x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E93BAC4CEC3; Wed, 25 Sep 2024 21:07:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727298438; bh=ODTKCHXxIZE3eYSHvfpmzYWSeBfhCgyCnxo8sL2fUHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UqUeN44x2CyaBUPaNDkT98k6QN3VewzS7CUSKeQCD7Er05TZWE0qz2tzTPJ5xFD/o SZdsfPJBUcVK4dRlnz8/NqnIbj/TOm7FASPiv+Zps96TFrJjYpEVq4XxK0nqdTGty8 cVz2cOJxhyz6vRclrGlh3FDM1KAMq5JWGh1Z3LYFBAgcqBisNYyEg6kxvm+G+h1/34 AKFLgqXcNy+hn1N/9l0tNjYChvvNXi0fQ3/AHQvp7aGYCZu8vedTaYrNErzVdPI0aH yTvTayfqA+sFZUYQ+NLii51HXTvqMUHW975iSPHKFjGcwkF95HyatEteJJwpOUEYZt xQwPkqnb9dgXw== From: Arnd Bergmann To: linux-mm@kvack.org 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@st-md-mailman.stormreply.com, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org Subject: [PATCH 5/5] [RFC] mm: Remove MAP_UNINITIALIZED support Date: Wed, 25 Sep 2024 21:06:15 +0000 Message-Id: <20240925210615.2572360-6-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240925210615.2572360-1-arnd@kernel.org> References: <20240925210615.2572360-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnd Bergmann 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 Cc: Damien Le Moal Cc: Alexandre Torgue Cc: linux-stm32@st-md-mailman.stormreply.com Cc: Greg Ungerer Cc: Vladimir Murzin Cc: Max Filippov Signed-off-by: Arnd Bergmann --- 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);