From patchwork Mon Dec 9 09:47:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Khrustalev X-Patchwork-Id: 13899160 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36BC0E77173 for ; Mon, 9 Dec 2024 09:47:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A47446B03AF; Mon, 9 Dec 2024 04:47:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 983096B03F5; Mon, 9 Dec 2024 04:47:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B16D6B039D; Mon, 9 Dec 2024 04:47:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5DAD36B03F4 for ; Mon, 9 Dec 2024 04:47:53 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E32821203E7 for ; Mon, 9 Dec 2024 09:47:52 +0000 (UTC) X-FDA: 82874943186.06.7F39C0A Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf05.hostedemail.com (Postfix) with ESMTP id 3A99F100011 for ; Mon, 9 Dec 2024 09:47:12 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of yury.khrustalev@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=yury.khrustalev@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733737652; a=rsa-sha256; cv=none; b=JPueD06q6Kvy6AYX/fSVrc/1K0LoEvuvgeAe17n5rDtVNSQsBqLCbEokdgPN8IT7/UCZ9n 5HjezPiv/Xd2Jjt7WDSPWNc2Cm31hFt2fCC+10X4F6SdptmXujRiFHKeFBerXJPQGbL/+h MnJU2liEa6BPqWz+tkT4juxFnWqb5XY= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of yury.khrustalev@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=yury.khrustalev@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733737652; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+b1vwyUt9X+x+fq4vNsQWkXSJqfTlOBMiVr4yBA8vrE=; b=zBdZ7TW7rOvOUgy0muonD9HuL0A+UgDrhVNrwc8JUHmV9GELwhad6CqFZkMrsw2TZLQ1BM s1Phgo0Ebo6Z9HAJQw1TBrWQzXud1J4l5S0qY0rr111wjpk/2nIS7hwVcN8t80QYUY11qW tPrYDirV8s8kA3LDBI9+oZSNLH5TDvk= 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 9EF0A1650; Mon, 9 Dec 2024 01:48:18 -0800 (PST) Received: from udebian.localdomain (unknown [10.1.35.36]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7538B3F720; Mon, 9 Dec 2024 01:47:48 -0800 (PST) From: Yury Khrustalev To: linux-arch@vger.kernel.org Cc: Arnd Bergmann , Kevin Brodsky , Joey Gouly , Dave Hansen , Sandipan Das , Michael Ellerman , Catalin Marinas , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, nd@arm.com, Yury Khrustalev Subject: [RESEND v4 2/3] selftests/mm: Use PKEY_UNRESTRICTED macro Date: Mon, 9 Dec 2024 09:47:18 +0000 Message-Id: <20241209094719.2431126-3-yury.khrustalev@arm.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241209094719.2431126-1-yury.khrustalev@arm.com> References: <20241209094719.2431126-1-yury.khrustalev@arm.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3A99F100011 X-Stat-Signature: xatwhkddzpsimxehuqafkak5oymmg67z X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1733737632-476603 X-HE-Meta: U2FsdGVkX19DK99jo7xm9euNk+mzZo4kuDDnimHszJcf+Hc82D9pVRF40RC0VnoLX8ip1aLQq//OgrcE+m/CJRCsGddLo2uZdr8Y/CEdVO5ekjgoX5v/hZfo+eVs6cRKljssN0d6sdfDNn5vPtSu6SbsxpjIbmd9TBKM7guvmyeBQNC24zWova95E7xldpOXybxrXm3JD/SkJgTHDX8nnickOktGwZtE8dGZX25J5rMu/QU1Omg0dgqucNqJSujJmDks/vZAW4nI34d2Tu1YsfnwrVnhKaLcemDFomAQJzQuzOtpLHQosnmGQ/dEncr5StJSjWFMqp+TNKxD+ySwwIvBrcPNDIpXAkbf3wp/WfiuGe6dIcnr3f40yg6DGLVcYl3JfNyPrzaeSSlFkkxl8fHhdI9LFrFOl3VqXBb6xQjJqS7VYgNkX/Iqn4KRguEK7Rf8MfreQE5DcHpTAcHqrCYOMrroaqDnf87YokpPA9LowfrSvgybhijtVBt691zcJdvIoZ9CjjbpSNnehNdg+5S8Kb8x9nK6d8LTogHmGfaJgLlI1SsPN0l97WSs7vRvCZFDCGEbJGnY1aMIvldFPD7jFw9YiSM8TKppZQFDNZ1f1wF8T6p3CKnt/kiZ8HtuerI1FG7PcyoRjF7x+UcY9picu9eox/tE6I2DR7o9WXlGpnNtt4BvqbKd05iRIumW26yrU+EaldHutwGvrM09tJWnIE6T+OiUa1UTz8aJtn89pvyXhSfF1prQ5DZBNvKRhVfiDTxPzRkEk0FeK7EAtiynz6TIvv60FEVMTB8+AYZzIfEcbf5SDj2eveaVBvcVGB44JAluSGsITxbYfO9ldIBnTj48bReqTqJXPqK4rFaGFjitllWDfOtK8mBn8+HkXFjVN8PBaMogreeAikvIS/eJSX8ZjzD6BWoFYvZ4p4C3pnH+pEMqTUYOCQlfZ/4OQPwVujzB/JxUwo72fAI S8iHZWEU WfuBcyrVsnlWRQ+tFDGMhqmjlTKdf4SVQ1rd/W51/pjPy8llOldrSQeALG22MOqKeLJx0Gr7ajpbHxUWngU+lq6JI7OCR9V07J8kCVFHWf2nq20zkRPCfAEKiJG111F4JZ9zBalOJ6QKg/QIdMFeSnoqTdLbY9wx4r2iEy2TDnLjSkaiuuBy7Jfs0mSPn2muhEA7Ndq8P1PR/RIQleK3S0yQxPYT2Nzp1nlpt0gXGkgMItoDy47abfpF/1x1eLqUOKeQSnYCVlu4J9dtAY+al5i7pSrdkvu5GQd0/c+/D0wzRyToaIU5cPaBeteDrDUYDXJ56WSR1KdWcrhp3K086HOtOaBJEhJFA+H4p X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Acked-by: Dave Hansen --- tools/testing/selftests/mm/mseal_test.c | 6 +++--- 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, 8 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/mm/mseal_test.c b/tools/testing/selftests/mm/mseal_test.c index 01675c412b2a..30ea37e8ecf8 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); @@ -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); diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/selftests/mm/pkey-helpers.h index f7cfe163b0ff..10fa3ca9b05b 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" @@ -224,7 +225,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 c593a426341c..2015ed7e0928 100644 --- a/tools/testing/selftests/mm/pkey_sighandler_tests.c +++ b/tools/testing/selftests/mm/pkey_sighandler_tests.c @@ -314,7 +314,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 = 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 */ @@ -487,7 +487,7 @@ static void test_pkru_sigreturn(void) __write_pkey_reg(pkey_reg); /* 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);