From patchwork Mon Jun 6 17:00:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King X-Patchwork-Id: 9158859 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AD57A60759 for ; Mon, 6 Jun 2016 17:05:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DDE527B13 for ; Mon, 6 Jun 2016 17:05:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92F752834E; Mon, 6 Jun 2016 17:05:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2BFFD2834A for ; Mon, 6 Jun 2016 17:05:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b9xw3-0007Oa-Po; Mon, 06 Jun 2016 17:03:31 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b9xvw-0007Ci-K3 for linux-arm-kernel@bombadil.infradead.org; Mon, 06 Jun 2016 17:03:24 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by merlin.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1b9xvt-0005Fr-VZ for linux-arm-kernel@lists.infradead.org; Mon, 06 Jun 2016 17:03:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Date:Sender:Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References:In-Reply-To; bh=cAM5vbOSeIo6rLcAEv+VonnipoptMBKa5z+SE2NqPbA=; b=c5wMeXvMYgJRhF4fy/0PDQytCENgV/OFoz9snbimEaHMo4biell9jDI20g2QxBzqPIawElmKnXiDP/goql8X9t6oIUINQ7hDyuiYIb6VAVYqv+WCIsdgPg+KjRLhn7xHKylFJ774svqZWrGxjTZTdd4RekRp5J0a9amFrwI4v2s=; Received: from [2002:4e20:1eda:1:b4eb:e902:622d:f2f0] (port=45154 helo=e0050434b2927.dyn.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES128-SHA:128) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1b9xtI-0000Is-KG; Mon, 06 Jun 2016 18:00:41 +0100 Received: from rmk by e0050434b2927.dyn.armlinux.org.uk with local (Exim 4.82) (envelope-from ) id 1b9xt9-0003tS-Ng; Mon, 06 Jun 2016 18:00:31 +0100 In-Reply-To: <20160606164129.GM1041@n2100.armlinux.org.uk> References: <20160606164129.GM1041@n2100.armlinux.org.uk> From: Russell King To: kexec@lists.infradead.org,linux-arm-kernel@lists.infradead.org Subject: [PATCH kexec-tools v2 21/32] arm: parse crash_reserved_mem early MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Mon, 06 Jun 2016 18:00:31 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160606_130322_550847_284AB466 X-CRM114-Status: GOOD ( 22.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pratyush Anand , Baoquan He Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We parse the crash kernel memory region in several locations in the kexec tools - once to check that there's a region, another time for real when we're locating the memory regions to dump, and another while loading the image. Move the real parsing step to is_crashkernel_mem_reserved(), which matches what x86 is doing. Reviewed-by: Pratyush Anand Signed-off-by: Russell King --- kexec/arch/arm/crashdump-arm.c | 47 +++++++++++++++++++++++++++++++----------- kexec/arch/arm/iomem.h | 7 +++++++ 2 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 kexec/arch/arm/iomem.h diff --git a/kexec/arch/arm/crashdump-arm.c b/kexec/arch/arm/crashdump-arm.c index 195b43f..85afd9f 100644 --- a/kexec/arch/arm/crashdump-arm.c +++ b/kexec/arch/arm/crashdump-arm.c @@ -31,6 +31,7 @@ #include "../../kexec-elf.h" #include "../../crashdump.h" #include "crashdump-arm.h" +#include "iomem.h" #if __BYTE_ORDER == __LITTLE_ENDIAN #define ELFDATANATIVE ELFDATA2LSB @@ -139,9 +140,8 @@ static int get_kernel_page_offset(struct kexec_info *info, * @length: size of the memory region * * This function is called once for each memory region found in /proc/iomem. It - * locates system RAM and crashkernel reserved memory and places these to - * variables: @crash_memory_ranges and @crash_reserved_mem. Number of memory - * regions is placed in @crash_memory_nr_ranges. + * locates system RAM and places these into @crash_memory_ranges. Number of + * memory regions is placed in @crash_memory_nr_ranges. */ static int crash_range_callback(void *UNUSED(data), int UNUSED(nr), char *str, unsigned long long base, @@ -159,10 +159,6 @@ static int crash_range_callback(void *UNUSED(data), int UNUSED(nr), range->end = base + length - 1; range->type = RANGE_RAM; usablemem_rgns.size++; - } else if (strncmp(str, "Crash kernel\n", 13) == 0) { - crash_reserved_mem.start = base; - crash_reserved_mem.end = base + length - 1; - crash_reserved_mem.type = RANGE_RAM; } return 0; @@ -424,12 +420,39 @@ int load_crashdump_segments(struct kexec_info *info, char *mod_cmdline) return 0; } -int is_crashkernel_mem_reserved(void) +/** + * iomem_range_callback() - callback called for each iomem region + * @data: not used + * @nr: not used + * @str: name of the memory region (not NULL terminated) + * @base: start address of the memory region + * @length: size of the memory region + * + * This function is called for each memory range in /proc/iomem, and stores + * the location of the crash kernel range into @crash_reserved_mem. + */ +static int iomem_range_callback(void *UNUSED(data), int UNUSED(nr), + char *str, unsigned long long base, + unsigned long long length) { - uint64_t start, end; + if (strncmp(str, CRASH_KERNEL, strlen(CRASH_KERNEL)) == 0) { + crash_reserved_mem.start = base; + crash_reserved_mem.end = base + length - 1; + crash_reserved_mem.type = RANGE_RAM; + } + return 0; +} - if (parse_iomem_single("Crash kernel\n", &start, &end) == 0) - return start != end; +/** + * is_crashkernel_mem_reserved() - check for the crashkernel reserved region + * + * Check for the crashkernel reserved region in /proc/iomem, and return + * true if it is present, or false otherwise. We use this to store the + * location of this region. + */ +int is_crashkernel_mem_reserved(void) +{ + kexec_iomem_for_each_line(NULL, iomem_range_callback, NULL); - return 0; + return crash_reserved_mem.start != crash_reserved_mem.end; } diff --git a/kexec/arch/arm/iomem.h b/kexec/arch/arm/iomem.h new file mode 100644 index 0000000..81c593d --- /dev/null +++ b/kexec/arch/arm/iomem.h @@ -0,0 +1,7 @@ +#ifndef IOMEM_H +#define IOMEM_H + +#define SYSTEM_RAM "System RAM\n" +#define CRASH_KERNEL "Crash kernel\n" + +#endif