From patchwork Mon May 31 12:29:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12289287 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=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 AF416C47080 for ; Mon, 31 May 2021 12:31:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 901DD61263 for ; Mon, 31 May 2021 12:31:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231530AbhEaMdE (ORCPT ); Mon, 31 May 2021 08:33:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:38480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231524AbhEaMcy (ORCPT ); Mon, 31 May 2021 08:32:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4C69E61263; Mon, 31 May 2021 12:31:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622464274; bh=nYK9qBjercVj0g6Vv+NGsdd2DIuSrcvW+FH79tlPIOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MlpI4+NBfpcRnUk2p9WdM+R+zCDdFBYfVK+3zwnxxQnmFLWqhxlf5Ho6ge/LWzGVb nZ+AnwUem6PB9mQd6Ze8IALrEJEGGMv74QJYt4ipJN/ZK1nVluMLJTnuuwRWj0PArE HQmd6+FDICPHAUZXJ6959+GgXcrfWdc2Hu9pNC5bP29gF2+/QrM6LzjGurbQuBA76P 1nYK5fZyzlfvijqrcdJHQ0dhWYS9C/2Nf5Nv/z4Y6OTYCZuSEFsvXnyegEUJ0g75DY EGGCul/YwrA6HnurFvtxliCuVYhV9+tyqSLHbWwi4AszS83kbrLDUwl7K7YLqJvsdI CAHIGrtRqU2YQ== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Catalin Marinas , Christian Borntraeger , David Hildenbrand , Heiko Carstens , Mike Rapoport , Mike Rapoport , Russell King , Thomas Bogendoerfer , Vasily Gorbik , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org Subject: [RFC/RFT PATCH 1/5] s390: make crashk_res resource a child of "System RAM" Date: Mon, 31 May 2021 15:29:55 +0300 Message-Id: <20210531122959.23499-2-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210531122959.23499-1-rppt@kernel.org> References: <20210531122959.23499-1-rppt@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Mike Rapoport Commit 4e042af463f8 ("s390/kexec: fix crash on resize of reserved memory") added a comment that says "crash kernel resource should not be part of the System RAM resource" but never explained why. As it looks from the code in the kernel and in kexec there is no actual reason for that. Keeping crashk_res inline with other resources makes code simpler and cleaner, and allows future consolidation of the resources setup across several architectures. Signed-off-by: Mike Rapoport --- arch/s390/kernel/setup.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c index 5aab59ad5688..30430e7c1b03 100644 --- a/arch/s390/kernel/setup.c +++ b/arch/s390/kernel/setup.c @@ -500,6 +500,9 @@ static struct resource __initdata *standard_resources[] = { &code_resource, &data_resource, &bss_resource, +#ifdef CONFIG_CRASH_DUMP + &crashk_res, +#endif }; static void __init setup_resources(void) @@ -535,7 +538,7 @@ static void __init setup_resources(void) for (j = 0; j < ARRAY_SIZE(standard_resources); j++) { std_res = standard_resources[j]; - if (std_res->start < res->start || + if (!std_res->end || std_res->start < res->start || std_res->start > res->end) continue; if (std_res->end > res->end) { @@ -552,20 +555,6 @@ static void __init setup_resources(void) } } } -#ifdef CONFIG_CRASH_DUMP - /* - * Re-add removed crash kernel memory as reserved memory. This makes - * sure it will be mapped with the identity mapping and struct pages - * will be created, so it can be resized later on. - * However add it later since the crash kernel resource should not be - * part of the System RAM resource. - */ - if (crashk_res.end) { - memblock_add_node(crashk_res.start, resource_size(&crashk_res), 0); - memblock_reserve(crashk_res.start, resource_size(&crashk_res)); - insert_resource(&iomem_resource, &crashk_res); - } -#endif } static void __init setup_ident_map_size(void) @@ -733,7 +722,7 @@ static void __init reserve_crashkernel(void) diag10_range(PFN_DOWN(crash_base), PFN_DOWN(crash_size)); crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size - 1; - memblock_remove(crash_base, crash_size); + memblock_reserve(crash_base, crash_size); pr_info("Reserving %lluMB of memory at %lluMB " "for crashkernel (System RAM: %luMB)\n", crash_size >> 20, crash_base >> 20, From patchwork Mon May 31 12:29:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12289289 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=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 7D4C8C47083 for ; Mon, 31 May 2021 12:31:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E57A61364 for ; Mon, 31 May 2021 12:31:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231546AbhEaMdI (ORCPT ); Mon, 31 May 2021 08:33:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:38552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231473AbhEaMc7 (ORCPT ); Mon, 31 May 2021 08:32:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C5F4B6124B; Mon, 31 May 2021 12:31:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622464279; bh=XhlObzucLkoYFjoHz2VHIuYEU9vYDszsHWXfe9qRcS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u1dBUT0wkfkJ3k++kH9Ef7OMLOsR7G9NIIcsy0Os68H0rNjYt6KDimJUzOcgJqD7z rbP5dssd7zUEjZ1K1TGnIpnAQuQyfcwYK+YJYkVcJiIRBBu7Z+IM47aJ+oGtBdtqsf G6vwd3GTCjL4jiiHreqEfdmLcS2AnjNjAG0kQNrBNFa7YhAk6VIk/yrQF9wujHeLS4 3SGCqvHkDx5N9n24PBBHFJdepXYu6PXGXe9nwMBCAMCICHkYopO5l8vh2m1jUbavbR zmGqeXyauouY+eaXpNSoLFDka/UZUrlj7LtDueOFE9D3ADiI92t0UHADLmUZr3gY6j CdR37L1LuFRrQ== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Catalin Marinas , Christian Borntraeger , David Hildenbrand , Heiko Carstens , Mike Rapoport , Mike Rapoport , Russell King , Thomas Bogendoerfer , Vasily Gorbik , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org Subject: [RFC/RFT PATCH 2/5] memblock: introduce generic memblock_setup_resources() Date: Mon, 31 May 2021 15:29:56 +0300 Message-Id: <20210531122959.23499-3-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210531122959.23499-1-rppt@kernel.org> References: <20210531122959.23499-1-rppt@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Mike Rapoport Several architecture have very similar implementation of the setup of the resource tree. The implementations loop over memory ranges registered in memblock, request a "System RAM" resource for each range and then reserve resource rages corresponding to various sections of the kernel image. If kexec/crash dump are enable the crashk_res region is also reserved. Move the implementation of resource tree setup from s390 to memblock. It will be then used by several other architectures as well. Signed-off-by: Mike Rapoport --- arch/s390/kernel/setup.c | 73 +-------------------------------- include/linux/memblock.h | 2 + mm/memblock.c | 87 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 72 deletions(-) diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c index 30430e7c1b03..6f3c82cc0b0d 100644 --- a/arch/s390/kernel/setup.c +++ b/arch/s390/kernel/setup.c @@ -481,80 +481,9 @@ static void __init setup_lowcore_dat_on(void) __ctl_set_bit(0, 28); } -static struct resource code_resource = { - .name = "Kernel code", - .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM, -}; - -static struct resource data_resource = { - .name = "Kernel data", - .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM, -}; - -static struct resource bss_resource = { - .name = "Kernel bss", - .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM, -}; - -static struct resource __initdata *standard_resources[] = { - &code_resource, - &data_resource, - &bss_resource, -#ifdef CONFIG_CRASH_DUMP - &crashk_res, -#endif -}; - static void __init setup_resources(void) { - struct resource *res, *std_res, *sub_res; - phys_addr_t start, end; - int j; - u64 i; - - code_resource.start = (unsigned long) _text; - code_resource.end = (unsigned long) _etext - 1; - data_resource.start = (unsigned long) _etext; - data_resource.end = (unsigned long) _edata - 1; - bss_resource.start = (unsigned long) __bss_start; - bss_resource.end = (unsigned long) __bss_stop - 1; - - for_each_mem_range(i, &start, &end) { - res = memblock_alloc(sizeof(*res), 8); - if (!res) - panic("%s: Failed to allocate %zu bytes align=0x%x\n", - __func__, sizeof(*res), 8); - res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; - - res->name = "System RAM"; - res->start = start; - /* - * In memblock, end points to the first byte after the - * range while in resourses, end points to the last byte in - * the range. - */ - res->end = end - 1; - request_resource(&iomem_resource, res); - - for (j = 0; j < ARRAY_SIZE(standard_resources); j++) { - std_res = standard_resources[j]; - if (!std_res->end || std_res->start < res->start || - std_res->start > res->end) - continue; - if (std_res->end > res->end) { - sub_res = memblock_alloc(sizeof(*sub_res), 8); - if (!sub_res) - panic("%s: Failed to allocate %zu bytes align=0x%x\n", - __func__, sizeof(*sub_res), 8); - *sub_res = *std_res; - sub_res->end = res->end; - std_res->start = res->end + 1; - request_resource(res, sub_res); - } else { - request_resource(res, std_res); - } - } - } + memblock_setup_resources(); } static void __init setup_ident_map_size(void) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 5984fff3f175..44c29ebae842 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -121,6 +121,8 @@ void memblock_free_all(void); void reset_node_managed_pages(pg_data_t *pgdat); void reset_all_zones_managed_pages(void); +void memblock_setup_resources(void); + /* Low level functions */ void __next_mem_range(u64 *idx, int nid, enum memblock_flags flags, struct memblock_type *type_a, diff --git a/mm/memblock.c b/mm/memblock.c index afaefa8fc6ab..504435753259 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include @@ -2062,6 +2064,91 @@ void __init memblock_free_all(void) totalram_pages_add(pages); } +static struct resource code_resource = { + .name = "Kernel code", + .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM, +}; + +static struct resource rodata_resource = { + .name = "Kernel rodata", + .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM, +}; + +static struct resource data_resource = { + .name = "Kernel data", + .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM, +}; + +static struct resource bss_resource = { + .name = "Kernel bss", + .flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM, +}; + +static struct resource __initdata *standard_resources[] = { + &code_resource, + &rodata_resource, + &data_resource, + &bss_resource, +#ifdef CONFIG_KEXEC_CORE + &crashk_res, +#endif +}; + +void __init memblock_setup_resources(void) +{ + struct resource *res, *kres, *sub_res; + phys_addr_t start, end; + int j; + u64 i; + + code_resource.start = __pa_symbol(_text); + code_resource.end = __pa_symbol(_etext)-1; + rodata_resource.start = __pa_symbol(__start_rodata); + rodata_resource.end = __pa_symbol(__end_rodata)-1; + data_resource.start = __pa_symbol(_sdata); + data_resource.end = __pa_symbol(_edata)-1; + bss_resource.start = __pa_symbol(__bss_start); + bss_resource.end = __pa_symbol(__bss_stop)-1; + + for_each_mem_range(i, &start, &end) { + res = memblock_alloc(sizeof(*res), 8); + if (!res) + panic("%s: Failed to allocate %zu bytes align=0x%x\n", + __func__, sizeof(*res), 8); + res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; + + res->name = "System RAM"; + res->start = start; + + /* + * In memblock, end points to the first byte after the + * range while in resourses, end points to the last byte in + * the range. + */ + res->end = end - 1; + request_resource(&iomem_resource, res); + + for (j = 0; j < ARRAY_SIZE(standard_resources); j++) { + kres = standard_resources[j]; + if (!kres->end || kres->start < res->start || + kres->start > res->end) + continue; + if (kres->end > res->end) { + sub_res = memblock_alloc(sizeof(*sub_res), 8); + if (!sub_res) + panic("%s: Failed to allocate %zu bytes align=0x%x\n", + __func__, sizeof(*sub_res), 8); + *sub_res = *kres; + sub_res->end = res->end; + kres->start = res->end + 1; + request_resource(res, sub_res); + } else { + request_resource(res, kres); + } + } + } +} + #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK) static int memblock_debug_show(struct seq_file *m, void *private) From patchwork Mon May 31 12:29:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12289291 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=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 2C545C47082 for ; Mon, 31 May 2021 12:31:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0FA9061263 for ; Mon, 31 May 2021 12:31:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231576AbhEaMdJ (ORCPT ); Mon, 31 May 2021 08:33:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:38614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231562AbhEaMdD (ORCPT ); Mon, 31 May 2021 08:33:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7DBDB610C9; Mon, 31 May 2021 12:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622464283; bh=2dnOTVI7zvTo/6jCrrAI5rKQuEMENUnjNWL7YAVd/TI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UAWkF05LhVrQJrPC2lEw2gMhfbIE1nUX/xsnFocDLULwsRSZMBTbzsCVHPl8oeKkb z2cMWXTTCLBjOEY1mQFiDLmuflFLMQRsM+jpmNmY2MW7WLyzkuQDAHSHGkdOebqCOd 1nh/SXYPVn1zoLjUR5E0W9fj+kHf85Oe/XnmA3rL8+DGy/owxS1wb/rDeThw5jZxXv qwF8nptukaL2cJqVyew84MeoNKalyCfFkoMPbKicTvt4lSZXrdSADUU6FUqt1tN54e 3kVF1vwHROoV9D+FXrxc0E7M0yg+L9Rm2SG0ELc+mdEp0Lq68OpMozWO3sm/VFX5P9 YvR7V2ZRQB5fQ== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Catalin Marinas , Christian Borntraeger , David Hildenbrand , Heiko Carstens , Mike Rapoport , Mike Rapoport , Russell King , Thomas Bogendoerfer , Vasily Gorbik , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org Subject: [RFC/RFT PATCH 3/5] arm: switch to generic memblock_setup_resources() Date: Mon, 31 May 2021 15:29:57 +0300 Message-Id: <20210531122959.23499-4-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210531122959.23499-1-rppt@kernel.org> References: <20210531122959.23499-1-rppt@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Mike Rapoport The registration of "System RAM" resources on arm is very similar to the generic version. The major differences are the registration of "System RAM (boot alias)" areas and minor differences in the way kernel image resources are reserved. Replace the open coded registration of the "System RAM" resource and the requests for kernel image and data areas in the resource tree with the generic implementation. Signed-off-by: Mike Rapoport --- arch/arm/kernel/setup.c | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index 1a5edf562e85..d14edf42815b 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -174,23 +174,9 @@ static struct resource mem_res[] = { .end = 0, .flags = IORESOURCE_MEM }, - { - .name = "Kernel code", - .start = 0, - .end = 0, - .flags = IORESOURCE_SYSTEM_RAM - }, - { - .name = "Kernel data", - .start = 0, - .end = 0, - .flags = IORESOURCE_SYSTEM_RAM - } }; #define video_ram mem_res[0] -#define kernel_code mem_res[1] -#define kernel_data mem_res[2] static struct resource io_res[] = { { @@ -849,10 +835,7 @@ static void __init request_standard_resources(const struct machine_desc *mdesc) struct resource *res; u64 i; - kernel_code.start = virt_to_phys(_text); - kernel_code.end = virt_to_phys(__init_begin - 1); - kernel_data.start = virt_to_phys(_sdata); - kernel_data.end = virt_to_phys(_end - 1); + memblock_setup_resources(); for_each_mem_range(i, &start, &end) { unsigned long boot_alias_start; @@ -881,24 +864,6 @@ static void __init request_standard_resources(const struct machine_desc *mdesc) res->flags = IORESOURCE_MEM | IORESOURCE_BUSY; request_resource(&iomem_resource, res); } - - res = memblock_alloc(sizeof(*res), SMP_CACHE_BYTES); - if (!res) - panic("%s: Failed to allocate %zu bytes\n", __func__, - sizeof(*res)); - res->name = "System RAM"; - res->start = start; - res->end = res_end; - res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; - - request_resource(&iomem_resource, res); - - if (kernel_code.start >= res->start && - kernel_code.end <= res->end) - request_resource(res, &kernel_code); - if (kernel_data.start >= res->start && - kernel_data.end <= res->end) - request_resource(res, &kernel_data); } if (mdesc->video_start) { From patchwork Mon May 31 12:29:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12289293 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=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 2A068C47082 for ; Mon, 31 May 2021 12:31:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DDA3610C9 for ; Mon, 31 May 2021 12:31:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231626AbhEaMdS (ORCPT ); Mon, 31 May 2021 08:33:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:38656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbhEaMdH (ORCPT ); Mon, 31 May 2021 08:33:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F3E666135F; Mon, 31 May 2021 12:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622464288; bh=309tkdm9I1/k2Co/st23BvuJob0lzdLSyQqCb3FEq5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=shfDXUt5Lezf1d+wGhhu727XGfae1hwajag2YZ137cnZTl0B/na6Vf8bUHnNhLWcT WDL60Wfo8EfCCBAwsr7gWELh2vywN4mSg5ZuH+KeAq3Pwl9n/EDdaxpSqRqzGw6lzF jz6t+S3yWvR8fD8/I/efykYVq8goZPliRZ+lqDA5PjiEl6id5iWfqxcXzTHq2SSf5P R3XUx/1lBgKklG8b5Ne/MMyJIdOZS4ey4MqYOW5bOIodhNki11uKX8zEIFwq4Y0P09 r9mcdDDc6cqMoPniLqJq3r7YlX/GBrJfp7Qn5kf3ivzA2MwWHqNFhEZcADG5BrH2I9 gIFsiBwqkFhgA== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Catalin Marinas , Christian Borntraeger , David Hildenbrand , Heiko Carstens , Mike Rapoport , Mike Rapoport , Russell King , Thomas Bogendoerfer , Vasily Gorbik , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org Subject: [RFC/RFT PATCH 4/5] MIPS: switch to generic memblock_setup_resources Date: Mon, 31 May 2021 15:29:58 +0300 Message-Id: <20210531122959.23499-5-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210531122959.23499-1-rppt@kernel.org> References: <20210531122959.23499-1-rppt@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Mike Rapoport MIPS version of resource setup is very similar to the generic one. The only difference is the reservation of the crash kernel area that is spread among several functions. Switch MIPS to use the generic version. Signed-off-by: Mike Rapoport --- arch/mips/kernel/setup.c | 78 +++------------------------------------- 1 file changed, 5 insertions(+), 73 deletions(-) diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 23a140327a0b..be49217f0f22 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -79,10 +79,6 @@ static const char builtin_cmdline[] __initconst = ""; unsigned long mips_io_port_base = -1; EXPORT_SYMBOL(mips_io_port_base); -static struct resource code_resource = { .name = "Kernel code", }; -static struct resource data_resource = { .name = "Kernel data", }; -static struct resource bss_resource = { .name = "Kernel bss", }; - unsigned long __kaslr_offset __ro_after_init; EXPORT_SYMBOL(__kaslr_offset); @@ -469,31 +465,18 @@ static void __init mips_parse_crashkernel(void) } } + memblock_reserve(crashk_res.start, resource_size(&crashk_res)); + crashk_res.start = crash_base; crashk_res.end = crash_base + crash_size - 1; -} - -static void __init request_crashkernel(struct resource *res) -{ - int ret; - - if (crashk_res.start == crashk_res.end) - return; - ret = request_resource(res, &crashk_res); - if (!ret) - pr_info("Reserving %ldMB of memory at %ldMB for crashkernel\n", - (unsigned long)(resource_size(&crashk_res) >> 20), - (unsigned long)(crashk_res.start >> 20)); + pr_info("Reserving %lldMB of memory at %lldMB for crashkernel\n", + crash_base >> 20, crash_size); } #else /* !defined(CONFIG_KEXEC) */ static void __init mips_parse_crashkernel(void) { } - -static void __init request_crashkernel(struct resource *res) -{ -} #endif /* !defined(CONFIG_KEXEC) */ static void __init check_kernel_sections_mem(void) @@ -656,10 +639,6 @@ static void __init arch_mem_init(char **cmdline_p) mips_reserve_vmcore(); mips_parse_crashkernel(); -#ifdef CONFIG_KEXEC - if (crashk_res.start != crashk_res.end) - memblock_reserve(crashk_res.start, resource_size(&crashk_res)); -#endif device_tree_init(); /* @@ -683,53 +662,6 @@ static void __init arch_mem_init(char **cmdline_p) early_memtest(PFN_PHYS(ARCH_PFN_OFFSET), PFN_PHYS(max_low_pfn)); } -static void __init resource_init(void) -{ - phys_addr_t start, end; - u64 i; - - if (UNCAC_BASE != IO_BASE) - return; - - code_resource.start = __pa_symbol(&_text); - code_resource.end = __pa_symbol(&_etext) - 1; - data_resource.start = __pa_symbol(&_etext); - data_resource.end = __pa_symbol(&_edata) - 1; - bss_resource.start = __pa_symbol(&__bss_start); - bss_resource.end = __pa_symbol(&__bss_stop) - 1; - - for_each_mem_range(i, &start, &end) { - struct resource *res; - - res = memblock_alloc(sizeof(struct resource), SMP_CACHE_BYTES); - if (!res) - panic("%s: Failed to allocate %zu bytes\n", __func__, - sizeof(struct resource)); - - res->start = start; - /* - * In memblock, end points to the first byte after the - * range while in resourses, end points to the last byte in - * the range. - */ - res->end = end - 1; - res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; - res->name = "System RAM"; - - request_resource(&iomem_resource, res); - - /* - * We don't know which RAM region contains kernel data, - * so we try it repeatedly and let the resource manager - * test it. - */ - request_resource(res, &code_resource); - request_resource(res, &data_resource); - request_resource(res, &bss_resource); - request_crashkernel(res); - } -} - #ifdef CONFIG_SMP static void __init prefill_possible_map(void) { @@ -771,7 +703,7 @@ void __init setup_arch(char **cmdline_p) arch_mem_init(cmdline_p); dmi_setup(); - resource_init(); + memblock_setup_resources(); plat_smp_setup(); prefill_possible_map(); From patchwork Mon May 31 12:29:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12289295 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=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 953FEC47083 for ; Mon, 31 May 2021 12:31:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76D21610C9 for ; Mon, 31 May 2021 12:31:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231637AbhEaMdV (ORCPT ); Mon, 31 May 2021 08:33:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:38740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231580AbhEaMdM (ORCPT ); Mon, 31 May 2021 08:33:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 799556135C; Mon, 31 May 2021 12:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622464292; bh=Y7haZXG6LCrkyiNf4al3/zg3oLPp7ZoFJvZMl/Ul6YQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wq4e57ItDLEqmiEcvSEIAazH6yHLyfo64u0lSaJOoctDXfqqrPCsOjjERbZhZBIVx ZK0WoswUqkIc0oodQhu7GQS9m8Cp5JxXTpYzjq2rIR156egj11Bx2hYUbQiwWKkY7B mJKQSkpud+trIX7xSxyLexZAZqn62t9FWnfr2+o6LbNDLLnOsU82S94co+4gJQ3mO/ 64R7Y9hhxOF2VJMni93fZlVUjWekIqV7nr8ng/0Aye3mzetPS/DaJ0u/ty6v2T+sgy amdz73Z/NgZyyrLxs6sb6DzWfPEVjfKFvPEMbaL8jst2H7E5+We7Eq5jk09RocHzGu NPL1iwhT2hj/w== From: Mike Rapoport To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Catalin Marinas , Christian Borntraeger , David Hildenbrand , Heiko Carstens , Mike Rapoport , Mike Rapoport , Russell King , Thomas Bogendoerfer , Vasily Gorbik , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-s390@vger.kernel.org Subject: [RFC/RFT PATCH 5/5] arm64: switch to generic memblock_setup_resources() Date: Mon, 31 May 2021 15:29:59 +0300 Message-Id: <20210531122959.23499-6-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210531122959.23499-1-rppt@kernel.org> References: <20210531122959.23499-1-rppt@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org From: Mike Rapoport The implementation of resource setup on arm64 takes into account NOMAP regions and registers them as "Reserved" rather than as "System RAM". In addition, there is an extra pass that adds regions that were reserved in memblock to the resource tree as well. Update the generic version of memblock_setup_resources() to take into the account NOMAP regions and move the registration of the reserved regions to memblock to have all the "System RAM" related resource data structures and code close to each other. Only enable requests for the reserved resources if an architecture selects CONFIG_ARCH_WANT_RESERVE_MEMBLOCK_RESERVED_REGIONS. Signed-off-by: Mike Rapoport --- arch/Kconfig | 7 +++ arch/arm64/Kconfig | 1 + arch/arm64/kernel/setup.c | 101 +------------------------------------- mm/memblock.c | 73 +++++++++++++++++++++------ 4 files changed, 68 insertions(+), 114 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index c45b770d3579..9c999dc8ab47 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1275,6 +1275,13 @@ config ARCH_SPLIT_ARG64 config ARCH_HAS_ELFCORE_COMPAT bool +config ARCH_WANT_RESERVE_MEMBLOCK_RESERVED_REGIONS + bool + help + If an architecture requires that memory regions reserved in + memblock will appear as "Reserved" in the resource tree, select + this option. + source "kernel/gcov/Kconfig" source "scripts/gcc-plugins/Kconfig" diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 9f1d8566bbf9..0e1f41650a6a 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -93,6 +93,7 @@ config ARM64 select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) select ARCH_WANT_LD_ORPHAN_WARN + select ARCH_WANT_RESERVE_MEMBLOCK_RESERVED_REGIONS select ARCH_HAS_UBSAN_SANITIZE_ALL select ARM_AMBA select ARM_ARCH_TIMER diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 61845c0821d9..90e97cf70844 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -51,32 +51,8 @@ #include #include -static int num_standard_resources; -static struct resource *standard_resources; - phys_addr_t __fdt_pointer __initdata; -/* - * Standard memory resources - */ -static struct resource mem_res[] = { - { - .name = "Kernel code", - .start = 0, - .end = 0, - .flags = IORESOURCE_SYSTEM_RAM - }, - { - .name = "Kernel data", - .start = 0, - .end = 0, - .flags = IORESOURCE_SYSTEM_RAM - } -}; - -#define kernel_code mem_res[0] -#define kernel_data mem_res[1] - /* * The recorded values of x0 .. x3 upon kernel entry. */ @@ -214,81 +190,6 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys) dump_stack_set_arch_desc("%s (DT)", name); } -static void __init request_standard_resources(void) -{ - struct memblock_region *region; - struct resource *res; - unsigned long i = 0; - size_t res_size; - - kernel_code.start = __pa_symbol(_stext); - kernel_code.end = __pa_symbol(__init_begin - 1); - kernel_data.start = __pa_symbol(_sdata); - kernel_data.end = __pa_symbol(_end - 1); - - num_standard_resources = memblock.memory.cnt; - res_size = num_standard_resources * sizeof(*standard_resources); - standard_resources = memblock_alloc(res_size, SMP_CACHE_BYTES); - if (!standard_resources) - panic("%s: Failed to allocate %zu bytes\n", __func__, res_size); - - for_each_mem_region(region) { - res = &standard_resources[i++]; - if (memblock_is_nomap(region)) { - res->name = "reserved"; - res->flags = IORESOURCE_MEM; - } else { - res->name = "System RAM"; - res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; - } - res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region)); - res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1; - - request_resource(&iomem_resource, res); - - if (kernel_code.start >= res->start && - kernel_code.end <= res->end) - request_resource(res, &kernel_code); - if (kernel_data.start >= res->start && - kernel_data.end <= res->end) - request_resource(res, &kernel_data); -#ifdef CONFIG_KEXEC_CORE - /* Userspace will find "Crash kernel" region in /proc/iomem. */ - if (crashk_res.end && crashk_res.start >= res->start && - crashk_res.end <= res->end) - request_resource(res, &crashk_res); -#endif - } -} - -static int __init reserve_memblock_reserved_regions(void) -{ - u64 i, j; - - for (i = 0; i < num_standard_resources; ++i) { - struct resource *mem = &standard_resources[i]; - phys_addr_t r_start, r_end, mem_size = resource_size(mem); - - if (!memblock_is_region_reserved(mem->start, mem_size)) - continue; - - for_each_reserved_mem_range(j, &r_start, &r_end) { - resource_size_t start, end; - - start = max(PFN_PHYS(PFN_DOWN(r_start)), mem->start); - end = min(PFN_PHYS(PFN_UP(r_end)) - 1, mem->end); - - if (start > mem->end || end < mem->start) - continue; - - reserve_region_with_split(mem, start, end, "reserved"); - } - } - - return 0; -} -arch_initcall(reserve_memblock_reserved_regions); - u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID }; u64 cpu_logical_map(unsigned int cpu) @@ -359,7 +260,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) kasan_init(); - request_standard_resources(); + memblock_setup_resources(); early_ioremap_reset(); diff --git a/mm/memblock.c b/mm/memblock.c index 504435753259..82d4b0f5bf5e 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2094,12 +2094,15 @@ static struct resource __initdata *standard_resources[] = { #endif }; +static int num_resources; +static struct resource *resources; + void __init memblock_setup_resources(void) { struct resource *res, *kres, *sub_res; - phys_addr_t start, end; - int j; - u64 i; + struct memblock_region *region; + size_t res_size; + int i; code_resource.start = __pa_symbol(_text); code_resource.end = __pa_symbol(_etext)-1; @@ -2110,26 +2113,36 @@ void __init memblock_setup_resources(void) bss_resource.start = __pa_symbol(__bss_start); bss_resource.end = __pa_symbol(__bss_stop)-1; - for_each_mem_range(i, &start, &end) { - res = memblock_alloc(sizeof(*res), 8); - if (!res) - panic("%s: Failed to allocate %zu bytes align=0x%x\n", - __func__, sizeof(*res), 8); - res->flags = IORESOURCE_BUSY | IORESOURCE_SYSTEM_RAM; + num_resources = memblock.memory.cnt; + res_size = num_resources * sizeof(*resources); + resources = memblock_alloc(res_size, SMP_CACHE_BYTES); - res->name = "System RAM"; - res->start = start; + if (!resources) + panic("%s: Failed to allocate %zu bytes align=0x%x\n", + __func__, res_size, 8); + + res = resources; + for_each_mem_region(region) { + if (memblock_is_nomap(region)) { + res->name = "reserved"; + res->flags = IORESOURCE_MEM; + } else { + res->name = "System RAM"; + res->flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY; + } + res->start = region->base; /* * In memblock, end points to the first byte after the * range while in resourses, end points to the last byte in * the range. */ - res->end = end - 1; + res->end = region->base + region->size - 1; + request_resource(&iomem_resource, res); - for (j = 0; j < ARRAY_SIZE(standard_resources); j++) { - kres = standard_resources[j]; + for (i = 0; i < ARRAY_SIZE(standard_resources); i++) { + kres = standard_resources[i]; if (!kres->end || kres->start < res->start || kres->start > res->end) continue; @@ -2146,9 +2159,41 @@ void __init memblock_setup_resources(void) request_resource(res, kres); } } + + res++; } } +#ifdef CONFIG_ARCH_WANT_RESERVE_MEMBLOCK_RESERVED_REGIONS +static int __init reserve_memblock_reserved_regions(void) +{ + u64 i, j; + + for (i = 0; i < num_resources; ++i) { + struct resource *mem = &resources[i]; + phys_addr_t r_start, r_end, mem_size = resource_size(mem); + + if (!memblock_is_region_reserved(mem->start, mem_size)) + continue; + + for_each_reserved_mem_range(j, &r_start, &r_end) { + resource_size_t start, end; + + start = max(PFN_PHYS(PFN_DOWN(r_start)), mem->start); + end = min(PFN_PHYS(PFN_UP(r_end)) - 1, mem->end); + + if (start > mem->end || end < mem->start) + continue; + + reserve_region_with_split(mem, start, end, "reserved"); + } + } + + return 0; +} +arch_initcall(reserve_memblock_reserved_regions); +#endif + #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK) static int memblock_debug_show(struct seq_file *m, void *private)