X-Received: by 2002:a63:e94b:0:b0:372:a6e1:f67a with SMTP id q11-20020a63e94b000000b00372a6e1f67amr1439064pgj.550.1645656331428; Wed, 23 Feb 2022 14:45:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645656331; cv=none; d=google.com; s=arc-20160816; b=uysuOuSpT5/jkgxUNvg5p2eTW7hz/X8RJBq1n/wyJnoIGb/zZbSgxGBmY/4puzpfCm 0efQmEbLwnWD4ycwMAnbcrsSoypSxVoGW9xcMUt3PN0BeJi9OPJ8opqs74zzbyxBq04B pxzjqPAAwa7cLLgOenXukVuI1oF3xHaWTDMzU0NJPPvic7elurLkVdpbdtLwPUm4gDc9 Lam/fiv/CmhRhRneY64ZAAkgDPCA4K/D0A9QIDCSJSN/lNMqm9YsLr5JBo5etAsOA0Ad cDHy9aywVzaEVOtF7/8hzv6YsNk14jMBSKW/03Xv2UKkjPiBkpmt7RyPWwratoW4q0tC vh1Q== 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=AubFU/DDFpEt7WMgdww7RXAhRAMd/Qzs/Nhi5iNAxDo=; b=EPpXnZ6AVRTLWNTfSTHTe+De/2IugTHljzmi93wO2Epqgelj/2IgQVbCp5ARmNRS08 bYAXHQ4Te8IB3iLyo/tRuwVCd4mlihD8UBbNXw5FjsWM1qrghmcDtMsVHiVxAPTI7H1I FFawV/vgVdz5OHAzejpEuVe852A65tGWcMwXNVsfMFASx0qcnpOlMxucZ6/5p7RjBCnC ISRTaxQvSCWksfTiXuXTgfyk04X8S3Zt+6A+GpyU7Epms12J6b5zv2hyJFkQsrCDSHcO FZWtaCPo8yN/uT82kQ1zHhyzBZoBtIdyFajVNNJXyRUyb3/dR0/2Yf3CxeOffSqekNAR xLyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=QzqTlkS2; 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 b4si944015pgs.199.2022.02.23.14.45.15; Wed, 23 Feb 2022 14:45:31 -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=QzqTlkS2; 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 S244557AbiBWT6J (ORCPT + 99 others); Wed, 23 Feb 2022 14:58:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244555AbiBWT6I (ORCPT ); Wed, 23 Feb 2022 14:58:08 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 682C82655C for ; Wed, 23 Feb 2022 11:57:40 -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 F3E0020C30E6; Wed, 23 Feb 2022 11:57:39 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com F3E0020C30E6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1645646260; bh=AubFU/DDFpEt7WMgdww7RXAhRAMd/Qzs/Nhi5iNAxDo=; h=From:To:Cc:Subject:Date:From; b=QzqTlkS2vkdazSn5oC4NjyQkDGwWeJ1SuS8bS8Q4kwbrwJyZ5jLFtUZifyKGwiC9x fYp7p3cE3wVYucci3vCjO30HAlISCsXsYkigMKn0JKR7zRRjEajiCdjaz2vja5g/EH licruoDmC8010cYN+VWOLK4haEof6NfNWNL/bjoM= 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 v2] arm64: Do not defer reserve_crashkernel() for platforms with no DMA memory zones Date: Wed, 23 Feb 2022 11:57:33 -0800 Message-Id: <1645646253-16072-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). 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. [1] https://lore.kernel.org/all/9436d033-579b-55fa-9b00-6f4b661c2dd7@linux.microsoft.com/ Signed-off-by: Vijay Balakrishna Cc: stable@vger.kernel.org --- Changes from v1 -> v2 --------------------- - replaced '!crashk_res.end' with IS_ENABLED(ZONE_DMA/DMA32) (Nicolas's comment) - minor change to make it uniform -- replaced #if defined(..) -> #if IS_ENABLED(..) - added new comment in arch/arm64/mm/init.c to ease future maintenance (Nicolas's comment) - test performed comment moved to commit message [v1] https://lore.kernel.org/all/1645056294-6509-1-git-send-email-vijayb@linux.microsoft.com/ --- arch/arm64/mm/init.c | 36 +++++++++++++++++++++++++++++++++--- arch/arm64/mm/mmu.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index db63cc885771..51869f9dfc33 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -61,8 +61,34 @@ EXPORT_SYMBOL(memstart_addr); * unless restricted on specific platforms (e.g. 30-bit on Raspberry Pi 4). * In such case, ZONE_DMA32 covers the rest of the 32-bit addressable memory, * otherwise it is empty. + * + * Memory reservation for crash kernel either done early or deferred + * depending on DMA memory zones configs (ZONE_DMA) -- + * + * In absence of ZONE_DMA configs arm64_dma_phys_limit initialized + * here instead of max_zone_phys(). This lets early reservation of + * crash kernel memory which has a dependency on arm64_dma_phys_limit. + * Reserving memory early for crash kernel allows linear creation of block + * mappings (greater than page-granularity) for all the memory bank rangs. + * In this scheme a comparatively quicker boot is observed. + * + * If ZONE_DMA configs are defined, crash kernel memory reservation + * is delayed until DMA zone memory range size initilazation performed in + * zone_sizes_init(). The defer is necessary to steer clear of DMA zone + * memory range to avoid overlap allocation. So crash kernel memory boundaries + * are not known when mapping all bank memory ranges, which otherwise means + * not possible to exclude crash kernel range from creating block mappings + * so page-granularity mappings are created for the entire memory range. + * Hence a slightly slower boot is observed. + * + * Note: Page-granularity mapppings are necessary for crash kernel memory + * range for shrinking its size via /sys/kernel/kexec_crash_size interface. */ -phys_addr_t arm64_dma_phys_limit __ro_after_init; +#if IS_ENABLED(CONFIG_ZONE_DMA) || IS_ENABLED(CONFIG_ZONE_DMA32) +phys_addr_t __ro_after_init arm64_dma_phys_limit; +#else +phys_addr_t __ro_after_init arm64_dma_phys_limit = PHYS_MASK + 1; +#endif #ifdef CONFIG_KEXEC_CORE /* @@ -153,8 +179,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 +339,10 @@ void __init arm64_memblock_init(void) early_init_fdt_scan_reserved_mem(); +#if !IS_ENABLED(CONFIG_ZONE_DMA) && !IS_ENABLED(CONFIG_ZONE_DMA32) + reserve_crashkernel(); +#endif + high_memory = __va(memblock_end_of_DRAM() - 1) + 1; } @@ -357,11 +385,13 @@ void __init bootmem_init(void) */ dma_contiguous_reserve(arm64_dma_phys_limit); +#if IS_ENABLED(CONFIG_ZONE_DMA) || IS_ENABLED(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..884b2c6d6cd9 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,18 @@ static void __init map_mem(pgd_t *pgdp) */ memblock_mark_nomap(kernel_start, kernel_end - kernel_start); +#if IS_ENABLED(CONFIG_KEXEC_CORE) + +#if IS_ENABLED(CONFIG_ZONE_DMA) || IS_ENABLED(CONFIG_ZONE_DMA32) + if (crash_mem_map) + flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; +#else + if (crashk_res.end) + memblock_mark_nomap(crashk_res.start, + resource_size(&crashk_res)); +#endif + +#endif /* map all the memory banks */ for_each_mem_range(i, &start, &end) { if (start >= end) @@ -554,6 +566,21 @@ 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); +#if IS_ENABLED(CONFIG_KEXEC_CORE) && \ + !IS_ENABLED(CONFIG_ZONE_DMA) && !IS_ENABLED(CONFIG_ZONE_DMA32) + /* + * 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