From patchwork Mon Jan 22 16:28:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 764952 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 DB6026A32C; Mon, 22 Jan 2024 16:28:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705940935; cv=none; b=kjTK66D/1xvp1kPSvKCeukkmD5WSzIP+N01A6StKCT4m1t0GAes3yObqm+uTb0c9TgKe3/sHFegIsj0Phsv+ZTJ0Vz711VSabF8B/sLeuSTcjUxbcQ/uPwfBCCtTT4tGQoF4jpQogDo2B6O1U2tpovIPLnwF1NBlczv68CcjVi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705940935; c=relaxed/simple; bh=irtBwegYB+DXpSWW34B5isPMLTYQBsVR3AqcPDPAR5U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E0RLToCHsdk4dGjc6yrZ5CGZrYZP3BzgMyJGHv1ikTFhzRSamWG6T3TiIWmQXKUWN9Q7aH5XGMoIfiersrs93f6CVdzz1HACFVUzUUl/ooqykqXZnewx3fOia4dUxhY79gAuZ3QjP/KomgAr+x/+f8LGyv476jstDXh1yacyaPo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gFjwqdAN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gFjwqdAN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4D98C43399; Mon, 22 Jan 2024 16:28:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705940934; bh=irtBwegYB+DXpSWW34B5isPMLTYQBsVR3AqcPDPAR5U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gFjwqdAN0T03M/XTDpefz8r+gy/n7+KgkkVaOK3wkvmS6gMc187kHOmKMv+LK9nQb 4gO207lFP/yC9n4UfokVlPUhZdtZepE0dTXO0lH5oBKvkD1XD+PG0e1pHIRnhoQ8L9 oX8zZUNENCbYGw3jy6ttZEiBaviT50DlKgLts4DOB8VeSxyRhpheDGQdK+ZPFIIkoS gL51qCCnjNM4nog9yiPcj1JO/JnNziNuNFlqGFtlsH5h9Kz0G6I73DjcSwrxMzo+ts CMHrLOu/PJu3bzNTqGGfLV7Wy9XN+wJzL7dcKsnlsF8jVwcfLoBypU5CSqN0kiBFR6 o87nATBrEr4fA== From: Mark Brown Date: Mon, 22 Jan 2024 16:28:11 +0000 Subject: [PATCH v4 08/14] kselftest/arm64: Add basic FPMR test Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240122-arm64-2023-dpisa-v4-8-776e094861df@kernel.org> References: <20240122-arm64-2023-dpisa-v4-0-776e094861df@kernel.org> In-Reply-To: <20240122-arm64-2023-dpisa-v4-0-776e094861df@kernel.org> To: Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Jonathan Corbet , Shuah Khan Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Dave Martin , kvmarm@lists.linux.dev, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-5c066 X-Developer-Signature: v=1; a=openpgp-sha256; l=2813; i=broonie@kernel.org; h=from:subject:message-id; bh=irtBwegYB+DXpSWW34B5isPMLTYQBsVR3AqcPDPAR5U=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBlrpeh9fLZ78HTZBG3zc7h3TeBhBhsmb4kU9AESgh6 XwWPMjyJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZa6XoQAKCRAk1otyXVSH0D3dB/ 9mOQG9XoEDR7Sl97MPuIIDCMRO3EA888069VdiAjm2cX7yKzLJ9SjabVFFfoHcffrVS4CkaQyq4KMa 3H5UkUB+a24CG5duqx4aoZu1i7yQM2VhwTS+X3KObQm7Rjev1HViK4JKPkf0zyymosdXNKX35UDW09 gVZ4xt99U4O3p80lJaObPm2w9VmdK4syDtexnIaiwsFvCq10oMVOzakXRz8hRQXxbLSqiF+xaWFRP2 lCywljTPIFu6hBPsPQEMX7nkjs1pZ13yhYQjixBqBBd3KBJFXlyKCsvqrlMVL+CU8Z2CgvxQ7M3yDo AgkyaSyoBytzvYexT8f/ykHtpWIraY X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Verify that a FPMR frame is generated on systems that support FPMR and not generated otherwise. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/signal/.gitignore | 1 + .../arm64/signal/testcases/fpmr_siginfo.c | 82 ++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/tools/testing/selftests/arm64/signal/.gitignore b/tools/testing/selftests/arm64/signal/.gitignore index 839e3a252629..1ce5b5eac386 100644 --- a/tools/testing/selftests/arm64/signal/.gitignore +++ b/tools/testing/selftests/arm64/signal/.gitignore @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only mangle_* fake_sigreturn_* +fpmr_* sme_* ssve_* sve_* diff --git a/tools/testing/selftests/arm64/signal/testcases/fpmr_siginfo.c b/tools/testing/selftests/arm64/signal/testcases/fpmr_siginfo.c new file mode 100644 index 000000000000..e9d24685e741 --- /dev/null +++ b/tools/testing/selftests/arm64/signal/testcases/fpmr_siginfo.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2023 ARM Limited + * + * Verify that the FPMR 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_FPMR "S3_3_C4_C4_2" + +static uint64_t get_fpmr(void) +{ + uint64_t val; + + asm volatile ( + "mrs %0, " SYS_FPMR "\n" + : "=r"(val) + : + : "cc"); + + return val; +} + +int fpmr_present(struct tdescr *td, siginfo_t *si, ucontext_t *uc) +{ + struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context); + struct fpmr_context *fpmr_ctx; + size_t offset; + bool in_sigframe; + bool have_fpmr; + __u64 orig_fpmr; + + have_fpmr = getauxval(AT_HWCAP2) & HWCAP2_FPMR; + if (have_fpmr) + orig_fpmr = get_fpmr(); + + if (!get_current_context(td, &context.uc, sizeof(context))) + return 1; + + fpmr_ctx = (struct fpmr_context *) + get_header(head, FPMR_MAGIC, td->live_sz, &offset); + + in_sigframe = fpmr_ctx != NULL; + + fprintf(stderr, "FPMR sigframe %s on system %s FPMR\n", + in_sigframe ? "present" : "absent", + have_fpmr ? "with" : "without"); + + td->pass = (in_sigframe == have_fpmr); + + if (have_fpmr && fpmr_ctx) { + if (fpmr_ctx->fpmr != orig_fpmr) { + fprintf(stderr, "FPMR in frame is %llx, was %llx\n", + fpmr_ctx->fpmr, orig_fpmr); + td->pass = false; + } + } + + return 0; +} + +struct tdescr tde = { + .name = "FPMR", + .descr = "Validate that FPMR is present as expected", + .timeout = 3, + .run = fpmr_present, +};