From patchwork Tue May 3 10:22:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King X-Patchwork-Id: 9002711 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8E44E9F1C1 for ; Tue, 3 May 2016 10:43:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 97E7B201B4 for ; Tue, 3 May 2016 10:43:48 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id B8F8E2011D for ; Tue, 3 May 2016 10:43:47 +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 1axXlg-0007W8-5U; Tue, 03 May 2016 10:41:28 +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 1axXis-00028N-8n for linux-arm-kernel@bombadil.infradead.org; Tue, 03 May 2016 10:38:34 +0000 Received: from pandora.arm.linux.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 1axXU9-0002kR-FE for linux-arm-kernel@lists.infradead.org; Tue, 03 May 2016 10:23:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.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=eXZAsLeCGDNAW/RauCSlRdUkOTnWZGk6KT4HHTKz1rg=; b=hHvf4T7hbzLJaKP+x0rsK5nujJeEYZoOPuPgJAkTlahuSNdmnhBCoHdKJUsVs5bBMKI+JMNSw/AOJUhW+n23F9eFOaGkRbJ1c12o2Sc5GilyEoUadxNnX1MK6SlfLyrOjVaJuU3zxOXp6bGtcxL96ysO5C69VNySVdRrq0dTr+c=; Received: from [2001:4d48:ad52:3201:452d:3855:1c55:6d46] (port=48574 helo=e0050434b2927.dyn.arm.linux.org.uk) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:DHE-RSA-AES128-SHA:128) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1axXTi-0004xx-Q8; Tue, 03 May 2016 11:22:55 +0100 Received: from rmk by e0050434b2927.dyn.arm.linux.org.uk with local (Exim 4.82) (envelope-from ) id 1axXTg-0004iz-CQ; Tue, 03 May 2016 11:22:52 +0100 In-Reply-To: References: From: Russell King To: kexec@lists.infradead.org,linux-arm-kernel@lists.infradead.org Subject: [PATCH kexec-tools 21/32] arm: parse crash_reserved_mem early MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Tue, 03 May 2016 11:22:52 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160503_062322_161625_7025800E X-CRM114-Status: GOOD ( 22.99 ) X-Spam-Score: -5.3 (-----) 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 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.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. Signed-off-by: Russell King Reviewed-by: Pratyush Anand --- 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