Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4658196imm; Fri, 18 May 2018 08:36:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr39LcemAfBZksWt81UoJTGkdnzAiCzy+SlSnPWA6kV4714mlUV3UYr/jAbs0rlQ9mA71Ib X-Received: by 2002:a62:dc8a:: with SMTP id c10-v6mr9942462pfl.183.1526657792369; Fri, 18 May 2018 08:36:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526657792; cv=none; d=google.com; s=arc-20160816; b=gE0L3KKL/+On98Ui1ZsQtd/Ps8VjuAN+CFwAmo3eCMBdklfr4qyUWEHUBndhRY9pKA 1UgOmX6Yv4SzMiSrp0x9FQeVgTmNBmIHg8uCDY33krmlOGaqtVmo14fV0qMZ8c9l5qHt cOdAK4U/eKXMEDDZzcJ60BVhtt00v4Aq0uRb6wMNhh3Ob7gQ0mU9SeFGb3G4DkYrx39z lp6vZ7co+SW2dFwMnU6rrjoVjnBr0gw4w+v7ygqt6zW8nIvUH9Fgk6hq1tahbHIRO7q7 F6fD313Ei/ALcp670o2nxJZOvJxhq1uZQdiRoFSp4ZAW3CpM6bOCwt54LYV/UiQlTO/9 ucFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=siINpoFqPOwK9m4V+VoxlL3vWTQaVOOMDcgXmSnvhuQ=; b=KsL84KXTwQ5U3izNzLblbLgvd2qFyxfxkQiAoRL1JxJ293CvCHOjBp17TaQmrmQpLl A/Ky9dR6S/tIpySKC3D2Sc5XrR1Xr1ehPobBHDiQeHAhmn+4in+UfN/cycvlxwLCh/mq QGKhOVrlxYXYctBNrGdnEZA5Rd/eAWIUeDZtnkE7K7fFMNPQ9Uxtd3dT7n+UjvxrdpPN odfJL1EIN6G7hPXZBXCwnzHD30f66p7E/seeYchx/DNam3wt90I3sn1yXDE6Ts3587kw z+EkrqypVtz2nNxZ5VIOXU5d/fH4rNs/77xPU+ex05v5y39slcAK4eXrvtAIIz7O4k5u yYMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b37-v6si7921172pla.65.2018.05.18.08.36.17; Fri, 18 May 2018 08:36:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752056AbeERPf5 (ORCPT + 99 others); Fri, 18 May 2018 11:35:57 -0400 Received: from mail-ot0-f193.google.com ([74.125.82.193]:43280 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751577AbeERPfy (ORCPT ); Fri, 18 May 2018 11:35:54 -0400 Received: by mail-ot0-f193.google.com with SMTP id y10-v6so9571256otg.10; Fri, 18 May 2018 08:35:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=siINpoFqPOwK9m4V+VoxlL3vWTQaVOOMDcgXmSnvhuQ=; b=QtAcCCFYV1+IzQhznw2MKh0Y+nJJNYIlAnOnVOV1M0sLzBacq4iqHwgnYyTWerCilc CHE2hwBvybnHazuSX15swiCpq6b136BO/bmKk05KCdVMeo8mwkdDnXR3TMVIWylZzY/B F9uSe0RPZAPZaUj9+n/wuVDEkgj5JeXTluklDbFNopNlmdjwtxLdjSgk48GIuF78Yxlw xYGnva/I5XQQffXrpgmsOy9oOPz1UyTDlmN434V0B73jdgpweueNSWZd+tZhl/jv0cmQ RH+7f1rMAeUz9u+brOESsnu1ErDLHiGbX2DeA19lNj+Ft7DxLeHvNQsL6t8YqI73Tau5 L2VQ== X-Gm-Message-State: ALKqPwcpKCBcEyQ/JV13MVNCWuKqoUIvFsclMWWywAIkziZbmFpogCxe 31iFsgoU4W0XLAvYsrpgNA== X-Received: by 2002:a9d:5508:: with SMTP id l8-v6mr6212969oth.159.1526657753804; Fri, 18 May 2018 08:35:53 -0700 (PDT) Received: from localhost (216-188-254-6.dyn.grandenetworks.net. [216.188.254.6]) by smtp.gmail.com with ESMTPSA id n50-v6sm4724613otb.14.2018.05.18.08.35.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 May 2018 08:35:53 -0700 (PDT) Date: Fri, 18 May 2018 10:35:52 -0500 From: Rob Herring To: James Morse Cc: AKASHI Takahiro , catalin.marinas@arm.com, will.deacon@arm.com, dhowells@redhat.com, vgoyal@redhat.com, herbert@gondor.apana.org.au, davem@davemloft.net, dyoung@redhat.com, bhe@redhat.com, arnd@arndb.de, ard.biesheuvel@linaro.org, bhsharma@redhat.com, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH v9 07/11] arm64: kexec_file: add crash dump support Message-ID: <20180518153552.GA23468@rob-hp-laptop> References: <20180425062629.29404-1-takahiro.akashi@linaro.org> <20180425062629.29404-8-takahiro.akashi@linaro.org> <0aba6388-8a73-d371-7b92-3594639eb27e@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0aba6388-8a73-d371-7b92-3594639eb27e@arm.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 15, 2018 at 06:12:59PM +0100, James Morse wrote: > Hi guys, > > (CC: +RobH, devicetree list) Thanks. > On 25/04/18 07:26, AKASHI Takahiro wrote: > > Enabling crash dump (kdump) includes > > * prepare contents of ELF header of a core dump file, /proc/vmcore, > > using crash_prepare_elf64_headers(), and > > * add two device tree properties, "linux,usable-memory-range" and > > "linux,elfcorehdr", which represent repsectively a memory range > > to be used by crash dump kernel and the header's location BTW, I intend to move existing parsing these out of the arch code. Please don't add more DT handling to arch/ unless it is *really* arch specific. I'd assume that the next arch to add kexec support will use these bindings instead of the powerpc way. > kexec_file_load() on arm64 needs to be able to create a prop encoded array to > the FDT, but there doesn't appear to be a libfdt helper to do this. > > Akashi's code below adds fdt_setprop_range() to the arch code, and duplicates > bits of libfdt_internal.h to do the work. > > How should this be done? I'm assuming this is something we need a new API in > libfdt.h for. How do these come about, and is there an interim step we can use > until then? Submit patches to upstream dtc and then we can pull it in. Ahead of that you can add it to drivers/of/fdt.c (or maybe fdt_address.c because that's really what this is dealing with). libfdt has only recently gained the beginnings of address handling. > > Thanks! > > James > > > diff --git a/arch/arm64/kernel/machine_kexec_file.c b/arch/arm64/kernel/machine_kexec_file.c > > index 37c0a9dc2e47..ec674f4d267c 100644 > > --- a/arch/arm64/kernel/machine_kexec_file.c > > +++ b/arch/arm64/kernel/machine_kexec_file.c > > @@ -76,6 +81,78 @@ int arch_kexec_walk_mem(struct kexec_buf *kbuf, > > return ret; > > } > > > > +static int __init arch_kexec_file_init(void) > > +{ > > + /* Those values are used later on loading the kernel */ > > + __dt_root_addr_cells = dt_root_addr_cells; > > + __dt_root_size_cells = dt_root_size_cells; I intend to make dt_root_*_cells private, so don't add another user outside of drivers/of/. > > + > > + return 0; > > +} > > +late_initcall(arch_kexec_file_init); > > + > > +#define FDT_ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) > > +#define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) > > + > > +static int fdt_prop_len(const char *prop_name, int len) > > +{ > > + return (strlen(prop_name) + 1) + > > + sizeof(struct fdt_property) + > > + FDT_TAGALIGN(len); > > +} > > + > > +static bool cells_size_fitted(unsigned long base, unsigned long size) I can't imagine this would happen. However, when this is moved to drivers/of/ or dtc, these need to be u64 types to work on 32-bit. > > +{ > > + /* if *_cells >= 2, cells can hold 64-bit values anyway */ > > + if ((__dt_root_addr_cells == 1) && (base >= (1ULL << 32))) > > + return false; > > + > > + if ((__dt_root_size_cells == 1) && (size >= (1ULL << 32))) > > + return false; > > + > > + return true; > > +} > > + > > +static void fill_property(void *buf, u64 val64, int cells) > > +{ > > + u32 val32; This should be a __be32 or fdt32 type. So should buf. > > + > > + if (cells == 1) { > > + val32 = cpu_to_fdt32((u32)val64); > > + memcpy(buf, &val32, sizeof(val32)); > > + } else { > > + memset(buf, 0, cells * sizeof(u32) - sizeof(u64)); > > + buf += cells * sizeof(u32) - sizeof(u64); > > + > > + val64 = cpu_to_fdt64(val64); > > + memcpy(buf, &val64, sizeof(val64)); Look how of_read_number() is implemented. You should be able to do something similar here looping and avoiding the if/else. > > + } > > +} > > + > > +static int fdt_setprop_range(void *fdt, int nodeoffset, const char *name, > > + unsigned long addr, unsigned long size) A very generic sounding function, but really only works on addresses in children of the root node. > > +{ > > + void *buf, *prop; > > + size_t buf_size; > > + int result; > > + > > + buf_size = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32); > > + prop = buf = vmalloc(buf_size); This can go on the stack instead (and would be required to to work in libfdt). > > + if (!buf) > > + return -ENOMEM; > > + > > + fill_property(prop, addr, __dt_root_addr_cells); > > + prop += __dt_root_addr_cells * sizeof(u32); > > + > > + fill_property(prop, size, __dt_root_size_cells); > > + > > + result = fdt_setprop(fdt, nodeoffset, name, buf, buf_size); > > + > > + vfree(buf); > > + > > + return result; > > +} > > + > > static int setup_dtb(struct kimage *image, > > unsigned long initrd_load_addr, unsigned long initrd_len, > > char *cmdline, unsigned long cmdline_len, > > @@ -88,10 +165,26 @@ static int setup_dtb(struct kimage *image, > > int range_len; > > int ret; > > > > + /* check ranges against root's #address-cells and #size-cells */ > > + if (image->type == KEXEC_TYPE_CRASH && > > + (!cells_size_fitted(image->arch.elf_load_addr, > > + image->arch.elf_headers_sz) || > > + !cells_size_fitted(crashk_res.start, > > + crashk_res.end - crashk_res.start + 1))) { > > + pr_err("Crash memory region doesn't fit into DT's root cell sizes.\n"); > > + ret = -EINVAL; > > + goto out_err; > > + } > > + > > /* duplicate dt blob */ > > buf_size = fdt_totalsize(initial_boot_params); > > range_len = (__dt_root_addr_cells + __dt_root_size_cells) * sizeof(u32); > > > > + if (image->type == KEXEC_TYPE_CRASH) > > + buf_size += fdt_prop_len("linux,elfcorehdr", range_len) > > + + fdt_prop_len("linux,usable-memory-range", > > + range_len); > > + > > if (initrd_load_addr) > > buf_size += fdt_prop_len("linux,initrd-start", sizeof(u64)) > > + fdt_prop_len("linux,initrd-end", sizeof(u64)); > > @@ -113,6 +206,23 @@ static int setup_dtb(struct kimage *image, > > if (nodeoffset < 0) > > goto out_err; > > > > + if (image->type == KEXEC_TYPE_CRASH) { > > + /* add linux,elfcorehdr */ > > + ret = fdt_setprop_range(buf, nodeoffset, "linux,elfcorehdr", > > + image->arch.elf_load_addr, > > + image->arch.elf_headers_sz); > > + if (ret) > > + goto out_err; > > + > > + /* add linux,usable-memory-range */ > > + ret = fdt_setprop_range(buf, nodeoffset, > > + "linux,usable-memory-range", > > + crashk_res.start, > > + crashk_res.end - crashk_res.start + 1); > > + if (ret) > > + goto out_err; > > + } > > + > > /* add bootargs */ > > if (cmdline) { > > ret = fdt_setprop(buf, nodeoffset, "bootargs", >