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 6E19AFA3741 for ; Mon, 31 Oct 2022 20:41:48 +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=EHjq/oSD0sSYyD J7rzxPmudH1hIyqtc4og/BX92/FNrA93ZW7lvRbn8XpXxl7ss/M6tXh8G7LGsFGnWWl/nQA4v3tYT NqinXbP+x4bIe9rCxgddZa6IrGdpRvVd75IJrVFwyanbUsN3UiNLz7v+moyYBlQQD0YXs+d7exVOu RdPnj5LqKntLxOELmuVjygzmEjHUsHfmLNHm403P44KNJKjqeQdzdXog522WVLC04t+cl+WpajG/t AlxyZ08R1h0PG1rtox408v3LWV+wOm3Wi1TrTErBzDiRlWI1WcnyWdCbe0/yd+zYt/2kyfxtU9p8b LxXJrJV9MKyRn0U+yU5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1opbaW-00FG4s-3m; Mon, 31 Oct 2022 20:40:52 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1opba1-00FFxq-Jz for linux-arm-kernel@lists.infradead.org; Mon, 31 Oct 2022 20:40:23 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 3B1FE60C25; Mon, 31 Oct 2022 20:40:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96179C433D6; Mon, 31 Oct 2022 20:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667248820; bh=P5rqQ618McYUUSdtgnaP6PAhDhI4tHN6kMrWWIxUjso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G8MnthIWQ1qUwNTjmEmt6WRl3ALNRWHRxaVhOMBDI+HuIyI1CDedf2jxaPNf2Fn88 ch3RK+Kstoi963d1QPSg3L8qJns3uHgA3QDWMVTvhIGXFIecIcLZAY8PgDLdMjKVai 0HZKHF8EjlaNj1zvayVNKjgAiql5CX/rz20TPug06t1wKQT2uApqo6OdUIViZJTyNE yxx1EsTWkA7/ATAxali3siFbHUBt4+GSNNQhEvK2Opf67r/jwB+Wmnddn1orZuTGlv 1gdNpyGV3hKpYOF3npZKt/f4LZcUc/EkIw3gegyzPFUYjsLyd69bNf+6oONp/3+GW1 eZC15STxBrQ2w== 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 v2 4/4] kselftest/arm64: Add test case for TPIDR2 signal frame records Date: Mon, 31 Oct 2022 20:17:36 +0000 Message-Id: <20221031201736.894374-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221031201736.894374-1-broonie@kernel.org> References: <20221031201736.894374-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/pANAwAKASTWi3JdVIfQAcsmYgBjYC1fGl6EYC7Moun7iMrzvtZ4H3/YPG7FrMBy7MUl xyJXGaGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCY2AtXwAKCRAk1otyXVSH0HzTB/ 4+ot6JYlOqAyFnusdf6Y1ZUuiXzWfZ75MeoRa0Izw7a26WSpsaAlAsHghVHe1PJwDNseyazYmSM0vc 87c8oMcG2kVtQjeplU75548JoZNv9eGDICutIyGZ7T0myGg/WmNz8ToNfB7wn4y7H+5JjeUApZt2tP ZMrPT+BIDEVrylTHLDc8QxJLnwZ/Lgmmd5GZ4wUohRWsc1xJdaoR4sj1FpXbSJiY2NdUyFSoPzezrn iRXFidWcX9BnoOZfASnTaBbjNO3NBgtp/qhd79gMmBlfNKrb0dJcYB25AS5ECj9w9AKA3ah/fIhO4I NFuTKg/IOv0PQjyaLalmwPPLk6oL9P 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-20221031_134021_765597_31E98C7E X-CRM114-Status: GOOD ( 21.53 ) 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