linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/pkey: Add PKEY_UNRESTRICTED macro
@ 2024-10-22 12:01 Yury Khrustalev
  2024-10-22 12:56 ` Kevin Brodsky
  2024-10-22 14:04 ` Dave Hansen
  0 siblings, 2 replies; 8+ messages in thread
From: Yury Khrustalev @ 2024-10-22 12:01 UTC (permalink / raw)
  To: linux-arch
  Cc: Arnd Bergmann, Kevin Brodsky, Joey Gouly, Dave Hansen, nd,
	Yury Khrustalev

Memory protection keys (pkeys) uapi previously used two macros:

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

---
Applies to 42f7652d3eb5 (tag: v6.12-rc4).

For context, this change will also allow for more consistent update of the
Glibc manual [1] which in turn will help with introducing memory protection
keys on AArch64 targets [2].

[1] https://inbox.sourceware.org/libc-alpha/20241022073837.151355-1-yury.khrustalev@arm.com/
[2] https://inbox.sourceware.org/libc-alpha/20241011153614.3189334-1-yury.khrustalev@arm.com/

Is this patch OK?

Kind regards,
Yury

---
 include/uapi/asm-generic/mman-common.h | 1 +
 1 file changed, 1 insertion(+)

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 |\
-- 
2.39.5


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

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

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-22 12:01 [PATCH] mm/pkey: Add PKEY_UNRESTRICTED macro Yury Khrustalev
2024-10-22 12:56 ` Kevin Brodsky
2024-10-22 14:04 ` Dave Hansen
2024-10-22 15:11   ` Kevin Brodsky
2024-10-22 17:15     ` Dave Hansen
2024-10-25  8:26       ` Kevin Brodsky
2024-10-25 14:48         ` Dave Hansen
2024-10-28  8:33           ` Yury Khrustalev

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