Skip to content

Commit 3809cef

Browse files
yury-khrustalevctmarinas
authored andcommitted
selftests/mm: Use PKEY_UNRESTRICTED macro
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>
1 parent 6d61527 commit 3809cef

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

tools/testing/selftests/mm/mseal_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ bool seal_support(void)
218218
bool pkey_supported(void)
219219
{
220220
#if defined(__i386__) || defined(__x86_64__) /* arch */
221-
int pkey = sys_pkey_alloc(0, 0);
221+
int pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
222222

223223
if (pkey > 0)
224224
return true;
@@ -1671,7 +1671,7 @@ static void test_seal_discard_ro_anon_on_pkey(bool seal)
16711671
setup_single_address_rw(size, &ptr);
16721672
FAIL_TEST_IF_FALSE(ptr != (void *)-1);
16731673

1674-
pkey = sys_pkey_alloc(0, 0);
1674+
pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
16751675
FAIL_TEST_IF_FALSE(pkey > 0);
16761676

16771677
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)
16831683
}
16841684

16851685
/* sealing doesn't take effect if PKRU allow write. */
1686-
set_pkey(pkey, 0);
1686+
set_pkey(pkey, PKEY_UNRESTRICTED);
16871687
ret = sys_madvise(ptr, size, MADV_DONTNEED);
16881688
FAIL_TEST_IF_FALSE(!ret);
16891689

tools/testing/selftests/mm/pkey-helpers.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <ucontext.h>
1414
#include <sys/mman.h>
1515

16+
#include <linux/mman.h>
1617
#include <linux/types.h>
1718

1819
#include "../kselftest.h"
@@ -193,7 +194,7 @@ static inline u32 *siginfo_get_pkey_ptr(siginfo_t *si)
193194
static inline int kernel_has_pkeys(void)
194195
{
195196
/* try allocating a key and see if it succeeds */
196-
int ret = sys_pkey_alloc(0, 0);
197+
int ret = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
197198
if (ret <= 0) {
198199
return 0;
199200
}

tools/testing/selftests/mm/pkey_sighandler_tests.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static void test_sigsegv_handler_with_different_pkey_for_stack(void)
311311
__write_pkey_reg(pkey_reg);
312312

313313
/* Protect the new stack with MPK 1 */
314-
pkey = sys_pkey_alloc(0, 0);
314+
pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
315315
sys_mprotect_pkey(stack, STACK_SIZE, PROT_READ | PROT_WRITE, pkey);
316316

317317
/* Set up alternate signal stack that will use the default MPK */
@@ -484,7 +484,7 @@ static void test_pkru_sigreturn(void)
484484
__write_pkey_reg(pkey_reg);
485485

486486
/* Protect the stack with MPK 2 */
487-
pkey = sys_pkey_alloc(0, 0);
487+
pkey = sys_pkey_alloc(0, PKEY_UNRESTRICTED);
488488
sys_mprotect_pkey(stack, STACK_SIZE, PROT_READ | PROT_WRITE, pkey);
489489

490490
/* Set up alternate signal stack that will use the default MPK */

tools/testing/selftests/mm/protection_keys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static pid_t fork_lazy_child(void)
463463
static int alloc_pkey(void)
464464
{
465465
int ret;
466-
unsigned long init_val = 0x0;
466+
unsigned long init_val = PKEY_UNRESTRICTED;
467467

468468
dprintf1("%s()::%d, pkey_reg: 0x%016llx shadow: %016llx\n",
469469
__func__, __LINE__, __read_pkey_reg(), shadow_pkey_reg);

0 commit comments

Comments
 (0)