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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68018C433FE for ; Fri, 18 Nov 2022 16:25:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=e3X/UqI2Me3GZHdGYFCWznWKMsJwBquC4YioVJ6R3uc=; b=JPU0goqhJnsXgG aMqcWO4ftuRshfB5o4s7GDlwaaiiJcYLs7XjXSh0/zfxyAffEO/Kv26DNzVENeZzozHp+5/fumejV Fkf5/54uLrGqXhRkm0GkMdb2N0Kj+eysD11gomrsf+Y5kB8PIAcvv/S5lkG4dkarl6M4G1ppg6WDV FUYWe+m8PkDbGyCfrSCWx3EjLKdb8vrH3xLEEP4nxQyWxMyEr4EPm9XAsviN7YuL3xUV2U/0Lt3Do izZdDs7pNSJzUb2RsV7nZ2K8HJ8pBi4ss5prbPN/aiTzlTWP6PALtt0yl2ZS4tr2ZUy80USQ0W6FZ T8pJoSehXDH7srsZ+mXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ow49g-005GxU-3s; Fri, 18 Nov 2022 16:23:52 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ow48a-005GOb-Hg for linux-arm-kernel@lists.infradead.org; Fri, 18 Nov 2022 16:22:46 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 386C2B822B5; Fri, 18 Nov 2022 16:22:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7407C433C1; Fri, 18 Nov 2022 16:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668788562; bh=P5rqQ618McYUUSdtgnaP6PAhDhI4tHN6kMrWWIxUjso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=taXyEk/NweciL+l3xAGKYx2yj5Yp/Lp6WY+F4lIj5o1RDDIdOSjjVdk7tqgb5rqqQ Grw64FsNhj8yC10/0I3ZaCCakGzha6TySsEkBkw8hsfejk1V9npt8I2TZ+fbM3xZI9 gBxQy9dYXLOyPSQwxdp3tZDwUien92wDktV7f1klp0tJU0a0w6p+pSayX6YNc60Vdm zyUfof15iQNjXgFtTIAn/8/i9V9DidBUtwpB1u8cPUobSntBHIV3dV49n6r8XdSwf9 J7or1JLvy3I6iuTOKWnGm+Vvnq+5o1JV9bi6M1R1TsVSAdb3nXIh3wZC1i+/OXchJX zPOf61Oeg+q/g== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan , Shuah Khan Cc: Szabolcs Nagy , linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v3 5/5] kselftest/arm64: Add test case for TPIDR2 signal frame records Date: Fri, 18 Nov 2022 16:22:24 +0000 Message-Id: <20221118162224.1068916-6-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221118162224.1068916-1-broonie@kernel.org> References: <20221118162224.1068916-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3467; i=broonie@kernel.org; h=from:subject; bh=P5rqQ618McYUUSdtgnaP6PAhDhI4tHN6kMrWWIxUjso=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjd7E+Gl6EYC7Moun7iMrzvtZ4H3/YPG7FrMBy7MUl xyJXGaGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCY3exPgAKCRAk1otyXVSH0K6BB/ 9s7Qg6lYkl8FTAWK2bz/DhvNKbC8B4hYtbxqPwCPXUvcWsRQ0G0wQDVKiE1Wx6FlkS5okvpnHMWSHw 5j3D/6NBkAFN66PerBGL8kRMoqsQXUKHxLXuSrgjMO0B1iZ6NNWBzPivL+qwac08vDeSbsSWAuCARw qn9u5zQkj4MORugZiIRSTS6BaXgxqtkPE9NQPB0SOlcs1i33EcXfWWuQXfSeAh/RQU1JCbWvYbPisg Hghkj1EAGRPLmiqp9Rt8nCAHfH/I9kFK//FslLX7MzzyLsM7AefYWgPM7Ew6EssmZQfwxfZ4jWfhe1 RveKvl9Q2uFBmAzDoJoeMzvYhX5fcx X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221118_082244_918643_5636888A X-CRM114-Status: GOOD ( 21.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Ensure that we get signal context for TPIDR2 if and only if SME is present on the system. Since TPIDR2 is owned by libc we merely validate that the value is whatever it was set to, this isn't ideal since it's likely to just be the default of 0 with current systems but it avoids future false positives. Signed-off-by: Mark Brown --- .../testing/selftests/arm64/signal/.gitignore | 1 + .../arm64/signal/testcases/tpidr2_siginfo.c | 90 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c diff --git a/tools/testing/selftests/arm64/signal/.gitignore b/tools/testing/selftests/arm64/signal/.gitignore index e8d2b57f73ec..e1b6c4d961b5 100644 --- a/tools/testing/selftests/arm64/signal/.gitignore +++ b/tools/testing/selftests/arm64/signal/.gitignore @@ -4,5 +4,6 @@ fake_sigreturn_* sme_* ssve_* sve_* +tpidr2_siginfo za_* !*.[ch] diff --git a/tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c b/tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c new file mode 100644 index 000000000000..6a2c82bf7ead --- /dev/null +++ b/tools/testing/selftests/arm64/signal/testcases/tpidr2_siginfo.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 ARM Limited + * + * Verify that the TPIDR2 register context in signal frames is set up as + * expected. + */ + +#include +#include +#include +#include +#include +#include + +#include "test_signals_utils.h" +#include "testcases.h" + +static union { + ucontext_t uc; + char buf[1024 * 128]; +} context; + +#define SYS_TPIDR2 "S3_3_C13_C0_5" + +static uint64_t get_tpidr2(void) +{ + uint64_t val; + + asm volatile ( + "mrs %0, " SYS_TPIDR2 "\n" + : "=r"(val) + : + : "cc"); + + return val; +} + +int tpidr2_present(struct tdescr *td, siginfo_t *si, ucontext_t *uc) +{ + struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context); + struct tpidr2_context *tpidr2_ctx; + size_t offset; + bool in_sigframe; + bool have_sme; + __u64 orig_tpidr2; + + have_sme = getauxval(AT_HWCAP2) & HWCAP2_SME; + if (have_sme) + orig_tpidr2 = get_tpidr2(); + + if (!get_current_context(td, &context.uc, sizeof(context))) + return 1; + + tpidr2_ctx = (struct tpidr2_context *) + get_header(head, TPIDR2_MAGIC, td->live_sz, &offset); + + in_sigframe = tpidr2_ctx != NULL; + + fprintf(stderr, "TPIDR2 sigframe %s on system %s SME\n", + in_sigframe ? "present" : "absent", + have_sme ? "with" : "without"); + + td->pass = (in_sigframe == have_sme); + + /* + * Check that the value we read back was the one present at + * the time that the signal was triggered. TPIDR2 is owned by + * libc so we can't safely choose the value and it is possible + * that we may need to revisit this in future if something + * starts deciding to set a new TPIDR2 between us reading and + * the signal. + */ + if (have_sme && tpidr2_ctx) { + if (tpidr2_ctx->tpidr2 != orig_tpidr2) { + fprintf(stderr, "TPIDR2 in frame is %llx, was %llx\n", + tpidr2_ctx->tpidr2, orig_tpidr2); + td->pass = false; + } + } + + return 0; +} + +struct tdescr tde = { + .name = "TPIDR2", + .descr = "Validate that TPIDR2 is present as expected", + .timeout = 3, + .run = tpidr2_present, +}; -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel