]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/mm: Use PKEY_UNRESTRICTED macro
authorYury Khrustalev <yury.khrustalev@arm.com>
Mon, 13 Jan 2025 17:06:18 +0000 (17:06 +0000)
committerCatalin Marinas <catalin.marinas@arm.com>
Mon, 17 Feb 2025 18:16:36 +0000 (18:16 +0000)
Replace literal 0 with macro PKEY_UNRESTRICTED where pkey_*() functions
are used in mm selftests for memory protection keys.

Signed-off-by: Yury Khrustalev <yury.khrustalev@arm.com>
Suggested-by: Joey Gouly <joey.gouly@arm.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: https://lore.kernel.org/r/20250113170619.484698-3-yury.khrustalev@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
tools/testing/selftests/mm/mseal_test.c
tools/testing/selftests/mm/pkey-helpers.h
tools/testing/selftests/mm/pkey_sighandler_tests.c
tools/testing/selftests/mm/protection_keys.c

index ad17005521a8e9dd6d3edfa4017fae969a2fb5a1..005f29c86484ec6379b94a2f09bb07262251d14c 100644 (file)
@@ -218,7 +218,7 @@ bool seal_support(void)
 bool pkey_supported(void)
 {
 #if defined(__i386__) || defined(__x86_64__) /* arch */
-       int pkey = sys_pkey_alloc(0, 0);
+       int pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
 
        if (pkey > 0)
                return true;
@@ -1671,7 +1671,7 @@ static void test_seal_discard_ro_anon_on_pkey(bool seal)
        setup_single_address_rw(size, &ptr);
        FAIL_TEST_IF_FALSE(ptr != (void *)-1);
 
-       pkey = sys_pkey_alloc(0, 0);
+       pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
        FAIL_TEST_IF_FALSE(pkey > 0);
 
        ret = sys_mprotect_pkey((void *)ptr, size, PROT_READ | PROT_WRITE, pkey);
@@ -1683,7 +1683,7 @@ static void test_seal_discard_ro_anon_on_pkey(bool seal)
        }
 
        /* sealing doesn't take effect if PKRU allow write. */
-       set_pkey(pkey, 0);
+       set_pkey(pkey, PKEY_UNRESTRICTED);
        ret = sys_madvise(ptr, size, MADV_DONTNEED);
        FAIL_TEST_IF_FALSE(!ret);
 
index f080e97b39bea9ef214f4ff238d38c3e4437efe7..ea404f80e6cb929c35beaa0dead26d9e9dc8abac 100644 (file)
@@ -13,6 +13,7 @@
 #include <ucontext.h>
 #include <sys/mman.h>
 
+#include <linux/mman.h>
 #include <linux/types.h>
 
 #include "../kselftest.h"
@@ -193,7 +194,7 @@ static inline u32 *siginfo_get_pkey_ptr(siginfo_t *si)
 static inline int kernel_has_pkeys(void)
 {
        /* try allocating a key and see if it succeeds */
-       int ret = sys_pkey_alloc(0, 0);
+       int ret = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
        if (ret <= 0) {
                return 0;
        }
index 1ac8c880988076de9949efec4ab542170efb0d8f..b5e076a564c952fc198335a66776f170df10e840 100644 (file)
@@ -311,7 +311,7 @@ static void test_sigsegv_handler_with_different_pkey_for_stack(void)
        __write_pkey_reg(pkey_reg);
 
        /* Protect the new stack with MPK 1 */
-       pkey = sys_pkey_alloc(0, 0);
+       pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
        sys_mprotect_pkey(stack, STACK_SIZE, PROT_READ | PROT_WRITE, pkey);
 
        /* Set up alternate signal stack that will use the default MPK */
@@ -484,7 +484,7 @@ static void test_pkru_sigreturn(void)
        __write_pkey_reg(pkey_reg);
 
        /* Protect the stack with MPK 2 */
-       pkey = sys_pkey_alloc(0, 0);
+       pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
        sys_mprotect_pkey(stack, STACK_SIZE, PROT_READ | PROT_WRITE, pkey);
 
        /* Set up alternate signal stack that will use the default MPK */
index a4683f2476f2728d813a32ede08cf90dcca82f81..434d8a8dc637c731067ca7b0db34c398404cff33 100644 (file)
@@ -463,7 +463,7 @@ static pid_t fork_lazy_child(void)
 static int alloc_pkey(void)
 {
        int ret;
-       unsigned long init_val = 0x0;
+       unsigned long init_val = PKEY_UNRESTRICTED;
 
        dprintf1("%s()::%d, pkey_reg: 0x%016llx shadow: %016llx\n",
                        __func__, __LINE__, __read_pkey_reg(), shadow_pkey_reg);