Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp4269960pxt; Wed, 11 Aug 2021 01:53:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4kgmnCd6157O7ZdbaKO+I4xtQ9hAWiliQbZZ/pOMiKQU6xA4ZDh46mAVGoWxHNzZ/m+YB X-Received: by 2002:a17:906:551:: with SMTP id k17mr2587901eja.391.1628672002151; Wed, 11 Aug 2021 01:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628672002; cv=none; d=google.com; s=arc-20160816; b=znETakPLadXAdTxj69QxpQCxr9ck37Gsh7T2L2wEUFG/O/Ecct4FgW5D0CaKDaEafs +yGx9xpY4KaQZSpp7J5hDP9YSOCT0HaDaJhcBg++/CpXauuivlF/lNtqsj1LOVpZdr6s RI6IdRlBz6HrQTlfqHAJmNH+Tvd6ncWUzAkXaUzJi0bLmdzJ5bp+RF4QRwDJZ5pwJAh2 1ygSjKJd7QDxlQiVG45KjitVdnvptNhyy3homH8fqCjzH74Py3sdjUTY3cbBldeW9MLl 06bvxrcsJ1WyPDiVDJCZs8rnLqCn940X8XcveUOEFA1zOPbcJuSryYkFRms/Jic0yr7I SV6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=RLbsQ+M6vcwNouwMwyHvDx5eqpVljj/HaK1+Ekn8wxc=; b=CCtNp9sC8IQf8RydBc7pAuUOUg5rvE5HsSo60JFdHPT3H0zn2rbFjHPhl6WDbDgi5R GSSSjVXr4Vynq+EbtYzAfGHgzQa0yqqw3N+1InMT+fdC+k1WLecL2NPpb9qzfNGa+PO/ g0ey1fBLzEbmEO8gzBQCm+qbZgrFNHWplRUxenShmeOln+gvxaHqULN90PuyM9qI67iT bitXwkRBzlGsFBrGEMGEk/veLj63TE3ew8MH6HgP8MZZ1ymYp8mT3WuUGEKEAD0hjE9Z BYo0K6Mhcivd7tEN9c3/GprQl7v5POvCirXNHPGxgy2DaM8NcR2jpOstPPrPhQU+4Abz PvJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o10si24191604edw.236.2021.08.11.01.52.58; Wed, 11 Aug 2021 01:53:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236473AbhHKIwA (ORCPT + 99 others); Wed, 11 Aug 2021 04:52:00 -0400 Received: from newton.telenet-ops.be ([195.130.132.45]:53360 "EHLO newton.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233053AbhHKIv6 (ORCPT ); Wed, 11 Aug 2021 04:51:58 -0400 Received: from baptiste.telenet-ops.be (baptiste.telenet-ops.be [IPv6:2a02:1800:120:4::f00:13]) by newton.telenet-ops.be (Postfix) with ESMTPS id 4Gl3TK6v7YzMqlKB for ; Wed, 11 Aug 2021 10:51:33 +0200 (CEST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed20:438:1ff1:1071:f524]) by baptiste.telenet-ops.be with bizsmtp id g8rG2500G1gJxCh018rG4C; Wed, 11 Aug 2021 10:51:33 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mDjxE-001ya8-9x; Wed, 11 Aug 2021 10:51:16 +0200 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from ) id 1mDjxD-0058wx-B1; Wed, 11 Aug 2021 10:51:15 +0200 From: Geert Uytterhoeven To: Rob Herring , Russell King , Nicolas Pitre , Ard Biesheuvel , Linus Walleij , Catalin Marinas , Will Deacon , Thomas Bogendoerfer , Nick Kossifidis , Paul Walmsley , Palmer Dabbelt , Albert Ou , Frank Rowand , Dave Young Cc: Baoquan He , Vivek Goyal , Mike Rapoport , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-riscv@lists.infradead.org, kexec@lists.infradead.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH v5 3/9] of: fdt: Add generic support for handling elf core headers property Date: Wed, 11 Aug 2021 10:51:01 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are two methods to specify the location of the elf core headers: using the "elfcorehdr=" kernel parameter, as handled by generic code in kernel/crash_dump.c, or using the "linux,elfcorehdr" property under the "/chosen" node in the Device Tree, as handled by architecture-specific code in arch/arm64/mm/init.c. Extend support for "linux,elfcorehdr" to all platforms supporting DT by adding platform-agnostic handling for handling this property to the FDT core code. This can co-exist safely with the architecture-specific handling, until the latter has been removed. This requires moving the call to of_scan_flat_dt() up, as the code scanning the "/chosen" node now needs to be aware of the values of "#address-cells" and "#size-cells". Signed-off-by: Geert Uytterhoeven --- Notes: 1. To avoid reserving the region twice, this depends on "MIPS: Avoid duplicate elf core header reservation", 2. IA64 also has custom code to reserve the region, but is not affected, as IA64 does not use DT, 3. About the change to chosen.txt: I have a similar change for schemas/chosen.yaml in dt-schema. v5: - Handle the actual reservation in generic code, too, v4: - Use IS_ENABLED() instead of #ifdef, - Clarify what architecture-specific code is still responsible for. --- Documentation/devicetree/bindings/chosen.txt | 6 +- drivers/of/fdt.c | 59 +++++++++++++++++++- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/chosen.txt b/Documentation/devicetree/bindings/chosen.txt index 45e79172a646c537..5b0b94eb2d04e79d 100644 --- a/Documentation/devicetree/bindings/chosen.txt +++ b/Documentation/devicetree/bindings/chosen.txt @@ -106,9 +106,9 @@ respectively, of the root node. linux,elfcorehdr ---------------- -This property (currently used only on arm64) holds the memory range, -the address and the size, of the elf core header which mainly describes -the panicked kernel's memory layout as PT_LOAD segments of elf format. +This property holds the memory range, the address and the size, of the elf +core header which mainly describes the panicked kernel's memory layout as +PT_LOAD segments of elf format. e.g. / { diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 9e5074d52879649b..99be3e03af29089f 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) "OF: fdt: " fmt +#include #include #include #include @@ -581,6 +582,30 @@ static int __init __fdt_scan_reserved_mem(unsigned long node, const char *uname, return 0; } +/* + * reserve_elfcorehdr() - reserves memory for elf core header + * + * This function reserves the memory occupied by an elf core header + * described in the device tree. This region contains all the + * information about primary kernel's core image and is used by a dump + * capture kernel to access the system memory on primary kernel. + */ +static void __init reserve_elfcorehdr(void) +{ + if (!IS_ENABLED(CONFIG_CRASH_DUMP) || !elfcorehdr_size) + return; + + if (memblock_is_region_reserved(elfcorehdr_addr, elfcorehdr_size)) { + pr_warn("elfcorehdr is overlapped\n"); + return; + } + + memblock_reserve(elfcorehdr_addr, elfcorehdr_size); + + pr_info("Reserving %llu KiB of memory at 0x%llx for elfcorehdr\n", + elfcorehdr_size >> 10, elfcorehdr_addr); +} + /** * early_init_fdt_scan_reserved_mem() - create reserved memory regions * @@ -606,6 +631,7 @@ void __init early_init_fdt_scan_reserved_mem(void) of_scan_flat_dt(__fdt_scan_reserved_mem, NULL); fdt_init_reserved_mem(); + reserve_elfcorehdr(); } /** @@ -904,6 +930,32 @@ static inline void early_init_dt_check_for_initrd(unsigned long node) } #endif /* CONFIG_BLK_DEV_INITRD */ +/** + * early_init_dt_check_for_elfcorehdr - Decode elfcorehdr location from flat + * tree + * @node: reference to node containing elfcorehdr location ('chosen') + */ +static void __init early_init_dt_check_for_elfcorehdr(unsigned long node) +{ + const __be32 *prop; + int len; + + if (!IS_ENABLED(CONFIG_CRASH_DUMP)) + return; + + pr_debug("Looking for elfcorehdr property... "); + + prop = of_get_flat_dt_prop(node, "linux,elfcorehdr", &len); + if (!prop || (len < (dt_root_addr_cells + dt_root_size_cells))) + return; + + elfcorehdr_addr = dt_mem_next_cell(dt_root_addr_cells, &prop); + elfcorehdr_size = dt_mem_next_cell(dt_root_size_cells, &prop); + + pr_debug("elfcorehdr_start=0x%llx elfcorehdr_size=0x%llx\n", + elfcorehdr_addr, elfcorehdr_size); +} + #ifdef CONFIG_SERIAL_EARLYCON int __init early_init_dt_scan_chosen_stdout(void) @@ -1051,6 +1103,7 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, return 0; early_init_dt_check_for_initrd(node); + early_init_dt_check_for_elfcorehdr(node); /* Retrieve command line */ p = of_get_flat_dt_prop(node, "bootargs", &l); @@ -1195,14 +1248,14 @@ void __init early_init_dt_scan_nodes(void) { int rc = 0; + /* Initialize {size,address}-cells info */ + of_scan_flat_dt(early_init_dt_scan_root, NULL); + /* Retrieve various information from the /chosen node */ rc = of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line); if (!rc) pr_warn("No chosen node found, continuing without\n"); - /* Initialize {size,address}-cells info */ - of_scan_flat_dt(early_init_dt_scan_root, NULL); - /* Setup memory, calling early_init_dt_add_memory_arch */ of_scan_flat_dt(early_init_dt_scan_memory, NULL); } -- 2.25.1