Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F2581CD2C for ; Sun, 27 Oct 2024 17:01:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730048503; cv=none; b=s49djCNBQ0fTeIwDwejhGXeCNhddo8pBM+X4ieIXpTJE2mnNI/HIZXuLzHS4Ex9BkLscmHCDdcTJmDjUcUp0s8IqMwfd3CmeYYbgSt5a/OvlSFAclqz+50T/8xoZElhAhMoo0dt6B6eKcREXPDQwOZuJvvGNJzem5bGUyaR9LwQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730048503; c=relaxed/simple; bh=lgXTmdqpVdJHabc0rIajR8ncy5AYRzyx1JGHRq0MXBg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Cusr9a/s63mz1TNGgqlIRuiW9U5CZREidSr02S+QL3Eo9zbX0lNgEQR/AShRSOuwyfPyzHe4RvpdT+0stsgHJ2ROVkxnrlPRaxlG6MqdyhSBGUSPPyqz8zGTCCdLQ4Spvrf6FJkS8xyRm9JTKdgox7huHRzey9ABFcYl/xeQ5IU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5545A497; Sun, 27 Oct 2024 10:02:09 -0700 (PDT) Received: from udebian.localdomain (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6FB5E3F66E; Sun, 27 Oct 2024 10:01:38 -0700 (PDT) From: Yury Khrustalev To: linux-arch@vger.kernel.org Cc: Arnd Bergmann , Kevin Brodsky , Joey Gouly , Dave Hansen , Sandipan Das , Michael Ellerman , nd@arm.com, Yury Khrustalev Subject: [PATCH v2 2/3] selftests/mm: Use PKEY_UNRESTRICTED macro Date: Sun, 27 Oct 2024 17:00:05 +0000 Message-Id: <20241027170006.464252-3-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241027170006.464252-1-yury.khrustalev@arm.com> References: <20241027170006.464252-1-yury.khrustalev@arm.com> Precedence: bulk X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Replace literal 0 with macro PKEY_UNRESTRICTED where pkey_*() functions are used in mm selftests for memory protection keys. Signed-off-by: Yury Khrustalev Suggested-by: Joey Gouly --- tools/testing/selftests/mm/mseal_test.c | 4 ++-- tools/testing/selftests/mm/pkey-helpers.h | 3 ++- tools/testing/selftests/mm/pkey_sighandler_tests.c | 4 ++-- tools/testing/selftests/mm/protection_keys.c | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c index 01675c412b2a..eab214997de0 100644 --- a/tools/testing/selftests/mm/mseal_test.c +++ b/tools/testing/selftests/mm/mseal_test.c @@ -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); diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/selftests/mm/pkey-helpers.h index 9ab6a3ee153b..e7fb0fcfcb05 100644 --- a/tools/testing/selftests/mm/pkey-helpers.h +++ b/tools/testing/selftests/mm/pkey-helpers.h @@ -12,6 +12,7 @@ #include #include #include +#include #include "../kselftest.h" @@ -217,7 +218,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; } diff --git a/tools/testing/selftests/mm/pkey_sighandler_tests.c b/tools/testing/selftests/mm/pkey_sighandler_tests.c index a8088b645ad6..76e85d2cf698 100644 --- a/tools/testing/selftests/mm/pkey_sighandler_tests.c +++ b/tools/testing/selftests/mm/pkey_sighandler_tests.c @@ -260,7 +260,7 @@ static void test_sigsegv_handler_with_different_pkey_for_stack(void) __write_pkey_reg(0x55555550); /* Protect the new stack with MPK 1 */ - pkey = pkey_alloc(0, 0); + pkey = pkey_alloc(0, PKEY_UNRESTRICTED); pkey_mprotect(stack, STACK_SIZE, PROT_READ | PROT_WRITE, pkey); /* Set up alternate signal stack that will use the default MPK */ @@ -421,7 +421,7 @@ static void test_pkru_sigreturn(void) __write_pkey_reg(0x55555544); /* Protect the stack with MPK 2 */ - pkey = pkey_alloc(0, 0); + pkey = pkey_alloc(0, PKEY_UNRESTRICTED); pkey_mprotect(stack, STACK_SIZE, PROT_READ | PROT_WRITE, pkey); /* Set up alternate signal stack that will use the default MPK */ diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/selftests/mm/protection_keys.c index 4990f7ab4cb7..cca7435a7bc5 100644 --- a/tools/testing/selftests/mm/protection_keys.c +++ b/tools/testing/selftests/mm/protection_keys.c @@ -491,7 +491,7 @@ int sys_pkey_alloc(unsigned long flags, unsigned long init_val) 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); -- 2.39.5