From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 039EBC48BDF for ; Tue, 15 Jun 2021 14:02:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D344761446 for ; Tue, 15 Jun 2021 14:02:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231265AbhFOOEK (ORCPT ); Tue, 15 Jun 2021 10:04:10 -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-Google-Smtp-Source: ABdhPJxVqI8MHrcAWKd/OVKi4zXYd9o5Ej5sqMSK1SDKoChQIuRHCXHX7nfhLloiCMRd7u65oO394YM97kSgD621jRA= 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