From nobody Mon Jun 8 23:58:39 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7E163D3323; Mon, 25 May 2026 07:30:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779694213; cv=none; b=R5g6rI+mM+tqmZbHNc6XD0DlnHrMBbsK+wLbI8J+uctzDv0u5UwO0DXI6S9ZP8yYqfB6JNYuUFHk0Q+5SLbXh1OGrV9Dnlp6t5+MIYF7OHKpqdMa4pOMwfCqY1yyJKQFEpi8VHCKj9N3hIFLslQetbiEwopqWHg38nFQCC8pj50= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779694213; c=relaxed/simple; bh=AbHvoyGI2qVMetuC9YAAZ702NE4Kh0uEmzdyEYzklDs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fGTkVFj8941pjkfKqKyOLPXY3X8ajqTbbpsQIUtq8CjwnjbJpT2IOHemLBo1LKypVvd+ROodripYg/rVqw3MHBsm/3JXm5T+U2eqbrEa7T5DxMuzHcLSZyCv+sXYCJ4NvCAAeIt07KFhQ7j1IeFZugb+giCv4W71IQlSxMMFrm0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 8bdc1aea580b11f1aa26b74ffac11d73-20260525 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT HR_TO_NO_NAME, IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED, SA_TRUSTED SA_EXISTED, SN_TRUSTED, SN_EXISTED, SPF_NOPASS, DKIM_NOPASS DMARC_NOPASS, CIE_BAD, CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS GTI_RG_INFO, GTI_C_BU, AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:2d607d9e-0bbe-496a-8473-99bc0d7ef1b5,IP:10, URL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-15 X-CID-INFO: VERSION:1.3.12,REQID:2d607d9e-0bbe-496a-8473-99bc0d7ef1b5,IP:10,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-15 X-CID-META: VersionHash:e7bac3a,CLOUDID:341bd9be7fc0d3c603e395929ad45ecd,BulkI D:2605251530051OC24BVG,BulkQuantity:0,Recheck:0,SF:17|19|38|66|78|81|82|10 2|127|850|865|898,TC:nil,Content:0|15|50,EDM:-3,IP:-2,URL:0,File:nil,RT:ni l,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0, BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 8bdc1aea580b11f1aa26b74ffac11d73-20260525 X-User: lihongfu@kylinos.cn Received: from localhost.localdomain [(223.70.159.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 2044545035; Mon, 25 May 2026 15:30:03 +0800 From: Hongfu Li To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, shuah@kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Hongfu Li Subject: [PATCH v2 1/2] selftests/mm: refactor pkey test helpers and unify assertions Date: Mon, 25 May 2026 15:30:25 +0800 Message-Id: <20260525073026.27594-2-lihongfu@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260525073026.27594-1-lihongfu@kylinos.cn> References: <20260525073026.27594-1-lihongfu@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move shared tracing and assertion helpers to a common file, then convert the sighandler test to use pkey_assert() for consistent diagnostic output, and add per-test tracing around test execution. Signed-off-by: Hongfu Li --- tools/testing/selftests/mm/pkey-helpers.h | 5 +- .../selftests/mm/pkey_sighandler_tests.c | 18 ++-- tools/testing/selftests/mm/pkey_util.c | 81 ++++++++++++++++++ tools/testing/selftests/mm/protection_keys.c | 82 ------------------- 4 files changed, 96 insertions(+), 90 deletions(-) diff --git a/tools/testing/selftests/mm/pkey-helpers.h b/tools/testing/self= tests/mm/pkey-helpers.h index 7c29f075e40b..de9052386343 100644 --- a/tools/testing/selftests/mm/pkey-helpers.h +++ b/tools/testing/selftests/mm/pkey-helpers.h @@ -68,7 +68,10 @@ static inline void sigsafe_printf(const char *format, ..= .) #define dprintf3(args...) dprintf_level(3, args) #define dprintf4(args...) dprintf_level(4, args) =20 -extern void abort_hooks(void); +void cat_into_file(char *str, char *file); +void tracing_on(void); +void tracing_off(void); +void abort_hooks(void); #define pkey_assert(condition) do { \ if (!(condition)) { \ dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \ diff --git a/tools/testing/selftests/mm/pkey_sighandler_tests.c b/tools/tes= ting/selftests/mm/pkey_sighandler_tests.c index 302fef54049c..a390d183ebdc 100644 --- a/tools/testing/selftests/mm/pkey_sighandler_tests.c +++ b/tools/testing/selftests/mm/pkey_sighandler_tests.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -36,6 +35,10 @@ static pthread_mutex_t mutex =3D PTHREAD_MUTEX_INITIALIZ= ER; static pthread_cond_t cond =3D PTHREAD_COND_INITIALIZER; static siginfo_t siginfo =3D {0}; =20 +int iteration_nr =3D 1; +int test_nr; +int dprint_in_signal; + /* * We need to use inline assembly instead of glibc's syscall because glibc= 's * syscall will attempt to access the PLT in order to call a library funct= ion @@ -302,7 +305,7 @@ static void test_sigsegv_handler_with_different_pkey_fo= r_stack(void) stack =3D mmap(0, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); =20 - assert(stack !=3D MAP_FAILED); + pkey_assert(stack !=3D MAP_FAILED); =20 /* Allow access to MPK 0 and MPK 1 */ pkey_reg =3D pkey_reg_restrictive_default(); @@ -470,7 +473,7 @@ static void test_pkru_sigreturn(void) stack =3D mmap(0, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); =20 - assert(stack !=3D MAP_FAILED); + pkey_assert(stack !=3D MAP_FAILED); =20 /* * Allow access to MPK 0 and MPK 2. The child thread (to be created @@ -530,16 +533,17 @@ static void (*pkey_tests[])(void) =3D { =20 int main(int argc, char *argv[]) { - int i; - ksft_print_header(); ksft_set_plan(ARRAY_SIZE(pkey_tests)); =20 if (!is_pkeys_supported()) ksft_exit_skip("pkeys not supported\n"); =20 - for (i =3D 0; i < ARRAY_SIZE(pkey_tests); i++) - (*pkey_tests[i])(); + for (test_nr =3D 0; test_nr < ARRAY_SIZE(pkey_tests); test_nr++) { + tracing_on(); + (*pkey_tests[test_nr])(); + tracing_off(); + } =20 ksft_finished(); return 0; diff --git a/tools/testing/selftests/mm/pkey_util.c b/tools/testing/selftes= ts/mm/pkey_util.c index 255b332f7a08..a080d1dcc82d 100644 --- a/tools/testing/selftests/mm/pkey_util.c +++ b/tools/testing/selftests/mm/pkey_util.c @@ -2,9 +2,90 @@ #define __SANE_USERSPACE_TYPES__ #include #include +#include +#include +#include =20 #include "pkey-helpers.h" =20 +void cat_into_file(char *str, char *file) +{ + int fd =3D open(file, O_RDWR); + int ret; + + dprintf2("%s(): writing '%s' to '%s'\n", __func__, str, file); + if (fd < 0) { + fprintf(stderr, "error opening '%s'\n", str); + perror("error: "); + exit(__LINE__); + } + + ret =3D write(fd, str, strlen(str)); + if (ret !=3D strlen(str)) { + perror("write to file failed"); + fprintf(stderr, "filename: '%s' str: '%s'\n", file, str); + exit(__LINE__); + } + close(fd); +} + +#if CONTROL_TRACING > 0 +static int warned_tracing; +static int tracing_root_ok(void) +{ + if (geteuid() !=3D 0) { + if (!warned_tracing) + fprintf(stderr, "WARNING: not run as root, " + "can not do tracing control\n"); + warned_tracing =3D 1; + return 0; + } + return 1; +} +#endif + +void tracing_on(void) +{ +#if CONTROL_TRACING > 0 +#define TRACEDIR "/sys/kernel/tracing" + char pidstr[32]; + + if (!tracing_root_ok()) + return; + + sprintf(pidstr, "%d", getpid()); + cat_into_file("0", TRACEDIR "/tracing_on"); + cat_into_file("\n", TRACEDIR "/trace"); + if (1) { + cat_into_file("function_graph", TRACEDIR "/current_tracer"); + cat_into_file("1", TRACEDIR "/options/funcgraph-proc"); + } else { + cat_into_file("nop", TRACEDIR "/current_tracer"); + } + cat_into_file(pidstr, TRACEDIR "/set_ftrace_pid"); + cat_into_file("1", TRACEDIR "/tracing_on"); + dprintf1("enabled tracing\n"); +#endif +} + +void tracing_off(void) +{ +#if CONTROL_TRACING > 0 + if (!tracing_root_ok()) + return; + cat_into_file("0", "/sys/kernel/tracing/tracing_on"); +#endif +} + +void abort_hooks(void) +{ + fprintf(stderr, "running %s()...\n", __func__); + tracing_off(); +#ifdef SLEEP_ON_ABORT + sleep(SLEEP_ON_ABORT); +#endif +} + int sys_pkey_alloc(unsigned long flags, unsigned long init_val) { int ret =3D syscall(SYS_pkey_alloc, flags, init_val); diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/s= elftests/mm/protection_keys.c index 2085982dba69..3c0cbf8f3eaa 100644 --- a/tools/testing/selftests/mm/protection_keys.c +++ b/tools/testing/selftests/mm/protection_keys.c @@ -61,88 +61,6 @@ noinline int read_ptr(int *ptr) return *ptr; } =20 -static void cat_into_file(char *str, char *file) -{ - int fd =3D open(file, O_RDWR); - int ret; - - dprintf2("%s(): writing '%s' to '%s'\n", __func__, str, file); - /* - * these need to be raw because they are called under - * pkey_assert() - */ - if (fd < 0) { - fprintf(stderr, "error opening '%s'\n", str); - perror("error: "); - exit(__LINE__); - } - - ret =3D write(fd, str, strlen(str)); - if (ret !=3D strlen(str)) { - perror("write to file failed"); - fprintf(stderr, "filename: '%s' str: '%s'\n", file, str); - exit(__LINE__); - } - close(fd); -} - -#if CONTROL_TRACING > 0 -static int warned_tracing; -static int tracing_root_ok(void) -{ - if (geteuid() !=3D 0) { - if (!warned_tracing) - fprintf(stderr, "WARNING: not run as root, " - "can not do tracing control\n"); - warned_tracing =3D 1; - return 0; - } - return 1; -} -#endif - -static void tracing_on(void) -{ -#if CONTROL_TRACING > 0 -#define TRACEDIR "/sys/kernel/tracing" - char pidstr[32]; - - if (!tracing_root_ok()) - return; - - sprintf(pidstr, "%d", getpid()); - cat_into_file("0", TRACEDIR "/tracing_on"); - cat_into_file("\n", TRACEDIR "/trace"); - if (1) { - cat_into_file("function_graph", TRACEDIR "/current_tracer"); - cat_into_file("1", TRACEDIR "/options/funcgraph-proc"); - } else { - cat_into_file("nop", TRACEDIR "/current_tracer"); - } - cat_into_file(pidstr, TRACEDIR "/set_ftrace_pid"); - cat_into_file("1", TRACEDIR "/tracing_on"); - dprintf1("enabled tracing\n"); -#endif -} - -static void tracing_off(void) -{ -#if CONTROL_TRACING > 0 - if (!tracing_root_ok()) - return; - cat_into_file("0", "/sys/kernel/tracing/tracing_on"); -#endif -} - -void abort_hooks(void) -{ - fprintf(stderr, "running %s()...\n", __func__); - tracing_off(); -#ifdef SLEEP_ON_ABORT - sleep(SLEEP_ON_ABORT); -#endif -} - /* * This attempts to have roughly a page of instructions followed by a few * instructions that do a write, and another page of instructions. That --=20 2.50.1 From nobody Mon Jun 8 23:58:39 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C07B3A7F57; Mon, 25 May 2026 07:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779694216; cv=none; b=IyvqKEn7+VAe6cJM5BcTpqSfuK7LmrjKM+nvBunygW7C6Cf4QapBxMSezFcOTeM+DSnEq4MxlhuksIOO8r7V2NJqap++C44uV2qxWcWtRwdpA0//4c4YsxuOrtHgiKF+RTOExFQB4IfyKDSP45xJu0fD6iyEAyD5/CojKIkZE1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779694216; c=relaxed/simple; bh=kJGzW2bXhqAPfmxpJFHta5TRCcmNNdkk8Dpyh6vFYeE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oJiA0SswTJ77O7wgM9JNep0IxJPKUyxKuYpm/zFjBJRcXOaSsGo+BiTU2qcVfVUWd1d9GMALQRhHSKFGrKnjiGc/axYV1iiIqTDnQMzvBmTH++qOHKLVzWg5jXsPtpj495lM9+eupa+IyYkejWrbgeZYeLiqKfwVzG8JslM7ruY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 8d92659c580b11f1aa26b74ffac11d73-20260525 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT HR_TO_NO_NAME, IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED, SA_TRUSTED SA_EXISTED, SN_TRUSTED, SN_EXISTED, SPF_NOPASS, DKIM_NOPASS DMARC_NOPASS, CIE_BAD, CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS GTI_RG_INFO, GTI_C_BU, AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:e20a2a85-badf-486e-9b8e-38006600a15c,IP:10, URL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-15 X-CID-INFO: VERSION:1.3.12,REQID:e20a2a85-badf-486e-9b8e-38006600a15c,IP:10,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-15 X-CID-META: VersionHash:e7bac3a,CLOUDID:cc07f8eb02a872ef031ba1554e11b9d8,BulkI D:260525153008XY0789IE,BulkQuantity:0,Recheck:0,SF:17|19|38|66|78|81|82|10 2|127|850|865|898,TC:nil,Content:0|15|50,EDM:-3,IP:-2,URL:0,File:nil,RT:ni l,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0, BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 8d92659c580b11f1aa26b74ffac11d73-20260525 X-User: lihongfu@kylinos.cn Received: from localhost.localdomain [(223.70.159.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 701083469; Mon, 25 May 2026 15:30:06 +0800 From: Hongfu Li To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, shuah@kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Hongfu Li Subject: [PATCH v2 2/2] selftests/mm: add missing mmap() return checks in pkey tests Date: Mon, 25 May 2026 15:30:26 +0800 Message-Id: <20260525073026.27594-3-lihongfu@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260525073026.27594-1-lihongfu@kylinos.cn> References: <20260525073026.27594-1-lihongfu@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add missing checks against mmap() return value, replace (void *)-1 with MAP_FAILED for better readability and consistency. In the unsupported pkeys CPU test path, replace assert() with an explicit MAP_FAILED check that provides a clearer error message on failure. Signed-off-by: Hongfu Li --- tools/testing/selftests/mm/pkey-powerpc.h | 2 +- .../testing/selftests/mm/pkey_sighandler_tests.c | 2 ++ tools/testing/selftests/mm/protection_keys.c | 16 ++++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/mm/pkey-powerpc.h b/tools/testing/self= tests/mm/pkey-powerpc.h index 17bf2d1b0192..f482b1abcf55 100644 --- a/tools/testing/selftests/mm/pkey-powerpc.h +++ b/tools/testing/selftests/mm/pkey-powerpc.h @@ -126,7 +126,7 @@ static inline void *malloc_pkey_with_mprotect_subpage(l= ong size, int prot, u16 p size, prot, pkey); pkey_assert(pkey < NR_PKEYS); ptr =3D mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - pkey_assert(ptr !=3D (void *)-1); + pkey_assert(ptr !=3D MAP_FAILED); =20 ret =3D syscall(__NR_subpage_prot, ptr, size, NULL); if (ret) { diff --git a/tools/testing/selftests/mm/pkey_sighandler_tests.c b/tools/tes= ting/selftests/mm/pkey_sighandler_tests.c index a390d183ebdc..eb7893ac6ebf 100644 --- a/tools/testing/selftests/mm/pkey_sighandler_tests.c +++ b/tools/testing/selftests/mm/pkey_sighandler_tests.c @@ -320,6 +320,7 @@ static void test_sigsegv_handler_with_different_pkey_fo= r_stack(void) /* Set up alternate signal stack that will use the default MPK */ sigstack.ss_sp =3D mmap(0, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + pkey_assert(sigstack.ss_sp !=3D MAP_FAILED); sigstack.ss_flags =3D 0; sigstack.ss_size =3D STACK_SIZE; =20 @@ -493,6 +494,7 @@ static void test_pkru_sigreturn(void) /* Set up alternate signal stack that will use the default MPK */ sigstack.ss_sp =3D mmap(0, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + pkey_assert(sigstack.ss_sp !=3D MAP_FAILED); sigstack.ss_flags =3D 0; sigstack.ss_size =3D STACK_SIZE; =20 diff --git a/tools/testing/selftests/mm/protection_keys.c b/tools/testing/s= elftests/mm/protection_keys.c index 3c0cbf8f3eaa..ae474e65f3aa 100644 --- a/tools/testing/selftests/mm/protection_keys.c +++ b/tools/testing/selftests/mm/protection_keys.c @@ -585,7 +585,7 @@ static void *malloc_pkey_with_mprotect(long size, int p= rot, u16 pkey) size, prot, pkey); pkey_assert(pkey < NR_PKEYS); ptr =3D mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - pkey_assert(ptr !=3D (void *)-1); + pkey_assert(ptr !=3D MAP_FAILED); ret =3D mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey); pkey_assert(!ret); record_pkey_malloc(ptr, size, prot); @@ -608,7 +608,7 @@ static void *malloc_pkey_anon_huge(long size, int prot,= u16 pkey) */ size =3D ALIGN_UP(size, HPAGE_SIZE * 2); ptr =3D mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - pkey_assert(ptr !=3D (void *)-1); + pkey_assert(ptr !=3D MAP_FAILED); record_pkey_malloc(ptr, size, prot); mprotect_pkey(ptr, size, prot, pkey); =20 @@ -688,7 +688,7 @@ static void *malloc_pkey_hugetlb(long size, int prot, u= 16 pkey) size =3D ALIGN_UP(size, HPAGE_SIZE * 2); pkey_assert(pkey < NR_PKEYS); ptr =3D mmap(NULL, size, PROT_NONE, flags, -1, 0); - pkey_assert(ptr !=3D (void *)-1); + pkey_assert(ptr !=3D MAP_FAILED); mprotect_pkey(ptr, size, prot, pkey); =20 record_pkey_malloc(ptr, size, prot); @@ -717,7 +717,7 @@ static void *malloc_pkey(long size, int prot, u16 pkey) pkey_assert(malloc_type < nr_malloc_types); =20 ret =3D pkey_malloc[malloc_type](size, prot, pkey); - pkey_assert(ret !=3D (void *)-1); + pkey_assert(ret !=3D MAP_FAILED); =20 malloc_type++; if (malloc_type >=3D nr_malloc_types) @@ -1135,6 +1135,7 @@ static void arch_force_pkey_reg_init(void) * doing the XSAVE size enumeration dance. */ buf =3D mmap(NULL, 1*MB, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE,= -1, 0); + pkey_assert(buf !=3D MAP_FAILED); =20 /* These __builtins require compiling with -mxsave */ =20 @@ -1693,7 +1694,10 @@ int main(void) printf("running PKEY tests for unsupported CPU/OS\n"); =20 ptr =3D mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); - assert(ptr !=3D (void *)-1); + if (ptr =3D=3D MAP_FAILED) { + perror("mmap"); + return EXIT_FAILURE; + } test_mprotect_pkey_on_unsupported_cpu(ptr, 1); exit(0); } @@ -1706,5 +1710,5 @@ int main(void) run_tests_once(); =20 printf("done (all tests OK)\n"); - return 0; + return EXIT_SUCCESS; } --=20 2.50.1