From patchwork Tue May 25 02:45:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12277739 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 938CCC2B9F8 for ; Tue, 25 May 2021 03:50:16 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 5723C61417 for ; Tue, 25 May 2021 03:50:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5723C61417 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synaptics.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=W2unTo389ANNrzeIobZl+amRtdTKTgXt6dF1Tt80/E4=; b=NvuyiLAm87vXKv o+Dcgwfqb2/8DTYfew2wIDXRWvHU54LhAdYcIiAs2eQdpDSZogSjWvQBYYPfcE3TK9Zwo36VySdnY 2d8eEnzTiglHlJ73Fe9sDSfDlhYyQea5RbM/d6c3eEeQAbrADM2ERjdpDyutw8SfpAAXSE7rwka0t +nNh+kvM7aw16HHz0GFFkoG0N1DS0MzNy8N0573aN3zCiKXQ8VIaJ+4+zf+aCxCvc2RaclzoYG6dP /jYMCkO6M44SqQLUj4orqykPPWgDO9WX4VgLu5BIuDoHZfBEq2qA05rB4qap702z4ntc0uZmDhXSb z9x66h5qaFj16z9CscZg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1llO2c-003Chx-BC; Tue, 25 May 2021 03:47:39 +0000 Received: from mail-bn1nam07on2041.outbound.protection.outlook.com ([40.107.212.41] helo=NAM02-BN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1llN52-002yyf-AB for linux-arm-kernel@lists.infradead.org; Tue, 25 May 2021 02:46:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LcCIyzOsAKU/p8GSjKLBZbMuqWtpTXpbDykBWWuM+XX0ducMA4zNqYF1HpvLdRgEoRbvKp01Y1/x/SqM60Ws8HjcdWJQ6gZMjC9TpCy7Aqxi3Ujg77yJSoyyqck+qtx3dvdl6nuneHuRv5//0lfmmZ3yCr+PQxYHiACGy2RaKFVLvq0e+gvcZo+xHk2MkAYB1ZvAAof+s2Wc96ayXnVmKYxBssg8DiuuGjzhr/cTakSAA90s11N0rblOrpKd0wDqPgdEWk1U1T4rdZ1DHhMboL+zHmaFHuKNqUeaL0wPKjz97fx/g+yAuss3SIvCeOGRoznvDkMS6o1RN0WoCPPxfA== 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-SenderADCheck; bh=4O0cmhqdU1T2dED8gA2hFPZMnoQw1+GtaPBIWVaMvU4=; b=GqnFGZfdcTaJd/fhTiGRvLsWKdvshoPhyzoUZpugKRJV4fS37Zrh8bBv8WcUHpV3QdxqIX30jCsCRweUcP/Wa3C/jICNA28DfYfIXDdFY3FdJ8iHabcyzIWLfJibwikXBaaToKn5yo6WdWfs/9Sr5y1wDNTDR/TfK4p9I/svmp/6AsWyelh9odZayckZilrXIWOarub04DoVFmtIPBgGBvyoaM8vbu5gQlrRnjIAYAmuxqbeKATtepcJ8ySv1i6d3jxzZpjrpP0k3ZV44BG4iB+R7TY3O4epDJx32UzAQTS0avehK4/SeFVX8O+V3ylFrAYJNOzJrga2lWLDKU6H8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=synaptics.com; dmarc=pass action=none header.from=synaptics.com; dkim=pass header.d=synaptics.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector2-Synaptics-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4O0cmhqdU1T2dED8gA2hFPZMnoQw1+GtaPBIWVaMvU4=; b=E0A0LzpOoI9mNIv4CKNW7ml2Y7Tfu2YQEB9Cc8mCzQ2KOzOe4+px9rY6FAGLickRcyf+HxdabyfCHt9+126N3xhpZdbqrLghHQ7AYgEeuG/vWiNeimC3oZ0orQc6kUDgyJha0FPZF8519iwKypbMqMCYJ09+8Z8W1DKbmarMHE0= Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=synaptics.com; Received: from BN9PR03MB6058.namprd03.prod.outlook.com (2603:10b6:408:137::15) by BN8PR03MB5041.namprd03.prod.outlook.com (2603:10b6:408:d5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Tue, 25 May 2021 02:46:01 +0000 Received: from BN9PR03MB6058.namprd03.prod.outlook.com ([fe80::308b:9168:78:9791]) by BN9PR03MB6058.namprd03.prod.outlook.com ([fe80::308b:9168:78:9791%4]) with mapi id 15.20.4150.027; Tue, 25 May 2021 02:46:01 +0000 Date: Tue, 25 May 2021 10:45:51 +0800 From: Jisheng Zhang To: Catalin Marinas , Will Deacon , Mark Rutland , Marco Elver Cc: Alexander Potapenko , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2] arm64: mm: don't use CON and BLK mapping if KFENCE is enabled Message-ID: <20210525104551.2ec37f77@xhacker.debian> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) X-Originating-IP: [192.147.44.204] X-ClientProxiedBy: SJ0PR05CA0097.namprd05.prod.outlook.com (2603:10b6:a03:334::12) To BN9PR03MB6058.namprd03.prod.outlook.com (2603:10b6:408:137::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xhacker.debian (192.147.44.204) by SJ0PR05CA0097.namprd05.prod.outlook.com (2603:10b6:a03:334::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.14 via Frontend Transport; Tue, 25 May 2021 02:45:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d5057732-9aa3-4e56-527e-08d91f273b8e X-MS-TrafficTypeDiagnostic: BN8PR03MB5041: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FwOVY6Gc/ieYGEyRSXMRnm/6qN84jLMIcNiSBl+rWUWyApc121ON6EVxNEyIB5kjD002FoCe4SzOiFg8VZW0E7yl4yEFtauVMDURHWlkUcN/1h2GlVaS0dgCxffC0TJEdtg1oNNMmxHxqWOzd2+VSu31pR9NT5RUyQ/F2ZtfHVofDAEDjJpgouPOGxFRBItn6jVKpr6tW5oi7jqHkaT2xzJ+KgfKosLzbh39qs4uhDD9QnWSNk3aAXf+qeMk0kt5P9S0m0h+W1AjZ2P6prgAi2vV9FUX6EIFb+kf1zRYRS8HP1vl7d9mBP1pfCRY8d3ZceKYoHxBbZ1bnizmcoQG7FKPtFQGa6378/DEVW/b3/pB4enG22d31NeJDwDzNl+qypqV3S01Ks/Ev5obFUZ8UpLk1YzSCdYljPy+B0gF8nvPffinhal6AYsNDKpFf5cjbnlmTfSPkgHVrXoI2qiU34aTq9v2zvqBGVqrRTfdf9CDzEKPBFCvmXMSupGAV8AZ2ipiv+xA3r4BLW/H1fNJeK348w4+1qJZqsFZatXtddEb92kdPMNJjbE3Ft34ammfy02vrvkIFuXsWcPUffagrI5qs0GGJTqBPwtZBQ/eZZIVhLc0tVOJIrHiGiamtaZ8KS3udNnkDh+TtL9SkbxB5Kp3BQxUgiOkMAOT/msXjg0= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN9PR03MB6058.namprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(346002)(376002)(136003)(39850400004)(366004)(186003)(956004)(86362001)(66476007)(38100700002)(52116002)(38350700002)(8676002)(8936002)(6506007)(7696005)(16526019)(66556008)(4326008)(1076003)(478600001)(9686003)(5660300002)(110136005)(6666004)(66946007)(83380400001)(2906002)(316002)(26005)(55016002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 5w0zH2ROGyavK3Hx2AuHEmODvGJlzcJT3YHSWZrHmCMe//YWJkdhWe6f2KNhQfLAAOpBbjduLpCoY+Bc0+XhTuR0O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tIDzMJbV6gsfa7eSXwwEs6aVhyFs9DRm+eh0i8Wbs7ty9NioxWEaoRd4bj1sEkWzYEHHVELOiQhp2LNoGh/gcDs3CfK6vneYWRgu6SmzXg4EJt+Ux4fq5WnnUEOBNgMDQgWoIvNPoyDvrKQj6BNOtn2PTG+CT8ig636nY5K3l9FoAE2 X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-Network-Message-Id: d5057732-9aa3-4e56-527e-08d91f273b8e X-MS-Exchange-CrossTenant-AuthSource: BN9PR03MB6058.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2021 02:46:01.4438 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UsDr6m1q64M2lSWTXvPd9D4IeYMWw7BUwoXNBW7O7cV5ZP207LgWNenBRqdRsXhAnT2bbycXRx3hDnwBuRnDjA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR03MB5041 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210524_194604_469868_5BCE9317 X-CRM114-Status: GOOD ( 12.49 ) 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 When we added KFENCE support for arm64, we intended that it would force the entire linear map to be mapped at page granularity, but we only enforced this in arch_add_memory() and not in map_mem(), so memory mapped at boot time can be mapped at a larger granularity. When booting a kernel with KFENCE=y and RODATA_FULL=n, this results in the following WARNING at boot: [ 0.000000] ------------[ cut here ]------------ [ 0.000000] WARNING: CPU: 0 PID: 0 at mm/memory.c:2462 apply_to_pmd_range+0xec/0x190 [ 0.000000] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.13.0-rc1+ #10 [ 0.000000] Hardware name: linux,dummy-virt (DT) [ 0.000000] pstate: 600000c5 (nZCv daIF -PAN -UAO -TCO BTYPE=--) [ 0.000000] pc : apply_to_pmd_range+0xec/0x190 [ 0.000000] lr : __apply_to_page_range+0x94/0x170 [ 0.000000] sp : ffffffc010573e20 [ 0.000000] x29: ffffffc010573e20 x28: ffffff801f400000 x27: ffffff801f401000 [ 0.000000] x26: 0000000000000001 x25: ffffff801f400fff x24: ffffffc010573f28 [ 0.000000] x23: ffffffc01002b710 x22: ffffffc0105fa450 x21: ffffffc010573ee4 [ 0.000000] x20: ffffff801fffb7d0 x19: ffffff801f401000 x18: 00000000fffffffe [ 0.000000] x17: 000000000000003f x16: 000000000000000a x15: ffffffc01060b940 [ 0.000000] x14: 0000000000000000 x13: 0098968000000000 x12: 0000000098968000 [ 0.000000] x11: 0000000000000000 x10: 0000000098968000 x9 : 0000000000000001 [ 0.000000] x8 : 0000000000000000 x7 : ffffffc010573ee4 x6 : 0000000000000001 [ 0.000000] x5 : ffffffc010573f28 x4 : ffffffc01002b710 x3 : 0000000040000000 [ 0.000000] x2 : ffffff801f5fffff x1 : 0000000000000001 x0 : 007800005f400705 [ 0.000000] Call trace: [ 0.000000] apply_to_pmd_range+0xec/0x190 [ 0.000000] __apply_to_page_range+0x94/0x170 [ 0.000000] apply_to_page_range+0x10/0x20 [ 0.000000] __change_memory_common+0x50/0xdc [ 0.000000] set_memory_valid+0x30/0x40 [ 0.000000] kfence_init_pool+0x9c/0x16c [ 0.000000] kfence_init+0x20/0x98 [ 0.000000] start_kernel+0x284/0x3f8 Fixes: 840b23986344 ("arm64, kfence: enable KFENCE for ARM64") Cc: # 5.12.x Signed-off-by: Jisheng Zhang Acked-by: Mark Rutland Acked-by: Marco Elver Tested-by: Marco Elver --- Since v1: - improve commit msg as Mark suggested - add "Cc: stable@vger.kernel.org" - collect Mark and Marco's Acks arch/arm64/mm/mmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 6dd9369e3ea0..89b66ef43a0f 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -515,7 +515,8 @@ static void __init map_mem(pgd_t *pgdp) */ BUILD_BUG_ON(pgd_index(direct_map_end - 1) == pgd_index(direct_map_end)); - if (rodata_full || crash_mem_map || debug_pagealloc_enabled()) + if (rodata_full || crash_mem_map || debug_pagealloc_enabled() || + IS_ENABLED(CONFIG_KFENCE)) flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; /*