Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp110559pxb; Wed, 16 Feb 2022 23:21:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNAI/mIkj0Q4sxdNdefLybrUuGdtLg70EwyKniyacOFkRCqhSi6pbiwDtMIbeSJ/sbenNB X-Received: by 2002:a17:906:8557:b0:6cf:2730:b5cf with SMTP id h23-20020a170906855700b006cf2730b5cfmr1340828ejy.368.1645082476040; Wed, 16 Feb 2022 23:21:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645082476; cv=none; d=google.com; s=arc-20160816; b=PNDFGZBY4vaJkmu2WZfPUU0hG4215Cb2FvOp0woBmT+7vQ3tTmQljgt6Vpr43dKMQY TaYM/z7y3Q6BCNDAK02VZphlBQ+IFzR0N5lHogGjtoOz8e8P3VRVJ+SYRdtD5BoIbAaG g6QYnOspjHN58LImsPkrf4Dmqqaykp7uKZeFsDYPlLvBjq9O4mUvpItJiSpO3MW79m6M Uwp7KY9Wk4otNWY/z2T6rn+T+UhI8xLBDgKeSh7zjPgiRPjcWf3fzTnLI0B7iAdqhNVm D2Y/1cyFWszewDhAuKi6dMQD+FAMbKolAsBg2+ZbYzpfmgJVN5EuFw3pwzz11ct8wgZ4 5Fgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=F3AN2ic/8lzp1pIxcJQUmsKv75Hq/rfeI9BL68XqI/w=; b=Exg9X7uvAZXb/iwNyWpcLjE0idG/H6LJeoYNFE/2iRMoAbNZD63AtDrWeb/3G+Yf2P MWenTpP6SmTOFBIC+k7GtyTNYslOwJppv1/PJOpLCop0UIapT4bUfEQmeGDZtT70F65Z SWUZr9a0VTByclEKavWSvn8TjEBoTX7biUQVAzG/Y6i+piJglH1/cSG/ERpVe/ooHSzg EERRAl8yMJPlJqtclE219npwlWdjBH8K9Xw7AJt4E00SfzdkBDdClNlKF3Y5Z42ul9ms y1olOLpXBRjkLZzMU+d7E4aUDzWbwytN8ZH/PyTNm0wzwDIv4KZ/9wZS9tZpKdhieGGr 05Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=gmeDVDf7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ec28si3219570edb.495.2022.02.16.23.20.52; Wed, 16 Feb 2022 23:21:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=gmeDVDf7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238598AbiBQAF3 (ORCPT + 99 others); Wed, 16 Feb 2022 19:05:29 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbiBQAF2 (ORCPT ); Wed, 16 Feb 2022 19:05:28 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3C4A029C10C for ; Wed, 16 Feb 2022 16:05:14 -0800 (PST) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 9F4C920BCFD5; Wed, 16 Feb 2022 16:05:13 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9F4C920BCFD5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1645056313; bh=F3AN2ic/8lzp1pIxcJQUmsKv75Hq/rfeI9BL68XqI/w=; h=From:To:Cc:Subject:Date:From; b=gmeDVDf7XVsqJ2qcB7c4ATQ9zEj4zSlFYa8xDqDOHv/4Wgj703Ri8GoSQLboIn1Zs 7X9WjZJoR8JNlQXOmadafsNad79w7rruIQKqM5rkmdi36t7HhqA8v1d5p2zeI5heIY rKN18Mg1JCYQ6ji9AE0+fYYU8qff6stDMRrr4Ecw= From: Vijay Balakrishna To: Catalin Marinas , Will Deacon Cc: Nicolas Saenz Julienne , Anshuman Khandual , Mike Rapoport , Ard Biesheuvel , Pavel Tatashin , Vijay Balakrishna , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm64: Do not defer reserve_crashkernel() for platforms with no DMA memory zones Date: Wed, 16 Feb 2022 16:04:54 -0800 Message-Id: <1645056294-6509-1-git-send-email-vijayb@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following patches resulted in deferring crash kernel reservation to mem_init(), mainly aimed at platforms with DMA memory zones (no IOMMU), in particular Raspberry Pi 4. commit 1a8e1cef7603 ("arm64: use both ZONE_DMA and ZONE_DMA32") commit 8424ecdde7df ("arm64: mm: Set ZONE_DMA size based on devicetree's dma-ranges") commit 0a30c53573b0 ("arm64: mm: Move reserve_crashkernel() into mem_init()") commit 2687275a5843 ("arm64: Force NO_BLOCK_MAPPINGS if crashkernel reservation is required") Above changes introduced boot slowdown due to linear map creation for all the memory banks with NO_BLOCK_MAPPINGS, see discussion[1]. The proposed changes restore crash kernel reservation to earlier behavior thus avoids slow boot, particularly for platforms with IOMMU (no DMA memory zones). [1] https://lore.kernel.org/all/9436d033-579b-55fa-9b00-6f4b661c2dd7@linux.microsoft.com/ Signed-off-by: Vijay Balakrishna Cc: stable@vger.kernel.org --- Tested changes to confirm no ~150ms boot slowdown on our SoC with IOMMU and 8GB memory. Also tested with ZONE_DMA and/or ZONE_DMA32 configs to confirm no regression to deferring scheme of crash kernel memory reservation. In both cases successfully collected kernel crash dump. --- arch/arm64/mm/init.c | 14 +++++++++++--- arch/arm64/mm/mmu.c | 24 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index db63cc885771..f2a982c19b75 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -62,7 +62,11 @@ EXPORT_SYMBOL(memstart_addr); * In such case, ZONE_DMA32 covers the rest of the 32-bit addressable memory, * otherwise it is empty. */ -phys_addr_t arm64_dma_phys_limit __ro_after_init; +#if !defined(CONFIG_ZONE_DMA) && !defined(CONFIG_ZONE_DMA32) +phys_addr_t __ro_after_init arm64_dma_phys_limit = PHYS_MASK + 1; +#else +phys_addr_t __ro_after_init arm64_dma_phys_limit; +#endif #ifdef CONFIG_KEXEC_CORE /* @@ -153,8 +157,6 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) if (!arm64_dma_phys_limit) arm64_dma_phys_limit = dma32_phys_limit; #endif - if (!arm64_dma_phys_limit) - arm64_dma_phys_limit = PHYS_MASK + 1; max_zone_pfns[ZONE_NORMAL] = max; free_area_init(max_zone_pfns); @@ -315,6 +317,10 @@ void __init arm64_memblock_init(void) early_init_fdt_scan_reserved_mem(); +#if !defined(CONFIG_ZONE_DMA) && !defined(CONFIG_ZONE_DMA32) + reserve_crashkernel(); +#endif + high_memory = __va(memblock_end_of_DRAM() - 1) + 1; } @@ -357,11 +363,13 @@ void __init bootmem_init(void) */ dma_contiguous_reserve(arm64_dma_phys_limit); +#if defined(CONFIG_ZONE_DMA) || defined(CONFIG_ZONE_DMA32) /* * request_standard_resources() depends on crashkernel's memory being * reserved, so do it here. */ reserve_crashkernel(); +#endif memblock_dump_all(); } diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index acfae9b41cc8..e7faf5edccfc 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -517,7 +517,7 @@ static void __init map_mem(pgd_t *pgdp) */ BUILD_BUG_ON(pgd_index(direct_map_end - 1) == pgd_index(direct_map_end)); - if (can_set_direct_map() || crash_mem_map || IS_ENABLED(CONFIG_KFENCE)) + if (can_set_direct_map() || IS_ENABLED(CONFIG_KFENCE)) flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; /* @@ -528,6 +528,14 @@ static void __init map_mem(pgd_t *pgdp) */ memblock_mark_nomap(kernel_start, kernel_end - kernel_start); +#ifdef CONFIG_KEXEC_CORE + if (crash_mem_map && !crashk_res.end) + flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; + + if (crashk_res.end) + memblock_mark_nomap(crashk_res.start, + resource_size(&crashk_res)); +#endif /* map all the memory banks */ for_each_mem_range(i, &start, &end) { if (start >= end) @@ -554,6 +562,20 @@ static void __init map_mem(pgd_t *pgdp) __map_memblock(pgdp, kernel_start, kernel_end, PAGE_KERNEL, NO_CONT_MAPPINGS); memblock_clear_nomap(kernel_start, kernel_end - kernel_start); +#ifdef CONFIG_KEXEC_CORE + /* + * Use page-level mappings here so that we can shrink the region + * in page granularity and put back unused memory to buddy system + * through /sys/kernel/kexec_crash_size interface. + */ + if (crashk_res.end) { + __map_memblock(pgdp, crashk_res.start, crashk_res.end + 1, + PAGE_KERNEL, + NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS); + memblock_clear_nomap(crashk_res.start, + resource_size(&crashk_res)); + } +#endif } void mark_rodata_ro(void) -- 2.35.1