From patchwork Fri Mar 11 13:51:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 552422 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 8D907C433F5 for ; Fri, 11 Mar 2022 13:52:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348999AbiCKNxQ (ORCPT ); Fri, 11 Mar 2022 08:53:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348976AbiCKNxI (ORCPT ); Fri, 11 Mar 2022 08:53:08 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC4941C57C1 for ; Fri, 11 Mar 2022 05:52: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 ams.source.kernel.org (Postfix) with ESMTPS id 740F9B82BFA for ; Fri, 11 Mar 2022 13:52:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AE33C340F4; Fri, 11 Mar 2022 13:51:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647006721; bh=xDJBAJu/5veMEVeVdUV21/gXIWmfA4m9JztlrzCV77E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tcnwki3MVgr+s5gVHac/R43x6AQjpFocPVC1K5I7uAJwZ80uQ+2/G1HkPwYl69Zec 6mNKSOH+Bql/yF1+5C+tsAjX/Zt1VJMg5nwW89kLGcdqxSTJqQon0J7kBEeM3ByLuz oM+deOX98nVYKeFFpW6sYTgjS47g8wXGk5hil7VtV73eapoBsqD9f4OmB5Us7BS3DH BxwSoPOhUNoVIu2JIWITP+VqVN+wOYRTV0nsDyNEQ1oAYnwfNPNVHcnw8obHNUvSK5 HDawVNKOf6s1eN4Rii5DQPS2XjUFwPvlkJp8WtVAuQOQVfFr69nMAnphIE2eqE3zOI xMJ0GrG+JEL/Q== 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: Fri, 11 Mar 2022 13:51:45 +0000 Message-Id: <20220311135148.410366-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220311135148.410366-1-broonie@kernel.org> References: <20220311135148.410366-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/pANAwAKASTWi3JdVIfQAcsmYgBiK1PvPQt3fHsS6WLGobnHqIeZInPVzKOE7Uw0KVpH GpocEQKJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYitT7wAKCRAk1otyXVSH0IAqB/ 4gypIvvqzwiX5fljwxQC0EKVKfR3aDhK5U+TvEnXTR6wBK+XfzkagtEt7YWSdXNplRaI/f+TXPnupv T+j9OH1egsXNysCz56t2g1FwcGtYw5xQS7AXFiQUyQZL4RTbXXq5TbPkPJ24PAr5R5OjqAnwXaViMr XvvSy6aXwzJeUJnUCsBVGPZh6g+cpa5vsq5kwjjWe8HUF3EuTvHZZndRnbHNYdFQXX5O6WgKqWCM2X Ex/kOVNuPljWgLWxFgMu5WWH/4GA3Q2dqoicWJBz+fMmyGgZ5ilz3eP6pjUsKPhr764WRHcG+lEoKo AEQ8hUAsYlKGHcR8g+1MilU10Wj4rL 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 Fri Mar 11 13:51:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 550680 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 1C63BC433EF for ; Fri, 11 Mar 2022 13:52:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348994AbiCKNxQ (ORCPT ); Fri, 11 Mar 2022 08:53:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348989AbiCKNxJ (ORCPT ); Fri, 11 Mar 2022 08:53:09 -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 329261C57C5 for ; Fri, 11 Mar 2022 05:52:04 -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 C09FB61E0A for ; Fri, 11 Mar 2022 13:52:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FE59C340EE; Fri, 11 Mar 2022 13:52:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647006723; bh=kEQALFvVnF2JUNgXMicTSPE1AfxRggwyPGzRYL7rWak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LBVe9DTpYWpIsSAOZ/w08tlqk44E8xW8p7DbYxifXx+nQRpFYdk+ON2uNtJ826zFd AqeTPkECHqhHD95Jn/V9omZpbir/VWXCG4f1KVChICx/TWnVsiXM9fGeozPqW7FtLc okeU1M7e9O6CFkfN9oCWSiV7Fx3MO3cjrQvRriVxFzcZSTNYiHUYXTm1QINUXqmqHl 0aGszBUdi2Bc33QIpmCYnVZHgNoxNXXr3qTgysZdM/Ftry6bGWXYk8iJz6MIUeMlkb bQhZ/5AWheUH+1t/4GSHUFRRSvjKIOEMvVpLBFsZa6RYtWsXU0CwIvJStZq1gAZYiW uU91JnmkpVM2Q== 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: Fri, 11 Mar 2022 13:51:46 +0000 Message-Id: <20220311135148.410366-3-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220311135148.410366-1-broonie@kernel.org> References: <20220311135148.410366-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/pANAwAKASTWi3JdVIfQAcsmYgBiK1PwoXEdRQ7/5KuVtfTwYvHv3UfBHnjTUblpso4O pdkhaOOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYitT8AAKCRAk1otyXVSH0OooB/ 9Xxw+HNPV/Lggv1Dc9e4GRdku0bi80hmkg90+6JN2CLPpnrWr+szi0KntnOVQTvEwG4LB7lGm6RiCs J+/hjP6X1iEydZkkR2vtK0AG4N1TrcSatLZz9LwhGp3NBKhgnEmaSvO3UJFSKORmlLkIJ1/Bz2BuHb Oz/kYN88TaUSe00PLAVzlxb3DurX8U8Y05dhDstAbhbZyDbOzUSQmlhCbVVZN47Be8ZLslYUoHR40R Dcm2p3vf/dOS0Xjf+GqzMMvkJRR3mIHRzKNJgAE7AQLMH5aT/DmTVl3d3RwTFXeHvdpxm+epTZ6niR /3JaecvlCDCp1XPsyHsJeRwlgaRRxn 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 Fri Mar 11 13:51:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 552421 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 7D703C4332F for ; Fri, 11 Mar 2022 13:52:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348989AbiCKNxR (ORCPT ); Fri, 11 Mar 2022 08:53:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348974AbiCKNxP (ORCPT ); Fri, 11 Mar 2022 08:53:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79ADB1C57CB for ; Fri, 11 Mar 2022 05:52:06 -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 0AA3761E8C for ; Fri, 11 Mar 2022 13:52:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6519C36AE5; Fri, 11 Mar 2022 13:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647006725; bh=34rEfnqbjHz3xCdTv2DILwIPZbwZa5CKK5iLFEGhXK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h2hk9tdIESLa9AZHLELfrLv9ATrCaW2qFph/9lir0wazDRL+YLrP06OY8xV5+1Nzr aNZ2/+vZRjmCPRBkQnpRhH7XZc5z1y+3T8ZvSO2dKWQ3+BiXLlUqyxeEVlJK97Pa5c /bC3lE0K8pmlhrtwO1btivRyindDgDcCVUYkgUl6tA1rpv/y71diPpDlAJvbPrimBP OxKtkKbC6YRf6bSoMwqeJuIMIrsrhYT8B41NNuuWNxhI8Q56GtFTBPS4Lf42QP+Yxl Rnw8hN8dzzr9Mn89tRuGxbqNhxidggURQg1878JBWCFh4xHVD4wgIrhMPTUC55HTQB WX7riggLgwjIg== 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: Fri, 11 Mar 2022 13:51:47 +0000 Message-Id: <20220311135148.410366-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220311135148.410366-1-broonie@kernel.org> References: <20220311135148.410366-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/pANAwAKASTWi3JdVIfQAcsmYgBiK1PxsgCHfdzOtIithI78zwesLOJSNsoRWIPM1F1x xF8GIpOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYitT8QAKCRAk1otyXVSH0MuiB/ 9bfvfiR5fUneWwgBTuIfPd7UYkCjB3zA8puBcxG9CeFKwPiS7k+HfDeIBijS/4C7H2cckItR2+IyEU VgX9PyOsNp0li1X7Ew9qCnvOFHMUo7Ed+2riKMXiw3gyuoDUfxFt6GE9FrmdLGQ/TnFm6ISHE4sTpT 4UY00O25sHm3XJgfgHKTZmhGXMiR+hkjaZhfwkoY2kNeoWbeeWkXZdLhQk5E3JeoB+rKBjv7bE3lPl AWkGeyQqZnRR2TuPgglfB9+GCkT7uwo7fXM+t9oMSRA01OJC1NF8dBw2t250oqUBm11EWugORIBGKL w7X+vHCtRA1Hnc7HNZJWy+9cle5E6R 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 Fri Mar 11 13:51:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 550679 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 B655DC433FE for ; Fri, 11 Mar 2022 13:52:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245064AbiCKNxS (ORCPT ); Fri, 11 Mar 2022 08:53:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348976AbiCKNxQ (ORCPT ); Fri, 11 Mar 2022 08:53:16 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8894B1C4B05 for ; Fri, 11 Mar 2022 05:52:10 -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 ams.source.kernel.org (Postfix) with ESMTPS id 0EB58B82BF4 for ; Fri, 11 Mar 2022 13:52:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE761C36AE2; Fri, 11 Mar 2022 13:52:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647006727; bh=hMdi/2FK0D/IjT+fUziwBHzOtEJWdD1HREKm5mcfz5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DBa9AbKYLQvne7ETMwxWq9RnLZD0/ot3kGSR6ra+AIc1ZBfNONKEeT3Ph+vJ62WLh vtssTtBFplU4KQx2nUVeG0fGxFCU/Wcw6UcGn6TO/IZ+7lGjk+slPt//o5kRvK+B2Y nY0o3a0w47Hg3wOAehJgO4ZeK6lBUeyGONaEQVg8zY7cRCtRJ6jVPTacAXYW8Ud62w XQEwMeCtXQhquMulq2c4lEA/yUBZ5KMBdH/3LrXApWTduSSLawpHkKzq15GwGNwps7 rK5xxQAtzZipXPXXOTVBgfaLCYHqyeWpYI5J0zyoJJkvciiTxtTZa9POH4SrkrjCsM sP0D2/A/BPlwQ== 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: Fri, 11 Mar 2022 13:51:48 +0000 Message-Id: <20220311135148.410366-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220311135148.410366-1-broonie@kernel.org> References: <20220311135148.410366-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/pANAwAKASTWi3JdVIfQAcsmYgBiK1PyuP4PIJEfS/gV2HlOeCPq1merlrlRslXeyqjH kr4QV0SJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYitT8gAKCRAk1otyXVSH0AM3B/ 95PUS55mTecPOu+D+MoVGY4xc6Pb9NoHBrrYNbTrwc6pTbVHs9QKhvkzAEIPYkvBnJwEeA/NW25HC2 rxol4zfyZG66O6L9goO1WJ2CEKRf5KU+rw0twcj8eMDMamnxxAAnV7GeDw3Qk0fFHhwdzuG9AzvqzE XP1gsE9pvBlljpu4XOaQccFja9gQ3+7MZi70/DQF50h1ZSdG7r76FblaHi4CbvEJhq+n9TEGInFV7o G4zVEI/YZJsYq2gkZEzEw+qW2jfEPeXIr6QwbeeVMpWFQaEoYyeFtas45KvS70woyRhjU0KX2aGEC1 YxsCqXWqHLVF6lAmK/3g/P8gfrVnpW 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; +}