From patchwork Thu Feb 17 00:04:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vijay Balakrishna X-Patchwork-Id: 12749172 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 4DE81C433EF for ; Thu, 17 Feb 2022 00:07:03 +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:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id: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:In-Reply-To:References: List-Owner; bh=1QTkPDLIEbwf+uY9U5MS6ffQ+WAuqBuJXVpi2exOp3I=; b=OlN+SunrdNQDb/ zHwGj6tCTObyCkxzMdLF5GQnz/gCQ+qJT627yLH7zkYMoa1XN82hCwAFTGH0Ffo8lQMfFc/8n/sUo aNM7FhcGDqI5SxP0RqF5xCgAz23XyPnCEPD0FKQ4DHJ9/c9m0hFFPf3hiTEWvjxgrhU+SXbH+XV6j KovHlBIap54NRqpSieAeiWIx70Cqxe45AJcG+144HfsVmcyZLb1lBfueLF3J1DZkA9MCrHayn+2hA lD96b5PoMjzIKVir9u10I+xaNW8yUDVXjlga7cgo5QZVnb2jY6aNUiuKDrzEyQxwCgrgKzMVyT0h8 EjuDjYwrLsjCmBMt8/cg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKUIU-008YiW-Dq; Thu, 17 Feb 2022 00:05:22 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKUIQ-008Ygm-6i for linux-arm-kernel@lists.infradead.org; Thu, 17 Feb 2022 00:05:20 +0000 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220216_160518_320573_45D26E00 X-CRM114-Status: GOOD ( 14.40 ) 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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)