From patchwork Tue Mar 20 10:43:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 10296799 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 E94AE602C2 for ; Tue, 20 Mar 2018 10:43:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D432A1FFDB for ; Tue, 20 Mar 2018 10:43:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7BA827F92; Tue, 20 Mar 2018 10:43:37 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 796EB1FFDB for ; Tue, 20 Mar 2018 10:43:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fL5DYHZl66Bzvn+nZbqR8vWXqH5Lhrs55R+ycfxJfNs=; b=UrtC3Rg2T88SLh pfUhV71f6G5Rq5YaUaMCIsOTwYUNyEMG5OqMy4CloxocnXII4qWm5maJlomjVopW9L36TV1zzKhML 6xcJN0z0llskm8dLU98hBU8T11GN6dug5LtLUtX3Uj1ZMdvuKWYtsUsqvPwJuQxfuWpcSQascNnDF UbDqAqpNrCaHgJYp9ubNGBqNetvH5CywPU2P2dioqMKM/FIgOSrrYMbMfYeG1msVTdey4SzQ2mmu2 CKYKmMb4a07a7wHXxehqbNMFlcDXrqNFOoG6otUoCvvNeGlQ/UEQKEz6O+pVUG7v/bn4lYzamthbV nS7PHC+V/UAFcDtJdZyQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1eyEjt-0005t4-3h; Tue, 20 Mar 2018 10:43:33 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1eyEjo-0005qQ-Gs for linux-arm-kernel@lists.infradead.org; Tue, 20 Mar 2018 10:43:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=1/Hvbo/+q1YIACVmRf6unL6OWeqgMeKjAbZKYdK4zl0=; b=N3+4lXfARCCmAnOzWPRVQUD0SW1eHi7KyECclGn+qxV7eq4JrKn7VB3MbC8mSg8GB8O5OqJyWOQakjkxneWQV/Ph6r9x3dG9MREbLay82F64xvnJCtARKB9LMjWBmlim+s2umUD0ScUDvv+hpC1/pTJYqK4uzPXOi5QH9VbR1wo=; Received: from n2100.armlinux.org.uk ([fd8f:7570:feb6:1:214:fdff:fe10:4f86]:55201) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1eyEjZ-0005C0-8T; Tue, 20 Mar 2018 10:43:13 +0000 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1eyEjS-0002zM-5Q; Tue, 20 Mar 2018 10:43:06 +0000 Date: Tue, 20 Mar 2018 10:43:02 +0000 From: Russell King - ARM Linux To: Arthur LAMBERT Subject: Re: issue with kexec/kdump on imx6ull Message-ID: <20180320104302.GG2743@n2100.armlinux.org.uk> References: <20180320100427.GA21933@arthur-bzh> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180320100427.GA21933@arthur-bzh> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180320_034329_207849_9232B1AE X-CRM114-Status: GOOD ( 27.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org 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 On Tue, Mar 20, 2018 at 11:04:27AM +0100, Arthur LAMBERT wrote: > Hi, > > I am trying to use kexec/kdump on imx6ull evaluation kit without success. > kernel : git://git.freescale.com/imx/linux-imx.git > kernel tag : rel_imx_4.9.x_1.0.0_ga > defconfig : imx_v7 > device tree : imx6ull-14x14-evk The wrong patch was merged into kexec-tools, breaking ARM support for kexec. I think I pointed this out to the kexec-tools maintainers after it had already taken ages to get the patches merged, but never received any response, so I now no longer care about the allegedly maintained kexec-tools, sorry. I've been considering putting a working git tree on git.armlinux.org.uk to replace the "official" kexec-tools. The patch which fixes the mis-merge is below: 8<===== From: Russell King Subject: [PATCH] ARM: read kernel size from zImage Signed-off-by: Russell King --- kexec/arch/arm/kexec-zImage-arm.c | 106 ++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 32 deletions(-) diff --git a/kexec/arch/arm/kexec-zImage-arm.c b/kexec/arch/arm/kexec-zImage-arm.c index a8c40cb6cd6a..76a0b5b66745 100644 --- a/kexec/arch/arm/kexec-zImage-arm.c +++ b/kexec/arch/arm/kexec-zImage-arm.c @@ -355,6 +355,34 @@ static int setup_dtb_prop(char **bufp, off_t *sizep, int parentoffset, return 0; } +static const struct zimage_tag *find_extension_tag(const char *buf, off_t len, + uint32_t tag_id) +{ + const struct zimage_header *hdr = (const struct zimage_header *)buf; + const struct zimage_tag *tag; + uint32_t offset, size; + uint32_t max = len - sizeof(struct tag_header); + + if (len < sizeof(*hdr) || + hdr->magic != ZIMAGE_MAGIC || + hdr->magic2 != ZIMAGE_MAGIC2) + return NULL; + + for (offset = hdr->extension_tag_offset; + (tag = (void *)(buf + offset)) != NULL && + offset < max && + (size = le32_to_cpu(byte_size(tag))) != 0 && + offset + size < len; + offset += size) { + dbgprintf(" offset 0x%08x tag 0x%08x size %u\n", + offset, le32_to_cpu(tag->hdr.tag), size); + if (tag->hdr.tag == tag_id) + return tag; + } + + return NULL; +} + int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, struct kexec_info *info) { @@ -362,6 +390,7 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, unsigned long base, kernel_base; unsigned int atag_offset = 0x1000; /* 4k offset from memory start */ unsigned int extra_size = 0x8000; /* TEXT_OFFSET */ + const struct zimage_tag *tag; size_t kernel_mem_size; const char *command_line; char *modified_cmdline = NULL; @@ -480,35 +509,6 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, if (size < len) len = size; } - - /* Do we have an extension table? */ - if (hdr->magic2 == ZIMAGE_MAGIC2 && !kexec_arm_image_size) { - uint32_t offset = hdr->extension_tag_offset; - uint32_t max = len - sizeof(struct tag_header); - struct zimage_tag *tag; - - dbgprintf("zImage has tags\n"); - - for (offset = hdr->extension_tag_offset; - (tag = (void *)(buf + offset)) != NULL && - offset < max && byte_size(tag) && - offset + byte_size(tag) < len; - offset += byte_size(tag)) { - dbgprintf(" offset 0x%08x tag 0x%08x size %u\n", - offset, tag->hdr.tag, byte_size(tag)); - if (tag->hdr.tag == ZIMAGE_TAG_KRNL_SIZE) { - uint32_t *p = (void *)buf + - tag->u.krnl_size.size_ptr; - - kexec_arm_image_size = - get_unaligned(p) + - tag->u.krnl_size.bss_size; - } - } - - dbgprintf("kernel image size: 0x%08x\n", - kexec_arm_image_size); - } } /* Handle android images, 2048 is the minimum page size */ @@ -553,9 +553,40 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, kernel_mem_size = len + 4; /* - * If the user didn't specify the size of the image, assume the - * maximum kernel compression ratio is 4. Note that we must - * include space for the compressed image here as well. + * Check for a kernel size extension, and set or validate the + * image size. This is the total space needed to avoid the + * boot kernel BSS, so other data (such as initrd) does not get + * overwritten. + */ + tag = find_extension_tag(buf, len, ZIMAGE_TAG_KRNL_SIZE); + if (tag) { + uint32_t *p = (void *)buf + le32_to_cpu(tag->u.krnl_size.size_ptr); + uint32_t edata_size = le32_to_cpu(get_unaligned(p)); + uint32_t bss_size = le32_to_cpu(tag->u.krnl_size.bss_size); + uint32_t kernel_size = edata_size + bss_size; + + /* + * While decompressing, the zImage is placed past _edata + * of the decompressed kernel. Ensure we account for that. + */ + if (kernel_size < edata_size + len) + kernel_size = edata_size + len; + + if (kexec_arm_image_size == 0) + kexec_arm_image_size = kernel_size; + else if (kexec_arm_image_size < kernel_size) { + fprintf(stderr, + "Kernel size is too small, increasing to 0x%lx\n", + (unsigned long)kernel_size); + kexec_arm_image_size = kernel_size; + } + } + + /* + * If the user didn't specify the size of the image, and we don't + * have the extension tables, assume the maximum kernel compression + * ratio is 4. Note that we must include space for the compressed + * image here as well. */ if (!kexec_arm_image_size) kexec_arm_image_size = len * 5; @@ -617,6 +648,10 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, */ initrd_base = kernel_base + _ALIGN(kexec_arm_image_size, page_size); + dbgprintf("%-6s: address=0x%08lx size=0x%08lx\n", "Kernel", + (unsigned long)kernel_base, + (unsigned long)kexec_arm_image_size); + if (ramdisk_buf) { /* * Find a hole to place the initrd. The crash kernel use @@ -630,6 +665,10 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, return -1; } + dbgprintf("%-6s: address=0x%08lx size=0x%08lx\n", "Initrd", + (unsigned long)initrd_base, + (unsigned long)initrd_size); + add_segment(info, ramdisk_buf, initrd_size, initrd_base, initrd_size); } @@ -708,6 +747,9 @@ int zImage_arm_load(int argc, char **argv, const char *buf, off_t len, return -1; } + dbgprintf("%-6s: address=0x%08lx size=0x%08lx\n", "DT", + (unsigned long)dtb_offset, (unsigned long)dtb_length); + add_segment(info, dtb_buf, dtb_length, dtb_offset, dtb_length); }