From patchwork Mon Aug 29 15:57:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958103 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 434DCECAAD5 for ; Mon, 29 Aug 2022 15:57:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229649AbiH2P5v (ORCPT ); Mon, 29 Aug 2022 11:57:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiH2P5v (ORCPT ); Mon, 29 Aug 2022 11:57:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6838296779 for ; Mon, 29 Aug 2022 08:57:50 -0700 (PDT) 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 04FE5611D6 for ; Mon, 29 Aug 2022 15:57:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38F8FC433B5; Mon, 29 Aug 2022 15:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661788669; bh=mvOc/8cUdGxzIqrwz0EePKC3ZU/yxeDw11W9Ibm+0ns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T+QqQkofozBdeTbm1tGQ1cWeLvYtbiyLFq2bIYmco+rnqh/m1b3R46EU8386rzqPv YdbZ71EXLQGCh1OqOQS4ygsrGDk9jRrH2A6Y/VPNuTtmDg59BfUIlpMs/EkxCuULih jv3rkMFLMtSUbKbGY3tKtFQPNEZnRz4fM9fmdfs7rKmvffa7ny0WvRojra1+mtx6PP OC4R6lVsaG982goY0QojIRc4M4XbF/Ym6vaV4xXgpyjmKVzPjWlxr7OTwWiSVbSgB8 gLKohqBCbYudm5bns+rZo1Yzin6Or3Khheh+IdoW7mVkjBh1bxFuyu5bMHWO7AR0E5 UJHC11yFE/sXA== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan , Shuah Khan Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown Subject: [PATCH v2 1/2] kselftest/arm64: Tighten up validation of ZA signal context Date: Mon, 29 Aug 2022 16:57:27 +0100 Message-Id: <20220829155728.854947-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829155728.854947-1-broonie@kernel.org> References: <20220829155728.854947-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1874; i=broonie@kernel.org; h=from:subject; bh=mvOc/8cUdGxzIqrwz0EePKC3ZU/yxeDw11W9Ibm+0ns=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOHnq554edjZ4LhfZqZf9K7H9cXh++0PwGRZBP38 y9uOMC+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzh5wAKCRAk1otyXVSH0DPaB/ 4jo1LugwnJ8yGJgncCn4tfCLj6WxYcT/GLXTTosJff7PUMWehmxi+2tG7ElmREuST52F/oAfpHON8J mxha7hg83MifEbBYi40fNF7uzKDRI4fandyRFG/Amxcb0cxYuLgwGTPjJQJx47Fms8Vipiqh70NmD+ 41USUOnBf30WJA6vfcm/rRPh1qpkQlfP/xAknS3fhUIxkecKOEgrKWJLdry4d8hQ+/o7DB4Hac985Q ZVcLpzqxPOdE024LKra/wT5Mj+7Bg0tciIDNAOUYtHwXoyMjVS2mQbFSxhWee4qgFZBbrhCyzNhS0g M7Fu4aWzT4e/sCrEnrajHh7RVjrDUb X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Currently we accept any size for the ZA signal context that the shared code will accept which means we don't verify that any data is present. Since we have enabled ZA we know that there must be data so strengthen the check to only accept a signal frame with data, and while we're at it since we enabled ZA but did not set any data we know that ZA must contain zeros, confirm that. Signed-off-by: Mark Brown --- .../selftests/arm64/signal/testcases/za_regs.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/signal/testcases/za_regs.c b/tools/testing/selftests/arm64/signal/testcases/za_regs.c index b94e4f99fcac..2514cb7de525 100644 --- a/tools/testing/selftests/arm64/signal/testcases/za_regs.c +++ b/tools/testing/selftests/arm64/signal/testcases/za_regs.c @@ -52,6 +52,8 @@ static void setup_za_regs(void) asm volatile(".inst 0xd503457f" : : : ); } +static char zeros[ZA_SIG_REGS_SIZE(SVE_VQ_MAX)]; + static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, unsigned int vl) { @@ -87,10 +89,22 @@ static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, return 1; } - /* The actual size validation is done in get_current_context() */ + if (head->size != ZA_SIG_CONTEXT_SIZE(sve_vq_from_vl(vl))) { + fprintf(stderr, "ZA context size %u, expected %lu\n", + head->size, ZA_SIG_CONTEXT_SIZE(sve_vq_from_vl(vl))); + return 1; + } + fprintf(stderr, "Got expected size %u and VL %d\n", head->size, za->vl); + /* We didn't load any data into ZA so it should be all zeros */ + if (memcmp(zeros, (char *)za + ZA_SIG_REGS_OFFSET, + ZA_SIG_REGS_SIZE(sve_vq_from_vl(za->vl))) != 0) { + fprintf(stderr, "ZA data invalid\n"); + return 1; + } + return 0; } From patchwork Mon Aug 29 15:57:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958104 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEA47ECAAD5 for ; Mon, 29 Aug 2022 15:58:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229507AbiH2P6F (ORCPT ); Mon, 29 Aug 2022 11:58:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229900AbiH2P6E (ORCPT ); Mon, 29 Aug 2022 11:58:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4115597B1E for ; Mon, 29 Aug 2022 08:58:03 -0700 (PDT) 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 E2CEFB81103 for ; Mon, 29 Aug 2022 15:58:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52517C433D7; Mon, 29 Aug 2022 15:57:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661788680; bh=iho2djtRhDbfxqjfHfG89LpdrLeoz0UBV3Z/8njN3p0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AbSvpfD9dhwyc4Zv2M0U5Hy0+0I79y1CbZe6UkPQUOQsaHDN+eD3Qn9+OuzhK7g1f jMgoERTGDopSjfOIvv+GJxsyvbK3fvEHaR8/pJcQ+moQxD0kBN2EkazDEr250KmWJI uy4d+BloibUkOoYT0bOKVCLvtyiGzN7aJmw/uBPusJKf9qf9TL04BIXQjj5HtHP4ci fscbvEpEo+s0LX0U+ZYGjAUQMO9lxHbolLS+/KkHgAzQi0c71rxbYQun5/fodL4uKX SpUs5UlyuS9WWAf9inp5gidIBresvHtcu7nLUIRETCVareLTbX7/ilc2/kcL67zp+9 9Jm5FMTLVjSew== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan , Shuah Khan Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown Subject: [PATCH v2 2/2] kselftest/arm64: Add a test for signal frames with ZA disabled Date: Mon, 29 Aug 2022 16:57:28 +0100 Message-Id: <20220829155728.854947-3-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829155728.854947-1-broonie@kernel.org> References: <20220829155728.854947-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3267; i=broonie@kernel.org; h=from:subject; bh=iho2djtRhDbfxqjfHfG89LpdrLeoz0UBV3Z/8njN3p0=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOHn3OrybsFfa//wTPFMuFZjpQMJkhLh0Qj9ttPh DI05uumJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzh5wAKCRAk1otyXVSH0L8UB/ 4gxod6F3fb3AyRaqG4K2lxvW92mQxHYR7OkzQvuSw9nE6NxiEmn41MqHlF7fMKtAXaXvwJPqUxcdBG 1b+5NHoTF+t6TwM4nEMxM+vXsdTcMX6WmX/xBauRS7DJ84Yc8ch0NZg2MC7Qs4MHJVmEJpffXWS8cv BdKxqeKvzvJMfGmfQxXkSPREgjIksveDnX2ngLop8l/ESaWwrz3Ex8n+RX/cGgG3GHlmWkffsMguqg yupkWeDT45Ql+ZN6jA3DzJs01RRgMmWnChPdRZL1HdMv5fd49kowmFXm8T58dkyKkg82rMhNDN1gYv K6T/DSrmdMbiSiKqsf9pnmAJCCRckc X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When ZA is disabled there should be no register data in the ZA signal frame, add a test case which confirms that this is the case. Signed-off-by: Mark Brown --- .../arm64/signal/testcases/za_no_regs.c | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 tools/testing/selftests/arm64/signal/testcases/za_no_regs.c diff --git a/tools/testing/selftests/arm64/signal/testcases/za_no_regs.c b/tools/testing/selftests/arm64/signal/testcases/za_no_regs.c new file mode 100644 index 000000000000..4d6f94b6178f --- /dev/null +++ b/tools/testing/selftests/arm64/signal/testcases/za_no_regs.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2021 ARM Limited + * + * Verify that the ZA register context in signal frames is set up as + * expected. + */ + +#include +#include +#include + +#include "test_signals_utils.h" +#include "testcases.h" + +static union { + ucontext_t uc; + char buf[1024 * 128]; +} context; +static unsigned int vls[SVE_VQ_MAX]; +unsigned int nvls = 0; + +static bool sme_get_vls(struct tdescr *td) +{ + int vq, vl; + + /* + * Enumerate up to SME_VQ_MAX vector lengths + */ + for (vq = SVE_VQ_MAX; vq > 0; --vq) { + vl = prctl(PR_SME_SET_VL, vq * 16); + if (vl == -1) + return false; + + vl &= PR_SME_VL_LEN_MASK; + + /* Skip missing VLs */ + vq = sve_vq_from_vl(vl); + + vls[nvls++] = vl; + } + + /* We need at least one VL */ + if (nvls < 1) { + fprintf(stderr, "Only %d VL supported\n", nvls); + return false; + } + + return true; +} + +static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, + unsigned int vl) +{ + size_t offset; + struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context); + struct za_context *za; + + fprintf(stderr, "Testing VL %d\n", vl); + + if (prctl(PR_SME_SET_VL, vl) != vl) { + fprintf(stderr, "Failed to set VL\n"); + return 1; + } + + /* + * Get a signal context which should have a SVE frame and registers + * in it. + */ + if (!get_current_context(td, &context.uc, sizeof(context))) + return 1; + + head = get_header(head, ZA_MAGIC, GET_BUF_RESV_SIZE(context), &offset); + if (!head) { + fprintf(stderr, "No ZA context\n"); + return 1; + } + + za = (struct za_context *)head; + if (za->vl != vl) { + fprintf(stderr, "Got VL %d, expected %d\n", za->vl, vl); + return 1; + } + + if (head->size != ZA_SIG_REGS_OFFSET) { + fprintf(stderr, "Context size %u, expected %lu\n", + head->size, ZA_SIG_REGS_OFFSET); + return 1; + } + + /* The actual size validation is done in get_current_context() */ + fprintf(stderr, "Got expected size %u and VL %d\n", + head->size, za->vl); + + return 0; +} + +static int sme_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc) +{ + int i; + + for (i = 0; i < nvls; i++) { + if (do_one_sme_vl(td, si, uc, vls[i])) + return 1; + } + + td->pass = 1; + + return 0; +} + +struct tdescr tde = { + .name = "ZA registers - ZA disabled", + .descr = "Check ZA context with ZA disabled", + .feats_required = FEAT_SME, + .timeout = 3, + .init = sme_get_vls, + .run = sme_regs, +};