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=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 38C88C48BE8 for ; Tue, 15 Jun 2021 12:18:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22F6C61463 for ; Tue, 15 Jun 2021 12:18:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230303AbhFOMUS (ORCPT ); Tue, 15 Jun 2021 08:20:18 -0400 Received: from mail-vs1-f45.google.com ([209.85.217.45]:33345 "EHLO mail-vs1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230225AbhFOMUQ (ORCPT ); Tue, 15 Jun 2021 08:20:16 -0400 Received: by mail-vs1-f45.google.com with SMTP id j8so4772614vsd.0; Tue, 15 Jun 2021 05:18:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jrlwSWatHznx383NLiMm7Z2IuN1e5i6noGzyC8CFebk=; b=JXgz3Hk+7sIEaidPVL0SjP1aAxZguujDNAUK4cz9GPtzwTgirq8WWB3HoXQhkSYGkB QOd9ExbCf3xlkp/alTx6m9LayVnrDGHGP7L2aI8qPwTYtew+pjUCQRvBwKRR7xL1zfYa 1Wtj+oFR79fULkbH6/2E6ANthEXHa1a7oeG7D6esCAXgT0MbLjWOPDDVSfeRJTfKAq22 O/7DZIjIn/1luKveEk2JbOX4/O2YTg1NY+GvBApFTiYiO2oM9SOWjw8FqROIVFW7k/tH 73EsJW8PpaC88s6oAAcWPw/C0euP014L7eEZjMedipVBhIE2AGzKVtK3Ud1UrewlNoYl 0f5Q== X-Gm-Message-State: AOAM530ruPR+f+h2nkXM7AH1VpzbH9kXv46gJ8JtRkrWWNMng0IhbR+6 HvYvu7P4J1SD26nrRjnH0CVDZOL/18/qbNTBbLM= X-Google-Smtp-Source: ABdhPJyWLBtsARFbraykVxhSly+mYdsijjLf5u4llpgj1CcBtHFQinLCCrvpCrriX7X558sqTXYumrMOgaLjD7ZGGnM= X-Received: by 2002:a05:6102:2011:: with SMTP id p17mr4770704vsr.40.1623759490847; Tue, 15 Jun 2021 05:18:10 -0700 (PDT) MIME-Version: 1.0 References: <20210221174930.27324-1-nramas@linux.microsoft.com> <20210221174930.27324-6-nramas@linux.microsoft.com> In-Reply-To: <20210221174930.27324-6-nramas@linux.microsoft.com> From: Geert Uytterhoeven Date: Tue, 15 Jun 2021 14:17:59 +0200 Message-ID: Subject: Re: [PATCH v19 05/13] of: Add a common kexec FDT setup function To: Lakshmi Ramasubramanian , Rob Herring Cc: 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 , prsriva@linux.microsoft.com, 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 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. linux/Documentation/arm/uefi.rst says 64-bit, dt-schema/schemas/chosen.yaml says 32-bit. > + > + /* > + * kexec reserves exact initrd size, while firmware may > + * reserve a multiple of PAGE_SIZE, so check for both. > + */ > + tmp_size = tmp_end - tmp_start; > + ret = fdt_find_and_del_mem_rsv(fdt, tmp_start, tmp_size); > + if (ret == -ENOENT) > + ret = fdt_find_and_del_mem_rsv(fdt, tmp_start, > + round_up(tmp_size, PAGE_SIZE)); > + if (ret == -EINVAL) > + goto out; > + } > + > + /* add initrd-* */ > + if (initrd_load_addr) { > + ret = fdt_setprop_u64(fdt, chosen_node, FDT_PROP_INITRD_START, > + initrd_load_addr); > + if (ret) > + goto out; > + > + ret = fdt_setprop_u64(fdt, chosen_node, FDT_PROP_INITRD_END, > + initrd_load_addr + initrd_len); > + if (ret) > + goto out; > + > + ret = fdt_add_mem_rsv(fdt, initrd_load_addr, initrd_len); > + if (ret) > + goto out; > + > + } else { > + ret = fdt_delprop(fdt, chosen_node, FDT_PROP_INITRD_START); > + if (ret && (ret != -FDT_ERR_NOTFOUND)) > + goto out; > + > + ret = fdt_delprop(fdt, chosen_node, FDT_PROP_INITRD_END); > + if (ret && (ret != -FDT_ERR_NOTFOUND)) > + goto out; > + } Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds