]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/pkey: Add PKEY_UNRESTRICTED macro
authorYury Khrustalev <yury.khrustalev@arm.com>
Mon, 13 Jan 2025 17:06:17 +0000 (17:06 +0000)
committerCatalin Marinas <catalin.marinas@arm.com>
Mon, 17 Feb 2025 18:11:18 +0000 (18:11 +0000)
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>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com>
Link: https://lore.kernel.org/r/20250113170619.484698-2-yury.khrustalev@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
include/uapi/asm-generic/mman-common.h

index 1ea2c4c33b86a2638b03335ad5bfcfd1691cef3e..ef1c27fa3c570fa4ff06fc6f742914925f8b02c8 100644 (file)
@@ -85,6 +85,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 |\