mm/pkey: Add PKEY_UNRESTRICTED macro
Subsystems (2)
PATCH 1/1 mm/pkey: Add PKEY_UNRESTRICTED macro
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/[email protected]/
[2] https://inbox.sourceware.org/libc-alpha/[email protected]/
Is this patch OK?
Kind regards,
Yury
--- include/uapi/asm-generic/mman-common.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/asm-generic/mman-common.h +1 -0
@@ -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 |\
Signature · 1 line
2.39.5
Quoted 1 line · Yury Khrustalev
Memory protection keys (pkeys) uapi previously used two macros:
Nit: I would remove "previously" as it's not clear what it means here.
Quoted 11 lines
-
PKEY_DISABLE_ACCESS0x1
-PKEY_DISABLE_WRITE0x2with implicit literal value of
0x0that 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.0x0or 0) and also because 0 in the context of pkeys can be mistaken for "no permissions" (akinPROT_NONE) while it actually means "no restrictions". This is important because pkeys are oftentimes used nearmprotect()that usesPROT_macros.
Quoted 1 line
This patch adds
PKEY_UNRESTRICTEDmacro defined as0x0.
Your Signed-off-by is missing.
With that fixed:
- Kevin
Quoted 31 lines
---
Applies to42f7652d3eb5(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/[email protected]/
[2] https://inbox.sourceware.org/libc-alpha/[email protected]/Is this patch OK?
Kind regards,
Yury--- include/uapi/asm-generic/mman-common.h | 1 + 1 file changed, 1 insertion(+)include/uapi/asm-generic/mman-common.h +1
-0@@ -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 |\
include/uapi/asm-generic/mman-common.h line 88
Quoted 12 lines · Yury Khrustalev
include/uapi/asm-generic/mman-common.h +1
-0@@ -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 |\
It seems sane, but it would be nice to have at least site or two use it in the kernel so show that it's useful in practice. Is there any kernel code or anything in selftests/ that would be improved with this?
That said, it's pretty harmless:
Quoted 9 lines · Dave Hansen
Quoted 8 lines · Yury Khrustalev
include/uapi/asm-generic/mman-common.h +0
-0@@ -82,6 +82,7 @@/* compatibility flags */ #define MAP_FILE 0
Quoted 7 lines
include/uapi/asm-generic/mman-common.h line 88
Quoted 4 lines
include/uapi/asm-generic/mman-common.h +1
-0+#define PKEY_UNRESTRICTED 0x0#define PKEY_DISABLE_ACCESS 0x1#define PKEY_DISABLE_WRITE 0x2#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\It seems sane, but it would be nice to have at least site or two use it in the kernel so show that it's useful in practice. Is there any kernel code or anything in selftests/ that would be improved with this?
As a matter of fact this would improve the readability of [1] quite a
bit: all those set_pkey_bits(..., 0) calls would become set_pkey_bits(..., PKEY_UNRESTRICTED). I'm sure other pkey-related kselftests could benefit too.
Kevin
[1]
https://lore.kernel.org/linux-arm-kernel/[email protected]/
Quoted 11 lines · Kevin Brodsky
Quoted 7 lines
Quoted 4 lines
+#define
PKEY_UNRESTRICTED0x0
#definePKEY_DISABLE_ACCESS0x1
#definePKEY_DISABLE_WRITE0x2
#definePKEY_ACCESS_MASK(PKEY_DISABLE_ACCESS|\It seems sane, but it would be nice to have at least site or two use it in the kernel so show that it's useful in practice. Is there any kernel code or anything in selftests/ that would be improved with this?
As a matter of fact this would improve the readability of [1] quite a
bit: all thoseset_pkey_bits(..., 0)calls would becomeset_pkey_bits(..., PKEY_UNRESTRICTED). I'm sure other pkey-related kselftests could benefit too.
It would be much appreciated if someone could make a pass over kernel code and fix up the places where PKEY_UNRESTRICTED makes things more clear.
Quoted 8 lines · Dave Hansen
Quoted 7 lines · Kevin Brodsky
Quoted 7 lines
Quoted 4 lines
+#define
PKEY_UNRESTRICTED0x0
#definePKEY_DISABLE_ACCESS0x1
#definePKEY_DISABLE_WRITE0x2
#definePKEY_ACCESS_MASK(PKEY_DISABLE_ACCESS|\It seems sane, but it would be nice to have at least site or two use it in the kernel so show that it's useful in practice. Is there any kernel code or anything in selftests/ that would be improved with this?
Quoted 6 lines
Quoted 4 lines
As a matter of fact this would improve the readability of [1] quite a
bit: all thoseset_pkey_bits(..., 0)calls would becomeset_pkey_bits(..., PKEY_UNRESTRICTED). I'm sure other pkey-related kselftests could benefit too.It would be much appreciated if someone could make a pass over kernel code and fix up the places where
PKEY_UNRESTRICTEDmakes things more clear.
It doesn't look like kernel code would have a use for it at the moment, but I have found a few places in kselftests (mm, ppc) where 0 could be replaced with PKEY_UNRESTRICTED. I can send a follow-up series.
Kevin
Quoted 5 lines · Kevin Brodsky
Quoted 2 lines
It would be much appreciated if someone could make a pass over kernel code and fix up the places where
PKEY_UNRESTRICTEDmakes things more clear.It doesn't look like kernel code would have a use for it at the moment, but I have found a few places in kselftests (mm, ppc) where 0 could be replaced with
PKEY_UNRESTRICTED. I can send a follow-up series.
Just doing it in the selftests would be great.
Hi,
Quoted 8 lines · Dave Hansen
Quoted 5 lines · Kevin Brodsky
Quoted 2 lines
It would be much appreciated if someone could make a pass over kernel code and fix up the places where
PKEY_UNRESTRICTEDmakes things more clear.It doesn't look like kernel code would have a use for it at the moment, but I have found a few places in kselftests (mm, ppc) where 0 could be replaced with
PKEY_UNRESTRICTED. I can send a follow-up series.Just doing it in the selftests would be great.
Thank you for the feedback, I've sent v2 with updated tests [1].
[1] https://lore.kernel.org/linux-arch/[email protected]/
Kind regards,
Yury