Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1164290lqt; Tue, 19 Mar 2024 15:01:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWmP42GbtKDmwfWY47XInDtBW7UKWworaKbmaUwYqYafn8ygwr7MAxJy6Fcpzu7pevgLnYCEoOej4pIKtjp9ddrqbDaX26mCGUTpX4SEA== X-Google-Smtp-Source: AGHT+IEg6/AJQt88N27Kvtvj6JsYCxU4quzRVIs3NNFScsak+7L+D3TYQiBUsWFe/j1lqIo2X6NK X-Received: by 2002:a9d:61c7:0:b0:6e5:1715:9a86 with SMTP id h7-20020a9d61c7000000b006e517159a86mr19413644otk.0.1710885704393; Tue, 19 Mar 2024 15:01:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710885704; cv=pass; d=google.com; s=arc-20160816; b=ZtoF1LgXKN8cfDaObLR+RGCXaOVcwBAd+hJoDIvef5VgSOB/OkUeZ3U+eWrtZJX1xl L8xJRGfEO1rk6xTrD3DCGVeZzvUqmLMlUpuN8Ke1FMgkxxF9j0UKGdssazejKcVM4fHl YDqWXEEA5Pp5dkb9q3aUkgs1YPt3OK0Lz1It5uUWXlomXGxYZ1QKXkK8nlw4x3XGd87L wUQtnnGU+RBs75bs2ikKK0VM3TXrwI7AO0Y+EPPcD/gjy622nNA/1YkB3lAfpdFWzhDI asqFCceiCIAf5nRphZzWJZLn/TIjzUY5rAM+g1lfnTpSlzr/DkiwBilsKGGQk8BZBY5m TqCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Pby1JczWDGJraZTWE5gkOPCKAXwxysMeCn/eal1+wiY=; fh=OzxtJpDkvbLwnkvIcZ7boFaUB8oJzHqS2AeEXYyFQAE=; b=NIV4HOFJC0TQ8EPMRq6yvjwDL2h/zZS6JX/VztGxlbU8UT2ZL4OEmgEuxrX6H901s4 LsV1CyQKwIOpvLabD0dGuY/+dyxonoJAbBGe12S82Uu5P+30Rr1uivJp117SFhVpr5dt Vx2NKOnB9t64924Vr8MJEVHaFzCnL0rJY+E2vFQb+Px9E7tAQM7LVgIxjnuxdimUy1kN otumXw+MU67D3uFuqjiZp4Km8+8TDGgHq8jHgOFaQti+/ue+zpTAkbJeV36fudhRhImR lQpn8e9GryQZ1az4C2/wW6mL7ljP1YZOL18hRN55yav4PpY3LcrM8YVJvLXhop7cXfJ4 0/Ug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=daXxp4aU; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-108174-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t13-20020a05621421ad00b006962091c239si4325007qvc.613.2024.03.19.15.01.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 15:01:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108174-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=daXxp4aU; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-108174-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CC71A1C21B5E for ; Tue, 19 Mar 2024 22:01:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16424604B9; Tue, 19 Mar 2024 21:59:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="daXxp4aU" Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00BA7604A4 for ; Tue, 19 Mar 2024 21:59:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710885570; cv=none; b=NW4XKYy1aLWBkbUs16Z8oliJf0XQqpqhOjB2NqUV4+Kc2NILw/SQPZkfP+HTWwjmbzVgAZI0xDZdZZi+3/ZMXOHGg0Y99N3DonAnV13tVaJ0i9NWHyjnOHx4sQirxR8bBQe2thIieh6a5KOeWvB2axjKWrw2n+CeH34PDwB/OOc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710885570; c=relaxed/simple; bh=cVj0XaDyfC/7/EeYMbsI/MsTXEy09yrHAqmoUC/Oaaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fG0tV4hlxbX04pth4aUp892s9dCscZMOtoaTIEGWrdSjm5Z90xQcEp6e/0LA4L4/nK8scy6/9XV++bpF3LlYqFfMsu9L3zW4/aUCihNAjCd6GXDFdbge0gDyQk0QsycWmAXMmsbQLhFaUVSSA4vdNP4zlUQLIjvhDzh2+Tc+2EY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=daXxp4aU; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-5ce2aada130so4792832a12.1 for ; Tue, 19 Mar 2024 14:59:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1710885568; x=1711490368; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Pby1JczWDGJraZTWE5gkOPCKAXwxysMeCn/eal1+wiY=; b=daXxp4aUGlOHqKXHbFqYeo+rrEuVw+Zu2CdODB+SzWP3FpKEqrEhVQgoPmGn32OHgK D9cFCnzjQbaO/5BoFwq02x8VrR/9oRlmnB/A/Y4qHu8w0TTSeOF4pHUVvdY8MFO/5aXL YmyEiiwzyXKcCHT1x+g83X3BQnxTfXXwJF0FvAJPg11uqoR9aLos0UX4cFyTI7PFS70f QLmxeQzh3n9wi01Zzevs/upIA5m0bluGVRLowodgWhcm3CUGoCJvkkPSBd5TxUexODy2 KVaRJeSEzslv3SoP07P7AfMeistDyI3NCO2KwQVWN/lr3YarMLlckhbgtdDslqu52jjX Hing== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710885568; x=1711490368; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pby1JczWDGJraZTWE5gkOPCKAXwxysMeCn/eal1+wiY=; b=qvhNFq+tpYfivktAvu0jKvE9ZEDL95LS6AsiIFe68q8Uxf2HcKnV9lC9zp4SEGxcEK hOrjX4f2TjZHdosR4zK53EPGXUhLFct+1wb8BczMjv4NdoH3AR51+Oa1BuyvlLRk9mtL SvByIQ7nFpOesC0Gi28AUSvm3Tsr447O2Aa8pzDLCRhBZvQU068H5Z8RtXsZ0TEOWNce IPd/Haix4lEMmI6xa6jF36XYyHpJByb6kYzI76AnT5A4R1PC39WMbKtbyXrXxZsKMMLi Hq8BKDjI/bGwgB4i7oon2KYGh7+SDvENDovaebJ3gXY35NL4MOreg3KJPQ0n/EyIrBPD 1swg== X-Forwarded-Encrypted: i=1; AJvYcCU4UI16e/EnaQOJgQiCvljzD5DLupmNR7saXH3yk3Yj+ULCwia+R3iBi9xn9AdFPuC2Z4INjxYWRTCiXO17gzQq25/HCDXZY/q7u3k2 X-Gm-Message-State: AOJu0Yy4E6BXTsnUAdum4xg04Dp0d/MziDikRPBtRo19PGFvKYDaVf/8 D42EVMGYzSVj43JWbDGMaaoycZqGaT8urLMJXnALY76YGhJiz6ngpCdGpTm05Ks= X-Received: by 2002:a05:6a20:c91b:b0:1a1:15ff:43b with SMTP id gx27-20020a056a20c91b00b001a115ff043bmr15335731pzb.23.1710885568321; Tue, 19 Mar 2024 14:59:28 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id z25-20020aa785d9000000b006e6c61b264bsm10273892pfn.32.2024.03.19.14.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 14:59:28 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: devicetree@vger.kernel.org, Catalin Marinas , linux-kernel@vger.kernel.org, tech-j-ext@lists.risc-v.org, Conor Dooley , kasan-dev@googlegroups.com, Evgenii Stepanov , Krzysztof Kozlowski , Rob Herring , Samuel Holland , Albert Ou , Shuah Khan Subject: [RFC PATCH 9/9] selftests: riscv: Add a pointer masking test Date: Tue, 19 Mar 2024 14:58:35 -0700 Message-ID: <20240319215915.832127-10-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240319215915.832127-1-samuel.holland@sifive.com> References: <20240319215915.832127-1-samuel.holland@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This test covers the behavior of the PR_SET_TAGGED_ADDR_CTRL and PR_GET_TAGGED_ADDR_CTRL prctl() operations, their effects on the userspace ABI, and their effects on the system call ABI. Signed-off-by: Samuel Holland --- tools/testing/selftests/riscv/Makefile | 2 +- tools/testing/selftests/riscv/tags/Makefile | 10 + .../selftests/riscv/tags/pointer_masking.c | 307 ++++++++++++++++++ 3 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/riscv/tags/Makefile create mode 100644 tools/testing/selftests/riscv/tags/pointer_masking.c diff --git a/tools/testing/selftests/riscv/Makefile b/tools/testing/selftests/riscv/Makefile index 4a9ff515a3a0..6e7e6621a71a 100644 --- a/tools/testing/selftests/riscv/Makefile +++ b/tools/testing/selftests/riscv/Makefile @@ -5,7 +5,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),riscv)) -RISCV_SUBTARGETS ?= hwprobe vector mm +RISCV_SUBTARGETS ?= hwprobe mm tags vector else RISCV_SUBTARGETS := endif diff --git a/tools/testing/selftests/riscv/tags/Makefile b/tools/testing/selftests/riscv/tags/Makefile new file mode 100644 index 000000000000..ed82ff9c664e --- /dev/null +++ b/tools/testing/selftests/riscv/tags/Makefile @@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 + +CFLAGS += -I$(top_srcdir)/tools/include + +TEST_GEN_PROGS := pointer_masking + +include ../../lib.mk + +$(OUTPUT)/pointer_masking: pointer_masking.c + $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^ diff --git a/tools/testing/selftests/riscv/tags/pointer_masking.c b/tools/testing/selftests/riscv/tags/pointer_masking.c new file mode 100644 index 000000000000..c9f66e8436ab --- /dev/null +++ b/tools/testing/selftests/riscv/tags/pointer_masking.c @@ -0,0 +1,307 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../kselftest.h" + +#ifndef PR_PMLEN_SHIFT +#define PR_PMLEN_SHIFT 24 +#endif +#ifndef PR_PMLEN_MASK +#define PR_PMLEN_MASK (0x7fUL << PR_PMLEN_SHIFT) +#endif + +static int dev_zero; + +static sigjmp_buf jmpbuf; + +static void sigsegv_handler(int sig) +{ + siglongjmp(jmpbuf, 1); +} + +static int min_pmlen; +static int max_pmlen; + +static inline bool valid_pmlen(int pmlen) +{ + return pmlen == 0 || pmlen == 7 || pmlen == 16; +} + +static void test_pmlen(void) +{ + ksft_print_msg("Testing available PMLEN values\n"); + + for (int request = 0; request <= 16; request++) { + int pmlen, ret; + + ret = prctl(PR_SET_TAGGED_ADDR_CTRL, request << PR_PMLEN_SHIFT, 0, 0, 0); + if (ret) { + ksft_test_result_skip("PMLEN=%d PR_GET_TAGGED_ADDR_CTRL\n", request); + ksft_test_result_skip("PMLEN=%d constraint\n", request); + ksft_test_result_skip("PMLEN=%d validity\n", request); + continue; + } + + ret = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0); + ksft_test_result(ret >= 0, "PMLEN=%d PR_GET_TAGGED_ADDR_CTRL\n", request); + if (ret < 0) { + ksft_test_result_skip("PMLEN=%d constraint\n", request); + ksft_test_result_skip("PMLEN=%d validity\n", request); + continue; + } + + pmlen = (ret & PR_PMLEN_MASK) >> PR_PMLEN_SHIFT; + ksft_test_result(pmlen >= request, "PMLEN=%d constraint\n", request); + ksft_test_result(valid_pmlen(pmlen), "PMLEN=%d validity\n", request); + + if (min_pmlen == 0) + min_pmlen = pmlen; + if (max_pmlen < pmlen) + max_pmlen = pmlen; + } + + if (max_pmlen == 0) + ksft_exit_fail_msg("Failed to enable pointer masking\n"); +} + +static int set_tagged_addr_ctrl(int pmlen, bool tagged_addr_abi) +{ + int arg, ret; + + arg = pmlen << PR_PMLEN_SHIFT | tagged_addr_abi; + ret = prctl(PR_SET_TAGGED_ADDR_CTRL, arg, 0, 0, 0); + if (!ret) { + ret = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0); + if (ret == arg) + return 0; + } + + return ret < 0 ? -errno : -ENODATA; +} + +static void test_dereference_pmlen(int pmlen) +{ + static volatile int i; + volatile int *p; + int ret; + + ret = set_tagged_addr_ctrl(pmlen, false); + if (ret) + return ksft_test_result_error("PMLEN=%d setup (%d)\n", pmlen, ret); + + i = pmlen; + + if (pmlen) { + p = (volatile int *)((uintptr_t)&i | 1UL << __riscv_xlen - pmlen); + + /* These dereferences should succeed. */ + if (sigsetjmp(jmpbuf, 1)) + return ksft_test_result_fail("PMLEN=%d valid tag\n", pmlen); + if (*p != pmlen) + return ksft_test_result_fail("PMLEN=%d bad value\n", pmlen); + *p++; + } + + p = (volatile int *)((uintptr_t)&i | 1UL << __riscv_xlen - pmlen - 1); + + /* These dereferences should raise SIGSEGV. */ + if (sigsetjmp(jmpbuf, 1)) + return ksft_test_result_pass("PMLEN=%d dereference\n", pmlen); + *p++; + ksft_test_result_fail("PMLEN=%d invalid tag\n", pmlen); +} + +static void test_dereference(void) +{ + ksft_print_msg("Testing userspace pointer dereference\n"); + + signal(SIGSEGV, sigsegv_handler); + + test_dereference_pmlen(0); + test_dereference_pmlen(min_pmlen); + test_dereference_pmlen(max_pmlen); + + signal(SIGSEGV, SIG_DFL); +} + +static void test_fork_exec(void) +{ + int ret, status; + + ksft_print_msg("Testing fork/exec behavior\n"); + + ret = set_tagged_addr_ctrl(min_pmlen, false); + if (ret) + return ksft_test_result_error("setup (%d)\n", ret); + + if (fork()) { + wait(&status); + ksft_test_result(WIFEXITED(status) && WEXITSTATUS(status) == 0, + "dereference after fork\n"); + } else { + static volatile int i; + volatile int *p = (volatile int *)((uintptr_t)&i | 1UL << __riscv_xlen - min_pmlen); + + exit(*p); + } + + if (fork()) { + wait(&status); + ksft_test_result(WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV, + "dereference after fork+exec\n"); + } else { + execl("/proc/self/exe", "", NULL); + } +} + +static void test_tagged_addr_abi_sysctl(void) +{ + char value; + int fd; + + ksft_print_msg("Testing tagged address ABI sysctl\n"); + + fd = open("/proc/sys/abi/tagged_addr_disabled", O_WRONLY); + if (fd < 0) { + ksft_test_result_skip("failed to open sysctl file\n"); + ksft_test_result_skip("failed to open sysctl file\n"); + return; + } + + value = '1'; + pwrite(fd, &value, 1, 0); + ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == -EINVAL, + "sysctl disabled\n"); + + value = '0'; + pwrite(fd, &value, 1, 0); + ksft_test_result(set_tagged_addr_ctrl(min_pmlen, true) == 0, + "sysctl enabled\n"); + + set_tagged_addr_ctrl(0, false); + + close(fd); +} + +static void test_tagged_addr_abi_pmlen(int pmlen) +{ + int i, *p, ret; + + i = ~pmlen; + + if (pmlen) { + p = (int *)((uintptr_t)&i | 1UL << __riscv_xlen - pmlen); + + ret = set_tagged_addr_ctrl(pmlen, false); + if (ret) + return ksft_test_result_error("PMLEN=%d ABI disabled setup (%d)\n", + pmlen, ret); + + ret = write(dev_zero, p, sizeof(*p)); + if (ret >= 0 || errno != EFAULT) + return ksft_test_result_fail("PMLEN=%d ABI disabled write\n", pmlen); + + ret = read(dev_zero, p, sizeof(*p)); + if (ret >= 0 || errno != EFAULT) + return ksft_test_result_fail("PMLEN=%d ABI disabled read\n", pmlen); + + if (i != ~pmlen) + return ksft_test_result_fail("PMLEN=%d ABI disabled value\n", pmlen); + + ret = set_tagged_addr_ctrl(pmlen, true); + if (ret) + return ksft_test_result_error("PMLEN=%d ABI enabled setup (%d)\n", + pmlen, ret); + + ret = write(dev_zero, p, sizeof(*p)); + if (ret != sizeof(*p)) + return ksft_test_result_fail("PMLEN=%d ABI enabled write\n", pmlen); + + ret = read(dev_zero, p, sizeof(*p)); + if (ret != sizeof(*p)) + return ksft_test_result_fail("PMLEN=%d ABI enabled read\n", pmlen); + + if (i) + return ksft_test_result_fail("PMLEN=%d ABI enabled value\n", pmlen); + + i = ~pmlen; + } else { + /* The tagged address ABI cannot be enabled when PMLEN == 0. */ + ret = set_tagged_addr_ctrl(pmlen, true); + if (ret != -EINVAL) + return ksft_test_result_error("PMLEN=%d ABI setup (%d)\n", + pmlen, ret); + } + + p = (int *)((uintptr_t)&i | 1UL << __riscv_xlen - pmlen - 1); + + ret = write(dev_zero, p, sizeof(*p)); + if (ret >= 0 || errno != EFAULT) + return ksft_test_result_fail("PMLEN=%d invalid tag write (%d)\n", pmlen, errno); + + ret = read(dev_zero, p, sizeof(*p)); + if (ret >= 0 || errno != EFAULT) + return ksft_test_result_fail("PMLEN=%d invalid tag read\n", pmlen); + + if (i != ~pmlen) + return ksft_test_result_fail("PMLEN=%d invalid tag value\n", pmlen); + + ksft_test_result_pass("PMLEN=%d tagged address ABI\n", pmlen); +} + +static void test_tagged_addr_abi(void) +{ + ksft_print_msg("Testing tagged address ABI\n"); + + test_tagged_addr_abi_pmlen(0); + test_tagged_addr_abi_pmlen(min_pmlen); + test_tagged_addr_abi_pmlen(max_pmlen); +} + +static struct test_info { + unsigned int nr_tests; + void (*test_fn)(void); +} tests[] = { + { .nr_tests = 17 * 3, test_pmlen }, + { .nr_tests = 3, test_dereference }, + { .nr_tests = 2, test_fork_exec }, + { .nr_tests = 2, test_tagged_addr_abi_sysctl }, + { .nr_tests = 3, test_tagged_addr_abi }, +}; + +int main(int argc, char **argv) +{ + unsigned int plan = 0; + + /* Check if this is the child process after execl(). */ + if (!argv[0][0]) { + static volatile int i; + volatile int *p = (volatile int *)((uintptr_t)&i | 1UL << __riscv_xlen - 7); + + return *p; + } + + dev_zero = open("/dev/zero", O_RDWR); + if (dev_zero < 0) + return 1; + + ksft_print_header(); + + for (int i = 0; i < ARRAY_SIZE(tests); ++i) + plan += tests[i].nr_tests; + + ksft_set_plan(plan); + + for (int i = 0; i < ARRAY_SIZE(tests); ++i) + tests[i].test_fn(); + + ksft_finished(); +} -- 2.43.1