From patchwork Mon Aug 29 16:06:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958113 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 E21D3ECAAD2 for ; Mon, 29 Aug 2022 16:07:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230094AbiH2QHZ (ORCPT ); Mon, 29 Aug 2022 12:07:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbiH2QHY (ORCPT ); Mon, 29 Aug 2022 12:07:24 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43CBE8307A for ; Mon, 29 Aug 2022 09:07:23 -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 ECDA7B810FD for ; Mon, 29 Aug 2022 16:07:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E344EC433D7; Mon, 29 Aug 2022 16:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661789240; bh=pk7Q79jKBzZEn+CCEUhIxWG1JcQQiZbxATsJw8fMdG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JNHHxO3PDEM/3kD3ad3LgTr82b8EMAX0f02krGMx1GVJ6tDWXEuhZGohpdwZ6POiF Muu4iNRfuwEKwq2NZsDfLbYAvYFvI0UQIU0GuXt2E30WzbjID586NNaWw13/FXjKB/ H+T6K0OPbeNU2XMpGWyzJ/bDZB1IVqZ9356U4mOQJZODYVT1ZMNoqCg8vIo9mNoMQp 3Us4wULGFoAkix3b5tkZF2uReTdMHhJtFAySa5IojXrgeQkJWToISAPYe1USnpJoGo Odoix8C5GdnutXQjBCb2HL87vqrTjVDU/QXCM/IU2/CNLpydf6NUNtCpVlM87gcpcR tT7ncJjqpRhTg== 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 01/10] kselftest/arm64: Enumerate SME rather than SVE vector lengths for za_regs Date: Mon, 29 Aug 2022 17:06:54 +0100 Message-Id: <20220829160703.874492-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829160703.874492-1-broonie@kernel.org> References: <20220829160703.874492-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1039; i=broonie@kernel.org; h=from:subject; bh=pk7Q79jKBzZEn+CCEUhIxWG1JcQQiZbxATsJw8fMdG8=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOQelixHbkYrQD02PlN/alJJwbAH4e3wF+X4P6z3 2La5WAGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzkHgAKCRAk1otyXVSH0GLuB/ 4+xVMiV25xWnWmQv4cg4XglKhR8WJWxMDeo8gVuYdNhHuMxLDCjrBK1Zo5rCdOUfJTRCsY+/YwSjvp mFeQy6KkK6ed9TjmxSQshD8iD1pUP8Rsusx0nwr/+CJkRp0zZ1fXjSHNYoCdPCiP/pZLbgrBjB/RlZ eW/tnB1SE9jnOyCSLNCc7zFYFw5RLfHqkYtVN1vdrIIcsJMrriTgLG0TpE5rKWeUFAWGbbd3j7aB2b ENuf5n/C5d+jCKTlke62zhP/QVAQvUJh3+TRhapMd7C0gBIIbm7oEa1QQYrqjD3DeyrqeqisGzpsrQ ATz1ppjdQhdeedaMRmZ4Gcz7M/dsVM X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The za_regs signal test was enumerating the SVE vector lengths rather than the SME vector lengths through cut'n'paste error when determining what to test. Enumerate the SME vector lengths instead. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/signal/testcases/za_regs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/arm64/signal/testcases/za_regs.c b/tools/testing/selftests/arm64/signal/testcases/za_regs.c index b94e4f99fcac..9f1dd70289be 100644 --- a/tools/testing/selftests/arm64/signal/testcases/za_regs.c +++ b/tools/testing/selftests/arm64/signal/testcases/za_regs.c @@ -22,10 +22,10 @@ static bool sme_get_vls(struct tdescr *td) int vq, vl; /* - * Enumerate up to SVE_VQ_MAX vector lengths + * Enumerate up to SME_VQ_MAX vector lengths */ for (vq = SVE_VQ_MAX; vq > 0; --vq) { - vl = prctl(PR_SVE_SET_VL, vq * 16); + vl = prctl(PR_SME_SET_VL, vq * 16); if (vl == -1) return false; From patchwork Mon Aug 29 16:06:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958114 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 0006AECAAD5 for ; Mon, 29 Aug 2022 16:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230152AbiH2QHb (ORCPT ); Mon, 29 Aug 2022 12:07:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbiH2QHa (ORCPT ); Mon, 29 Aug 2022 12:07:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95141857D2 for ; Mon, 29 Aug 2022 09:07:29 -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 309B7611F5 for ; Mon, 29 Aug 2022 16:07:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D621C433C1; Mon, 29 Aug 2022 16:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661789248; bh=Dxt22W8Em96QEF9sjlP0/VfqCLzptWgJwiuX8Wed7dw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qldtaT3Pf4yslygdL47ecbEGFUOfy2wY+DsjHRgK06Uzva8cAwX+kv3VGvow2hDEx z4HUUVg8gKOsfr7oKONW6UNjLn5I3NBcaX51pmZCb3HgVIT/LvpZLMnWi5ivFQux/z gRq0DgmzAx8R5E7xfrD1gLfcZMmZ6qPzwEq4RpaSvXw7KW7cGP28zbVnCgyTn4pQbr oK1RB2b7nx960BCU8nWNRpmk/LvXn+qz+kgH8yuW21wbsezLayJBzFuKfwsafqzNYH F1+KtrnhA4qaPr7jd0/T4cwVY0RUHGsFoocxmZYI8ryjD2Rm7BX/xmpqZBQhx3Uu2+ P8oVBP+w8WlLg== 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 02/10] kselftest/arm64: Validate signal ucontext in place Date: Mon, 29 Aug 2022 17:06:55 +0100 Message-Id: <20220829160703.874492-3-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829160703.874492-1-broonie@kernel.org> References: <20220829160703.874492-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1680; i=broonie@kernel.org; h=from:subject; bh=Dxt22W8Em96QEF9sjlP0/VfqCLzptWgJwiuX8Wed7dw=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOQfrr6pXSdNsaCjPzZcsv9NuPUamlQgH8zMcvpo Nhmt7KiJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzkHwAKCRAk1otyXVSH0D0kB/ 42txWh/FT2tTjSTaAz8ndvkC2r5L/wCL+nPhlCIh0gvqiGY1QhbnxrVS2f8zwJjoY+/6lQ88XgQrra hbv8CwB7uroxm3SfJ6ayB3ek9g/kgBVNaUEpCxILlShKrQjAAujqQfaFRcecyk0HG1gMtm0UCOuLMP XoJoPfeMHOJSjr691odiMM2Plaq8y+TnAqZB5ywpKEBadHMLr5Zl4rLWeeiWB+ME0KTnuZEHxd6Lo0 kWxkvnm7HHkgSth/nzguOITWp95oi6bmHWSlGbbxb6kfsTDNPQQP6mpWyzE3w1x/Zdh+1aPRN+W6jV 5hJLjl0Cko7pxwyZzKuoQ8yPws1vei X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org In handle_input_signal_copyctx() we use ASSERT_GOOD_CONTEXT() to validate that the context we are saving meets expectations however we do this on the saved copy rather than on the actual signal context passed in. This breaks validation of EXTRA_CONTEXT since we attempt to validate the ABI requirement that the additional space supplied is immediately after the termination record in the standard context which will not be the case after it has been copied to another location. Fix this by doing the validation before we copy. Note that nothing actually looks inside the EXTRA_CONTEXT at present. Signed-off-by: Mark Brown --- .../testing/selftests/arm64/signal/test_signals_utils.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.c b/tools/testing/selftests/arm64/signal/test_signals_utils.c index b588d10afd5b..a54dc1b6f35c 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.c +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.c @@ -165,12 +165,15 @@ static bool handle_signal_ok(struct tdescr *td, } static bool handle_signal_copyctx(struct tdescr *td, - siginfo_t *si, void *uc) + siginfo_t *si, void *uc_in) { + ucontext_t *uc = uc_in; + + ASSERT_GOOD_CONTEXT(uc); + /* Mangling PC to avoid loops on original BRK instr */ - ((ucontext_t *)uc)->uc_mcontext.pc += 4; + uc->uc_mcontext.pc += 4; memcpy(td->live_uc, uc, td->live_sz); - ASSERT_GOOD_CONTEXT(td->live_uc); td->live_uc_valid = 1; fprintf(stderr, "GOOD CONTEXT grabbed from sig_copyctx handler\n"); From patchwork Mon Aug 29 16:06:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958115 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 3E7BAECAAD2 for ; Mon, 29 Aug 2022 16:07:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230211AbiH2QHj (ORCPT ); Mon, 29 Aug 2022 12:07:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbiH2QHg (ORCPT ); Mon, 29 Aug 2022 12:07:36 -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 317E885FD0 for ; Mon, 29 Aug 2022 09:07:35 -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 D226DB8111B for ; Mon, 29 Aug 2022 16:07:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27AEEC43470; Mon, 29 Aug 2022 16:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661789252; bh=V8kvWQdcoruSY2BGzEtAHoX5MY2BJ0by5Hd6bThqyO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JtbUMolVkiz4eiZU0Gy+BakCXKEEjuIsRg7LciRTgofT3hrH/SuWPktaEWjqQ115h 5TlgL6nu+OnNaJ3jntyVbRygGEsgZdt8eRa+/+TryPxTfyvfR8rpIZHY1kO5Ht+TYl QExbA8tELV3ItzxT6V8uBhSwPUTUp3MhGQU/G+LX8Jcz/zfkgC/HA7rR4pMUrJdrTM 3ENeohXkn7i3mEEk2eDUl9qLs3Wgyy/WMrvZ6z+MMhKOKDwKh0S+yNG7P4z+Orlbcl pYueaeF0Criw3V9T3dZhpUeQ+2HwhLOBFkb6JM1COGQQHWjG9LsTb4C4U+mVAlbJqy ZcfnfdO2vCtBw== 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 03/10] kselftest/arm64: Fix validatation termination record after EXTRA_CONTEXT Date: Mon, 29 Aug 2022 17:06:56 +0100 Message-Id: <20220829160703.874492-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829160703.874492-1-broonie@kernel.org> References: <20220829160703.874492-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1709; i=broonie@kernel.org; h=from:subject; bh=V8kvWQdcoruSY2BGzEtAHoX5MY2BJ0by5Hd6bThqyO8=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOQgy0PRjapkJNbtLYlRyJSLUtCtMGiZLxJxN4VR arsmbjWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzkIAAKCRAk1otyXVSH0EFgB/ 9prONbldDZNnLJh4GtRqxxwOysyXe5W3UIZVRpEbuREle7Dl4SKFZgKGZeL7bAuNv7zdpDPzlmid+x XW7v6wtGv1Woeh7G/T/Pl/Umpqw4/5WB24e0DTcrKkSenHAJfIr6RKNMJrFLGcijPtCYbmznfZaF74 U8DtqQKNz9KkWU6tuIf30kLS44FwtsKzuZ69rnfq4ilcoOQONLS0IMT8vYl118N1b6FNO6/SoWiPFn 2yVVdxpU345hScfomI05lQvKLaSUyGP/4LvwtfQjg1kBVUsw23yWkpjqB05KDqEUmgOz15esjLD+w/ opsdzmrFBKz3tJaXf793GXqdmNo/aX X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When arm64 signal context data overflows the base struct sigcontext it gets placed in an extra buffer pointed to by a record of type EXTRA_CONTEXT in the base struct sigcontext which is required to be the last record in the base struct sigframe. The current validation code attempts to check this by using GET_RESV_NEXT_HEAD() to step forward from the current record to the next but that is a macro which assumes it is being provided with a struct _aarch64_ctx and uses the size there to skip forward to the next record. Instead validate_extra_context() passes it a struct extra_context which has a separate size field. This compiles but results in us trying to validate a termination record in completely the wrong place, at best failing validation and at worst just segfaulting. Fix this by passing the struct _aarch64_ctx we meant to into the macro. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/signal/testcases/testcases.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/signal/testcases/testcases.c b/tools/testing/selftests/arm64/signal/testcases/testcases.c index 84c36bee4d82..d98828cb542b 100644 --- a/tools/testing/selftests/arm64/signal/testcases/testcases.c +++ b/tools/testing/selftests/arm64/signal/testcases/testcases.c @@ -33,7 +33,7 @@ bool validate_extra_context(struct extra_context *extra, char **err) return false; fprintf(stderr, "Validating EXTRA...\n"); - term = GET_RESV_NEXT_HEAD(extra); + term = GET_RESV_NEXT_HEAD(&extra->head); if (!term || term->magic || term->size) { *err = "Missing terminator after EXTRA context"; return false; From patchwork Mon Aug 29 16:06:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958116 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 4CF1FECAAD5 for ; Mon, 29 Aug 2022 16:07:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230218AbiH2QHp (ORCPT ); Mon, 29 Aug 2022 12:07:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbiH2QHo (ORCPT ); Mon, 29 Aug 2022 12:07:44 -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 29FCF85FD0 for ; Mon, 29 Aug 2022 09:07:42 -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 D1DD8B81118 for ; Mon, 29 Aug 2022 16:07:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D2F8C433D7; Mon, 29 Aug 2022 16:07:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661789259; bh=OEluHX2rINw79r1ixw5NAaWYr6eeAln8ZyuAwVaM4PU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LiJ/hTIl4lOl3Yvc1JCHm05fhIGyj/MSjoFGXLWeAWaJRyXnKyMhMyc5D80C3fq8w DxEtbeHA4GfYxiTYlp4oNXBCjFx3t8UsFG0IHmOzDTBK7jRzcI8Bh2QMSAa7h+mHbn tE/1TaOXb5dzcyLRAOd18sp+JaX0HF44cW4OhCy486ND+e5rslCHeAubNTaD700SYz E7npn0Itky3iiGpmWmGshWTblMkhi8e4/zg33NhOCPqU7zme3fE3evSrgO/RqQiGR/ NGUPNjqXjI+QhcI7TCkjkMm19t9r0/4jQdZ87M+y8Y0ejVEHGDSzGy8crm6zCc73Ir kRa+9ZYQQieMQ== 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 04/10] kselftest/arm64: Fix validation of EXTRA_CONTEXT signal context location Date: Mon, 29 Aug 2022 17:06:57 +0100 Message-Id: <20220829160703.874492-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829160703.874492-1-broonie@kernel.org> References: <20220829160703.874492-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1431; i=broonie@kernel.org; h=from:subject; bh=OEluHX2rINw79r1ixw5NAaWYr6eeAln8ZyuAwVaM4PU=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOQh53ACy+qtRh8Sc/w53mW6y7ChJCJBs5P7thFO wOL9vv+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzkIQAKCRAk1otyXVSH0CQlB/ oCOs07QltSZ2zCRtD/6CXoh9aJ05Kfs8LhaSqg9SyLGTwqglp+UP13urM+/1mL1FAHdisje1GHs6mn rIgrHOYL4HW4vZ0B7fS+mH1pKKRnDsj3THUdx8brr+cERfp3zxhNhjX9WzkeSZWlz2u5/nBUkUM0qD pwFsARjnkkqdP8aBTrm4xKwqEq/zSUvuaPGBD8CY5X3Y1WuE7r0M7/MfsHGow9BXeWzsx/9VNDUIxG Q/HxAUp6nsmX8BidDgI22lDdnqSN63ArGcDdEo50kAsCzYrI7yi0PeSatVEPZCuLzCYcyPfXTj31bJ OQ/WduM0jvQ85lp0rNFHyTYbpJxQKc X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Currently in validate_extra_context() we assert both that the extra data pointed to by the EXTRA_CONTEXT is 16 byte aligned and that it immediately follows the struct _aarch64_ctx providing the terminator for the linked list of contexts in the signal frame. Since struct _aarch64_ctx is an 8 byte structure which must be 16 byte aligned these cannot both be true. As documented in sigcontext.h and implemented by the kernel the extra data should be at the next 16 byte aligned address after the terminator so fix the validation to match. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/signal/testcases/testcases.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/signal/testcases/testcases.c b/tools/testing/selftests/arm64/signal/testcases/testcases.c index d98828cb542b..16dc916939f9 100644 --- a/tools/testing/selftests/arm64/signal/testcases/testcases.c +++ b/tools/testing/selftests/arm64/signal/testcases/testcases.c @@ -42,7 +42,7 @@ bool validate_extra_context(struct extra_context *extra, char **err) *err = "Extra DATAP misaligned"; else if (extra->size & 0x0fUL) *err = "Extra SIZE misaligned"; - else if (extra->datap != (uint64_t)term + sizeof(*term)) + else if (extra->datap != (uint64_t)term + 0x10UL) *err = "Extra DATAP misplaced (not contiguous)"; if (*err) return false; From patchwork Mon Aug 29 16:06:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958117 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 51236C0502C for ; Mon, 29 Aug 2022 16:07:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230204AbiH2QHu (ORCPT ); Mon, 29 Aug 2022 12:07:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230215AbiH2QHt (ORCPT ); Mon, 29 Aug 2022 12:07:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97DC0861C3 for ; Mon, 29 Aug 2022 09:07:46 -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 DA47460FBD for ; Mon, 29 Aug 2022 16:07:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FE5EC433C1; Mon, 29 Aug 2022 16:07:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661789265; bh=hGKsg3UedEP/7h/cGhmdjQQzBHXgVmuy3ZE9b+PwvgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cG8y9ZP/ctPcRs6IpxJ29mQvIrilumQUnrX8dgcXlJp5z8kCZ8n4LhH/XsQvjcFrz Zg8h0m7fIYT/cOdP4zs3Z5f98yKMTiY/la3KZuIIEKUCeVa5+mfRC/aFBEyJvXancT Z0aiYk/bnCi7t8MV4bUMrRFkiylvHo+rcKwy85cWmw3Vi0eD7Jw8hBfVC+/kKucqLm qka2y7OzU3FikFZ8Tskq05iqsRGJFhqCf0kULolP2BXgE1LTFIDlsyHZwh1ffJVz7j 7ul6qWCHenqEGhkfw+pEawPnSubjzKRLsB8DzeWhA9k+tlFm/rCGdEbxwvF0HTFMZs gWdKGdz9I8Rvw== 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 05/10] kselftest/arm64: Remove unneeded protype for validate_extra_context() Date: Mon, 29 Aug 2022 17:06:58 +0100 Message-Id: <20220829160703.874492-6-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829160703.874492-1-broonie@kernel.org> References: <20220829160703.874492-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=910; i=broonie@kernel.org; h=from:subject; bh=hGKsg3UedEP/7h/cGhmdjQQzBHXgVmuy3ZE9b+PwvgU=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOQhTVYAh3LqfmHJ9Va/vprJOKc1AViua+o3JGuY nPMRrWeJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzkIQAKCRAk1otyXVSH0H9AB/ 4+Cd0LY+UXoElrGl9Xq1ympSQ13xAJAWdbmTu2y8VgVAyDi67xW5sdHdf+KCqvLl50WZwfwcw1VaoR gCMyyj2ZEbnNNPvlqeZeE+8Aw/20x8GlfD0LpYL92sUE2MNXYXbBd/NIzd4fPMizr3ZJvtrsy6v/wd 7Kw1x5+ZkR5Ymrdrm5zcF5+bPWd+oNs+sbdPf960kkcuJvjILcF+9Msp7z5plBKJQe3Fbbzterko/A 3Z6py2rEtxcZO0ljyt+m7UYfs4LAzcDxz5opYNF0jMxQwW1zOZPmb89aEn51+dWe422/Kq+kswqyKo i7FJdMDvec5vbzpQgsHQtCF+wJDVif X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Nothing outside testcases.c should need to use validate_extra_context(), remove the prototype to ensure nothing does. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/signal/testcases/testcases.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/selftests/arm64/signal/testcases/testcases.h b/tools/testing/selftests/arm64/signal/testcases/testcases.h index 49f1d5de7b5b..b39f538c7be1 100644 --- a/tools/testing/selftests/arm64/signal/testcases/testcases.h +++ b/tools/testing/selftests/arm64/signal/testcases/testcases.h @@ -79,8 +79,6 @@ struct fake_sigframe { bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err); -bool validate_extra_context(struct extra_context *extra, char **err); - struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic, size_t resv_sz, size_t *offset); From patchwork Mon Aug 29 16:06:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958118 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 01152ECAAD5 for ; Mon, 29 Aug 2022 16:07:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229988AbiH2QHy (ORCPT ); Mon, 29 Aug 2022 12:07:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbiH2QHx (ORCPT ); Mon, 29 Aug 2022 12:07:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D014083F39 for ; Mon, 29 Aug 2022 09:07:52 -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 608C7611F5 for ; Mon, 29 Aug 2022 16:07:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE83BC433C1; Mon, 29 Aug 2022 16:07:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661789271; bh=+LI8T2tA3D0W4jHBlk8SZzjrz3GUYnCv7SGlY2zQn2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IvAd2vpjjGkZoh3Dt40OQ0P0FXl2Xj0dy3zbIqy8ugeN0ToMTCKBKLNBnrdTmrnUc qhNvsqld1PJkxNz8zDdL64fNWa5GzFep35CfC/M11LhxBxTnzo7hAsmzY4JA44ykys dz7tvzFL5uN33WtHLKnEf0xbvYNZC0MajJ7k0o97sKU2LJ91VwUGV8Om1JjU4oidut +Ehl9I0NOUC9ibbivFddjDyEQsY/XaTnaUkp3LI2GQ0Bk4uALCxJKj8GqEyxmRSTlq H43T7GcRLV76sdAYNMp7+URU6RIrl6rQoZh1oM1zU0yxZNQjy0gmp7Y7jDv0nTpqoQ BkcZYYrttriZA== 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 06/10] kselftest/arm64: Only validate each signal context once Date: Mon, 29 Aug 2022 17:06:59 +0100 Message-Id: <20220829160703.874492-7-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829160703.874492-1-broonie@kernel.org> References: <20220829160703.874492-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3258; i=broonie@kernel.org; h=from:subject; bh=+LI8T2tA3D0W4jHBlk8SZzjrz3GUYnCv7SGlY2zQn2Q=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOQjJUXK/s/g3rF4Rh7MBT99qYdZEnt7xAeJcKyV 7ykOlU6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzkIwAKCRAk1otyXVSH0H68B/ wP1lu959Kr9WV8EaLTP5AAjUyXvmZeAMtUgSueARcLQdjmsQE+zJTmYdTtZS1ODwhCvvbuiozAo98S 4cuah5K/b4CEBpDKxHA6ASIV34NkoPWXl0lMJ9nqr99C+zj2pkPQRCu2jlE/gugzH8ySeUsdpowVBt djZYEy01MKsUxdusymL13sPbiz3sQBHuul4anr484ZZT+rgXSjypA/8tTQnHyYV/0UrlMmrlGWQOyj qza9NxuKcZWHzYUdfjQ0DjDyWzzFl3snmXAEPGVaJ6GwZ49vkbVqoRTZAAjwonHJJCFdUFsG90J+eL 8uHCr0Wy+x9uyUSZm4aHKd/dKkzgbd X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Currently for the more complex signal context types we validate the context specific details the end of the parsing loop validate_reserved() if we've ever seen a context of that type. This is currently merely a bit inefficient but will get a bit awkward when we start parsing extra_context, at which point we will need to reset the head to advance into the extra space that extra_context provides. Instead only do the more detailed checks on each context type the first time we see that context type. Signed-off-by: Mark Brown --- .../arm64/signal/testcases/testcases.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/arm64/signal/testcases/testcases.c b/tools/testing/selftests/arm64/signal/testcases/testcases.c index 16dc916939f9..0b3c9b4b1d39 100644 --- a/tools/testing/selftests/arm64/signal/testcases/testcases.c +++ b/tools/testing/selftests/arm64/signal/testcases/testcases.c @@ -105,6 +105,7 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) bool terminated = false; size_t offs = 0; int flags = 0; + int new_flags; struct extra_context *extra = NULL; struct sve_context *sve = NULL; struct za_context *za = NULL; @@ -120,6 +121,8 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) return false; } + new_flags = 0; + switch (head->magic) { case 0: if (head->size) @@ -133,7 +136,7 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) else if (head->size != sizeof(struct fpsimd_context)) *err = "Bad size for fpsimd_context"; - flags |= FPSIMD_CTX; + new_flags |= FPSIMD_CTX; break; case ESR_MAGIC: if (head->size != sizeof(struct esr_context)) @@ -144,14 +147,14 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) *err = "Multiple SVE_MAGIC"; /* Size is validated in validate_sve_context() */ sve = (struct sve_context *)head; - flags |= SVE_CTX; + new_flags |= SVE_CTX; break; case ZA_MAGIC: if (flags & ZA_CTX) *err = "Multiple ZA_MAGIC"; /* Size is validated in validate_za_context() */ za = (struct za_context *)head; - flags |= ZA_CTX; + new_flags |= ZA_CTX; break; case EXTRA_MAGIC: if (flags & EXTRA_CTX) @@ -159,7 +162,7 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) else if (head->size != sizeof(struct extra_context)) *err = "Bad size for extra_context"; - flags |= EXTRA_CTX; + new_flags |= EXTRA_CTX; extra = (struct extra_context *)head; break; case KSFT_BAD_MAGIC: @@ -192,16 +195,18 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) return false; } - if (flags & EXTRA_CTX) + if (new_flags & EXTRA_CTX) if (!validate_extra_context(extra, err)) return false; - if (flags & SVE_CTX) + if (new_flags & SVE_CTX) if (!validate_sve_context(sve, err)) return false; - if (flags & ZA_CTX) + if (new_flags & ZA_CTX) if (!validate_za_context(za, err)) return false; + flags |= new_flags; + head = GET_RESV_NEXT_HEAD(head); } From patchwork Mon Aug 29 16:07:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958119 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 6C4CBECAAD2 for ; Mon, 29 Aug 2022 16:08:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230200AbiH2QIB (ORCPT ); Mon, 29 Aug 2022 12:08:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbiH2QIA (ORCPT ); Mon, 29 Aug 2022 12:08:00 -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 E417085FD0 for ; Mon, 29 Aug 2022 09:07:59 -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 A22A6B81117 for ; Mon, 29 Aug 2022 16:07:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB25FC433C1; Mon, 29 Aug 2022 16:07:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661789277; bh=/WFb/N5O8AgUjIFzL8VcJC649OnWoCnCH7PCPPopE9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SMqZkA0CCFkexegb313WYj1l5N9R2f1OENbYP+SuA2LFKo8hljsbe8Nfk0hvMEo5r 0eS1xsxiCCQGk2aquJQ3bloJfHSHN/DJK3KuxwFn1qYCxl04v8oQc1RWiZV8jmbWR6 MmBgSXJEdQh+IGAZ6MUKkqU5B/LguCPnSKpw29+jbD64E0aqTe0enVq3c7ggNIxIi3 B0RHlMZYkB9Exv8RDhoWfhaogWFEVGhafklv0Rmc3RxvLVRxkSnkhgo3gSoz9qUNPM d/MJznUVOe73tHr4/K2HnTNTNXBDMQHJ9gHplZ8Yik3PrkVtDce+SWM2EeuXym8Vf5 B7DzQtlUQOW2A== 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 07/10] kselftest/arm64: Validate contents of EXTRA_CONTEXT blocks Date: Mon, 29 Aug 2022 17:07:00 +0100 Message-Id: <20220829160703.874492-8-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829160703.874492-1-broonie@kernel.org> References: <20220829160703.874492-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2567; i=broonie@kernel.org; h=from:subject; bh=/WFb/N5O8AgUjIFzL8VcJC649OnWoCnCH7PCPPopE9s=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOQkyKH9XTGK6DuYhZ+zZkKmkU3wcSyOtiyMcOTO t5F2Yu+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzkJAAKCRAk1otyXVSH0LixB/ 4uNsX9qNsUs5jRW7TeGC9um/kxH9XKg56Jd7hvcSPaNJPteO8vxXLZP9ixSzgLi8aXkBic+pEGzjLX U9LtDhV3RL53oITzoIpSqVjTdsink2qH2Ayutai0ytDHT4S3e78WFhWE0K3gCc9Bu4Lo9yjGeXuXvI 49iBARXujpiZ7BIRHzpOW+abzz1uTtR4fyxIzCMaN3yIcTFwPYoT3mxVOjiKKOipu6JCXtg+UkKoAC DAGLg/d0ex8NmpGnWvzN8OMH6oaVMHPO1wDI3AmXtbqd1h6H49+wt3aG6G5Ojzp/8zg65QBWpey3Wj 31oQEsDdAJ4QQDLXcUwsH03p0FnrBU X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Currently in validate_reserved() we check the basic form and contents of an EXTRA_CONTEXT block but do not actually validate anything inside the data block it provides. Extend the validation to do so, when we get to the terminator for the main data block reset and start walking the extra data block instead. Signed-off-by: Mark Brown --- .../arm64/signal/testcases/testcases.c | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/arm64/signal/testcases/testcases.c b/tools/testing/selftests/arm64/signal/testcases/testcases.c index 0b3c9b4b1d39..e1c625b20ac4 100644 --- a/tools/testing/selftests/arm64/signal/testcases/testcases.c +++ b/tools/testing/selftests/arm64/signal/testcases/testcases.c @@ -25,7 +25,8 @@ struct _aarch64_ctx *get_header(struct _aarch64_ctx *head, uint32_t magic, return found; } -bool validate_extra_context(struct extra_context *extra, char **err) +bool validate_extra_context(struct extra_context *extra, char **err, + void **extra_data, size_t *extra_size) { struct _aarch64_ctx *term; @@ -47,6 +48,9 @@ bool validate_extra_context(struct extra_context *extra, char **err) if (*err) return false; + *extra_data = (void *)extra->datap; + *extra_size = extra->size; + return true; } @@ -111,6 +115,8 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) struct za_context *za = NULL; struct _aarch64_ctx *head = (struct _aarch64_ctx *)uc->uc_mcontext.__reserved; + void *extra_data = NULL; + size_t extra_sz = 0; if (!err) return false; @@ -125,10 +131,20 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) switch (head->magic) { case 0: - if (head->size) + if (head->size) { *err = "Bad size for terminator"; - else + } else if (extra_data) { + /* End of main data, walking the extra data */ + head = extra_data; + resv_sz = extra_sz; + offs = 0; + + extra_data = NULL; + extra_sz = 0; + continue; + } else { terminated = true; + } break; case FPSIMD_MAGIC: if (flags & FPSIMD_CTX) @@ -196,7 +212,8 @@ bool validate_reserved(ucontext_t *uc, size_t resv_sz, char **err) } if (new_flags & EXTRA_CTX) - if (!validate_extra_context(extra, err)) + if (!validate_extra_context(extra, err, + &extra_data, &extra_sz)) return false; if (new_flags & SVE_CTX) if (!validate_sve_context(sve, err)) From patchwork Mon Aug 29 16:07:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958120 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 1133CC0502C for ; Mon, 29 Aug 2022 16:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230229AbiH2QIM (ORCPT ); Mon, 29 Aug 2022 12:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230227AbiH2QII (ORCPT ); Mon, 29 Aug 2022 12:08:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C46018F94E for ; Mon, 29 Aug 2022 09:08:07 -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 207F5B8111B for ; Mon, 29 Aug 2022 16:08:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BC02C433B5; Mon, 29 Aug 2022 16:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661789284; bh=6rK/9PZALGAoGA9wCW1CCtvSgsEbMadnadvWyxX6Jfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZRn61gt5bPOB20vCX17QjBR8d8a/XVMl8NqmgsqclXu77O2tZ6ldmWrdVA4wOQbIw X6mejvW5t81Eyep9bF//cGStCsdTLddSQCaoZWSD5I13kY6I3zH8e6KLOixC1i2Vgo X0YYdC5ucIRdOZ7MQiQRfF0X4rqovHMRFViJGWU9LtUjg1SCiqE4spn1Noy1+etB8t dKvLuC5EOcQehh7scG1Q9gP/GEE+ciTkjfvUoxGQL4OEVJWpIIowTXwepd7Dzo0WGV y7D46kzHJvwx87+gl6CE9WO34WbBPcKEYWnfBOJ1AWLs3IJJRquIB+QSGsCTiVEs/0 11u5cn3hG2FHg== 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 08/10] kselftest/arm64: Preserve any EXTRA_CONTEXT in handle_signal_copyctx() Date: Mon, 29 Aug 2022 17:07:01 +0100 Message-Id: <20220829160703.874492-9-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829160703.874492-1-broonie@kernel.org> References: <20220829160703.874492-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3106; i=broonie@kernel.org; h=from:subject; bh=6rK/9PZALGAoGA9wCW1CCtvSgsEbMadnadvWyxX6Jfw=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOQlODfg/LpIpbn9yartoDqNbxpiXcDV5WNM7X2h 3GTCDmSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzkJQAKCRAk1otyXVSH0ALcB/ 4q6mQL1rc2kwlCUnrbDpGS3WIutjDxNgGZ9pEZBkvQpZv5CeaClDIt3ngB5lw2KX43/pnBs1ObGY1Q mTIbKb4ut7IXu45tx6dbptkoHUXglfv0bdSQ9UpA0BIJIHLwRM+adw5Onkrzvie79x9BfRwYltjHo0 xfhTzj6S+TxzzXUZrzvMkmHXmzR0z5fr54iU6gnC5SG/xIqDpfxyF0VGe5DP3+Uins/fGiLsq0x+EA YWfWHgOo12shgZEtSX6ju+YOD5MMuYI3V8I1hPZoKmK7NRhpL6vHrswaquZr+gbmxdLoluhcEdeJwz R27u5r1KVP5IIdUuSC6qCyjFTprlx4 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When preserving the signal context for later verification by testcases check for and include any EXTRA_CONTEXT block if enough space has been provided. Since the EXTRA_CONTEXT block includes a pointer to the start of the additional data block we need to do at least some fixup on the copied data. For simplicity in users we do this by extending the length of the EXTRA_CONTEXT to include the following termination record, this will cause users to see the extra data as part of the linked list of contexts without needing any special handling. Care will be needed if any specific tests for EXTRA_CONTEXT are added beyond the validation done in ASSERT_GOOD_CONTEXT. Signed-off-by: Mark Brown --- .../arm64/signal/test_signals_utils.c | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.c b/tools/testing/selftests/arm64/signal/test_signals_utils.c index a54dc1b6f35c..308e229e58ab 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.c +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.c @@ -168,15 +168,61 @@ static bool handle_signal_copyctx(struct tdescr *td, siginfo_t *si, void *uc_in) { ucontext_t *uc = uc_in; + struct _aarch64_ctx *head; + struct extra_context *extra, *copied_extra; + size_t offset = 0; + size_t to_copy; ASSERT_GOOD_CONTEXT(uc); /* Mangling PC to avoid loops on original BRK instr */ uc->uc_mcontext.pc += 4; - memcpy(td->live_uc, uc, td->live_sz); + + /* + * Check for an preserve any extra data too with fixups. + */ + head = (struct _aarch64_ctx *)uc->uc_mcontext.__reserved; + head = get_header(head, EXTRA_MAGIC, td->live_sz, &offset); + if (head) { + extra = (struct extra_context *)head; + + /* + * The extra buffer must be immediately after the + * extra_context and a 16 byte terminator. Include it + * in the copy, this was previously validated in + * ASSERT_GOOD_CONTEXT(). + */ + to_copy = offset + sizeof(struct extra_context) + 16 + + extra->size; + copied_extra = (struct extra_context *)&(td->live_uc->uc_mcontext.__reserved[offset]); + } else { + copied_extra = NULL; + to_copy = sizeof(ucontext_t); + } + + if (to_copy > td->live_sz) { + fprintf(stderr, + "Not enough space to grab context, %lu/%lu bytes\n", + td->live_sz, to_copy); + return false; + } + + memcpy(td->live_uc, uc, to_copy); + + /* + * If there was any EXTRA_CONTEXT fix up the size to be the + * struct extra_context and the following terminator record, + * this means that the rest of the code does not need to have + * special handling for the record and we don't need to fix up + * datap for the new location. + */ + if (copied_extra) + copied_extra->head.size = sizeof(*copied_extra) + 16; + td->live_uc_valid = 1; fprintf(stderr, - "GOOD CONTEXT grabbed from sig_copyctx handler\n"); + "%lu byte GOOD CONTEXT grabbed from sig_copyctx handler\n", + to_copy); return true; } From patchwork Mon Aug 29 16:07:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958121 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 6A931C0502E for ; Mon, 29 Aug 2022 16:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230234AbiH2QIN (ORCPT ); Mon, 29 Aug 2022 12:08:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229502AbiH2QIL (ORCPT ); Mon, 29 Aug 2022 12:08:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D528886B7A for ; Mon, 29 Aug 2022 09:08:09 -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 6368D611F5 for ; Mon, 29 Aug 2022 16:08:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F393FC433D7; Mon, 29 Aug 2022 16:08:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661789288; bh=WmjLrlsOGKq+ByRsZM4AhGMMlLHgonmzqct5aiBJM7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hK/AkzxfFSDGtOcf4lzPkqWuIoCODGybf7e8oNji0ZFa/3LTV/LpdoBA27Y7yWv/W YRo4A7NcZPVYWfbuC+TuUtngMz6D1jOp1aoejsn/9qZkrrMrp+MtmN286YBFqoJUH5 l5tdz+Zm9dNiKcGhrxmYXD9eRgum0ex8rS9DM/AAtKarCWxi+uLIfEsOo6ExPTB7Og Y1mjY/z4xEI1Yz0y3w5DpPhQf2XU4clfCqK1Kb4wrvm93SniJgzvbS+B4ZmmY58lr4 GkqC3m3PMwWquQU/jfoKR/Uvc/ZvUIY0P5AXFRX0QNDLt6AoJX8PIT2dPWKooqZTb/ B632Ij1tIXkfA== 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 09/10] kselftest/arm64: Allow larger buffers in get_signal_context() Date: Mon, 29 Aug 2022 17:07:02 +0100 Message-Id: <20220829160703.874492-10-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829160703.874492-1-broonie@kernel.org> References: <20220829160703.874492-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=11112; i=broonie@kernel.org; h=from:subject; bh=WmjLrlsOGKq+ByRsZM4AhGMMlLHgonmzqct5aiBJM7U=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOQl2YcqxXrLMyIhLBY6VScgNSPAIiddROkzOLa+ tL9dhLaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzkJQAKCRAk1otyXVSH0FyXB/ 93Frnr2ssluyl6JhswtzunIDYLbMRjo529URJxRDnKBCFwrwGwQROL1OMrE5mOUlQ60apzSQR27uQl qOrhZprt28D1pcF55GMoyJuOeaPyau0N0l2o+HOr0vCSgp8edD63frzfwdUJvE7a5bXyyYRWZQlLqc pFs+6pD3TYLS+n+t7q5lj9/GUc52VF3JroMz9nIqScj6ZHVe7TQ7gUuTLvCd3COfxF5xAnf+MC1T0f djBWcE5yLrrMiGBAF69IAZHIbq+rEyBKZZRdyaSryb7S6skz/u+VJ1hFvSueU3AI/MOPUNys6nc26F Qr6GGjL/m+sdfmmeKhLnG34Eo+kE6m X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org In order to allow testing of signal contexts that overflow the base signal frame allow callers to pass the buffer size for the user context into get_signal_context(). No functional change. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/signal/test_signals_utils.h | 5 +++-- .../arm64/signal/testcases/fake_sigreturn_bad_magic.c | 2 +- .../arm64/signal/testcases/fake_sigreturn_bad_size.c | 2 +- .../signal/testcases/fake_sigreturn_bad_size_for_magic0.c | 2 +- .../signal/testcases/fake_sigreturn_duplicated_fpsimd.c | 2 +- .../arm64/signal/testcases/fake_sigreturn_misaligned_sp.c | 2 +- .../arm64/signal/testcases/fake_sigreturn_missing_fpsimd.c | 2 +- .../arm64/signal/testcases/fake_sigreturn_sme_change_vl.c | 2 +- .../arm64/signal/testcases/fake_sigreturn_sve_change_vl.c | 2 +- tools/testing/selftests/arm64/signal/testcases/sme_vl.c | 2 +- tools/testing/selftests/arm64/signal/testcases/ssve_regs.c | 2 +- tools/testing/selftests/arm64/signal/testcases/sve_regs.c | 2 +- tools/testing/selftests/arm64/signal/testcases/sve_vl.c | 2 +- tools/testing/selftests/arm64/signal/testcases/za_regs.c | 2 +- 14 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/arm64/signal/test_signals_utils.h b/tools/testing/selftests/arm64/signal/test_signals_utils.h index f3aa99ba67bb..222093f51b67 100644 --- a/tools/testing/selftests/arm64/signal/test_signals_utils.h +++ b/tools/testing/selftests/arm64/signal/test_signals_utils.h @@ -56,7 +56,8 @@ static inline bool feats_ok(struct tdescr *td) * at sizeof(ucontext_t). */ static __always_inline bool get_current_context(struct tdescr *td, - ucontext_t *dest_uc) + ucontext_t *dest_uc, + size_t dest_sz) { static volatile bool seen_already; @@ -64,7 +65,7 @@ static __always_inline bool get_current_context(struct tdescr *td, /* it's a genuine invocation..reinit */ seen_already = 0; td->live_uc_valid = 0; - td->live_sz = sizeof(*dest_uc); + td->live_sz = dest_sz; memset(dest_uc, 0x00, td->live_sz); td->live_uc = dest_uc; /* diff --git a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_magic.c b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_magic.c index 8dc600a7d4fd..8c7f00ea9823 100644 --- a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_magic.c +++ b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_magic.c @@ -21,7 +21,7 @@ static int fake_sigreturn_bad_magic_run(struct tdescr *td, struct _aarch64_ctx *shead = GET_SF_RESV_HEAD(sf), *head; /* just to fill the ucontext_t with something real */ - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; /* need at least 2*HDR_SZ space: KSFT_BAD_MAGIC + terminator. */ diff --git a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_size.c b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_size.c index b3c362100666..1c03f6b638e0 100644 --- a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_size.c +++ b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_size.c @@ -24,7 +24,7 @@ static int fake_sigreturn_bad_size_run(struct tdescr *td, struct _aarch64_ctx *shead = GET_SF_RESV_HEAD(sf), *head; /* just to fill the ucontext_t with something real */ - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; resv_sz = GET_SF_RESV_SIZE(sf); diff --git a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_size_for_magic0.c b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_size_for_magic0.c index a44b88bfc81a..bc22f64b544e 100644 --- a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_size_for_magic0.c +++ b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_bad_size_for_magic0.c @@ -21,7 +21,7 @@ static int fake_sigreturn_bad_size_for_magic0_run(struct tdescr *td, struct _aarch64_ctx *shead = GET_SF_RESV_HEAD(sf), *head; /* just to fill the ucontext_t with something real */ - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; /* at least HDR_SZ for the badly sized terminator. */ diff --git a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_duplicated_fpsimd.c b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_duplicated_fpsimd.c index afe8915f0998..63e3906b631c 100644 --- a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_duplicated_fpsimd.c +++ b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_duplicated_fpsimd.c @@ -21,7 +21,7 @@ static int fake_sigreturn_duplicated_fpsimd_run(struct tdescr *td, struct _aarch64_ctx *shead = GET_SF_RESV_HEAD(sf), *head; /* just to fill the ucontext_t with something real */ - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; head = get_starting_head(shead, sizeof(struct fpsimd_context) + HDR_SZ, diff --git a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_misaligned_sp.c b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_misaligned_sp.c index 1e089e66f9f3..d00625ff12c2 100644 --- a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_misaligned_sp.c +++ b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_misaligned_sp.c @@ -19,7 +19,7 @@ static int fake_sigreturn_misaligned_run(struct tdescr *td, siginfo_t *si, ucontext_t *uc) { /* just to fill the ucontext_t with something real */ - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; /* Forcing sigframe on misaligned SP (16 + 3) */ diff --git a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_missing_fpsimd.c b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_missing_fpsimd.c index 08ecd8073a1a..f805138cb20d 100644 --- a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_missing_fpsimd.c +++ b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_missing_fpsimd.c @@ -23,7 +23,7 @@ static int fake_sigreturn_missing_fpsimd_run(struct tdescr *td, struct _aarch64_ctx *head = GET_SF_RESV_HEAD(sf); /* just to fill the ucontext_t with something real */ - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; resv_sz = GET_SF_RESV_SIZE(sf); diff --git a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sme_change_vl.c b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sme_change_vl.c index 7ed762b7202f..ebd5815b54bb 100644 --- a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sme_change_vl.c +++ b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sme_change_vl.c @@ -54,7 +54,7 @@ static int fake_sigreturn_ssve_change_vl(struct tdescr *td, struct sve_context *sve; /* Get a signal context with a SME ZA frame in it */ - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; resv_sz = GET_SF_RESV_SIZE(sf); diff --git a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sve_change_vl.c b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sve_change_vl.c index 915821375b0a..e2a452190511 100644 --- a/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sve_change_vl.c +++ b/tools/testing/selftests/arm64/signal/testcases/fake_sigreturn_sve_change_vl.c @@ -56,7 +56,7 @@ static int fake_sigreturn_sve_change_vl(struct tdescr *td, struct sve_context *sve; /* Get a signal context with a SVE frame in it */ - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; resv_sz = GET_SF_RESV_SIZE(sf); diff --git a/tools/testing/selftests/arm64/signal/testcases/sme_vl.c b/tools/testing/selftests/arm64/signal/testcases/sme_vl.c index 13ff3b35cbaf..75f387f2db81 100644 --- a/tools/testing/selftests/arm64/signal/testcases/sme_vl.c +++ b/tools/testing/selftests/arm64/signal/testcases/sme_vl.c @@ -34,7 +34,7 @@ static int sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc) struct za_context *za; /* Get a signal context which should have a ZA frame in it */ - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; resv_sz = GET_SF_RESV_SIZE(sf); diff --git a/tools/testing/selftests/arm64/signal/testcases/ssve_regs.c b/tools/testing/selftests/arm64/signal/testcases/ssve_regs.c index 9022a6cab4b3..71f14632c524 100644 --- a/tools/testing/selftests/arm64/signal/testcases/ssve_regs.c +++ b/tools/testing/selftests/arm64/signal/testcases/ssve_regs.c @@ -73,7 +73,7 @@ static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, * in it. */ setup_ssve_regs(); - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; resv_sz = GET_SF_RESV_SIZE(sf); diff --git a/tools/testing/selftests/arm64/signal/testcases/sve_regs.c b/tools/testing/selftests/arm64/signal/testcases/sve_regs.c index 4b2418aa08a9..4cdedb706786 100644 --- a/tools/testing/selftests/arm64/signal/testcases/sve_regs.c +++ b/tools/testing/selftests/arm64/signal/testcases/sve_regs.c @@ -71,7 +71,7 @@ static int do_one_sve_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, * in it. */ setup_sve_regs(); - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; resv_sz = GET_SF_RESV_SIZE(sf); diff --git a/tools/testing/selftests/arm64/signal/testcases/sve_vl.c b/tools/testing/selftests/arm64/signal/testcases/sve_vl.c index 92904653add1..aa835acec062 100644 --- a/tools/testing/selftests/arm64/signal/testcases/sve_vl.c +++ b/tools/testing/selftests/arm64/signal/testcases/sve_vl.c @@ -34,7 +34,7 @@ static int sve_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc) struct sve_context *sve; /* Get a signal context which should have a SVE frame in it */ - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; resv_sz = GET_SF_RESV_SIZE(sf); diff --git a/tools/testing/selftests/arm64/signal/testcases/za_regs.c b/tools/testing/selftests/arm64/signal/testcases/za_regs.c index 9f1dd70289be..1c008bca73a1 100644 --- a/tools/testing/selftests/arm64/signal/testcases/za_regs.c +++ b/tools/testing/selftests/arm64/signal/testcases/za_regs.c @@ -71,7 +71,7 @@ static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, * in it. */ setup_za_regs(); - if (!get_current_context(td, &sf.uc)) + if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) return 1; resv_sz = GET_SF_RESV_SIZE(sf); From patchwork Mon Aug 29 16:07:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12958122 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 76A03C0502F for ; Mon, 29 Aug 2022 16:08:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229457AbiH2QIR (ORCPT ); Mon, 29 Aug 2022 12:08:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbiH2QIQ (ORCPT ); Mon, 29 Aug 2022 12:08:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE3838B9A9 for ; Mon, 29 Aug 2022 09:08:15 -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 4AA5960FBD for ; Mon, 29 Aug 2022 16:08:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F30BC433D7; Mon, 29 Aug 2022 16:08:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661789294; bh=uQocCmCf8k/A6P+eCrG+zLjWeDLQEf5/ywHNv0Ynfis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BzpRDYiMqHMgbWWrx5Snh3z72dvDfl+pWF+VE2j01icjaUooo4KQgl1MGD2qWsrk2 XMLiReIObD3gUcMWAntU20XXnmeVuD059H9eV17drKl9q7yqgTNavM9O1Q/X4oRVzU A3vq+7iV22uCkoa+klPG00qXnVfQumpfN97JFp7MvWyCheans7e4GzKwOqNRsVT2NA kdhuW5tR29DYESc/E0IyrW7QFEkc69SxWUSPJFcrLgkeEZCmMWGlsSW3ZlqhpfNmHA SpZNvyVTsJWNEwVH4tRV4NurT+irxDPAAB47UHAr4r7zmO8LoJmkK+FECi0Bq6adgy ifdgl/b72Gaxg== 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 10/10] kselftest/arm64: Include larger SVE and SME VLs in signal tests Date: Mon, 29 Aug 2022 17:07:03 +0100 Message-Id: <20220829160703.874492-11-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220829160703.874492-1-broonie@kernel.org> References: <20220829160703.874492-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=7369; i=broonie@kernel.org; h=from:subject; bh=uQocCmCf8k/A6P+eCrG+zLjWeDLQEf5/ywHNv0Ynfis=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjDOQmhmkNqeBcht3FxXt1jcBGuQuERWUJEr1epuio CRPgrGOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYwzkJgAKCRAk1otyXVSH0DN5B/ 0RTJ4djUEZb3hc38wrBngaUW5MNfZ2bGb7l+vXRWfaA7wx+rFdqtYhMacuu7If2Bkyt+U/NsPRKEsK q09tQM9C5RYvbS8uGVr6cFrYJRXaV+IDNEbLJiFM9r2zw/e8vaOo2KODr9yBaE6vb4sj5q4NMtVUh4 G5zjWmbIlH1j+meSyxuPPpGbnySAAwjYUI/BuePX3x+7CI6SzAxMeF3EIszMlp8FiS98nPWcrKKbxt Of6YcYHMFOMd1dQud/vedZrgwiVgSnjnhuboLcV9YFpwasK3yn3hMgKRs/kl6DkDiJJFN1A0gzuNrV vf9UAFqAm6NaUU3P6i4yLom0cRKNkW X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Now that the core utilities for signal testing support handling data in EXTRA_CONTEXT blocks we can test larger SVE and SME VLs which spill over the limits in the base signal context. This is done by defining storage for the context as a union with a ucontext_t and a buffer together with some helpers for getting relevant sizes and offsets like we do for fake_sigframe, this isn't the most lovely code ever but is fairly straightforward to implement and much less invasive to the somewhat unclear and indistinct layers of abstraction in the signal handling test code. Signed-off-by: Mark Brown --- .../arm64/signal/testcases/ssve_regs.c | 25 +++++++------------ .../arm64/signal/testcases/sve_regs.c | 23 +++++++---------- .../arm64/signal/testcases/testcases.h | 7 ++++++ .../arm64/signal/testcases/za_regs.c | 24 ++++++------------ 4 files changed, 33 insertions(+), 46 deletions(-) diff --git a/tools/testing/selftests/arm64/signal/testcases/ssve_regs.c b/tools/testing/selftests/arm64/signal/testcases/ssve_regs.c index 71f14632c524..d0a178945b1a 100644 --- a/tools/testing/selftests/arm64/signal/testcases/ssve_regs.c +++ b/tools/testing/selftests/arm64/signal/testcases/ssve_regs.c @@ -13,7 +13,10 @@ #include "test_signals_utils.h" #include "testcases.h" -struct fake_sigframe sf; +static union { + ucontext_t uc; + char buf[1024 * 64]; +} context; static unsigned int vls[SVE_VQ_MAX]; unsigned int nvls = 0; @@ -55,8 +58,8 @@ static void setup_ssve_regs(void) static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, unsigned int vl) { - size_t resv_sz, offset; - struct _aarch64_ctx *head = GET_SF_RESV_HEAD(sf); + size_t offset; + struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context); struct sve_context *ssve; int ret; @@ -73,11 +76,11 @@ static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, * in it. */ setup_ssve_regs(); - if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) + if (!get_current_context(td, &context.uc, sizeof(context))) return 1; - resv_sz = GET_SF_RESV_SIZE(sf); - head = get_header(head, SVE_MAGIC, resv_sz, &offset); + head = get_header(head, SVE_MAGIC, GET_BUF_RESV_SIZE(context), + &offset); if (!head) { fprintf(stderr, "No SVE context\n"); return 1; @@ -101,16 +104,6 @@ static int sme_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc) int i; for (i = 0; i < nvls; i++) { - /* - * TODO: the signal test helpers can't currently cope - * with signal frames bigger than struct sigcontext, - * skip VLs that will trigger that. - */ - if (vls[i] > 64) { - printf("Skipping VL %u due to stack size\n", vls[i]); - continue; - } - if (do_one_sme_vl(td, si, uc, vls[i])) return 1; } diff --git a/tools/testing/selftests/arm64/signal/testcases/sve_regs.c b/tools/testing/selftests/arm64/signal/testcases/sve_regs.c index 4cdedb706786..8b16eabbb769 100644 --- a/tools/testing/selftests/arm64/signal/testcases/sve_regs.c +++ b/tools/testing/selftests/arm64/signal/testcases/sve_regs.c @@ -13,7 +13,10 @@ #include "test_signals_utils.h" #include "testcases.h" -struct fake_sigframe sf; +static union { + ucontext_t uc; + char buf[1024 * 64]; +} context; static unsigned int vls[SVE_VQ_MAX]; unsigned int nvls = 0; @@ -55,8 +58,8 @@ static void setup_sve_regs(void) static int do_one_sve_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, unsigned int vl) { - size_t resv_sz, offset; - struct _aarch64_ctx *head = GET_SF_RESV_HEAD(sf); + size_t offset; + struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context); struct sve_context *sve; fprintf(stderr, "Testing VL %d\n", vl); @@ -71,11 +74,11 @@ static int do_one_sve_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, * in it. */ setup_sve_regs(); - if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) + if (!get_current_context(td, &context.uc, sizeof(context))) return 1; - resv_sz = GET_SF_RESV_SIZE(sf); - head = get_header(head, SVE_MAGIC, resv_sz, &offset); + head = get_header(head, SVE_MAGIC, GET_BUF_RESV_SIZE(context), + &offset); if (!head) { fprintf(stderr, "No SVE context\n"); return 1; @@ -99,14 +102,6 @@ static int sve_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc) int i; for (i = 0; i < nvls; i++) { - /* - * TODO: the signal test helpers can't currently cope - * with signal frames bigger than struct sigcontext, - * skip VLs that will trigger that. - */ - if (vls[i] > 64) - continue; - if (do_one_sve_vl(td, si, uc, vls[i])) return 1; } diff --git a/tools/testing/selftests/arm64/signal/testcases/testcases.h b/tools/testing/selftests/arm64/signal/testcases/testcases.h index b39f538c7be1..040afded0b76 100644 --- a/tools/testing/selftests/arm64/signal/testcases/testcases.h +++ b/tools/testing/selftests/arm64/signal/testcases/testcases.h @@ -30,6 +30,13 @@ #define GET_SF_RESV_SIZE(sf) \ sizeof((sf).uc.uc_mcontext.__reserved) +#define GET_BUF_RESV_HEAD(buf) \ + (struct _aarch64_ctx *)(&(buf).uc.uc_mcontext.__reserved) + +#define GET_BUF_RESV_SIZE(buf) \ + (sizeof(buf) - sizeof(buf.uc) + \ + sizeof((buf).uc.uc_mcontext.__reserved)) + #define GET_UCP_RESV_SIZE(ucp) \ sizeof((ucp)->uc_mcontext.__reserved) diff --git a/tools/testing/selftests/arm64/signal/testcases/za_regs.c b/tools/testing/selftests/arm64/signal/testcases/za_regs.c index 1c008bca73a1..d334fe210595 100644 --- a/tools/testing/selftests/arm64/signal/testcases/za_regs.c +++ b/tools/testing/selftests/arm64/signal/testcases/za_regs.c @@ -13,7 +13,10 @@ #include "test_signals_utils.h" #include "testcases.h" -struct fake_sigframe sf; +static union { + ucontext_t uc; + char buf[1024 * 128]; +} context; static unsigned int vls[SVE_VQ_MAX]; unsigned int nvls = 0; @@ -55,8 +58,8 @@ static void setup_za_regs(void) static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, unsigned int vl) { - size_t resv_sz, offset; - struct _aarch64_ctx *head = GET_SF_RESV_HEAD(sf); + size_t offset; + struct _aarch64_ctx *head = GET_BUF_RESV_HEAD(context); struct za_context *za; fprintf(stderr, "Testing VL %d\n", vl); @@ -71,11 +74,10 @@ static int do_one_sme_vl(struct tdescr *td, siginfo_t *si, ucontext_t *uc, * in it. */ setup_za_regs(); - if (!get_current_context(td, &sf.uc, sizeof(sf.uc))) + if (!get_current_context(td, &context.uc, sizeof(context))) return 1; - resv_sz = GET_SF_RESV_SIZE(sf); - head = get_header(head, ZA_MAGIC, resv_sz, &offset); + head = get_header(head, ZA_MAGIC, GET_BUF_RESV_SIZE(context), &offset); if (!head) { fprintf(stderr, "No ZA context\n"); return 1; @@ -99,16 +101,6 @@ static int sme_regs(struct tdescr *td, siginfo_t *si, ucontext_t *uc) int i; for (i = 0; i < nvls; i++) { - /* - * TODO: the signal test helpers can't currently cope - * with signal frames bigger than struct sigcontext, - * skip VLs that will trigger that. - */ - if (vls[i] > 32) { - printf("Skipping VL %u due to stack size\n", vls[i]); - continue; - } - if (do_one_sme_vl(td, si, uc, vls[i])) return 1; }