From patchwork Tue Apr 19 10:32:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12817739 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 E481FC433EF for ; Tue, 19 Apr 2022 10:32:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241694AbiDSKfg (ORCPT ); Tue, 19 Apr 2022 06:35:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240529AbiDSKff (ORCPT ); Tue, 19 Apr 2022 06:35:35 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDA8D29CB2 for ; Tue, 19 Apr 2022 03: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 sin.source.kernel.org (Postfix) with ESMTPS id 39412CE13C8 for ; Tue, 19 Apr 2022 10:32:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2A1BC385AD; Tue, 19 Apr 2022 10:32:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650364370; bh=xDJBAJu/5veMEVeVdUV21/gXIWmfA4m9JztlrzCV77E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LS2W9vgCEz9aPE59dH87Nos/FEqoHQcq8SvC/Q/3bIzDYOrHX3bTNtFexsstSfSPv oFAQQKvkBv3SBevxm3lVY122IWMABl6zhWcuBVGz2kJ3miEJP82pcEoYhMlx5Dfkw5 usSI0rxAVIxM1ml82ZlCTS6vJu9WU+0cY+7TbliMQe0bkDkaZB2G/Hn3+s8FZHJC25 s5up6n4nVLQ6ktrojNwPtYA/X9LBCe5OzTqV2SPybnJ2Li8O3BH/KupVa0CKdOd65y B9/eNIuYT7Tho0r8PkqKhXj91dTEmEfpabQHg9S3AwpZ2LK7RnbvIpLyMCzTYsJn7t MEsjKs9Z0X+Mw== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , linux-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:32:40 +0100 Message-Id: <20220419103243.24774-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220419103243.24774-1-broonie@kernel.org> References: <20220419103243.24774-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/pANAwAKASTWi3JdVIfQAcsmYgBiXo/HPQt3fHsS6WLGobnHqIeZInPVzKOE7Uw0KVpH GpocEQKJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYl6PxwAKCRAk1otyXVSH0BhSB/ wNUiToQ30C3tQVHT36DspATIMEE1k2ETTO91U5kv/2VlNNmTvnZgUC+OoSXlJj1fBitLa9GJXUic3Y daVlmldyuPAxfBrFnaCTUNpi1xp23DHnhIxumsJRxvGATFwJXvFZsoyoIGmtvauk/qjzUNO2G4s3HR dE40KGr8D5jlYivJXyd1pJ2ybXnIN4kn5V537p6euRo1pD55AmbMeSZj4R/EQsJ4Sb6QUSSh1JJ4eY wRkgHmAPEfq1vIPDFnudrd28DKHWNNVGEOd+Sb2aTnzwbOASx9A7rxg0MXKcCZmhOiCsxIC0CX0HQT jyXXiFKq6us9QjJaek03tHJc45twCG 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:32:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12817740 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 40452C433EF for ; Tue, 19 Apr 2022 10:32:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343729AbiDSKfi (ORCPT ); Tue, 19 Apr 2022 06:35:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240529AbiDSKfh (ORCPT ); Tue, 19 Apr 2022 06:35:37 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17FC929CBE for ; Tue, 19 Apr 2022 03: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 sin.source.kernel.org (Postfix) with ESMTPS id 72EDECE1767 for ; Tue, 19 Apr 2022 10:32:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2F9BC385A7; Tue, 19 Apr 2022 10:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650364372; bh=kEQALFvVnF2JUNgXMicTSPE1AfxRggwyPGzRYL7rWak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pvl787b5m/ia7Bbs9L7/caC0DCE6h88rvWm92C6AH7V9FOyeTBkr44zlpZMkZeGvA sUl6OCiG9cc6SU5eimK2qfSoj0u6pE3YAHharL4QrHtRBv8x19Ei3+ZFoGR0OanjR9 SNfhKDdTs+5FDReNz5MhxQqVRf/URGQGr8cKapjOXjbWaGLZ9XwbI7y8BvP87feLgI /6b+w+dWuTeJLJxtEr1/2nv0FdJNAIEqeKlI7SzWRTAC1TdEyrcgOG0eESnrLq8RK1 +n/cO1R5IR3o5oSXUGdajvrZUD+0Gf4DazppMS8IcKjGSVC+zXNTuvCMbdXPHVpIYo 4vnYEp0xmMoTw== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , linux-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:32:41 +0100 Message-Id: <20220419103243.24774-3-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220419103243.24774-1-broonie@kernel.org> References: <20220419103243.24774-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/pANAwAKASTWi3JdVIfQAcsmYgBiXo/IoXEdRQ7/5KuVtfTwYvHv3UfBHnjTUblpso4O pdkhaOOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYl6PyAAKCRAk1otyXVSH0ENmB/ sEH5L2Gb81E4Zc+o+Zonzk1+7cy9yubPvybNq4KN71HJjv1KziAWp2q+TKhpolWzlAZIVjWduQvhFJ AjXpvvisQHYS6Dv66i/12uIVvAJTwUb10bmXGlWaBya89cFWcG6kn2MvISBF5ntLsBEP70nOMMbByz VpVKe4835BWhDZaMOpnXSmYYrG57IKrBNiw8HEvshF/MM6pTtx5KfmPcjZXDh7iwcjgJyYXTWVvWBE TCC999Djr3q2ePjduzHNcssXFsNMfsMo7l4zYqccAvhR5liN+4i7cT6ZHbYhyDNjwaZQP6FQ5mCy4k 19eVHv5vScvn9JmSm7jdGZAbqljhIt 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:32:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12817741 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 7ED57C433FE for ; Tue, 19 Apr 2022 10:32:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240529AbiDSKfj (ORCPT ); Tue, 19 Apr 2022 06:35:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232153AbiDSKfh (ORCPT ); Tue, 19 Apr 2022 06:35:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1F9429CB2 for ; Tue, 19 Apr 2022 03:32:55 -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 8C15A61236 for ; Tue, 19 Apr 2022 10:32:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 324B6C385AD; Tue, 19 Apr 2022 10:32:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650364375; bh=34rEfnqbjHz3xCdTv2DILwIPZbwZa5CKK5iLFEGhXK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TN6F69ep3sxDSelops6IMXtD3K6ro5R6vvzU9cysIXM06q3IoWxm6tXA3EVjzjbRC /jiBc3OTZKJWs7/h8GA1+mdsKxn0hzAj7FKQe9JZEw6ybIPtcJZuGyZpZYwRCLvXdh cX4GE4IEiZGfldCPm5QICj/0FFKyRFRMEk7FYIl+NaauFZWZHx+mxkjusWfQ8v5Ieq UFuPLA6ZS6RYpRHeJAx5JeEbqF8c1mGdQPnwQBlYoJDnYhJDcZhinHxhmdAJzn5/+h YAEyo9UYIpbcp9DSM5CzJanU9pPFFqy4Hr5tQJyyT+MD76RQuMJNNNcVXc6f9gBreB QUUluL5ZRx32Q== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , linux-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:32:42 +0100 Message-Id: <20220419103243.24774-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220419103243.24774-1-broonie@kernel.org> References: <20220419103243.24774-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/pANAwAKASTWi3JdVIfQAcsmYgBiXo/JsgCHfdzOtIithI78zwesLOJSNsoRWIPM1F1x xF8GIpOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYl6PyQAKCRAk1otyXVSH0N8XB/ 9GdPjAg9Y40vLk/QufgPZGAAI6mHXzK7z6KwFxs4Gt5AGxKeikKuPcqoqmE/HNJolXx4Uj2TvddnT5 WMxX3yu0T/s3SQHJdSh49Lf6wRNz7wedRzgQk0Flgkz+b/NQ7aiXiqrweN/lVn01tFguEaaG7yOAs0 WHgMz6SyXsu0UMPne58IbTC5XHP5L0c2+JirQd1m1MJSoX8onQvVz8xBTwAABHhDrIq+DLUdJ/w97h xESFZMQAESp2LLoRpqmFKYoM2SHFmZThDzpecZmnKT4VmaxqF90ZTW08/T22ma7+33xa3NJNPYpKPM /mHmB5FWuaCnHJiBjXgxLRKgjVJFwL 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:32:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12817742 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 0F3CBC433F5 for ; Tue, 19 Apr 2022 10:33:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232153AbiDSKfn (ORCPT ); Tue, 19 Apr 2022 06:35:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344803AbiDSKfn (ORCPT ); Tue, 19 Apr 2022 06:35:43 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78E3529CB2 for ; Tue, 19 Apr 2022 03: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 sin.source.kernel.org (Postfix) with ESMTPS id D8052CE1764 for ; Tue, 19 Apr 2022 10:32:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67F68C385A5; Tue, 19 Apr 2022 10:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650364377; bh=hMdi/2FK0D/IjT+fUziwBHzOtEJWdD1HREKm5mcfz5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QTKU6H0cnhICC51GFLH9JxzzAdWfiwN8bE3kuiGi4oE2n1OeV48QUDSCy5a+m4Q66 y2MFMPLa6Z3MI9/MBI7Yl17YXJBQiln84zhMGZlI1kFYhbO81xsGGaORdN0XhY3TCq 03AZ+ZlYXNrvbUq/o5veU9B75mnFUNuEtvIHFmmFxMLBGZxeLmZU8gwIPfc9+ivGn6 vEbm0Su0WNohaKFytGDtwKDoc4Q4r82Fs3BszNXoD+nPVBJZqE/3XFrb0mRfA8TNUj gR004tFSD/VL1sR9aGDeXqDEuidwtYxqKdHFcnsDAW3D0AgIAiDPaUZc1Z3OaF7faM qNMuzk0IZ/KQw== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , linux-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:32:43 +0100 Message-Id: <20220419103243.24774-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220419103243.24774-1-broonie@kernel.org> References: <20220419103243.24774-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/pANAwAKASTWi3JdVIfQAcsmYgBiXo/KuP4PIJEfS/gV2HlOeCPq1merlrlRslXeyqjH kr4QV0SJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYl6PygAKCRAk1otyXVSH0IrkB/ 41fuOwQGGw80hXOvXbLhkpts0A/xGFYkXYMwsj/HD77OnFL/KRsPMc/0YGMVKYiX+60i38KjODYP+6 Us5AmKztmLmKyc6xu4BdFPf1wEqk8jX0FQxH0Zbq7ieOA0iQeoJwPyVKZrRgTUPebp+rEsal0ba+oy EgZ3Ldfitm1vBFovooSmkg7I4tx1e7rgd/CwMCV59dPlaEt/SF/kSYduPV/4O5tQ5AfsDg/MIwOgrc 23t5jUlzTmyD+VCuOaRVu7DXA4ulocUWc9sm7Y+/s2PBcgaOkHghk1lo85yCp+1mkgqPxpRLoTznk6 KWgnlV2ihs2JpxfnyRyUe70nFEl2D5 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; +}