From patchwork Tue May 10 16:45:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12845252 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 D988BC433EF for ; Tue, 10 May 2022 16:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347599AbiEJQtt (ORCPT ); Tue, 10 May 2022 12:49:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347634AbiEJQtm (ORCPT ); Tue, 10 May 2022 12:49:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FBF025EB for ; Tue, 10 May 2022 09:45:43 -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 D80E0B81E21 for ; Tue, 10 May 2022 16:45:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF950C385C2; Tue, 10 May 2022 16:45:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652201140; bh=bBHuZB3zULNvaFpsWT5fr9FYDtOLi0zeAPokTzmjfqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q0kH0KjY7YmTJqcLEqtzoV6mQ7/6HsHcrGuQ0cFFhrPh4lWuvdJADQP/JM1XuBH3B aefboBw3QNsZSUcYLdImZhDjWMxZg3mA2YoSYLLUQCDHyiLa/JGtvKQI/7KTfWhIFA a2An9p1L+a1AH/V6E7j9w8tnTgIaHs52kgbhCSJik97U5OoSRyOwuAbWEiwhyzkJ96 ADt5I1b+hX/FMDJnSU/FT282UnS/wmVyhBR1sO3yt4SPgiL8hdYdqhFlM9dpZe3UML bxpS6RwOQoROr7jhBKNRsW8YNpZVvjxxEq01AgCxlpwmmpOA4ThrxR7O9yS9qHcTfc 1BIMjEvOn9uOg== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v1 1/5] selftests/arm64: Log errors in verify_mte_pointer_validity() Date: Tue, 10 May 2022 17:45:16 +0100 Message-Id: <20220510164520.768783-2-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220510164520.768783-1-broonie@kernel.org> References: <20220510164520.768783-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1644; h=from:subject; bh=bBHuZB3zULNvaFpsWT5fr9FYDtOLi0zeAPokTzmjfqA=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiepac0Qgac1/NPxTWgAvIWHQ7dB/Ha+LUV0+zx+lD hB9kdGGJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYnqWnAAKCRAk1otyXVSH0HqvB/ 9r00srnCW5vRnGS7RGk9uO6oewU+8+jGFd3VY+5pUq/uW6fjtW/meoNm2InIiWmW6dVxjnYMktXPo7 hv28YH+RxRVtkrG2cS4YYHKHkh9nD77sN3IvkQVLl2bqUMPVFqyzrqSMnXd08dZmJsinvhHZ8UHX3I Pndjzlp5sz6ltQT6lszV8iIxQaVSOnf6VE0ZWvWrhwMW3wsrpycb08O9His9QUmq+4vs4o9BSKIwUs 5hwDgxKEHssNyRteQQdykimeLF/96XmAfv7G8qrH4wTphvVgLyWz6Zqy1AWr/8Ef+4DJE/rUMzltpZ o0Vu1ITbiyQgaocMVEOG48V4pZ42m/ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When we detect a problem in verify_mte_pointer_validity() while checking tags we don't log what the problem was which makes debugging harder. Add some diagnostics. Signed-off-by: Mark Brown Reviewed-by: Shuah Khan --- .../selftests/arm64/mte/check_tags_inclusion.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/arm64/mte/check_tags_inclusion.c b/tools/testing/selftests/arm64/mte/check_tags_inclusion.c index deaef1f61076..b906914997ce 100644 --- a/tools/testing/selftests/arm64/mte/check_tags_inclusion.c +++ b/tools/testing/selftests/arm64/mte/check_tags_inclusion.c @@ -25,8 +25,11 @@ static int verify_mte_pointer_validity(char *ptr, int mode) /* Check the validity of the tagged pointer */ memset((void *)ptr, '1', BUFFER_SIZE); mte_wait_after_trig(); - if (cur_mte_cxt.fault_valid) + if (cur_mte_cxt.fault_valid) { + ksft_print_msg("Unexpected fault recorded for %p-%p in mode %x\n", + ptr, ptr + BUFFER_SIZE, mode); return KSFT_FAIL; + } /* Proceed further for nonzero tags */ if (!MT_FETCH_TAG((uintptr_t)ptr)) return KSFT_PASS; @@ -34,10 +37,13 @@ static int verify_mte_pointer_validity(char *ptr, int mode) /* Check the validity outside the range */ ptr[BUFFER_SIZE] = '2'; mte_wait_after_trig(); - if (!cur_mte_cxt.fault_valid) + if (!cur_mte_cxt.fault_valid) { + ksft_print_msg("No valid fault recorded for %p in mode %x\n", + ptr, mode); return KSFT_FAIL; - else + } else { return KSFT_PASS; + } } static int check_single_included_tags(int mem_type, int mode) From patchwork Tue May 10 16:45:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12845254 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 8A575C433FE for ; Tue, 10 May 2022 16:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343929AbiEJQtu (ORCPT ); Tue, 10 May 2022 12:49:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347636AbiEJQtm (ORCPT ); Tue, 10 May 2022 12:49:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 902217644 for ; Tue, 10 May 2022 09:45:43 -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 355FC61811 for ; Tue, 10 May 2022 16:45:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06CB6C385CD; Tue, 10 May 2022 16:45:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652201142; bh=+doQH0V5WrVXFxAnPAr+9FVdqU2NMS/NTVoUQBr2X+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xv9eky1VFhK56OWO3K77S8T1rRWOuwNbwJe+FCozmudeb9zKoxClA3BFioSorp/gb gfkvjNFnFN0zP7HriN6UPE/ypz1iamEPB/U3md1C5NdQl3ynf1dDXBrMciN2sk+orm m6eJ+sIn2WUKtijbYMHDQ/0AOsjEiCQkrpYzz4AMZJU1jUv1Fl6tq8Tk3ni2weAVSJ b4V2UryOGyF3LwaspcYkKRt3ICiJrQSJN9HlBL547qL2YJoOS4OBcpOgujYhwTxltm h8hmCfwG2+0+KMY49y6tbpPH/xVE7SejEa4xL5efGIGcXvGUPOoFgDy2HaclCGFS2M 7A3JoESBo7rXQ== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v1 2/5] selftests/arm64: Allow zero tags in mte_switch_mode() Date: Tue, 10 May 2022 17:45:17 +0100 Message-Id: <20220510164520.768783-3-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220510164520.768783-1-broonie@kernel.org> References: <20220510164520.768783-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1213; h=from:subject; bh=+doQH0V5WrVXFxAnPAr+9FVdqU2NMS/NTVoUQBr2X+o=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiepacjqDNrDfpJZfEr3DwpfcqFuan/SeP5LzD9VQK CAX7dCOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYnqWnAAKCRAk1otyXVSH0J00B/ 9k/VvTk83ITffqPZeHO8yhTPM8kJJUMoPQtCnahbvYY1OwB7szGoyB69Ksb9u0KDxGFLwSFTVsU1fZ iikZJrX2AFqJzAEa05XE2SqW6bBRUFuI8xev6pE4/PcViccpkIsXgzIO9ZOraB6LBpS1YgDLsUVcHu BcBXJuVxPR6tO62kuqg4mY3uZhQTy9u4CHgucvjNfryW/5d11nTl3rktiH6RQQ5C4S7fR7sSgHXDeA v4vmYt0TT+sw7oU2xIZ6yP+wBz2ht2aNsQ6f9xz9S0g+vHn0nUYGjSDB7RWZk2ceeoBQ/MHajDBuMW 84U8eieohLqlUZyHsMIdAW8Glum/zH X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org mte_switch_mode() currently rejects attempts to set a zero tag however there are tests such as check_tags_inclusion which attempt to cover cases with zero tags using mte_switch_mode(). Since it is not clear why we are rejecting zero tags change the test to accept them. The issue has not previously been as apparent as it should be since the return value of mte_switch_mode() was not always checked in the callers and the tests weren't otherwise failing. Signed-off-by: Mark Brown Reviewed-by: Shuah Khan --- tools/testing/selftests/arm64/mte/mte_common_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/arm64/mte/mte_common_util.c b/tools/testing/selftests/arm64/mte/mte_common_util.c index 260206f4dce0..6ff4c4bcbff1 100644 --- a/tools/testing/selftests/arm64/mte/mte_common_util.c +++ b/tools/testing/selftests/arm64/mte/mte_common_util.c @@ -283,7 +283,7 @@ int mte_switch_mode(int mte_option, unsigned long incl_mask) return -EINVAL; } - if (!(incl_mask <= MTE_ALLOW_NON_ZERO_TAG)) { + if (incl_mask & ~MT_INCLUDE_TAG_MASK) { ksft_print_msg("FAIL: Invalid incl_mask %lx\n", incl_mask); return -EINVAL; } From patchwork Tue May 10 16:45:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12845253 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 60533C43217 for ; Tue, 10 May 2022 16:45:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347636AbiEJQtv (ORCPT ); Tue, 10 May 2022 12:49:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236527AbiEJQtr (ORCPT ); Tue, 10 May 2022 12:49:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45FF71CFF2 for ; Tue, 10 May 2022 09:45:47 -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 00FAFB81DA5 for ; Tue, 10 May 2022 16:45:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14F87C385C2; Tue, 10 May 2022 16:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652201144; bh=0cKVUWis1xhOjJJFymdC0c8pQI3TwhTLrNfwGP0ncPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UocCC2nU0PdRxUuAvT6yNqsEVksAAEv4xrdq2mppRbBz+i8sn/aX8nlzyI9dt93gh /i0RbSFrfN58yBCtjxfXPkhOJLJpz++GibfJ1de+z5eWAhpXVVyN4qBxfZ5yscGtnC DUz/BhFkMFOPoAo8cInnBwOO3BKxfPslSJ2b55SvavDctRphAh80qfA31qlKJw+D61 JFXQmk8l6qaFyHMn3zT6EEmp1g49nyHDVBb1qh5vnjhgiyFOF2knyNqjafxmGTGxq3 ZsU/4MXJoCzEWWJskl6rAPw2nzteDNWvjLCACKa3QBEZUF6tO3tXgd9M+Nnl2q4jlK nE8ZIoL+eMitQ== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v1 3/5] selftests/arm64: Check failures to set tags in check_tags_inclusion Date: Tue, 10 May 2022 17:45:18 +0100 Message-Id: <20220510164520.768783-4-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220510164520.768783-1-broonie@kernel.org> References: <20220510164520.768783-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3100; h=from:subject; bh=0cKVUWis1xhOjJJFymdC0c8pQI3TwhTLrNfwGP0ncPY=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiepadwcjCghw03u2C4QRkkECWrCYPmnlFG2cD9N9q Ff1j56+JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYnqWnQAKCRAk1otyXVSH0JzvCA CF//KO+GghYYk75IIFjElDQUSOjNqaeluflcV2C0mLiL0D77v06fjAXe4Wgu9lTvNXsIXQ8G9X5vPr uXJ4rqxBGPsMVKWSwVFSdq61/3iPB+o0HWEY+/kmvq/+mjk/2tTN4kGOtAR9mdmxjIGCyq8FPmWaxp 1VAhXnDqLBPMb/XMqZGrXYSbOlL5jCd36vDHDm1Qrvyf3E51psieYP0MO29ZudKKbOgsOleTJ+J2F3 DGMbrItfzsPpVTOWW2shWWE0u/E+it3wDrUZ7Qe7GzTPHp7/mcN/7AQ7a2totTAfPWukoJZfPxG+ml yz1tE64iWPTJ4lunVl2rz+GsnlyaFd 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 check_tags_inclusion test uses the mte_switch_mode() helper but ignores the return values it generates meaning we might not be testing the things we're trying to test, fail the test if it reports an error. The helper will log any errors it returns. Signed-off-by: Mark Brown Reviewed-by: Shuah Khan --- .../selftests/arm64/mte/check_tags_inclusion.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/arm64/mte/check_tags_inclusion.c b/tools/testing/selftests/arm64/mte/check_tags_inclusion.c index b906914997ce..d180ba3df990 100644 --- a/tools/testing/selftests/arm64/mte/check_tags_inclusion.c +++ b/tools/testing/selftests/arm64/mte/check_tags_inclusion.c @@ -49,7 +49,7 @@ static int verify_mte_pointer_validity(char *ptr, int mode) static int check_single_included_tags(int mem_type, int mode) { char *ptr; - int tag, run, result = KSFT_PASS; + int tag, run, ret, result = KSFT_PASS; ptr = (char *)mte_allocate_memory(BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, 0, false); if (check_allocated_memory(ptr, BUFFER_SIZE + MT_GRANULE_SIZE, @@ -57,7 +57,9 @@ static int check_single_included_tags(int mem_type, int mode) return KSFT_FAIL; for (tag = 0; (tag < MT_TAG_COUNT) && (result == KSFT_PASS); tag++) { - mte_switch_mode(mode, MT_INCLUDE_VALID_TAG(tag)); + ret = mte_switch_mode(mode, MT_INCLUDE_VALID_TAG(tag)); + if (ret != 0) + result = KSFT_FAIL; /* Try to catch a excluded tag by a number of tries. */ for (run = 0; (run < RUNS) && (result == KSFT_PASS); run++) { ptr = (char *)mte_insert_tags(ptr, BUFFER_SIZE); @@ -111,14 +113,16 @@ static int check_multiple_included_tags(int mem_type, int mode) static int check_all_included_tags(int mem_type, int mode) { char *ptr; - int run, result = KSFT_PASS; + int run, ret, result = KSFT_PASS; ptr = (char *)mte_allocate_memory(BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, 0, false); if (check_allocated_memory(ptr, BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, false) != KSFT_PASS) return KSFT_FAIL; - mte_switch_mode(mode, MT_INCLUDE_TAG_MASK); + ret = mte_switch_mode(mode, MT_INCLUDE_TAG_MASK); + if (ret != 0) + return KSFT_FAIL; /* Try to catch a excluded tag by a number of tries. */ for (run = 0; (run < RUNS) && (result == KSFT_PASS); run++) { ptr = (char *)mte_insert_tags(ptr, BUFFER_SIZE); @@ -135,13 +139,15 @@ static int check_all_included_tags(int mem_type, int mode) static int check_none_included_tags(int mem_type, int mode) { char *ptr; - int run; + int run, ret; ptr = (char *)mte_allocate_memory(BUFFER_SIZE, mem_type, 0, false); if (check_allocated_memory(ptr, BUFFER_SIZE, mem_type, false) != KSFT_PASS) return KSFT_FAIL; - mte_switch_mode(mode, MT_EXCLUDE_TAG_MASK); + ret = mte_switch_mode(mode, MT_EXCLUDE_TAG_MASK); + if (ret != 0) + return KSFT_FAIL; /* Try to catch a excluded tag by a number of tries. */ for (run = 0; run < RUNS; run++) { ptr = (char *)mte_insert_tags(ptr, BUFFER_SIZE); From patchwork Tue May 10 16:45:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12845255 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 F3E91C4332F for ; Tue, 10 May 2022 16:45:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242155AbiEJQtu (ORCPT ); Tue, 10 May 2022 12:49:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347645AbiEJQts (ORCPT ); Tue, 10 May 2022 12:49:48 -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 22946275FF for ; Tue, 10 May 2022 09:45:49 -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 DC330B81DF7 for ; Tue, 10 May 2022 16:45:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DBEBC385CC; Tue, 10 May 2022 16:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652201146; bh=JdUSFlmAMJMiTXobkuC/AlKO+jPpDo6M4+rYKVDk2Yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rPzTYr+WVV2y1oJqvW80ygBmKoAop6d3D2u/BkYnLL7PHUScWDMhVMJnQXsHu1dv5 TDBA9gJZvbdadKemkhDUYxy+FgwcUHQeAZE7tqxoR3VRaKzys9mao8NHuWwMhhev2D TCOvMMnDD2rC3YeUBAJPdvW+4DNR8jNXsQx578T7DqZkQh8t4uayoGfw4nuZUN0xyN xhhWu45mVGOHGQZP7NS1+CUvwEDI3Hlt0otl5xhbqvCJnbSoZ26psgRaJXBaVIWDJP DYb8WknGNhCc6STvWOar7+krJsyh9qohfsPSb8sr01oOw2EOlDDZpU63YDkYeBZUKO 2IV+JJnOsIeJg== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v1 4/5] selftests/arm64: Remove casts to/from void in check_tags_inclusion Date: Tue, 10 May 2022 17:45:19 +0100 Message-Id: <20220510164520.768783-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220510164520.768783-1-broonie@kernel.org> References: <20220510164520.768783-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5393; h=from:subject; bh=JdUSFlmAMJMiTXobkuC/AlKO+jPpDo6M4+rYKVDk2Yo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiepaeCzI2vR3Tz8922+7B6ZA0MGW9qigOMqDYzLf5 4AmiuZaJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYnqWngAKCRAk1otyXVSH0MmJB/ sHjyiHXljNYCoYvAftRh5NlOi+l8olqXD8uTq7m9TZTov3ZK9GyjXKBRIgVMjfjtkXeo77MxnmpSnK F/LDG5dqUdE3ZkOiUMCp0PYreuPJZVJ8jxNdnIeoL4CzBDYbclwmceoVKbDEl9ceg3SuisFbp++Ulk 5goWIEhCptytI282QOEbhWkUTXeCnsv7I5KsjHZ6xDehrASdpMQLMu25CMRvsn0oxQKhxXI08WbXTV qJF235n486Ax0ShYHb9in36+Ut2wjqHh9qiJGFRg/elf+7MxiHP0/K2YspLBsYARa6rzU5papwY067 qNUQXCJajEtDTBLPm1bseDyQ7ryz3x X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Void pointers may be freely used with other pointer types in C, any casts between void * and other pointer types serve no purpose other than to mask potential warnings. Drop such casts from check_tags_inclusion to help with future review of the code. Signed-off-by: Mark Brown Reviewed-by: Shuah Khan --- .../arm64/mte/check_tags_inclusion.c | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/arm64/mte/check_tags_inclusion.c b/tools/testing/selftests/arm64/mte/check_tags_inclusion.c index d180ba3df990..2b1425b92b69 100644 --- a/tools/testing/selftests/arm64/mte/check_tags_inclusion.c +++ b/tools/testing/selftests/arm64/mte/check_tags_inclusion.c @@ -23,7 +23,7 @@ static int verify_mte_pointer_validity(char *ptr, int mode) { mte_initialize_current_context(mode, (uintptr_t)ptr, BUFFER_SIZE); /* Check the validity of the tagged pointer */ - memset((void *)ptr, '1', BUFFER_SIZE); + memset(ptr, '1', BUFFER_SIZE); mte_wait_after_trig(); if (cur_mte_cxt.fault_valid) { ksft_print_msg("Unexpected fault recorded for %p-%p in mode %x\n", @@ -51,7 +51,7 @@ static int check_single_included_tags(int mem_type, int mode) char *ptr; int tag, run, ret, result = KSFT_PASS; - ptr = (char *)mte_allocate_memory(BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, 0, false); + ptr = mte_allocate_memory(BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, 0, false); if (check_allocated_memory(ptr, BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, false) != KSFT_PASS) return KSFT_FAIL; @@ -62,7 +62,7 @@ static int check_single_included_tags(int mem_type, int mode) result = KSFT_FAIL; /* Try to catch a excluded tag by a number of tries. */ for (run = 0; (run < RUNS) && (result == KSFT_PASS); run++) { - ptr = (char *)mte_insert_tags(ptr, BUFFER_SIZE); + ptr = mte_insert_tags(ptr, BUFFER_SIZE); /* Check tag value */ if (MT_FETCH_TAG((uintptr_t)ptr) == tag) { ksft_print_msg("FAIL: wrong tag = 0x%x with include mask=0x%x\n", @@ -74,7 +74,7 @@ static int check_single_included_tags(int mem_type, int mode) result = verify_mte_pointer_validity(ptr, mode); } } - mte_free_memory_tag_range((void *)ptr, BUFFER_SIZE, mem_type, 0, MT_GRANULE_SIZE); + mte_free_memory_tag_range(ptr, BUFFER_SIZE, mem_type, 0, MT_GRANULE_SIZE); return result; } @@ -84,7 +84,7 @@ static int check_multiple_included_tags(int mem_type, int mode) int tag, run, result = KSFT_PASS; unsigned long excl_mask = 0; - ptr = (char *)mte_allocate_memory(BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, 0, false); + ptr = mte_allocate_memory(BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, 0, false); if (check_allocated_memory(ptr, BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, false) != KSFT_PASS) return KSFT_FAIL; @@ -94,7 +94,7 @@ static int check_multiple_included_tags(int mem_type, int mode) mte_switch_mode(mode, MT_INCLUDE_VALID_TAGS(excl_mask)); /* Try to catch a excluded tag by a number of tries. */ for (run = 0; (run < RUNS) && (result == KSFT_PASS); run++) { - ptr = (char *)mte_insert_tags(ptr, BUFFER_SIZE); + ptr = mte_insert_tags(ptr, BUFFER_SIZE); /* Check tag value */ if (MT_FETCH_TAG((uintptr_t)ptr) < tag) { ksft_print_msg("FAIL: wrong tag = 0x%x with include mask=0x%x\n", @@ -106,7 +106,7 @@ static int check_multiple_included_tags(int mem_type, int mode) result = verify_mte_pointer_validity(ptr, mode); } } - mte_free_memory_tag_range((void *)ptr, BUFFER_SIZE, mem_type, 0, MT_GRANULE_SIZE); + mte_free_memory_tag_range(ptr, BUFFER_SIZE, mem_type, 0, MT_GRANULE_SIZE); return result; } @@ -115,7 +115,7 @@ static int check_all_included_tags(int mem_type, int mode) char *ptr; int run, ret, result = KSFT_PASS; - ptr = (char *)mte_allocate_memory(BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, 0, false); + ptr = mte_allocate_memory(BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, 0, false); if (check_allocated_memory(ptr, BUFFER_SIZE + MT_GRANULE_SIZE, mem_type, false) != KSFT_PASS) return KSFT_FAIL; @@ -132,7 +132,7 @@ static int check_all_included_tags(int mem_type, int mode) */ result = verify_mte_pointer_validity(ptr, mode); } - mte_free_memory_tag_range((void *)ptr, BUFFER_SIZE, mem_type, 0, MT_GRANULE_SIZE); + mte_free_memory_tag_range(ptr, BUFFER_SIZE, mem_type, 0, MT_GRANULE_SIZE); return result; } @@ -141,7 +141,7 @@ static int check_none_included_tags(int mem_type, int mode) char *ptr; int run, ret; - ptr = (char *)mte_allocate_memory(BUFFER_SIZE, mem_type, 0, false); + ptr = mte_allocate_memory(BUFFER_SIZE, mem_type, 0, false); if (check_allocated_memory(ptr, BUFFER_SIZE, mem_type, false) != KSFT_PASS) return KSFT_FAIL; @@ -159,12 +159,12 @@ static int check_none_included_tags(int mem_type, int mode) } mte_initialize_current_context(mode, (uintptr_t)ptr, BUFFER_SIZE); /* Check the write validity of the untagged pointer */ - memset((void *)ptr, '1', BUFFER_SIZE); + memset(ptr, '1', BUFFER_SIZE); mte_wait_after_trig(); if (cur_mte_cxt.fault_valid) break; } - mte_free_memory((void *)ptr, BUFFER_SIZE, mem_type, false); + mte_free_memory(ptr, BUFFER_SIZE, mem_type, false); if (cur_mte_cxt.fault_valid) return KSFT_FAIL; else From patchwork Tue May 10 16:45:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 12845256 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 51FBBC433EF for ; Tue, 10 May 2022 16:45:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236527AbiEJQtw (ORCPT ); Tue, 10 May 2022 12:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347637AbiEJQtu (ORCPT ); Tue, 10 May 2022 12:49:50 -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 EBD624831B for ; Tue, 10 May 2022 09:45:51 -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 19E1AB81E21 for ; Tue, 10 May 2022 16:45:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26DA0C385CD; Tue, 10 May 2022 16:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652201148; bh=R622QNQB1UYRuVab/g4J3gyNgxnjsl8J4yUUXh33U/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U7CYpwXS3jfS0d7gemUqeyuF8U3fNPphpvuReMYYWUO0I2sGrq9XbWMV5cQF6Dj1E PN7dU6Er9D4FCN32zqQaMNUEEv33rZ3kLtIHCdy3BMDjBeiOVsXCOx92vARvdreSye JYwRJVy6Tt4gCz8b0InsW7/K17nHsU4D07Xi+1Qi0kGEL0poSh6PbJxHNNxM8pay80 3Zo2BylLcmHmtw03FBwMf+wetaO1POs8sfNKzJRQJPmGSWyL6M8LX4FYtIbPRzsvYq vSSdBpjWq4ZDbq4NwM+ifXTF1txUNvfTwz2oIBrUHNTAw2PDV0nf7VwNdqyfjQPsZs WpCbw3MY7iUUw== From: Mark Brown To: Catalin Marinas , Will Deacon , Shuah Khan Cc: Joey Gouly , linux-kselftest@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v1 5/5] selftests/arm64: Use switch statements in mte_common_util.c Date: Tue, 10 May 2022 17:45:20 +0100 Message-Id: <20220510164520.768783-6-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220510164520.768783-1-broonie@kernel.org> References: <20220510164520.768783-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2002; h=from:subject; bh=R622QNQB1UYRuVab/g4J3gyNgxnjsl8J4yUUXh33U/4=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBiepaflTvsXvbJC2100hDgI34fuA/jH3a/HV8aCd5v odizu02JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYnqWnwAKCRAk1otyXVSH0OIOB/ 4yTHQ+colx7wXK5q6ceUvpKz1T4+RTtShuDdu01immHnc+jgu9pQBPM/QqzvyST4sKQ018VU1xNw3P 8SXJnvS9d7SNz7FQF2MCmE50IGXoQGXY7A4BPp+GjJYnSc1qCzcr9gYif0aUZ88U8G3Uh1MorumUN4 CWupBedZyfC/SpR45J1aCKJJLL2j1D6mrthSMKvjxF11qi7lLoPIaQms13mov2ISXdh1ICJGUAGhrT eZgjlJZ4H/5zjM4nUXaz8/aNjfmityeLBQQoRnG5BLV7UzydElFd/F01V7rHQmVReZMuQ6L1UAhvrC TffbYIzCKF3UjICmBT79IxpFPW3vJg X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org In the MTE tests there are several places where we use chains of if statements to open code what could be written as switch statements, move over to switch statements to make the idiom clearer. Signed-off-by: Mark Brown --- .../selftests/arm64/mte/mte_common_util.c | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/arm64/mte/mte_common_util.c b/tools/testing/selftests/arm64/mte/mte_common_util.c index 6ff4c4bcbff1..00ffd34c66d3 100644 --- a/tools/testing/selftests/arm64/mte/mte_common_util.c +++ b/tools/testing/selftests/arm64/mte/mte_common_util.c @@ -128,13 +128,16 @@ static void *__mte_allocate_memory_range(size_t size, int mem_type, int mapping, int prot_flag, map_flag; size_t entire_size = size + range_before + range_after; - if (mem_type != USE_MALLOC && mem_type != USE_MMAP && - mem_type != USE_MPROTECT) { + switch (mem_type) { + case USE_MALLOC: + return malloc(entire_size) + range_before; + case USE_MMAP: + case USE_MPROTECT: + break; + default: ksft_print_msg("FAIL: Invalid allocate request\n"); return NULL; } - if (mem_type == USE_MALLOC) - return malloc(entire_size) + range_before; prot_flag = PROT_READ | PROT_WRITE; if (mem_type == USE_MMAP) @@ -287,13 +290,19 @@ int mte_switch_mode(int mte_option, unsigned long incl_mask) ksft_print_msg("FAIL: Invalid incl_mask %lx\n", incl_mask); return -EINVAL; } + en = PR_TAGGED_ADDR_ENABLE; - if (mte_option == MTE_SYNC_ERR) + switch (mte_option) { + case MTE_SYNC_ERR: en |= PR_MTE_TCF_SYNC; - else if (mte_option == MTE_ASYNC_ERR) + break; + case MTE_ASYNC_ERR: en |= PR_MTE_TCF_ASYNC; - else if (mte_option == MTE_NONE_ERR) + break; + case MTE_NONE_ERR: en |= PR_MTE_TCF_NONE; + break; + } en |= (incl_mask << PR_MTE_TAG_SHIFT); /* Enable address tagging ABI, mte error reporting mode and tag inclusion mask. */