From patchwork Thu Feb 3 14:36:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 12734238 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4FD48C433EF for ; Thu, 3 Feb 2022 14:39:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BsMwqCMYm399Xyuvu6HfJOok1tlP0mBhtPlbkDhQi3Q=; b=IG169cni8di28B GyJSc4crDG+JwjMdSlgFvQfT8B6M/K9so1D7zG5LTWYQvaDuxvmmkfso1abSjkwNHAf2MfSqD7mM7 NSI8JLEllUGM7fDrJDV8dw+MCXoxc4W8D4u9qQ6SUQUDTp2I0/j9ir6mae9BzHlJycH7HIujCDhnu WR5CGypVkZtrsVB6KRsVSbemmm0DarWQ2JicQHHwR1Vlv1ek0DfS1AZf194Lrha0/4JItE0ZtDvx3 0mTkTwEQeVZ79dW69AyIqUeyz1/UiPcnoCwUk5YrQxGEM3A+GRvTs+9CyswwaWBguqD4cELgG71m8 K1ZpfP9QnnnYcEvUqHfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFdEv-001eAB-Bh; Thu, 03 Feb 2022 14:37:38 +0000 Received: from mail-eopbgr50050.outbound.protection.outlook.com ([40.107.5.50] helo=EUR03-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFdED-001dxF-47 for linux-arm-kernel@lists.infradead.org; Thu, 03 Feb 2022 14:36:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7/UNaQFR7Da7ds1vHyvVOHbNerkFvOHS8Myo1vQOinU=; b=uhEa6ImL+724dv3awfFARwM99EUw3dbVmVONrjdLQ4tzCWNXgn4iFJDSkiw6WxGQs586w29G3DbIYAVyXQ9wxo3t41rmgcSEheEEG4p5dyNvG2erg+PfD7tEb3d/jBj/p0lSLUuWSh4vRq4tXO3iA6eoHgh7aVi5HHy6SyxIRfU= Received: from DB6P193CA0019.EURP193.PROD.OUTLOOK.COM (2603:10a6:6:29::29) by AM9PR08MB7031.eurprd08.prod.outlook.com (2603:10a6:20b:41d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Thu, 3 Feb 2022 14:36:44 +0000 Received: from DB5EUR03FT016.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:29:cafe::57) by DB6P193CA0019.outlook.office365.com (2603:10a6:6:29::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 14:36:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT016.mail.protection.outlook.com (10.152.20.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 14:36:44 +0000 Received: ("Tessian outbound 31aeb3346a45:v113"); Thu, 03 Feb 2022 14:36:44 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 929cfffc6c733a40 X-CR-MTA-TID: 64aa7808 Received: from 5a5037bb5044.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 8DF51FB9-A075-4265-9BF8-4A9D8AEE5E53.1; Thu, 03 Feb 2022 14:36:33 +0000 Received: from EUR01-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5a5037bb5044.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 03 Feb 2022 14:36:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yhz3Dl8ENy5ME1iX/oBtQ/WpQkwPndVp7X9a4zt9MFkjwu1m+ZN5vZv0TySRgP3b64jjma/NOmkbNi3Di+5PJzTMCwfn4reJo3Zrl7InrZhFz1aS2iMd9jDT2LXZGA9d7yQHXxG4xstY61m0z+NIqik9QkOUtUdzt5q06YsoUKxl2RpA7PtQmDrrwDtw9BILsmy/bJnqPP5Pol0gPFTWLR9XtodraeOd0pehBWZja8+K2ItdQSAe5+EQnLF539ZIyiqensQOj71ITkHUU4T+VY69elKaxNsujK/QEz+jM/4xZfN/c+1SqRPrYn6WaZxPttxgo43ep3kXUMvXJBsgAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7/UNaQFR7Da7ds1vHyvVOHbNerkFvOHS8Myo1vQOinU=; b=k6R2l/kRTzjfoe8+lhJ9i8hp+6IsxaAHscKlA0ZjWMJIifxu+Za8ChCNQF+GzaMmSIDEKofwP7hE74wje5N2yu27vNK010NR7FyUG4fU3aHNGKlHllubSARwjwQQb6gGGm4Ra3aHreXG7DYSs5rcbCc92uS39TMBSVa1NjVtttlg+2oqYLvI2Z56JEdPdn0rswhrSv92dRhrOer0+1prx32yIGtNcnKWjWNz7WwTzMJKLMcnn64Io/JGBzCuc7wOdGAUt5a25SfdXjeIjKHtn0SdQZw4jk8NZgn5ORiSAHqqZIkwA6KjlnT/3FBHiPIgxoudyKFK6squ0PbLjAK7nA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.infradead.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7/UNaQFR7Da7ds1vHyvVOHbNerkFvOHS8Myo1vQOinU=; b=uhEa6ImL+724dv3awfFARwM99EUw3dbVmVONrjdLQ4tzCWNXgn4iFJDSkiw6WxGQs586w29G3DbIYAVyXQ9wxo3t41rmgcSEheEEG4p5dyNvG2erg+PfD7tEb3d/jBj/p0lSLUuWSh4vRq4tXO3iA6eoHgh7aVi5HHy6SyxIRfU= Received: from AM6PR08CA0013.eurprd08.prod.outlook.com (2603:10a6:20b:b2::25) by GV1PR08MB7347.eurprd08.prod.outlook.com (2603:10a6:150:22::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Thu, 3 Feb 2022 14:36:31 +0000 Received: from AM5EUR03FT040.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:b2:cafe::f0) by AM6PR08CA0013.outlook.office365.com (2603:10a6:20b:b2::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 14:36:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT040.mail.protection.outlook.com (10.152.17.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 14:36:31 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 3 Feb 2022 14:36:32 +0000 Received: from e124191.cambridge.arm.com (10.1.197.45) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2308.20 via Frontend Transport; Thu, 3 Feb 2022 14:36:32 +0000 From: Joey Gouly To: CC: , , , , , Subject: [PATCH v2 3/6] kselftest/arm64: mte: user_mem: check different offsets and sizes Date: Thu, 3 Feb 2022 14:36:17 +0000 Message-ID: <20220203143620.30629-4-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220203143620.30629-1-joey.gouly@arm.com> References: <20220203143620.30629-1-joey.gouly@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 5971f84e-a5ca-4081-e432-08d9e72299f3 X-MS-TrafficTypeDiagnostic: GV1PR08MB7347:EE_|DB5EUR03FT016:EE_|AM9PR08MB7031:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:6790;OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 0ZK6YDIw73OnJhrwQczBv8aCGxFwmHQe0W+nt4xWZ9Ss9OFwZbPGB5hzM61esQdULW3OY6/NdN/2r79OIH6vaTQSU+x1SbJuigRwfwZx2fTzAEoJpoSQPM+7TrSizXRAs1K6M57TST9U5HNUWMCV6TNOKBor0DZLX1Z1NDc5WZmx9bQdeU/OKNjBwr4xzgOZJsppaFv++28W+QbjsKkwqZo2bBixvVuysrZdfigaSrXIhoQU+S2CvvH1uP891SA1O/QKbWxlDyyJ1QmSB1/wPd7ypsZY8Hh0iV1BddzZrX7y3Ooo7CJm2s1qcrMRNJ+UFN2v6Nxa4RXInmAefhp4YFQNEH2kwL3MiZuHOMTxwmbE/UkEr1aXdrNl+6M3SHxWrbjgMpV4eF9kzfcLquFV5O3UltLfBewaulrCcel93RNtdvmSwyUmE424VDueIMEwTDTN/Et/Dl5R9oyRFqQcB9DWELK8i4Bi461/aWaQIbhP0+APA1PGRRfw1Xsxt6LR3TdHk31MorM4/GIxpgiMKyk/jJ2GBFuPs/b/u9zRGha/NekPgmqAWpa83qLW/ekgsy/+ZSUseSChU+VKCxmX2iw2HtRQRO9nxVbq/jK23F9sUx18e3DNxMs14TJa5CjmtE+95cJSmA1/yWdHgWaAGgbgbEXa/0uSoPmpm1KvTDuUKCT3Fw/oARDc3/Sg3WouFwZs040N+e9EXnLVsjPVKw== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(86362001)(6916009)(5660300002)(2906002)(8676002)(44832011)(316002)(54906003)(70586007)(4326008)(70206006)(8936002)(508600001)(6666004)(426003)(81166007)(2616005)(7696005)(1076003)(336012)(82310400004)(356005)(36860700001)(186003)(26005)(47076005)(36756003)(40460700003)(83380400001)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB7347 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT016.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 730c3e0d-8069-4827-b998-08d9e722922c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TwWUBaVuDKWwFnhST4yLN4vF5AjaezDZb3CytAMZjjrAiOaMfb7z/6lkgKjmVShfgsdYtKHz/6k6gXGhcjuxYludFuHn2KvEE/QkibXAvRvGJ+qKnYW57CkjcYCg1U/0rIqDrqak1JN7RIjViXZOJI+3h59nNFkD8CCOEL/cgYRjmFHyNAj/+JLm0tKnlYPcqMeiYBE4e4uxF4vC59jTLQ5WakdN9Dgj5Rr/55A+XD5Y1XH7w5xGWobySq1BYTZ8VciZOnRPAbnyH7vlIt6I7EInGBRMerb8qqayV5nU/V4djCrVZeTI8pNsYxPVHBNqOujJ1v+a9rGTPU6b6kTwWWQtSUUO0AMzLJD8sS/cQnq0ZMWBuWZzIQuO3z6KRUUCUMnKc1R+Ahjhk2TWWCtsJrb7rqO3FKMNiRAT6Uhn8eGleT8pWBq7OlEO4c1N9hCLODDATfX3XzdqMsrr+IOTldloNezieWx9NFamT9TjA5PP7VIXRrk+pbKPPXn6lgIPML4O1FRvGZaPXaCu0GXxAzhGOMtQmQNXGe5iT6LZoGUNwGQ09CIWQxqSJv+/rS+O3tZ8iBUsQVNrcifwgedWV3ilyOi51u/444btVV4kkM5V/tnKt8a4fAqBvefmyuR2WrXcVWhYt2PAGVVAhB4fqGzeO13bORPvnUUzH+qu5koecI8tXJ6cIqA5IffJU4zz X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(70206006)(6666004)(83380400001)(8936002)(2616005)(2906002)(70586007)(40460700003)(44832011)(4326008)(8676002)(82310400004)(107886003)(7696005)(26005)(336012)(186003)(36860700001)(1076003)(316002)(508600001)(6916009)(54906003)(5660300002)(47076005)(426003)(36756003)(86362001)(81166007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 14:36:44.7367 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5971f84e-a5ca-4081-e432-08d9e72299f3 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT016.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB7031 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220203_063653_223710_3FC9ABE2 X-CRM114-Status: GOOD ( 15.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Iterate over different file offsets, pointer offsets and buffer sizes to exercise and test different behaviour. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Brown Cc: Shuah Khan Reviewed-by: Shuah Khan --- .../selftests/arm64/mte/check_user_mem.c | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c index e5bfeaeb64bb..35061ae23ed5 100644 --- a/tools/testing/selftests/arm64/mte/check_user_mem.c +++ b/tools/testing/selftests/arm64/mte/check_user_mem.c @@ -26,6 +26,8 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping, char val = 'A'; size_t len, read_len; void *ptr, *ptr_next; + int fileoff, ptroff, size; + int sizes[] = {1, 2, 3, 8, 16, 32, 4096, page_sz}; err = KSFT_PASS; len = 2 * page_sz; @@ -66,26 +68,33 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping, ptr_next = mte_insert_new_tag(ptr_next); mte_set_tag_address_range(ptr_next, tag_len); - lseek(fd, 0, 0); - /* Copy from file into buffer with invalid tag */ - read_len = read(fd, ptr, len); - mte_wait_after_trig(); - /* - * Accessing user memory in kernel with invalid tag should fail in sync - * mode without fault but may not fail in async mode as per the - * implemented MTE userspace support in Arm64 kernel. - */ - if (cur_mte_cxt.fault_valid) { - err = KSFT_FAIL; - goto usermem_acc_err; - } - if (mode == MTE_SYNC_ERR && read_len < len) { - /* test passed */ - } else if (mode == MTE_ASYNC_ERR && read_len == len) { - /* test passed */ - } else { - err = KSFT_FAIL; - goto usermem_acc_err; + for (fileoff = 0; fileoff < 16; fileoff++) { + for (ptroff = 0; ptroff < 16; ptroff++) { + for (i = 0; i < ARRAY_SIZE(sizes); i++) { + size = sizes[i]; + lseek(fd, 0, 0); + /* Copy from file into buffer with invalid tag */ + read_len = read(fd, ptr + ptroff, size); + mte_wait_after_trig(); + /* + * Accessing user memory in kernel with invalid tag should fail in sync + * mode without fault but may not fail in async mode as per the + * implemented MTE userspace support in Arm64 kernel. + */ + if (cur_mte_cxt.fault_valid) { + err = KSFT_FAIL; + goto usermem_acc_err; + } + if (mode == MTE_SYNC_ERR && read_len < len) { + /* test passed */ + } else if (mode == MTE_ASYNC_ERR && read_len == size) { + /* test passed */ + } else { + err = KSFT_FAIL; + goto usermem_acc_err; + } + } + } } usermem_acc_err: mte_free_memory((void *)ptr, len, mem_type, true);