Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3708020pxj; Tue, 15 Jun 2021 07:03:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLHf+t+t1Yv/KM7cmdK9WP1DK1kt+OIGMTyH4n9blrLF3IB6mBTHtJDn6MiMdDyHxpk4iw X-Received: by 2002:aa7:db95:: with SMTP id u21mr23590491edt.152.1623765817231; Tue, 15 Jun 2021 07:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623765817; cv=none; d=google.com; s=arc-20160816; b=Hc+aEGOoAu8stjH1KRDVfvgw7wYiF9Tnne+Z0tLhmqsCce1C/9r/0FG2YtCUIhvMne gGs5NN+mJEgHwQINsdm2HHDolUO9/ONiC6W/ZQv/GHBQPjTc3FV5DrhQDDIfiffPqdwX Sb87E/bAXx3fNN+4vZmtqwKs7WFoEUHefY0DLuZwTxqC5XJ8+9NVidfajxM+7xC/GXEe lScgnTZTfrv0+cJX4yT4g7nOd9LspJ8UgVSvYIglMJxdhgCg+4Nil4YZUZqfHzvMEGTn T1hMrgp3NNoNAsdczXs0ZDSqTyT6Og6tsZ/bltP2aVbuw/cJoxRfrWO/WEjx7eym1qBZ sBSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=uQvcw409bUYt5ntSksRRAtFhCkSszffh/wc89WWTrIQ=; b=JSCdrBDiUcm0LyZOkjLhGpesrFhS6+CwnA/gYoAr25cgc89oHkQhA0T0ZYiuLpGb2P qBW0axvUKxjNq3S72M8A2kGIHNO69/VG/zxsVaEp36tGvNvl6Dj4ZrDFABaQ+2r5MuZF s2r5Id93iAteze4Z+v2B3S0SZEv5pFQ3eoJM7c04IaFGYH3L1eRnXN/3kCADx940Yr2I 09HdR1vaFH+cqKTT/rkZLBR5b8vm11y8D3+7omHUnfLYSD5TIMgYN3i+NRO48UsjmIH/ K5MZHv9dyuXJfJMxLqeFvBLyi8aWPicvQ+tDLIjgL6kbV5tE0YTRiWxgldIqlHr/hzQV 1dYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rfpjv29R; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g22si14914415edr.155.2021.06.15.07.03.11; Tue, 15 Jun 2021 07:03:37 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rfpjv29R; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231274AbhFOOEG (ORCPT + 99 others); Tue, 15 Jun 2021 10:04:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:58640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231196AbhFOOEF (ORCPT ); Tue, 15 Jun 2021 10:04:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E26EF613F5; Tue, 15 Jun 2021 14:02:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623765720; bh=QlhAPeeyHHRjIGhNphYkDKi45QaQ5wrJVvOCJ5iwTZk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=rfpjv29R77uGBM9GpyweyP2mn6gvWGVSvO308lsxC06nt7DZixmwM+/1HVYX+4DvO MwqsUg6CAI/HB/Xg8d9KL6y5YnKIidcgnIzNPyvipMP/PsYTIcRbnhBzPcaw2YCruz FpiOnjAIoK7dYGKFuOnLSvZLNIqrAij0CEhDgX+m3AS5p/+qihR1rVKVWWeLyltBql uMvbNF7+FnpOmXJrx46WF6kAd25Ww7xeSEHEaloHSu4J8x+HdIAxzUliJrATrzXMpn +tLzcopXpl+0IFezIjCTDJnBO/1jaBY1A51ZjSAaWbqCl0nZNNACIgo+ElwtZI8t+B XbglZB58igmpA== Received: by mail-wr1-f46.google.com with SMTP id o3so18474052wri.8; Tue, 15 Jun 2021 07:02:00 -0700 (PDT) X-Gm-Message-State: AOAM530YXyJS+tbzk2+fN4hL2sZzcXuVBDugIIQoGoVvuMjQeKBKjYjS WZNN/VTLBicVzZqef+rNA3FKXd4nNVsTywbezw== X-Received: by 2002:a17:906:85d5:: with SMTP id i21mr20560813ejy.360.1623765708507; Tue, 15 Jun 2021 07:01:48 -0700 (PDT) MIME-Version: 1.0 References: <20210221174930.27324-1-nramas@linux.microsoft.com> <20210221174930.27324-6-nramas@linux.microsoft.com> In-Reply-To: From: Rob Herring Date: Tue, 15 Jun 2021 08:01:35 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v19 05/13] of: Add a common kexec FDT setup function To: Geert Uytterhoeven Cc: Lakshmi Ramasubramanian , Mimi Zohar , Thiago Jung Bauermann , AKASHI Takahiro , Greg KH , Will Deacon , Joe Perches , Catalin Marinas , Michael Ellerman , Stephen Rothwell , James Morse , Sasha Levin , Benjamin Herrenschmidt , Paul Mackerras , Frank Rowand , Vincenzo Frascino , Mark Rutland , dmitry.kasatkin@gmail.com, James Morris , "Serge E. Hallyn" , Pavel Tatashin , Allison Randal , Masahiro Yamada , Matthias Brugger , Hsin-Yi Wang , tao.li@vivo.com, Christophe Leroy , Prakhar Srivastava , balajib@linux.microsoft.com, linux-integrity , Linux Kernel Mailing List , Linux ARM , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , linuxppc-dev Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 15, 2021 at 6:18 AM Geert Uytterhoeven wrote: > > Hi Lakshmi and Rob, > > On Sun, Feb 21, 2021 at 6:52 PM Lakshmi Ramasubramanian > wrote: > > From: Rob Herring > > > > Both arm64 and powerpc do essentially the same FDT /chosen setup for > > kexec. The differences are either omissions that arm64 should have > > or additional properties that will be ignored. The setup code can be > > combined and shared by both powerpc and arm64. > > > > The differences relative to the arm64 version: > > - If /chosen doesn't exist, it will be created (should never happen). > > - Any old dtb and initrd reserved memory will be released. > > - The new initrd and elfcorehdr are marked reserved. > > - "linux,booted-from-kexec" is set. > > > > The differences relative to the powerpc version: > > - "kaslr-seed" and "rng-seed" may be set. > > - "linux,elfcorehdr" is set. > > - Any existing "linux,usable-memory-range" is removed. > > > > Combine the code for setting up the /chosen node in the FDT and updating > > the memory reservation for kexec, for powerpc and arm64, in > > of_kexec_alloc_and_setup_fdt() and move it to "drivers/of/kexec.c". > > > > Signed-off-by: Rob Herring > > Signed-off-by: Lakshmi Ramasubramanian > > > --- /dev/null > > +++ b/drivers/of/kexec.c > > > +/* > > + * of_kexec_alloc_and_setup_fdt - Alloc and setup a new Flattened Device Tree > > + * > > + * @image: kexec image being loaded. > > + * @initrd_load_addr: Address where the next initrd will be loaded. > > + * @initrd_len: Size of the next initrd, or 0 if there will be none. > > + * @cmdline: Command line for the next kernel, or NULL if there will > > + * be none. > > + * @extra_fdt_size: Additional size for the new FDT buffer. > > + * > > + * Return: fdt on success, or NULL errno on error. > > + */ > > +void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, > > + unsigned long initrd_load_addr, > > + unsigned long initrd_len, > > + const char *cmdline, size_t extra_fdt_size) > > +{ > > > + /* Did we boot using an initrd? */ > > + prop = fdt_getprop(fdt, chosen_node, "linux,initrd-start", NULL); > > + if (prop) { > > + u64 tmp_start, tmp_end, tmp_size; > > + > > + tmp_start = fdt64_to_cpu(*((const fdt64_t *) prop)); > > + > > + prop = fdt_getprop(fdt, chosen_node, "linux,initrd-end", NULL); > > + if (!prop) { > > + ret = -EINVAL; > > + goto out; > > + } > > + > > + tmp_end = fdt64_to_cpu(*((const fdt64_t *) prop)); > > Some kernel code assumes "linux,initrd-{start,end}" are 64-bit, > other code assumes 32-bit. It can be either. The above code was a merge of arm64 and powerpc both of which use 64-bit and still only runs on those arches. It looks like some powerpc platforms may use 32-bit, but this would have been broken before. The code in drivers/of/fdt.c handles either case. We should probably refactor early_init_dt_check_for_initrd() and this function to use a common routine. > linux/Documentation/arm/uefi.rst says 64-bit, > dt-schema/schemas/chosen.yaml says 32-bit. We should fix that. Rob