From nobody Mon May 11 08:31:19 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DDB8C433EF for ; Mon, 11 Apr 2022 09:12:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344274AbiDKJOh (ORCPT ); Mon, 11 Apr 2022 05:14:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241756AbiDKJOZ (ORCPT ); Mon, 11 Apr 2022 05:14:25 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75D5F3F892 for ; Mon, 11 Apr 2022 02:12:11 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KcNNB5P8yzFplN; Mon, 11 Apr 2022 17:09:46 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 11 Apr 2022 17:12:06 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 11 Apr 2022 17:12:05 +0800 From: Kefeng Wang To: , , , CC: , , Kefeng Wang , Pasha Tatashin Subject: [PATCH v3 1/3] arm64: mm: Do not defer reserve_crashkernel() if only ZONE_DMA32 Date: Mon, 11 Apr 2022 17:24:53 +0800 Message-ID: <20220411092455.1461-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220411092455.1461-1-wangkefeng.wang@huawei.com> References: <20220411092455.1461-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The kernel could benefit due to BLOCK_MAPPINGS, see commit 031495635b46 ("arm64: Do not defer reserve_crashkernel() for platforms with no DMA memory zones"), if only with ZONE_DMA32, set arm64_dma_phys_limit to max_zone_phys(32) earlier in arm64_memblock_init(), so platforms with just ZONE_DMA32 config enabled will benefit. Cc: Vijay Balakrishna Cc: Pasha Tatashin Cc: Will Deacon Reviewed-by: Vijay Balakrishna Signed-off-by: Kefeng Wang --- arch/arm64/mm/init.c | 23 ++++++++++++----------- arch/arm64/mm/mmu.c | 6 ++---- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 1e7b1550e2fc..897de41102d9 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -65,8 +65,9 @@ EXPORT_SYMBOL(memstart_addr); * 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 + * In absence of ZONE_DMA and ZONE_DMA32 configs arm64_dma_phys_limit + * initialized here and if only with ZONE_DMA32 arm64_dma_phys_limit + * initialised to max_zone_phys(32). 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. @@ -160,11 +161,10 @@ static phys_addr_t __init max_zone_phys(unsigned int = zone_bits) static void __init zone_sizes_init(unsigned long min, unsigned long max) { unsigned long max_zone_pfns[MAX_NR_ZONES] =3D {0}; - unsigned int __maybe_unused acpi_zone_dma_bits; - unsigned int __maybe_unused dt_zone_dma_bits; - phys_addr_t __maybe_unused dma32_phys_limit =3D max_zone_phys(32); - #ifdef CONFIG_ZONE_DMA + unsigned int acpi_zone_dma_bits; + unsigned int dt_zone_dma_bits; + acpi_zone_dma_bits =3D fls64(acpi_iort_dma_get_max_cpu_address()); dt_zone_dma_bits =3D fls64(of_dma_get_max_cpu_address(NULL)); zone_dma_bits =3D min3(32U, dt_zone_dma_bits, acpi_zone_dma_bits); @@ -172,9 +172,7 @@ static void __init zone_sizes_init(unsigned long min, u= nsigned long max) max_zone_pfns[ZONE_DMA] =3D PFN_DOWN(arm64_dma_phys_limit); #endif #ifdef CONFIG_ZONE_DMA32 - max_zone_pfns[ZONE_DMA32] =3D PFN_DOWN(dma32_phys_limit); - if (!arm64_dma_phys_limit) - arm64_dma_phys_limit =3D dma32_phys_limit; + max_zone_pfns[ZONE_DMA32] =3D PFN_DOWN(max_zone_phys(32)); #endif max_zone_pfns[ZONE_NORMAL] =3D max; =20 @@ -336,8 +334,11 @@ void __init arm64_memblock_init(void) =20 early_init_fdt_scan_reserved_mem(); =20 - if (!IS_ENABLED(CONFIG_ZONE_DMA) && !IS_ENABLED(CONFIG_ZONE_DMA32)) + if (!IS_ENABLED(CONFIG_ZONE_DMA)) { + if (IS_ENABLED(CONFIG_ZONE_DMA32)) + arm64_dma_phys_limit =3D max_zone_phys(32); reserve_crashkernel(); + } =20 high_memory =3D __va(memblock_end_of_DRAM() - 1) + 1; } @@ -385,7 +386,7 @@ void __init bootmem_init(void) * request_standard_resources() depends on crashkernel's memory being * reserved, so do it here. */ - if (IS_ENABLED(CONFIG_ZONE_DMA) || IS_ENABLED(CONFIG_ZONE_DMA32)) + if (IS_ENABLED(CONFIG_ZONE_DMA)) reserve_crashkernel(); =20 memblock_dump_all(); diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 626ec32873c6..23734481318a 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -529,8 +529,7 @@ static void __init map_mem(pgd_t *pgdp) =20 #ifdef CONFIG_KEXEC_CORE if (crash_mem_map) { - if (IS_ENABLED(CONFIG_ZONE_DMA) || - IS_ENABLED(CONFIG_ZONE_DMA32)) + if (IS_ENABLED(CONFIG_ZONE_DMA)) flags |=3D NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; else if (crashk_res.end) memblock_mark_nomap(crashk_res.start, @@ -571,8 +570,7 @@ static void __init map_mem(pgd_t *pgdp) * through /sys/kernel/kexec_crash_size interface. */ #ifdef CONFIG_KEXEC_CORE - if (crash_mem_map && - !IS_ENABLED(CONFIG_ZONE_DMA) && !IS_ENABLED(CONFIG_ZONE_DMA32)) { + if (crash_mem_map && !IS_ENABLED(CONFIG_ZONE_DMA)) { if (crashk_res.end) { __map_memblock(pgdp, crashk_res.start, crashk_res.end + 1, --=20 2.26.2 From nobody Mon May 11 08:31:19 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F515C433F5 for ; Mon, 11 Apr 2022 09:12:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344264AbiDKJOd (ORCPT ); Mon, 11 Apr 2022 05:14:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234039AbiDKJOX (ORCPT ); Mon, 11 Apr 2022 05:14:23 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E058D3ED30 for ; Mon, 11 Apr 2022 02:12:09 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KcNN73d5BzFpl0; Mon, 11 Apr 2022 17:09:43 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 11 Apr 2022 17:12:06 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 11 Apr 2022 17:12:06 +0800 From: Kefeng Wang To: , , , CC: , , Kefeng Wang Subject: [PATCH v3 2/3] arm64: mm: Don't defer reserve_crashkernel() with dma_force_32bit Date: Mon, 11 Apr 2022 17:24:54 +0800 Message-ID: <20220411092455.1461-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220411092455.1461-1-wangkefeng.wang@huawei.com> References: <20220411092455.1461-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" ARM64 enable ZONE_DMA by default, and with ZONE_DMA crash kernel memory reservation is delayed until DMA zone memory range size initilazation performed in zone_sizes_init(), but for most platforms use 32bit dma_zone_bits, so add dma_force_32bit kernel parameter if ZONE_DMA enabled, and initialize arm64_dma_phys_limit to max_zone_phys(32) in arm64_memblock_init() if dma_force_32bit is setup, this could let the crash kernel reservation earlier, and allows linear creation with block mapping. Reviewed-by: Vijay Balakrishna Signed-off-by: Kefeng Wang --- arch/arm64/include/asm/kexec.h | 1 + arch/arm64/mm/init.c | 43 +++++++++++++++++++++++++++------- arch/arm64/mm/mmu.c | 4 ++-- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/arch/arm64/include/asm/kexec.h b/arch/arm64/include/asm/kexec.h index 9839bfc163d7..624865d1cc71 100644 --- a/arch/arm64/include/asm/kexec.h +++ b/arch/arm64/include/asm/kexec.h @@ -95,6 +95,7 @@ void cpu_soft_restart(unsigned long el2_switch, unsigned = long entry, unsigned long arg0, unsigned long arg1, unsigned long arg2); #endif +bool crashkernel_early_reserve(void); =20 #define ARCH_HAS_KIMAGE_ARCH =20 diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 897de41102d9..18b0031eadd0 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -66,7 +67,8 @@ EXPORT_SYMBOL(memstart_addr); * depending on DMA memory zones configs (ZONE_DMA) -- * * In absence of ZONE_DMA and ZONE_DMA32 configs arm64_dma_phys_limit - * initialized here and if only with ZONE_DMA32 arm64_dma_phys_limit + * initialized here, and if only with ZONE_DMA32 or if with ZONE_DMA + * and dma_force_32bit kernel parameter, the arm64_dma_phys_limit is * initialised to max_zone_phys(32). 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 @@ -91,6 +93,27 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit; phys_addr_t __ro_after_init arm64_dma_phys_limit =3D PHYS_MASK + 1; #endif =20 +static bool __ro_after_init arm64_dma_force_32bit; +#ifdef CONFIG_ZONE_DMA +static int __init arm64_dma_force_32bit_setup(char *p) +{ + zone_dma_bits =3D 32; + arm64_dma_force_32bit =3D true; + + return 0; +} +early_param("dma_force_32bit", arm64_dma_force_32bit_setup); +#endif + +bool __init crashkernel_early_reserve(void) +{ + if (!IS_ENABLED(CONFIG_ZONE_DMA)) + return true; + if (arm64_dma_force_32bit) + return true; + return false; +} + /* * reserve_crashkernel() - reserves memory for crash kernel * @@ -162,12 +185,14 @@ static void __init zone_sizes_init(unsigned long min,= unsigned long max) { unsigned long max_zone_pfns[MAX_NR_ZONES] =3D {0}; #ifdef CONFIG_ZONE_DMA - unsigned int acpi_zone_dma_bits; - unsigned int dt_zone_dma_bits; + if (!arm64_dma_force_32bit) { + unsigned int acpi_zone_dma_bits; + unsigned int dt_zone_dma_bits; =20 - acpi_zone_dma_bits =3D fls64(acpi_iort_dma_get_max_cpu_address()); - dt_zone_dma_bits =3D fls64(of_dma_get_max_cpu_address(NULL)); - zone_dma_bits =3D min3(32U, dt_zone_dma_bits, acpi_zone_dma_bits); + acpi_zone_dma_bits =3D fls64(acpi_iort_dma_get_max_cpu_address()); + dt_zone_dma_bits =3D fls64(of_dma_get_max_cpu_address(NULL)); + zone_dma_bits =3D min3(32U, dt_zone_dma_bits, acpi_zone_dma_bits); + } arm64_dma_phys_limit =3D max_zone_phys(zone_dma_bits); max_zone_pfns[ZONE_DMA] =3D PFN_DOWN(arm64_dma_phys_limit); #endif @@ -334,8 +359,8 @@ void __init arm64_memblock_init(void) =20 early_init_fdt_scan_reserved_mem(); =20 - if (!IS_ENABLED(CONFIG_ZONE_DMA)) { - if (IS_ENABLED(CONFIG_ZONE_DMA32)) + if (crashkernel_early_reserve()) { + if (IS_ENABLED(CONFIG_ZONE_DMA32) || arm64_dma_force_32bit) arm64_dma_phys_limit =3D max_zone_phys(32); reserve_crashkernel(); } @@ -386,7 +411,7 @@ void __init bootmem_init(void) * request_standard_resources() depends on crashkernel's memory being * reserved, so do it here. */ - if (IS_ENABLED(CONFIG_ZONE_DMA)) + if (!crashkernel_early_reserve()) reserve_crashkernel(); =20 memblock_dump_all(); diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 23734481318a..46b626025b78 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -529,7 +529,7 @@ static void __init map_mem(pgd_t *pgdp) =20 #ifdef CONFIG_KEXEC_CORE if (crash_mem_map) { - if (IS_ENABLED(CONFIG_ZONE_DMA)) + if (!crashkernel_early_reserve()) flags |=3D NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS; else if (crashk_res.end) memblock_mark_nomap(crashk_res.start, @@ -570,7 +570,7 @@ static void __init map_mem(pgd_t *pgdp) * through /sys/kernel/kexec_crash_size interface. */ #ifdef CONFIG_KEXEC_CORE - if (crash_mem_map && !IS_ENABLED(CONFIG_ZONE_DMA)) { + if (crash_mem_map && crashkernel_early_reserve()) { if (crashk_res.end) { __map_memblock(pgdp, crashk_res.start, crashk_res.end + 1, --=20 2.26.2 From nobody Mon May 11 08:31:19 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFA97C433F5 for ; Mon, 11 Apr 2022 09:12:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344247AbiDKJOa (ORCPT ); Mon, 11 Apr 2022 05:14:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236641AbiDKJOX (ORCPT ); Mon, 11 Apr 2022 05:14:23 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71AA23F8A0 for ; Mon, 11 Apr 2022 02:12:10 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KcNN76dFHzFpk9; Mon, 11 Apr 2022 17:09:43 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 11 Apr 2022 17:12:07 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 11 Apr 2022 17:12:06 +0800 From: Kefeng Wang To: , , , CC: , , Kefeng Wang Subject: [PATCH v3 3/3] arm64: mm: Cleanup useless parameters in zone_sizes_init() Date: Mon, 11 Apr 2022 17:24:55 +0800 Message-ID: <20220411092455.1461-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220411092455.1461-1-wangkefeng.wang@huawei.com> References: <20220411092455.1461-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Directly use max_pfn for max and no one use min, kill them. Reviewed-by: Vijay Balakrishna Signed-off-by: Kefeng Wang --- arch/arm64/mm/init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 18b0031eadd0..788413fc2ecf 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -181,7 +181,7 @@ static phys_addr_t __init max_zone_phys(unsigned int zo= ne_bits) return min(zone_mask, memblock_end_of_DRAM() - 1) + 1; } =20 -static void __init zone_sizes_init(unsigned long min, unsigned long max) +static void __init zone_sizes_init(void) { unsigned long max_zone_pfns[MAX_NR_ZONES] =3D {0}; #ifdef CONFIG_ZONE_DMA @@ -199,7 +199,7 @@ static void __init zone_sizes_init(unsigned long min, u= nsigned long max) #ifdef CONFIG_ZONE_DMA32 max_zone_pfns[ZONE_DMA32] =3D PFN_DOWN(max_zone_phys(32)); #endif - max_zone_pfns[ZONE_NORMAL] =3D max; + max_zone_pfns[ZONE_NORMAL] =3D max_pfn; =20 free_area_init(max_zone_pfns); } @@ -400,7 +400,7 @@ void __init bootmem_init(void) * done after the fixed reservations */ sparse_init(); - zone_sizes_init(min, max); + zone_sizes_init(); =20 /* * Reserve the CMA area after arm64_dma_phys_limit was initialised. --=20 2.26.2