From patchwork Thu Mar 10 14:43: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: 12776514 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 37EF6C433FE for ; Thu, 10 Mar 2022 14:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242091AbiCJOze (ORCPT ); Thu, 10 Mar 2022 09:55:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346818AbiCJOuF (ORCPT ); Thu, 10 Mar 2022 09:50:05 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 753F818A7BD for ; Thu, 10 Mar 2022 06:44:59 -0800 (PST) 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 EA50F61019 for ; Thu, 10 Mar 2022 14:44:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD9D0C340F7; Thu, 10 Mar 2022 14:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646923498; bh=1ZcfM6fNgL6QzNDRPAHRIDvxY/f/Jl+4OdunBdGPjPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kgGXbj9B81OXFRO/3ttR9o2YRJ+vgnQzYDNRmE8RtDV2w7tafCNyUAzppOYpexPYz NkKN0kNvhEJudNm5UqvFHabRopXAjHZCL2YVX++muRPzI0VNzfV6ecbEuNEGljEGqM 3wWKdaVECI4FmulHumGsYT/NVzEsnoifZ3GPHQbU8T7d2gb0oiIkLJAay+jxVtw5Hx lPTQI54bR+EuUlpdzfIAPvshNbmVtTlP1YHWFPjVQjXCRC7jl+cwc6i5OP/Worq4bm iH8fN3mxviENwt2cvVp7TnY6V4YG4vMXRGLzPg4KGu63qeel25jyIZVzezW/Gred4X 3agsAgqn+5rgw== 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 Subject: [PATCH v1 1/4] kselftest/arm64: Handle more kselftest result codes in MTE helpers Date: Thu, 10 Mar 2022 14:43:32 +0000 Message-Id: <20220310144335.2097457-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220310144335.2097457-1-broonie@kernel.org> References: <20220310144335.2097457-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1443; h=from:subject; bh=1ZcfM6fNgL6QzNDRPAHRIDvxY/f/Jl+4OdunBdGPjPE=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiKg6SetzCRkzYMb9qtvanEidxRpe/RBV7Xb4+b8bL JE+047GJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYioOkgAKCRAk1otyXVSH0CTNB/ 0Z+mIwJhQrYB3x8bb5LbEyn+3NmEcjZjic7VNvxRmJD1xgRlj1haGU58KgcVnLHASs4cgQTTEgRDmn iF3+BygMSXd/f1BdoCw8JYT7OphRw1hOiJ5iYMlxnMCYM94fa/k0zX4627OCpcsp07OKS1041pCCNm gx1hH+5aLTaeJBYC6dKc4muyTcuPueK6PcxUasGuoXIXImcWYr6ViYPEQDQUHBtFkXMd8SKUiupU+r Z313rGo5RoRejY79ohDbh4MK4yEQArs0Z4dZG1lC5klAeNVpbNyG2EmFOHI/5So0ce8k+iMVIYHC5O Lt4nv4Da7/XTZeoS3k3M5jtUDLOKhI 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 Thu Mar 10 14:43: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: 12776517 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 2CDF0C43219 for ; Thu, 10 Mar 2022 14:54:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245400AbiCJOzg (ORCPT ); Thu, 10 Mar 2022 09:55:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346830AbiCJOuG (ORCPT ); Thu, 10 Mar 2022 09:50:06 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 698FC18BA4D for ; Thu, 10 Mar 2022 06:45:01 -0800 (PST) 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 F06A86101F for ; Thu, 10 Mar 2022 14:45:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C681DC340E8; Thu, 10 Mar 2022 14:44:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646923500; bh=4h0jyFl04wK6Vz/wb2kZmg2WDzho8RQ/eDWrs2L/kz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qGSSX9lPEvw6BNUhxVUd+Z7WPnPDXPLrefn0iDpDkW7xrvV+HUxUKXWbGMxS3BUnj VIAVLcQv/IY6tbmQUfgbgGoFkBlLBNMQtdbAysLCTknNzylMwI37ApdmzTsXPGxpAb mjwttrRDfs4CXSicRMwtFDstbQPi+VG4Zgb9rM2tKsXZE0lNWl5hXbPySmvRa37Er6 S6jX+4MByP6X8QJVhZgL8CgJO9uHsVN8GYtKDHLksvDH3fO+i4wMHsiqEHUpqYNYCs NEk9TUHA+in92RQNj4kRGDWgDgikP5k+uay/MJk8z4B2cRQvt8XZuscZ5R2Xno+N76 iiJF+1wFXi8aA== 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 Subject: [PATCH v1 2/4] kselftest/arm64: Log unexpected asynchronous MTE faults Date: Thu, 10 Mar 2022 14:43:33 +0000 Message-Id: <20220310144335.2097457-3-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220310144335.2097457-1-broonie@kernel.org> References: <20220310144335.2097457-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=889; h=from:subject; bh=4h0jyFl04wK6Vz/wb2kZmg2WDzho8RQ/eDWrs2L/kz4=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiKg6TiwBU/SdIu87f3y0jyt8PavdhNXXtlCv/2EK1 b/rIJXWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYioOkwAKCRAk1otyXVSH0PxeB/ 48veVsA9S6lmdWe0GCP/ixCuwjxvqJAefG1zkAL6ukxW8yCQcJH2td4y6amea4xNHzBpljCBHx7o9+ nwjCsMQJ2AWSjV3M43f10haydH/BBxxYoyzQ7XXDBVpyZwmeWYnBls3aW/Zz70eQVI56/ZGX26bGE/ 2aDLkhJtOkz4xc5Q9FqB4qHQeD4RjqZA6Cab4zAm6DSaViEEoJALzmpUM5qgpCwaWZulRqpyVA5siZ SydwWbxikAUX03Ujthf9plK5Upa4l2g7d3D18QGmuKsFWBsslavCJyvHSBta6jV5lcTbki17NDOE/3 Ozz8mRI96UG/QHrXFHkfTufRBYBKvh 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 | 2 ++ 1 file changed, 2 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..24b0c14203cb 100644 --- a/tools/testing/selftests/arm64/mte/mte_common_util.c +++ b/tools/testing/selftests/arm64/mte/mte_common_util.c @@ -37,6 +37,8 @@ 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\n"); return; } /* Compare the context for precise error */ From patchwork Thu Mar 10 14:43: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: 12776516 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 47B4FC4332F for ; Thu, 10 Mar 2022 14:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245361AbiCJOzf (ORCPT ); Thu, 10 Mar 2022 09:55:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346864AbiCJOuI (ORCPT ); Thu, 10 Mar 2022 09:50:08 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 925FA18BA6A for ; Thu, 10 Mar 2022 06:45:03 -0800 (PST) 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 0D19961015 for ; Thu, 10 Mar 2022 14:45:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D22C5C340F5; Thu, 10 Mar 2022 14:45:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646923502; bh=c/QRjRg/RfwQM4QUDJCU9l2+mRZW/DETr9jPGJCCKNs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GJ0L6EbPauPZB0q34twBFXLII9o/MMCYB5geKNxlvHpGz1LJ9iTlrs1shbEx4ZWr/ OPi1eYsghPGz0AuxM5oubIxmWrgblMeVOi6zVkocMuqVKxnIP4tMR9BvMSBxuAXljk 78VvkUs1QiqVecSnDqddt0sTse/tXOri8sgCZi1VMQABoAqvB30pXNHFMZA/5Fg7jf d9QcYsTwolaPpRM5F4hCmcakVLuksqmWSGZ3QHBSCb8xAXjHV/zwnxrxGPW/lDmJBI yrYsPrelfDBUhdC8uGKijW0N9qJ6DY7oHIxFTmOFuUpbnzXJ6a2F0PbMTTeJoOByzY GjkA4Mr+9voKw== 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 Subject: [PATCH v1 3/4] kselftest/arm64: Refactor parameter checking in mte_switch_mode() Date: Thu, 10 Mar 2022 14:43:34 +0000 Message-Id: <20220310144335.2097457-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220310144335.2097457-1-broonie@kernel.org> References: <20220310144335.2097457-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1416; h=from:subject; bh=c/QRjRg/RfwQM4QUDJCU9l2+mRZW/DETr9jPGJCCKNs=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiKg6UYO4Htw/wuc9XIZMUYMqZqBKEuEUSqdMjqtv3 2RBeeHWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYioOlAAKCRAk1otyXVSH0At8CA CGZMB/JMIYdKaUu3+UDmuyL/istCbmwuTNUd3Jsm0BZDkCJNDxSyRPD6TBaLjIfcOBJFn6z1m/htaA RwqnXQS6gtul5J6Idy3yFrAvupx9QfPxFik8po7AFekE6RV3xyimSqST3yoxbx74Sz/3q55GvYXvlJ BlYQtQHJsbI41jNonuxaJyK4J3mWCixl0AulokASI0yhlsMKEEaSNW66jCWPdTaJKBQyLIYIFBPBiz u4ZrCf6JrSMBeCwfMy4jQKtbuX5Khbq9reKtk8NmDgwai+02vXqDSlIrQOyvhQDyWJhE/+mhf+uRcv 3dq621gY2FnTG0STAq5y/iAwo9+vGF 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 24b0c14203cb..9b4529ef2b29 100644 --- a/tools/testing/selftests/arm64/mte/mte_common_util.c +++ b/tools/testing/selftests/arm64/mte/mte_common_util.c @@ -271,9 +271,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 Thu Mar 10 14:43: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: 12776518 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 20E24C433EF for ; Thu, 10 Mar 2022 14:54:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229520AbiCJOzi (ORCPT ); Thu, 10 Mar 2022 09:55:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346854AbiCJOuH (ORCPT ); Thu, 10 Mar 2022 09:50:07 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 967B513C9D8 for ; Thu, 10 Mar 2022 06:45:05 -0800 (PST) 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 2EB9261012 for ; Thu, 10 Mar 2022 14:45:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E20F0C340F3; Thu, 10 Mar 2022 14:45:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646923504; bh=1AzZS2fAcTElAWkUCJ66UnS7QEf1Fyn2CzlyW26dL/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VNjwPFQk2rk6pie66czuTDwwWpmQZSeRmoFt9ZvX4+OEqsVVg/x1bJMrXiPymCMl7 EC6qvStheDadp5z3Ye88WmqZuPGavU8m7+glXSv35iyIj4jUphZFvEzlb6uoM1qWuE O1/79Hkm4x+S/DyjRNH/+or12pQb8KJ9BD5GdI0G9nxaBED5b3zOLMqL81adesth27 UE9Yc/V0+DXoV9W3+fptxRGN92jViQyshYD1q1TOgyBXI86QJIXxmYNbV1lI7YE2fy kdc9tP8Hsx/TJIBUyCXg5AvAQAXFGii97i2ORshrqe5vlcayt57CeldkRO1xrDOgMe VwDJqUWY3R5dg== 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 Subject: [PATCH v1 4/4] kselftest/arm64: Add simple test for MTE prctl Date: Thu, 10 Mar 2022 14:43:35 +0000 Message-Id: <20220310144335.2097457-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220310144335.2097457-1-broonie@kernel.org> References: <20220310144335.2097457-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4024; h=from:subject; bh=1AzZS2fAcTElAWkUCJ66UnS7QEf1Fyn2CzlyW26dL/M=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiKg6Ux7WZ5KsGikQ/O+G8zzS04XzPG4mp2SrKBVyo 0iXbqn+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYioOlAAKCRAk1otyXVSH0JszB/ 9BHeTfkW5SvLdpmhI0t88KxF56jzeuUB3zOiGwbJUWnlpyHuW1tQgZ9jKGA55ftBwr7v2/8yIpbfk8 lF8Y9Ucu5op8ncv/hUpewdpzo/yVrCHtRJzmmLl5uzRM93Dh60/Wrm9x4YIGj/j1v/k1Kdp4QLFlPi DAXqYGJ1YKNaMf1QA8O8guU09rTbpDPMFVMDPDscjLIfKRwiK1AYk5atdbw0AE1zDJiZS4JQ7jouT5 4iDMJbYru6PU3YFo2+zEZZTmcGpb+ZWgQHG25aRxFUvT9w+S2XqjGzU3d8PHUIq6w/hLkCpwIwtAYC oXl9IGFh0a+oFMkZA4AmYHfl2ifFS2 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 | 123 ++++++++++++++++++ 2 files changed, 124 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..500aefc5d7cd --- /dev/null +++ b/tools/testing/selftests/arm64/mte/check_prctl.c @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2022 ARM Limited + +#include +#include +#include + +#include +#include + +#include + +#include "kselftest.h" + +static bool system_has_mte; + +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; + + system_has_mte = getauxval(AT_HWCAP2) & HWCAP2_MTE; + + 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; +}