From patchwork Tue Apr 19 10:28:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 564632 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 D2BB6C4167B for ; Tue, 19 Apr 2022 10:28:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350686AbiDSKbB (ORCPT ); Tue, 19 Apr 2022 06:31:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242200AbiDSKbA (ORCPT ); Tue, 19 Apr 2022 06:31:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A936E2AC65 for ; Tue, 19 Apr 2022 03:28:18 -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 6AF4BB81651 for ; Tue, 19 Apr 2022 10:28:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74567C385A9; Tue, 19 Apr 2022 10:28:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650364096; bh=xDJBAJu/5veMEVeVdUV21/gXIWmfA4m9JztlrzCV77E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W3Mj9yuM2Vr2L1pf6j7NLQVSPQ0ieOu2Rc9pbSHZbBxvlUXEfCG5LApc/jN4rdsF7 hPFlOIY/EpYCOwSuPiegVbak8OdGrbgdozGvSClv6PXsUdlDRwp/WRh5E6zhuKwBgs ptx/kWsmVprwtWb6RfI13i5PZov/QsgkEEwEvW+tBsAFziG4cTV4lU5M12HhV4oW4q nmNXrsOGT7lNLrPj8RdW0JSp6bRrQJT21tm5uBZJoUjBwe908br/39Fw2M115PenHF U6aX55mPlSzgEOUlBsJg9nCGCjq1MMMm+XSKoLWre+99sdJRsEyA0e1BJ393B5M/ZJ Dp9MIltLL9Jyw== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , inux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown , Shuah Khan Subject: [PATCH v2 1/4] kselftest/arm64: Handle more kselftest result codes in MTE helpers Date: Tue, 19 Apr 2022 11:28:05 +0100 Message-Id: <20220419102808.24522-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220419102808.24522-1-broonie@kernel.org> References: <20220419102808.24522-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1496; h=from:subject; bh=xDJBAJu/5veMEVeVdUV21/gXIWmfA4m9JztlrzCV77E=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiXo6yPQt3fHsS6WLGobnHqIeZInPVzKOE7Uw0KVpH GpocEQKJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYl6OsgAKCRAk1otyXVSH0KNDB/ 49M4qXwbVvJ5u5swAL/9RwFF4G7MQ32EnNOcRCLkAO+26a302ndC05Mlq1vN7LAsw9Vh+uJ3q4lLFg H0G5+pFWw5Ibxp0QXqfPv8wSkPxTqopMi0Grr6WCA9U6eQncdABjAb8wjJ+7CAy9WqmO150AfrcoN2 SjA/xNbKhiF0KbsR73GsR8ukUpde3WGav39/YVy3zW7XZ7/Vpb/rViMswLpZxke2/yzdfn2qiEY4f+ +mwwiAYu5OofHMLjhuI2YEx6gR54+FZo6wo5Va7sSKK8qeucJ/Vc3fssWJTM6S1BKOP0aGCUnthi2F XlpnPfVPe0Boctsx51Ultsy9LaCYCf X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The MTE selftests have a helper evaluate_test() which translates a return code into a call to ksft_test_result_*(). Currently this only handles pass and fail, silently ignoring any other code. Update the helper to support skipped tests and log any unknown return codes as an error so we get at least some diagnostic if anything goes wrong. Signed-off-by: Mark Brown Reviewed-by: Shuah Khan --- .../testing/selftests/arm64/mte/mte_common_util.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/arm64/mte/mte_common_util.h b/tools/testing/selftests/arm64/mte/mte_common_util.h index 195a7d1879e6..2d3e71724e55 100644 --- a/tools/testing/selftests/arm64/mte/mte_common_util.h +++ b/tools/testing/selftests/arm64/mte/mte_common_util.h @@ -75,10 +75,21 @@ unsigned int mte_get_pstate_tco(void); /* Test framework static inline functions/macros */ static inline void evaluate_test(int err, const char *msg) { - if (err == KSFT_PASS) + switch (err) { + case KSFT_PASS: ksft_test_result_pass(msg); - else if (err == KSFT_FAIL) + break; + case KSFT_FAIL: ksft_test_result_fail(msg); + break; + case KSFT_SKIP: + ksft_test_result_skip(msg); + break; + default: + ksft_test_result_error("Unknown return code %d from %s", + err, msg); + break; + } } static inline int check_allocated_memory(void *ptr, size_t size, From patchwork Tue Apr 19 10:28:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 563622 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 5AFBCC433F5 for ; Tue, 19 Apr 2022 10:28:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350714AbiDSKbL (ORCPT ); Tue, 19 Apr 2022 06:31:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350693AbiDSKbE (ORCPT ); Tue, 19 Apr 2022 06:31:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31DAD2898F for ; Tue, 19 Apr 2022 03:28:21 -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 C455CB816A9 for ; Tue, 19 Apr 2022 10:28:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA753C385AD; Tue, 19 Apr 2022 10:28:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650364098; bh=kEQALFvVnF2JUNgXMicTSPE1AfxRggwyPGzRYL7rWak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AVUUa4pu9E6mwdXErABgjCbVsHFBIf+lqXnDu8aV3tWuL3+7wt26XyA3o9UjO8o1C G+dpHwoTpJ1CIaqQuma+B6JWqUkEaUMJ5kZCyyBEuMg4gLckXqlbWDLn8pfjvyEB3l IfhKfOuiWsi1YxI6NefzjW/xJMTq2rVvh0ChuL53JooUJ0y7jXOfkCVGE8fFijmvvG K1lM0p9PUW9lO13ekPku2Z/PbsH5Qp+NOqB+nrCEeKc/acLdF/wBYu2jYrbEECGX3g hDHuMR6DIEUf6nnP/IOOE+6kI3R763oFXttSIE6pIxnunxG2w2BKTKx+9mTmupCMkJ zZ9JmBA5Rv8Ug== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , inux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown , Shuah Khan Subject: [PATCH v2 2/4] kselftest/arm64: Log unexpected asynchronous MTE faults Date: Tue, 19 Apr 2022 11:28:06 +0100 Message-Id: <20220419102808.24522-3-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220419102808.24522-1-broonie@kernel.org> References: <20220419102808.24522-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1041; h=from:subject; bh=kEQALFvVnF2JUNgXMicTSPE1AfxRggwyPGzRYL7rWak=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiXo6zoXEdRQ7/5KuVtfTwYvHv3UfBHnjTUblpso4O pdkhaOOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYl6OswAKCRAk1otyXVSH0CYsB/ 4yg3XLQWrKNXRYskaKjqaughEIXjxKjXRlZ3Tbye6UQGVa5W0djBpbJWhNfTfsjHYHPBhxrFAB4NK1 8/xa9Oa6jdRYdLfhYz/aOId99aUfEiPo0bDUHp68MjNJ9jCFDUx2GBp88IuaZs952ezj8u2KuiUtO7 t5iT60TttMnncnIxp5YoYJIr1kY8G21TgEwxSKHd0SE0ESpaYFgteg1onqYVjfoE99TK++DxabiqDr pzaodhf/AwOR6aHb8JZ15BmqsJ3IgoJEoK1B7mWYnb0nPnX+VvPKQ4znu7o+g77Tn3UM2us/wwmrim 7Z2iYj2NHVx59r9Sh5EkKb/tdp4/ca X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Help people figure out problems by printing a diagnostic when we get an unexpected asynchronous fault. Signed-off-by: Mark Brown Reviewed-by: Shuah Khan --- tools/testing/selftests/arm64/mte/mte_common_util.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/arm64/mte/mte_common_util.c b/tools/testing/selftests/arm64/mte/mte_common_util.c index 0328a1e08f65..5327aa958171 100644 --- a/tools/testing/selftests/arm64/mte/mte_common_util.c +++ b/tools/testing/selftests/arm64/mte/mte_common_util.c @@ -37,6 +37,10 @@ void mte_default_handler(int signum, siginfo_t *si, void *uc) if (si->si_code == SEGV_MTEAERR) { if (cur_mte_cxt.trig_si_code == si->si_code) cur_mte_cxt.fault_valid = true; + else + ksft_print_msg("Got unexpected SEGV_MTEAERR at pc=$lx, fault addr=%lx\n", + ((ucontext_t *)uc)->uc_mcontext.pc, + addr); return; } /* Compare the context for precise error */ From patchwork Tue Apr 19 10:28:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 563621 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 0F77CC433EF for ; Tue, 19 Apr 2022 10:28:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350739AbiDSKbR (ORCPT ); Tue, 19 Apr 2022 06:31:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350712AbiDSKbK (ORCPT ); Tue, 19 Apr 2022 06:31:10 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 641832CCA4 for ; Tue, 19 Apr 2022 03:28:24 -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 sin.source.kernel.org (Postfix) with ESMTPS id 5C91ECE1763 for ; Tue, 19 Apr 2022 10:28:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1F64C385A7; Tue, 19 Apr 2022 10:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650364100; bh=34rEfnqbjHz3xCdTv2DILwIPZbwZa5CKK5iLFEGhXK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VrjQ4UMyn44dOJoChwWt+queZWuyg4hKc04nI10qVUJ7s2pwwvB4sQbFAj7Vdlno3 G6uePOVgPET57kA8gVT/GgMmzo56bfB7EttO9EN4DAAbpADx9U6ZjX/BcCBG9rBU94 nGfAhNPYdVW8gAecaEBKqC+eike84408vjQxmmTtRd+L1+BbNRQi2iqsufFaUmSAXD 3+QTcx6F06hZipWOSzv1lv0gio0YorGiWboshC/HxSdpH+UV8wg1CrnBQxAWnt4VdN 6r+A46xi6VURdD+dfsgPxSnwiB7HhKCPiS3HqH5Ckt/RWSqYPiCJPrK1FKS0cHE4QK JzL/Ya6Ql8Y7w== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , inux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown , Shuah Khan Subject: [PATCH v2 3/4] kselftest/arm64: Refactor parameter checking in mte_switch_mode() Date: Tue, 19 Apr 2022 11:28:07 +0100 Message-Id: <20220419102808.24522-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220419102808.24522-1-broonie@kernel.org> References: <20220419102808.24522-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1469; h=from:subject; bh=34rEfnqbjHz3xCdTv2DILwIPZbwZa5CKK5iLFEGhXK0=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiXo60sgCHfdzOtIithI78zwesLOJSNsoRWIPM1F1x xF8GIpOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYl6OtAAKCRAk1otyXVSH0GWeB/ 90cd8aj3BhHopt+I9pf2QwuwwI0Tv6iESeWMq6Qp1vohcv5jovPT2/aOFWm5YghRbw0+jq8RtIs4Rb ZO+SYFOjMEb+zSh1u/bJrRWD+MPzz3xFF9ZS485OX5X53QXSKTQJWzWex8iVmwKNK5kQcSQeyUYt9Y iXhNY/sT0+G+BwZ+BZNmKlDbJwnvdxX3WWVC/9YTbajJMK1XVNeaRRfTbfa4I6pzcCXDOJf1en2Ab3 Nychhdazn8zYwGY5At9femnGXwfu1RUEb5NMVZXJofrG/rHUh/9Wbq+gidEpACMtan7fVkO7Vl2PTU aQVbSCPAbDIYdumIHAfd094z+CHtY8 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Currently we just have a big if statement with a non-specific diagnostic checking both the mode and the tag. Since we'll need to dynamically check for asymmetric mode support in the system and to improve debugability split these checks out. Signed-off-by: Mark Brown Reviewed-by: Shuah Khan --- .../testing/selftests/arm64/mte/mte_common_util.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/arm64/mte/mte_common_util.c b/tools/testing/selftests/arm64/mte/mte_common_util.c index 5327aa958171..260206f4dce0 100644 --- a/tools/testing/selftests/arm64/mte/mte_common_util.c +++ b/tools/testing/selftests/arm64/mte/mte_common_util.c @@ -273,9 +273,18 @@ int mte_switch_mode(int mte_option, unsigned long incl_mask) { unsigned long en = 0; - if (!(mte_option == MTE_SYNC_ERR || mte_option == MTE_ASYNC_ERR || - mte_option == MTE_NONE_ERR || incl_mask <= MTE_ALLOW_NON_ZERO_TAG)) { - ksft_print_msg("FAIL: Invalid mte config option\n"); + switch (mte_option) { + case MTE_NONE_ERR: + case MTE_SYNC_ERR: + case MTE_ASYNC_ERR: + break; + default: + ksft_print_msg("FAIL: Invalid MTE option %x\n", mte_option); + return -EINVAL; + } + + if (!(incl_mask <= MTE_ALLOW_NON_ZERO_TAG)) { + ksft_print_msg("FAIL: Invalid incl_mask %lx\n", incl_mask); return -EINVAL; } en = PR_TAGGED_ADDR_ENABLE; From patchwork Tue Apr 19 10:28:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 564631 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 6A9CCC433F5 for ; Tue, 19 Apr 2022 10:28:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350738AbiDSKbQ (ORCPT ); Tue, 19 Apr 2022 06:31:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350709AbiDSKbK (ORCPT ); Tue, 19 Apr 2022 06:31:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63F822A72F for ; Tue, 19 Apr 2022 03:28:24 -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 7C6EE611FC for ; Tue, 19 Apr 2022 10:28:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2733CC385A9; Tue, 19 Apr 2022 10:28:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650364102; bh=hMdi/2FK0D/IjT+fUziwBHzOtEJWdD1HREKm5mcfz5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R8Fjr18WvfAu22ycGqthLM3Fa0MYWLT/jdVfD7kWymfEzhg3fO2ESE9nv9hUC4iVP w4MJGa/tUmoH5s67d1Ij4KhMY/VUGI9C9lZM7bjwuRd/Y+LKb/etQzqlSYLlUNp+Rr aHy7GYdVyGybMjoHzkkANX7uzs62jHM/TRrjE5RKqy+Q+Et6m/e/4Lz99cDkU7Y1Kt z/ktCg1mnK1qz+aZUcW93oKNnsoKky3o3FnItegc2N1BZv1EDeg41ObLfaHLSEFUlB hqOr7Y9qxdEXvF8YM1JwJTLtYMmYKbeCgWmoAIp70kdG0mJPeS+QKejirsj6ewesqX 2PU425QBUWQ2w== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , inux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, Mark Brown , Shuah Khan Subject: [PATCH v2 4/4] kselftest/arm64: Add simple test for MTE prctl Date: Tue, 19 Apr 2022 11:28:08 +0100 Message-Id: <20220419102808.24522-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220419102808.24522-1-broonie@kernel.org> References: <20220419102808.24522-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3986; h=from:subject; bh=hMdi/2FK0D/IjT+fUziwBHzOtEJWdD1HREKm5mcfz5U=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiXo61uP4PIJEfS/gV2HlOeCPq1merlrlRslXeyqjH kr4QV0SJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYl6OtQAKCRAk1otyXVSH0E3rB/ 9Kg7tReR6Qlj54nXEtgtgTxahH6oC/aREh3mqqKXwbmfD1X+8iSdn3OURu+XUFSzlqRacn/LudoLQF RyNYPVOvja8XLXrEbIZQ4FM30cHVwL+THab6KwODVWlZuVVslhUkNIeEPv+006jbdLe9kr8kbZWdaK xhPsNlnvS9HUq6kUJzsdAGI6yfseXyZb80iCnDGE5PzMO+mvR04lj9eY+QNOGqN/sZuIEGtTdTcmYG TmDBRy9/Z+SvBQqjcclhuRz1dgryoQkL6YcKJ5iXBDsoSXUj41p42pnp02lrjtyNybuQmYacICtKyX xiibZvkUHK3KBaOyXXf5+P5+mHknVf X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The current tests use the prctls for various things but there's no coverage of the edges of the interface so add some basics. This isn't hugely useful as it is (it originally had some coverage for the combinations with asymmetric mode but we removed the prctl() for that) but it might be a helpful starting point for future work, for example covering error handling. Signed-off-by: Mark Brown Reviewed-by: Shuah Khan --- tools/testing/selftests/arm64/mte/.gitignore | 1 + .../testing/selftests/arm64/mte/check_prctl.c | 119 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 tools/testing/selftests/arm64/mte/check_prctl.c diff --git a/tools/testing/selftests/arm64/mte/.gitignore b/tools/testing/selftests/arm64/mte/.gitignore index d1fe4ddf1669..052d0f9f92b3 100644 --- a/tools/testing/selftests/arm64/mte/.gitignore +++ b/tools/testing/selftests/arm64/mte/.gitignore @@ -3,5 +3,6 @@ check_gcr_el1_cswitch check_tags_inclusion check_child_memory check_mmap_options +check_prctl check_ksm_options check_user_mem diff --git a/tools/testing/selftests/arm64/mte/check_prctl.c b/tools/testing/selftests/arm64/mte/check_prctl.c new file mode 100644 index 000000000000..f139a33a43ef --- /dev/null +++ b/tools/testing/selftests/arm64/mte/check_prctl.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2022 ARM Limited + +#include +#include +#include + +#include +#include + +#include + +#include "kselftest.h" + +static int set_tagged_addr_ctrl(int val) +{ + int ret; + + ret = prctl(PR_SET_TAGGED_ADDR_CTRL, val, 0, 0, 0); + if (ret < 0) + ksft_print_msg("PR_SET_TAGGED_ADDR_CTRL: failed %d %d (%s)\n", + ret, errno, strerror(errno)); + return ret; +} + +static int get_tagged_addr_ctrl(void) +{ + int ret; + + ret = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0); + if (ret < 0) + ksft_print_msg("PR_GET_TAGGED_ADDR_CTRL failed: %d %d (%s)\n", + ret, errno, strerror(errno)); + return ret; +} + +/* + * Read the current mode without having done any configuration, should + * run first. + */ +void check_basic_read(void) +{ + int ret; + + ret = get_tagged_addr_ctrl(); + if (ret < 0) { + ksft_test_result_fail("check_basic_read\n"); + return; + } + + if (ret & PR_MTE_TCF_SYNC) + ksft_print_msg("SYNC enabled\n"); + if (ret & PR_MTE_TCF_ASYNC) + ksft_print_msg("ASYNC enabled\n"); + + /* Any configuration is valid */ + ksft_test_result_pass("check_basic_read\n"); +} + +/* + * Attempt to set a specified combination of modes. + */ +void set_mode_test(const char *name, int hwcap2, int mask) +{ + int ret; + + if ((getauxval(AT_HWCAP2) & hwcap2) != hwcap2) { + ksft_test_result_skip("%s\n", name); + return; + } + + ret = set_tagged_addr_ctrl(mask); + if (ret < 0) { + ksft_test_result_fail("%s\n", name); + return; + } + + ret = get_tagged_addr_ctrl(); + if (ret < 0) { + ksft_test_result_fail("%s\n", name); + return; + } + + if ((ret & PR_MTE_TCF_MASK) == mask) { + ksft_test_result_pass("%s\n", name); + } else { + ksft_print_msg("Got %x, expected %x\n", + (ret & PR_MTE_TCF_MASK), mask); + ksft_test_result_fail("%s\n", name); + } +} + +struct mte_mode { + int mask; + int hwcap2; + const char *name; +} mte_modes[] = { + { PR_MTE_TCF_NONE, 0, "NONE" }, + { PR_MTE_TCF_SYNC, HWCAP2_MTE, "SYNC" }, + { PR_MTE_TCF_ASYNC, HWCAP2_MTE, "ASYNC" }, + { PR_MTE_TCF_SYNC | PR_MTE_TCF_ASYNC, HWCAP2_MTE, "SYNC+ASYNC" }, +}; + +int main(void) +{ + int i; + + ksft_print_header(); + ksft_set_plan(5); + + check_basic_read(); + for (i = 0; i < ARRAY_SIZE(mte_modes); i++) + set_mode_test(mte_modes[i].name, mte_modes[i].hwcap2, + mte_modes[i].mask); + + ksft_print_cnts(); + + return 0; +}