From patchwork Wed Feb 9 15:22:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joey Gouly X-Patchwork-Id: 12740383 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 45150C433EF for ; Wed, 9 Feb 2022 15:26:19 +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=gQaRb+jUhROGOrEEj6n+S6zVULVcEemMJOpZSHPhxJg=; b=q6pzXzBplJzP1e Uj/DnptbHiCGpA3ICxghGbafAO4KWyLkBxGcGWBgUluzCKPFiDMVuvbRTc1iQJRQZsGbx06XjNoU3 XkxIojGrpF7HgU0W28iGZoWBZOtgQNUzNBaR4MtAG0+tm5lA/yGqLiTzQNipUmnr2qLPHDo+hHYSQ skXj0ctjeeJNDaHqUaYr/o/o5k2q0oKkYF/e3Um4ApBKHmuwcNadLbnMOUQ8seJCBWK3iazYH+OH7 N/oMXHLxpDiuNwKA7TFS77ZTqhdC3moXyZ4mgiwHuUlX3iDMnRKE6PV0Avmeu3A2+CMai1GetncNg HhF+s6UUNEWJKIE3sDqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHopS-000YY2-KR; Wed, 09 Feb 2022 15:24:22 +0000 Received: from mail-vi1eur04on0614.outbound.protection.outlook.com ([2a01:111:f400:fe0e::614] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHooI-000YBY-08 for linux-arm-kernel@lists.infradead.org; Wed, 09 Feb 2022 15:23:14 +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=ZanT3lyN1gc3fQ/1uYZewHTiTDHs37oT+i2jKj450Ro=; b=DTgseelI/togpL+Po2OVRYC+eN/M9Biv7q9WeAQV+2ctVn9cyrpf2mL/wfutsVWIVX+zf+7w6nnd4LyGfORfkiGRCfrjK26sqfjadqMvNBWb0vVCwe53MzzGt5Rhuq9/kzkic9WCeFMXGlaGITaZmYicErpC/eBfuq1Lzfykhbs= Received: from AS8PR05CA0007.eurprd05.prod.outlook.com (2603:10a6:20b:311::12) by PAXPR08MB7041.eurprd08.prod.outlook.com (2603:10a6:102:1d8::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 9 Feb 2022 15:23:05 +0000 Received: from AM5EUR03FT033.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:311:cafe::3e) by AS8PR05CA0007.outlook.office365.com (2603:10a6:20b:311::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19 via Frontend Transport; Wed, 9 Feb 2022 15:23:05 +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 AM5EUR03FT033.mail.protection.outlook.com (10.152.16.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12 via Frontend Transport; Wed, 9 Feb 2022 15:23:05 +0000 Received: ("Tessian outbound 741ca6c82739:v113"); Wed, 09 Feb 2022 15:23:05 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3c0223871a9261da X-CR-MTA-TID: 64aa7808 Received: from ece15a54c64a.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 52E19A3B-1094-46AB-9DE6-B5E2A04C8133.1; Wed, 09 Feb 2022 15:22:55 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ece15a54c64a.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 09 Feb 2022 15:22:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kgwu0xORQQ9ZikGSX/fhxzQfsAJhJP4IJBCEIbpjGDYYysHhxupU+JUiHLzg56QVNi2K3mTgbVn8WEEZIBiSdUAEVoXtgPKlJ/tUfcAewOYp02QT4klrzkox2DA3xFV4yr1ZyJ1o0MqLxC9kkE5BWmZ0C0R/nCSsvDjugK5wgNMzqjTwUJBU7pliD2/sefuuHpvMg6SwRfH0nJfa56SpYGBT4pcttwlpdpp1qR/4u/lyE2fM3cmArpfbgz8+StuWrqQJajUTMRl8XkbgC03QSvj8p3/2qppeMRpg7S/fDntBfmqTNSZ+vsE1GNh2uCbbMREwx9rIjsBwSHmGxZ7oYg== 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=ZanT3lyN1gc3fQ/1uYZewHTiTDHs37oT+i2jKj450Ro=; b=N0pdEJwiUMAeg/JH6uP1hFHVKxT/irkIoOf+YAw+JXHgv8EdV2zddhXcCoglaR3unMB39A7jROzPO/dC563pSrSCku0EtMndXfeu7pDKXh6OCuw5C0AbENayO09GVpnfSeXHUzljaye9sVdifDtzJlnIwTkoWHtBeF7JW6sGFmQPBl/IGT2kS+YO/FIUkoBFi4t7hrx/m1XGe7BHPGDcuuOtkfly6K+U9iDZDsDi6fiSZejw9yfwlSogSxKeAl5G5sRnBq7Owkq79PrROxL3N5NH32jch7ClAM4oODiW2ZhEoTAluLW8C0gqdnrsTLMxlKRu0niXGwHkB4Gn/RowMg== 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=ZanT3lyN1gc3fQ/1uYZewHTiTDHs37oT+i2jKj450Ro=; b=DTgseelI/togpL+Po2OVRYC+eN/M9Biv7q9WeAQV+2ctVn9cyrpf2mL/wfutsVWIVX+zf+7w6nnd4LyGfORfkiGRCfrjK26sqfjadqMvNBWb0vVCwe53MzzGt5Rhuq9/kzkic9WCeFMXGlaGITaZmYicErpC/eBfuq1Lzfykhbs= Received: from AM6PR02CA0023.eurprd02.prod.outlook.com (2603:10a6:20b:6e::36) by GV1PR08MB7329.eurprd08.prod.outlook.com (2603:10a6:150:1c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 9 Feb 2022 15:22:53 +0000 Received: from AM5EUR03FT015.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:6e:cafe::29) by AM6PR02CA0023.outlook.office365.com (2603:10a6:20b:6e::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.19 via Frontend Transport; Wed, 9 Feb 2022 15:22:53 +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 AM5EUR03FT015.mail.protection.outlook.com (10.152.16.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4951.12 via Frontend Transport; Wed, 9 Feb 2022 15:22:52 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 9 Feb 2022 15:22:49 +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; Wed, 9 Feb 2022 15:22:49 +0000 From: Joey Gouly To: CC: , , , , , , , Subject: [PATCH v3 1/6] kselftest/arm64: mte: user_mem: introduce tag_offset and tag_len Date: Wed, 9 Feb 2022 15:22:35 +0000 Message-ID: <20220209152240.52788-2-joey.gouly@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220209152240.52788-1-joey.gouly@arm.com> References: <20220209152240.52788-1-joey.gouly@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: f38f9a5c-995d-4a04-8a09-08d9ebe011ea X-MS-TrafficTypeDiagnostic: GV1PR08MB7329:EE_|AM5EUR03FT033:EE_|PAXPR08MB7041:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 0nt3vRsz0pCNNLFi2D9egZVgy2iFyCAJpHWBrbIk8HQ5pDJzrnb9dHjefNJ11M7yJw2obddMF+Af1aO8UXJZIVTPq9b4j1qL3yxpYQpl2i2OzGzlWDqLR0enmvh0T+m8ByCQoobIx5/zRrDRwL8nvXOkt4s/IXXEYEuDFOaULBnRkHaNw36z2zU2foCclimp4bO0pg43CB9/jKuDOqaHOEPxJkSIU1CSyFB9+ctTc1m+p3aXHBnwSyi8AN979NfObT84nTwg+z1lqbtlD7vBFpiV2Fm4D5kI+cTD2xv+iIZucMllKrE1hOyjX1kcPln/hYwCWt8B6cZP8JH0BA8wvY2zebIGAOpNi/WCPaPt8JYTfgKcHm0Qai5p9KZ5C7tKCNYiIOxDjOvoLof8IpC4gSCmeDyVsSV49/MBduvF+zJoalaLjUmPhvT1Bx5wO03/o4t4uPg1Yx7Pe8ENmuoOfjG+UpI71kXPuQCQMfgrJlxxOOM97axcsS14EAJWzwDsShkSthhzI5yhTGvLUZsurUaxQSPY46Qh5WMaq08fcilQUDgf3Fi8627h66Ydtkj7MooxiZrbqTcAH2/ukxPIevWKPcwMAtTsScSwGhatRXm5Jk/iTGQ28VPpCN5Iz/HWt3NofSPX2vcm1FLFJ6jhtx5rkwepyZwn2rbr0GK+VSbbbXTevGAeeez0MpZ0tOA/W+lCt769e4hHGMWLecEVlw== 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)(46966006)(40470700004)(36840700001)(6666004)(86362001)(6916009)(2616005)(70586007)(7696005)(82310400004)(40460700003)(508600001)(36860700001)(5660300002)(54906003)(8676002)(47076005)(70206006)(8936002)(316002)(1076003)(44832011)(83380400001)(36756003)(26005)(426003)(356005)(4326008)(81166007)(336012)(186003)(2906002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB7329 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 64f74e5b-62cc-4639-a0af-08d9ebe00a6b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wn8IN9xpBPUXO6eU8VEqJGefuhcZv4us/xWXQj+s89oQcYPrGHzeTgDaQBQ9UwNjeIuIQQrsganWEtaWGM9L3oaGLttCNO7UG0IDBt2IUSVoMfdAkeyP2VxPV9sOejYtWt2XtbHmKV4q/qaN1yXdKCShEJKVkZ2s50AkOI4MdApkB24g7DsCEJIpZWVtOe6DZD2ArbUxM8mxsnPAp4bdhW976hIG25yverj2nRERfWxBNQDiqVizCRGCVrgvyFFv5KkljBr0uudUnxnEpZuC4KexB9p3griQrBXSApg1zlI1ndnz6IZJx7ZVdiKigmsZ2GB5zd6jGPXGFloM00pcgcCyedbSTiRGhgpFqe6tCRhkeofELI9kOWq4joXQGEY8x5cKkX9hLspVzwyefyQh3+LbkcdLOEA7RDaMZVAZ+fulc5eZk4z7cD9Z+fmYXJVicrjHFQgcldOBlLZY6rZFkEm4XGEXUkWeZBDLJsSqrFWr0NGsV43OuxGQfbjwt0x6rUUo+0CXFqHmegedv9WhieffEv8lDl4erKFBecItSckhYJsin0xp/2W6WvHQHlIZLCllIZDpcxvoQESMO4oZbf6BgEwwEbFZ4Fn9kYNtzo/HhKPxylmbW6Gm+v1EVUqhRJNMOe+cd8zckCljR9JzYwmpuqkZ/wbDw2R0ekGf3wYWn7YMtMTwzDcgKRjo9Qdm 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)(40470700004)(46966006)(86362001)(7696005)(40460700003)(508600001)(8936002)(54906003)(70206006)(70586007)(5660300002)(2906002)(36860700001)(186003)(81166007)(6916009)(316002)(4326008)(47076005)(36756003)(1076003)(426003)(2616005)(6666004)(8676002)(107886003)(83380400001)(82310400004)(26005)(336012)(44832011); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 15:23:05.4952 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f38f9a5c-995d-4a04-8a09-08d9ebe011ea 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: AM5EUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB7041 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220209_072310_098716_7C474119 X-CRM114-Status: GOOD ( 12.80 ) 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 These can be used to place an MTE tag at an address that is not at a page size boundary. The kernel prior to 295cf156231c ("arm64: Avoid premature usercopy failure"), would infinite loop if an MTE tag was placed not at a PAGE_SIZE boundary. This is because the kernel checked if the pages were readable by checking the first byte of each page, but would then fault in the middle of the page due to the MTE tag. Signed-off-by: Joey Gouly Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Brown Cc: Shuah Khan Reviewed-by: Mark Brown Tested-by: Mark Brown Reviewed-by: Shuah Khan Reviewed-by: Catalin Marinas --- .../selftests/arm64/mte/check_user_mem.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c index 1de7a0abd0ae..5a5a7e1f5789 100644 --- a/tools/testing/selftests/arm64/mte/check_user_mem.c +++ b/tools/testing/selftests/arm64/mte/check_user_mem.c @@ -19,7 +19,8 @@ static size_t page_sz; -static int check_usermem_access_fault(int mem_type, int mode, int mapping) +static int check_usermem_access_fault(int mem_type, int mode, int mapping, + int tag_offset, int tag_len) { int fd, i, err; char val = 'A'; @@ -54,10 +55,12 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping) if (i < len) goto usermem_acc_err; - /* Tag the next half of memory with different value */ - ptr_next = (void *)((unsigned long)ptr + page_sz); + if (!tag_len) + tag_len = len - tag_offset; + /* Tag a part of memory with different value */ + ptr_next = (void *)((unsigned long)ptr + tag_offset); ptr_next = mte_insert_new_tag(ptr_next); - mte_set_tag_address_range(ptr_next, page_sz); + mte_set_tag_address_range(ptr_next, tag_len); lseek(fd, 0, 0); /* Copy from file into buffer with invalid tag */ @@ -100,14 +103,14 @@ int main(int argc, char *argv[]) /* Set test plan */ ksft_set_plan(4); - evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE), + evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, page_sz, 0), "Check memory access from kernel in sync mode, private mapping and mmap memory\n"); - evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_SHARED), + evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_SHARED, page_sz, 0), "Check memory access from kernel in sync mode, shared mapping and mmap memory\n"); - evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_PRIVATE), + evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_PRIVATE, page_sz, 0), "Check memory access from kernel in async mode, private mapping and mmap memory\n"); - evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_SHARED), + evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_SHARED, page_sz, 0), "Check memory access from kernel in async mode, shared mapping and mmap memory\n"); mte_restore_setup();