From patchwork Mon Aug 15 13:32: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: 12943597 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 A463AC3F6B0 for ; Mon, 15 Aug 2022 13:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240848AbiHONdP (ORCPT ); Mon, 15 Aug 2022 09:33:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242755AbiHONcw (ORCPT ); Mon, 15 Aug 2022 09:32:52 -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 0185D175B2 for ; Mon, 15 Aug 2022 06:32: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 ams.source.kernel.org (Postfix) with ESMTPS id A3F4EB80EBB for ; Mon, 15 Aug 2022 13:32:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF100C43470; Mon, 15 Aug 2022 13:32:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660570369; bh=pk7Q79jKBzZEn+CCEUhIxWG1JcQQiZbxATsJw8fMdG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uW59T6LjlQr67aU9gYrcKAXoCb8WskckNjJGtcryJpaewZCQZPVYVug47NwbQgSex N/2VcIplMu/1N3vxg2LIkG3pnQkGzEyDx11BlDPkKMsf+KYnH/A3DUZP4wDXLGLY8K sBF0Wbf16XcXyBiKvq2S9C7Q1GbJ0xwRW9/lfCv9zi8wIsVeinRm/WlqCrC8N4tNlo VZgL3WULtR40RaODZvCKWzCdE7eAAlKkSAclZ6blp6xTIXFzWnW/j1b5oWifbDJb9O M6385Ytnhg6vkGwRRLSyjFmJekN18dM3cmk15hLCM5wZKeAXunggmIAPbF1cKOSh29 ssnnAsjWv1LVg== 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 v1 01/10] kselftest/arm64: Enumerate SME rather than SVE vector lengths for za_regs Date: Mon, 15 Aug 2022 14:32:27 +0100 Message-Id: <20220815133236.235464-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815133236.235464-1-broonie@kernel.org> References: <20220815133236.235464-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=owGbwMvMwMWocq27KDak/QLjabUkhqRfXq+n6bjnuWk72JrZBddnBXke3MD+8O0H8ac/7Nd8v7Ft ZwRjJ6MxCwMjF4OsmCLL2mcZq9LDJbbOfzT/FcwgViaQKQxcnAJwkSL2//7fhR/xts1Y8mhP7Du5gt R9pikfDNZkvsvSODpHb8XLv+mfeQPu5qXP5buSz3NYevXbg/fFYgqSEr+bxli7bxa0Lw5f4po+daXy Ge+3k1NVZp9NqQ3o2fxq4skNSosnrPvt8fD0qoYDZb4SLi19HkYOmblOx1wTfx5uuVlv3P362p6miz kLdSauex61gvfR6+cdOoU7e8WjlM+onqqeXrqE00lbPdVt4Uy59xNMtcXCHbTsfKryzn+KMORrjJ1X cH2+2fZ4eYezW14uVDt78uJ1plgxSe0ST99I85QKfd1AbVuLp5aLO49dLl52PD24xNzMsiZKmElOzf 6jtdWiwDWus045HvD9eFszL9MCAA== 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 15 13:32: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: 12943601 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 DC33AC25B06 for ; Mon, 15 Aug 2022 13:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242071AbiHONdQ (ORCPT ); Mon, 15 Aug 2022 09:33:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242838AbiHONcy (ORCPT ); Mon, 15 Aug 2022 09:32:54 -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 D6FD817053 for ; Mon, 15 Aug 2022 06:32:53 -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 90B44B80EBC for ; Mon, 15 Aug 2022 13:32:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2418C433D6; Mon, 15 Aug 2022 13:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660570371; bh=Dxt22W8Em96QEF9sjlP0/VfqCLzptWgJwiuX8Wed7dw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RVfREFIgYH/ba8Dn0zby6B5NIAwHYKMFxbbhQUzTZriH9pDHDM27KOQ2jfkzly0BB 744HG8OKf3gK8pOcFahr/SGA2bR6pDwW8ubtt+Zk/MXWty0XMRErxGOs36KzcdWZQX t7ixkVz0GTojK5PuSIQi5HOrJE08Bx7Jun5JQa7XViEr6GDSjsBKfGW/9TNqFXwBuG oFKoGlFc6LZvjlv7TSfepOxwqMC31QvkPp9NcxPpeyXZBE1foYjXHOE3X5g9euYuki /F7HtbrLNR6kXNGMEreqySj4mYijQqmcBmfu5fB3JpV8S/iOohZCnnIXoYJdeKCoeW SQt9Gycyh9HEQ== 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 v1 02/10] kselftest/arm64: Validate signal ucontext in place Date: Mon, 15 Aug 2022 14:32:28 +0100 Message-Id: <20220815133236.235464-3-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815133236.235464-1-broonie@kernel.org> References: <20220815133236.235464-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/pANAwAKASTWi3JdVIfQAcsmYgBi+krsrr6pXSdNsaCjPzZcsv9NuPUamlQgH8zMcvpo Nhmt7KiJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYvpK7AAKCRAk1otyXVSH0LwYB/ 0UNOOLBubNtJoAJf+3G4GxyvIPFx3sdmm2hr2Hc21/KpGoiNb6woKL1Nw/esHVywTjnONJjYRH/2+W 786cRMtBRJcKOzwtdqy38dQo7elMCai3NA/Rk8yVhEkdO5LiHd+O1qcZq2rEJZGqccBIpuEqqb6tBH vrIu+jQCvr1RCzAmdc9vAb8rLs1+FQzszrCtTVjNQP/hD7xZsxKnciUfSCZrsqU0oGxZcC/XxYj5Yk 3n+4Zau3dcQ5pPMqtN62EylDcwDll5+wr42uHUJmMl6tNk94k/IV+yXzLxc0sUBUTxMnuxr+XdhcWI 1SBD4AdLCIMzP2P3BGSZWCP898c1Z5 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 15 13:32:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12943600 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 C6170C282E7 for ; Mon, 15 Aug 2022 13:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242144AbiHONdR (ORCPT ); Mon, 15 Aug 2022 09:33:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242903AbiHONcz (ORCPT ); Mon, 15 Aug 2022 09:32:55 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8515E17A81 for ; Mon, 15 Aug 2022 06:32:54 -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 F0F8460EC3 for ; Mon, 15 Aug 2022 13:32:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C69BEC4347C; Mon, 15 Aug 2022 13:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660570373; bh=V8kvWQdcoruSY2BGzEtAHoX5MY2BJ0by5Hd6bThqyO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NVugO1vpq0HMhuJ8QUVqpORukDWjKyBNZ2e0cgDIWQewa5E2x7zlWjGiB6Wj1mAev rJRsH6QnhBjOLZdNgvV5S3kOEB/l+BLrToNeeTVF0IRs37vX/9HBB4q1n12mTn95C1 bYYunsTgmnwrdRQn14eyVKbrK1bFKookvjXVVlWAuKRNO62MefIa9e7sWTCfraUoJg R5cjy7MD9tynnwRzOCRXbYaXO0f3yezxRoYZq0C6lJKgjSykzeEM1vwRjijsC9KdVu 0vtUUW/0DB8Wms/FBzpWFPAW/5NPSRHYVL2nTvRrABc6sDkEgK3DfQnEuTCFUW+tts bXXCnUCV18Vwg== 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 v1 03/10] kselftest/arm64: Fix validatation termination record after EXTRA_CONTEXT Date: Mon, 15 Aug 2022 14:32:29 +0100 Message-Id: <20220815133236.235464-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815133236.235464-1-broonie@kernel.org> References: <20220815133236.235464-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/pANAwAKASTWi3JdVIfQAcsmYgBi+krty0PRjapkJNbtLYlRyJSLUtCtMGiZLxJxN4VR arsmbjWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYvpK7QAKCRAk1otyXVSH0NDGB/ 9vuputIr6mJBEKGUyk5ew6yyBBXsTobWtkXQDKomUAs9UM3E9xoaJd7n3ggnmmwhLFebTZvXAmtQgw UzLdjKNn+f/Fu53kdq9Y6NjohI9FreeH5tezAERQkBlWTvQkLjGDC7SA5Kp3tRxjltlvsmykIo7DE2 QgKfhMLcvinVekKkI1gWuGYPOGbBWzGkcG1CZWuP8qOwlxtrOTPX5/j3f9r8wp2igEFr0f6U+IYLzR vNqKLLEd4FkbTu4riPUjhmMjJJ9UC3SRKqd14UDR7TT4Lz2QcIPEN/ipX0AtYjXZol+IItJS67bCQ5 WKVHHD41wkjJhj/Bw8E9edmSa4LBTO 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 15 13:32:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12943599 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 B50CDC25B0E for ; Mon, 15 Aug 2022 13:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242234AbiHONdS (ORCPT ); Mon, 15 Aug 2022 09:33:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242929AbiHONc5 (ORCPT ); Mon, 15 Aug 2022 09:32:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66ECD17053 for ; Mon, 15 Aug 2022 06:32:56 -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 00FA860EC3 for ; Mon, 15 Aug 2022 13:32:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC049C43470; Mon, 15 Aug 2022 13:32:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660570375; bh=OEluHX2rINw79r1ixw5NAaWYr6eeAln8ZyuAwVaM4PU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FqjpqSdtvTVR00WtioVTRz5w/dnUqxr+tjd9LZ2lSuHIdHFgGxhp8kxhjAbMc+UIS RRHYBBHJKbh2vZOVwjuxcwP3OvEE5CJuRRE1XcphY7aCVU8ZV9d3TqZjgO9cyta0DP wpFyizqH3vVy7UWSPeq3D3HbSV+lqzvAf29ru6U0JErenhdHQDr6/u6zKINM0r9E3b L+dV24zCOysKUIWlJveydO4P4hOVKliUddsiu53/ryrHNqEvfsTVs4EIRn0pPeFTBM xWJK8OhfAOCJ/qRHOt7NVLDELfLuJcYNcxcI4ysz3sEpmtiTjXTWoZCEIjBbO7zh0m J5NI2ThtI1asQ== 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 v1 04/10] kselftest/arm64: Fix validation of EXTRA_CONTEXT signal context location Date: Mon, 15 Aug 2022 14:32:30 +0100 Message-Id: <20220815133236.235464-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815133236.235464-1-broonie@kernel.org> References: <20220815133236.235464-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/pANAwAKASTWi3JdVIfQAcsmYgBi+kru53ACy+qtRh8Sc/w53mW6y7ChJCJBs5P7thFO wOL9vv+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYvpK7gAKCRAk1otyXVSH0NIuB/ 0aTbFeU+6+7i0uom74XxllgBVR1jaf2adLdxxjq9sFkVP/mwEn3dcjTcX0pVk0HDRN0DoIKDHlyj8s AN8iCu4tSc1Xu1O5k5iyi01PDfTBc0NL4/de/agnPCWmVittKaZmG7rO4j7WWkP+HTmb7kaSQSF7Qh Mzp8lRSsn16zenytVTG7IpxDCnqEjK/rwXv5otETzrS2z9yZZ3R5ZGQQfyVMFLDDpsrdWzK7ebF45q 5xypYIGgABWqureil5VhROjWZ+RG+uBps0ifi+4/biHGLf87leMwDQl0+0fPsAMj2Q9k36iWWcyENA 1sPLBZ7not5WRTFRBd2NVc94Qa6K7T 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 15 13:32:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12943602 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 0CCF7C2BB41 for ; Mon, 15 Aug 2022 13:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242386AbiHONdT (ORCPT ); Mon, 15 Aug 2022 09:33:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242943AbiHONc7 (ORCPT ); Mon, 15 Aug 2022 09:32:59 -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 675C917053 for ; Mon, 15 Aug 2022 06:32:58 -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 0626460DE6 for ; Mon, 15 Aug 2022 13:32:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0B06C433D6; Mon, 15 Aug 2022 13:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660570377; bh=hGKsg3UedEP/7h/cGhmdjQQzBHXgVmuy3ZE9b+PwvgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rIZ1SY1RdpKJ0DLPv9m6oTD5kmQYmtn2ugfXlPR5e6tfKz8oECgxtSwG2DS+w/s9G CLUJ4ShzCqsJ4mTOdzCxyy/pSlMMGZu+iwwBeJrFSZlJntMc9zbKcuAs41Y/4EPwzJ O5ucTnsygL3tP6ct4zpr1dmL/AsM9sle6A5+nahVCtYaN0/t+5f6s7osST7uWGwUOu A9Jy/411fzkQTT+Qu8bXKrM5pek4G+Mw7H+DFx74WE13PblwRdOSOegXhme2T9uhDH D95EB5Gi9aGKh6KAGCL8aXcb4nO3RzS3xoMCCgmr28EL+zDW2F0jarTPsyF2+sOzkM KI1cxny/9MGxw== 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 v1 05/10] kselftest/arm64: Remove unneeded protype for validate_extra_context() Date: Mon, 15 Aug 2022 14:32:31 +0100 Message-Id: <20220815133236.235464-6-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815133236.235464-1-broonie@kernel.org> References: <20220815133236.235464-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/pANAwAKASTWi3JdVIfQAcsmYgBi+krvTVYAh3LqfmHJ9Va/vprJOKc1AViua+o3JGuY nPMRrWeJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYvpK7wAKCRAk1otyXVSH0KkNB/ 948vMXy+SZFbs/vZ4UcjevsoMS69CB4X/6NIolxFs4hx5B43ydt+ov+jQseN/QKcEMaAEmmvgXXdpv 1kw9xK7Ib0Qis5czJTeK3ys0y4mZjNOUPFQmVsHw+J40x9eHn6bmdqWyEQARO7WLpKjOJe9TMbLDKl fSFrNfv8LMZhNOUpTf6pZ5BD7mSIdj4M5ZvNvuoB0fpjEoVt5ZmCr3CfaWSHSeDQv0NPXV0Iiroor9 2mfPZ54Xu0NTK/ilLn5fb6UXHfOJ5WnCfYVnJVjKLow8C9ODC2EKN3Kkn29JSSp3In9KcaKYMKEAx7 y7qO/uZAmZYexBaicOtztwqE+vOni9 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 15 13:32:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12943603 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 F19FFC28B2B for ; Mon, 15 Aug 2022 13:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242413AbiHONdV (ORCPT ); Mon, 15 Aug 2022 09:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242981AbiHONdB (ORCPT ); Mon, 15 Aug 2022 09:33:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F29017053 for ; Mon, 15 Aug 2022 06:33:00 -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 0C7E160EC2 for ; Mon, 15 Aug 2022 13:33:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6DA6C4347C; Mon, 15 Aug 2022 13:32:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660570379; bh=+LI8T2tA3D0W4jHBlk8SZzjrz3GUYnCv7SGlY2zQn2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r1GmFRBFM0w+tDwWi23iCgrRV4kJa2wKqSBSZieRVWbZjH2NiSGHIAYlMi5934kJc HZ4mbYoUR5FCNDj2c+r+kWAPUtQxZr+NcewuWTlsh32OHfYSfZwLVdgxwG/+f4fb8z puJXvCD+gHxn7BP//8f7v0CoKz+ds8raakUo2YGDCyZ4r2F1aWlulhObL88MjXfaRj NaGye+1BYexCl3/1qNfMGmMiykPqx375L147hGO6+Q7q7HRTENH7MF9w5UhQj+eJPe T8Yye6IPYS+gZetzGbAKwAHZ62Df7/xq+Jb4JQ7UkHrPSNQcxWV3HTY44HQ65XpM0N jKPDjXDDhJA8g== 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 v1 06/10] kselftest/arm64: Only validate each signal context once Date: Mon, 15 Aug 2022 14:32:32 +0100 Message-Id: <20220815133236.235464-7-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815133236.235464-1-broonie@kernel.org> References: <20220815133236.235464-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/pANAwAKASTWi3JdVIfQAcsmYgBi+krwJUXK/s/g3rF4Rh7MBT99qYdZEnt7xAeJcKyV 7ykOlU6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYvpK8AAKCRAk1otyXVSH0L8rB/ 9/XHTCkhHe24fXfDewMBsFjhJxRy0vhgiB1aPOa9ssT5vDJkpaiuFpoithcaX0KYt+pAOSiZC5Bdax yhTCEDMEKLqDjwbMe+4Q6/STB36uEtXkUzg0eVp/G4o6QqT7BIf0C9ZguhrAYzollZl6HX5fyNbHVa /QvWZOGnZiLe5aH0ztl7lmnujeOX4/b8/7+xZxVYk2RS01u2++kRidYcPIP0nFpQmnqEvsP6AvSbPF bDG/rJePfmrGW+JiKHJ/+WQ3W5DhJfNFSL2W8wVXUeGRIOMjApyeo5h3AJ/uThP6PlJ9pcNIg3Xym7 1i+MRNmUpUiQnT1JT/l55qtGSNQ8BR 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 15 13:32:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12943604 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 23B24C28B2C for ; Mon, 15 Aug 2022 13:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242444AbiHONdW (ORCPT ); Mon, 15 Aug 2022 09:33:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243003AbiHONdF (ORCPT ); Mon, 15 Aug 2022 09:33:05 -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 0F33417053 for ; Mon, 15 Aug 2022 06:33:04 -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 BBC36B80EBB for ; Mon, 15 Aug 2022 13:33:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDE32C43140; Mon, 15 Aug 2022 13:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660570381; bh=/WFb/N5O8AgUjIFzL8VcJC649OnWoCnCH7PCPPopE9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iPL8OkTAmKG1hGzqzcIKGuqDDwu3BQ+IGbCnpSb3UyimTJfzkdA0IYDA48lA3ztA1 9/7NZs6zY+VrZThMBc5al4rny7NAqlQ3J142viRHEK5f+afFggnkMBAqabhVJ5BYCR i83Z7R9+zGNCAKJpFYw4yk9ftn0ZX6hTeqwppNinIkvx3c4wBw7xndTNxAZJDg9YSo Av1TZoDTM4Gdg8o0JsyH4pEgaEuOGIQoVqwBStQM6/Gs4lzAft5oUMEROtzbkbURh3 8IFrdC/sb5KmbDoYG/Laj/gTB6q+iHL1zvcmuzgAY6gp0m/UU1iYc4O/xBX23QaIlr 4qR2us7bV8g+g== 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 v1 07/10] kselftest/arm64: Validate contents of EXTRA_CONTEXT blocks Date: Mon, 15 Aug 2022 14:32:33 +0100 Message-Id: <20220815133236.235464-8-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815133236.235464-1-broonie@kernel.org> References: <20220815133236.235464-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/pANAwAKASTWi3JdVIfQAcsmYgBi+krxyKH9XTGK6DuYhZ+zZkKmkU3wcSyOtiyMcOTO t5F2Yu+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYvpK8QAKCRAk1otyXVSH0EbBB/ 9Y0tPy0Lm2REqQMvTlkO2i1hqRvqNXjkwjzVEeR9J98ZoAY2r3OKtcnTpXbRAMiugk55R/lwsxeDkC 2zrTXRuBQ3cYyx0S8nImhejdkKTIHGASa8BSZE2rkm/9Y2e9rCOyFPf+pHN5ySFV8BlSVQAeWDqkkj iHYyO5ZW9qslJ+Z0FiIGaeAN56QCgWO7ZG60R6+K+68PjlXTKDhSAhHUDZJcmhVNsJ4vOGWua6vkGj ze2QdjiTaZItRfi2jCPU8oG9rYD5BI9Tsq5vZYOjU6JC44dTGLVrNFC8n6QBMsIO3iKmnu8Mgwjr2o lPg59aDZfiiamWm0K/x+pF6Ij7mxVK 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 15 13:32:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12943605 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 4A083C2BB43 for ; Mon, 15 Aug 2022 13:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242588AbiHONdW (ORCPT ); Mon, 15 Aug 2022 09:33:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243008AbiHONdH (ORCPT ); Mon, 15 Aug 2022 09:33:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C4BC15718 for ; Mon, 15 Aug 2022 06:33:06 -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 DAA72B80EC0 for ; Mon, 15 Aug 2022 13:33:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF3F7C433D7; Mon, 15 Aug 2022 13:33:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660570383; bh=6rK/9PZALGAoGA9wCW1CCtvSgsEbMadnadvWyxX6Jfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RNSFYZHn14/n2pUZUyWgxyEkLiMDJSW+EXMKXQlUvXLvRx5jtva1eX2YNPCE1bwtt GjxS6TSr4eDdjOgl32eGd2H1rYgAFBeP5+rJaLASvZMn6Ac7aNCTcn9wvNMAQed+Ss ILcaDz1Dj3YJKqSXMrCQTwbqwuDcXh7GKFCSpZqJg/WqsWt32kIqWasqHYoY9ec9Ug GBTYwAp2lCsVR6MzU3e8vbZBwSRWpa9OivQnxeiQ2gnmSek4/aOE04TMnhn/DL+8tr A5D2Rr0UNbnF7wUvrD7UW3r5O7qfqjR4MKF9cXvlgFqTYT5zNDAGnD6y9zIfC9JzBi 7i3rOyf9QYY6w== 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 v1 08/10] kselftest/arm64: Preserve any EXTRA_CONTEXT in handle_signal_copyctx() Date: Mon, 15 Aug 2022 14:32:34 +0100 Message-Id: <20220815133236.235464-9-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815133236.235464-1-broonie@kernel.org> References: <20220815133236.235464-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/pANAwAKASTWi3JdVIfQAcsmYgBi+kryODfg/LpIpbn9yartoDqNbxpiXcDV5WNM7X2h 3GTCDmSJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYvpK8gAKCRAk1otyXVSH0FoBB/ 9KLCPXutzCqwR69nUAzD9nI23dyi0S9x5MXZpaqrRmnAwZfnfu0ckrGZUiLArQt6Ocr9sJUXItCfhC CSaudvgkoeSYR83i9dMKH4l631l0AS+VqoZitDtnfB8Pb3Xs6aNMXHFdglZdObE7UJq5WvFk6+/anF lqms00PLPMw4fh1oEhwEvFcnbJoopEon1qUnhR5tWjK0m0MCuvOycRVAu7cSnonZvI6OaFLoPRCl8O V73MVF0zX7bCGMlfa8Gi272G1IE9WURgPRqFLAt7mGTcyqS6AxpByEAenI05p2B3mNPqVMQX9Z056A AkNSkZ5vaUsmnF0mOExjefN3FQQ2nl 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 15 13:32:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12943606 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 33D1DC2BB45 for ; Mon, 15 Aug 2022 13:33:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242718AbiHONdX (ORCPT ); Mon, 15 Aug 2022 09:33:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243014AbiHONdI (ORCPT ); Mon, 15 Aug 2022 09:33:08 -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 E61BE17053 for ; Mon, 15 Aug 2022 06:33:06 -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 7728060EC2 for ; Mon, 15 Aug 2022 13:33:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3EB2C43140; Mon, 15 Aug 2022 13:33:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660570385; bh=WmjLrlsOGKq+ByRsZM4AhGMMlLHgonmzqct5aiBJM7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eCQEr204J/YyX9LUYkm1uAX3QM5XORzEXz5bkgIFGL99B6D+WdI+tYqLjSaCEY6+G chYSrOEg77/Gi8dXbLB7Ql6n0qwbm61vNR58lsaIyw6+A31/9LkZjGZfDFlI1xuc+D IGyzH1V5DP6qAPmSDa60oceza8KS1hanvXojTCGpbmo5PhwvI5aRUVuJOiMDstL6xR +CxsO3ebvHnD/7QKpE8zjisM1fvH8kAt/xzVTWekf4diwRwElvCQxU4ZZLGtpDGND2 6CBC9GUa6aBTBPlNIdFhva155+cQNMqbR9YOz/A9iFkNh7/Z4QFBbSZiSE8fds/5T3 pDI14P1W9jzAg== 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 v1 09/10] kselftest/arm64: Allow larger buffers in get_signal_context() Date: Mon, 15 Aug 2022 14:32:35 +0100 Message-Id: <20220815133236.235464-10-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815133236.235464-1-broonie@kernel.org> References: <20220815133236.235464-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/pANAwAKASTWi3JdVIfQAcsmYgBi+kry2YcqxXrLMyIhLBY6VScgNSPAIiddROkzOLa+ tL9dhLaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYvpK8gAKCRAk1otyXVSH0K/fB/ wKRUUi2phM6X1nj+0mgJNgnc6n8C5WyHfEpYc2syza1SLcy1r/fFSf+nXogZaPbMqpXYmB9JAzaLcM aaFMZ8LTWdjWPkSHZqhY+Hz7c52Vt1lWAtdvMC4Jy3PLXrm8JunmIE3UYCCTdax/3zmPiWe52ya5t0 Ru7r/tRvmWTrjnEOHYoZ4LPJfpvZsa/ER025/Mjr7wmsFydI8mBzWBcTOjzihQqvsC00mojMrlOw7I 1sN6tJmbZLU4Lwmb9xADO5pSXe7fBRoukf7KYIcqltI/RW3905sHkLraDPQtnBIMvlwpCEEeUD8cd2 p31AgnQpFO/RcKRUl6ITrwe2d/oXZ4 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 15 13:32:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12943607 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 B3D0AC00140 for ; Mon, 15 Aug 2022 13:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232727AbiHONdp (ORCPT ); Mon, 15 Aug 2022 09:33:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233194AbiHONdN (ORCPT ); Mon, 15 Aug 2022 09:33:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E66D515718 for ; Mon, 15 Aug 2022 06:33:10 -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 7704CB80EBC for ; Mon, 15 Aug 2022 13:33:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63358C43141; Mon, 15 Aug 2022 13:33:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660570388; bh=uQocCmCf8k/A6P+eCrG+zLjWeDLQEf5/ywHNv0Ynfis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H3G3598s/baZt5rgiF3jEwTzM8CII+mZaW5LbZEvhZcH1KNE524sqPAEnjScQUTMC jkBVsbcqCgIlamzPugFSnAurQw7wa7+LxpvnZZ1hSVmjnGjkY9dpUA8pBCKoC7lXwk Kl99MNRNn+z9WrSLI5p59HHpXVl6dUvDmMhTcknFpoBvWYwlI59eOP7R44K0/2RhNG 0ltrByo+G0G5DPAK3IDSwNLbeBjb3lWNp2kCJnN3ED4nNDw41YnXXde+5wUvwNvJCk hkHPZXfppCP86pwiyRgtq784wb8zRku2qbb8PcqsO8Bi5ChRPK1qJFaiLtbUmgtsWD k9NEoGWPxBArw== 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 v1 10/10] kselftest/arm64: Include larger SVE and SME VLs in signal tests Date: Mon, 15 Aug 2022 14:32:36 +0100 Message-Id: <20220815133236.235464-11-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220815133236.235464-1-broonie@kernel.org> References: <20220815133236.235464-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/pANAwAKASTWi3JdVIfQAcsmYgBi+krzhmkNqeBcht3FxXt1jcBGuQuERWUJEr1epuio CRPgrGOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYvpK8wAKCRAk1otyXVSH0AY/CA CDLgmbH3piu8jzJ2VKWtqdQGghV55g4H16MSqzYVbfpurgVU0OJ/GYsT0gxYuL4GtbKofAiU1HEJLB /S6bR84uCEzYmS2/1ZOwQuV/9UMEhWFJZB7KQL++T4uSDWRGSRnbuUFpdnTyvWUokS6HgCeobsIARO Uo2I+Ynkx5WK4EPGlC5GDLki73f/67Aq8RSqCHcVBT1E8PsL1THeWFu280oizii/XmE87yBvKSOWSR R+Bs+XlJhZ/AIF6PsBm5ujag8379gO7IvUji2Y+Rv7r8ttbWvbYKKQNgjWfLPZgkKTLZpkmKgLNdpj LBy9xy0NaPEd5sYqyYWnAL1nMrtTIg 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; }