Message ID | 20241028090715.509527-2-yury.khrustalev@arm.com (mailing list archive) |
---|---|
State | Handled Elsewhere |
Headers | show |
Series | mm/pkey: Add PKEY_UNRESTRICTED macro | expand |
Yury Khrustalev <yury.khrustalev@arm.com> writes: > Memory protection keys (pkeys) uapi has two macros for pkeys restrictions: > > - PKEY_DISABLE_ACCESS 0x1 > - PKEY_DISABLE_WRITE 0x2 > > with implicit literal value of 0x0 that means "unrestricted". Code that > works with pkeys has to use this literal value when implying that a pkey > imposes no restrictions. This may reduce readability because 0 can be > written in various ways (e.g. 0x0 or 0) and also because 0 in the context > of pkeys can be mistaken for "no permissions" (akin PROT_NONE) while it > actually means "no restrictions". This is important because pkeys are > oftentimes used near mprotect() that uses PROT_ macros. > > This patch adds PKEY_UNRESTRICTED macro defined as 0x0. > > Signed-off-by: Yury Khrustalev <yury.khrustalev@arm.com> > --- > include/uapi/asm-generic/mman-common.h | 1 + > tools/include/uapi/asm-generic/mman-common.h | 1 + > 2 files changed, 2 insertions(+) Apparently you're not meant to modify the copy in tools/, there's a script that does that, which is run by acme, see: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/include/uapi/README cheers
Hi Michael, On Wed, Nov 06, 2024 at 12:00:42PM +1100, Michael Ellerman wrote: > Yury Khrustalev <yury.khrustalev@arm.com> writes: > > Memory protection keys (pkeys) uapi has two macros for pkeys restrictions: > > > > - PKEY_DISABLE_ACCESS 0x1 > > - PKEY_DISABLE_WRITE 0x2 > > > > ... > > > > This patch adds PKEY_UNRESTRICTED macro defined as 0x0. > > > > ... > > Apparently you're not meant to modify the copy in tools/, there's a > script that does that, which is run by acme, see: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/include/uapi/README > > cheers Thank you for clarification. I've fixed the patch in v4 [1] [1] https://lore.kernel.org/all/20241108085358.777687-1-yury.khrustalev@arm.com/ Kind regards, Yury
diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h index 6ce1f1ceb432..ea40e27e6dea 100644 --- a/include/uapi/asm-generic/mman-common.h +++ b/include/uapi/asm-generic/mman-common.h @@ -82,6 +82,7 @@ /* compatibility flags */ #define MAP_FILE 0 +#define PKEY_UNRESTRICTED 0x0 #define PKEY_DISABLE_ACCESS 0x1 #define PKEY_DISABLE_WRITE 0x2 #define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\ diff --git a/tools/include/uapi/asm-generic/mman-common.h b/tools/include/uapi/asm-generic/mman-common.h index 6ce1f1ceb432..ea40e27e6dea 100644 --- a/tools/include/uapi/asm-generic/mman-common.h +++ b/tools/include/uapi/asm-generic/mman-common.h @@ -82,6 +82,7 @@ /* compatibility flags */ #define MAP_FILE 0 +#define PKEY_UNRESTRICTED 0x0 #define PKEY_DISABLE_ACCESS 0x1 #define PKEY_DISABLE_WRITE 0x2 #define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\
Memory protection keys (pkeys) uapi has two macros for pkeys restrictions: - PKEY_DISABLE_ACCESS 0x1 - PKEY_DISABLE_WRITE 0x2 with implicit literal value of 0x0 that means "unrestricted". Code that works with pkeys has to use this literal value when implying that a pkey imposes no restrictions. This may reduce readability because 0 can be written in various ways (e.g. 0x0 or 0) and also because 0 in the context of pkeys can be mistaken for "no permissions" (akin PROT_NONE) while it actually means "no restrictions". This is important because pkeys are oftentimes used near mprotect() that uses PROT_ macros. This patch adds PKEY_UNRESTRICTED macro defined as 0x0. Signed-off-by: Yury Khrustalev <yury.khrustalev@arm.com> --- include/uapi/asm-generic/mman-common.h | 1 + tools/include/uapi/asm-generic/mman-common.h | 1 + 2 files changed, 2 insertions(+)