From mboxrd@z Thu Jan 1 00:00:00 1970 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 C356DC38A02 for ; Fri, 28 Oct 2022 18:53:40 +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=mXjjsJ6q7ayZ2m 6lhb5JMwknvILcQzwQhywgRvV78ygBu84mJvY4rpbP4iwOow3ZI7RGIk+2ObCA8AaG/cL9tYD1Tzp exUdXrGpXsyZ/0eoRPweg4JjIhYE5FPUcAuc5ANeJ1tgsa8BWqfQtN0N2pTb8k8lBlDygLk5h2vf/ RvHqSpVd/ebHSUx4lq4XQ/ogd0NByp4mLnvUB0lnOt+jwoX2TeacUwScBhfayarpTPRSEeH44v3mr aEh9hGN6/pNnQjckwIFHCbeRwLLHT41F2nviYZhTGb7+hBtCVNpvd9vcoH5Dbt47trOkT6P/YlKAx tERGZAQxvfm1JIhyqaxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooUT9-001jXG-QA; Fri, 28 Oct 2022 18:52:40 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooUSO-001jGo-75 for linux-arm-kernel@lists.infradead.org; Fri, 28 Oct 2022 18:51:54 +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 E179DB82C3D; Fri, 28 Oct 2022 18:51:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03FDEC433C1; Fri, 28 Oct 2022 18:51:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666983109; bh=P5rqQ618McYUUSdtgnaP6PAhDhI4tHN6kMrWWIxUjso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kScrH1CyKVWByXayq5eXgGsruIOaG9AWl9QtNTCvxNUvFgZEP0nI67arfHE53ZgeU 5pHDxF57PqBqNQwz0S1jrSTUnmZDh1QPwKFfIm8HbID+nYnVJjSugl5gzmzoIDw6XZ CjOozgJ+rMuMAeCpvKSG5/Od4j2MgfqVBzTK9mizCF8G6DnQIB6fhaV0Ct7n5wDsTS nwMYoti8DpbqvBzrYfWqT2kuBcdm3p1Ik+R7GQmN4jPNdeJVeZMQCNjFDh+4JcRaRz E2LyfC1+Zs9sy1Nm/uOltBZmdrqHIZ7QdT+Da9wXm3/yRO3IqNX2G5fzbVywYMejZ0 tJJHRIyX5668w== 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 v1 4/4] kselftest/arm64: Add test case for TPIDR2 signal frame records Date: Fri, 28 Oct 2022 19:50:46 +0100 Message-Id: <20221028185046.1316730-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221028185046.1316730-1-broonie@kernel.org> References: <20221028185046.1316730-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/pANAwAKASTWi3JdVIfQAcsmYgBjXCSFGl6EYC7Moun7iMrzvtZ4H3/YPG7FrMBy7MUl xyJXGaGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCY1wkhQAKCRAk1otyXVSH0EAiB/ 42XGkbeiR2NlrbBO6M2l9KlZ2VIsjNfWMkbd2CzIyJsORgr9u88bQPn8duYYrkwxoKHqX+z9AwmA9Z 8ltgYB8mJYsDZdFtnkUltgaSD+0fgStg42mzKM1GefigihOplcVgKA38urjl6O86kJc9h6xm+YciYK auX6R51XrCITXZo9LVNBnIe+DqW3JoWrpG3GXYiHtFPnbsoHaP5WgWhekU0vxD8QWj2utjMC6Y3KTg 2KOe97VEJxQCZrjQKUDvRxyQhIyPwRsSs5HZRm43RdWhwUNsokE0Xn5ZJkTXAa1+qGOxYnXv7xvne0 IzThqE9fiMecYG52lE4JpXrbuOAOo7 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-20221028_115152_575620_177374B6 X-CRM114-Status: GOOD ( 21.75 ) 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