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.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 4831FC48BE5 for ; Tue, 15 Jun 2021 19:14:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0880E6109E for ; Tue, 15 Jun 2021 19:14:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0880E6109E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fTMd4y1I/mmniDcgHGYN76cTTsCnvFYBgrk7Imds27A=; b=jfWFiEWsEb6Ko3 VykyPvKO9QcmtRGnFF3Ym5lEEHjbFj/JpjV9c0MpLlGI8FHObIw7cYi0wZPrU9dYjztkhRitc+WJb 7zVxiH9f2d58V0nJvdXCN/QHQ65gHhmoN762iZMTfQKK3vpqJPhjfXx6VR39d7Y+N990sERoVzHpM gclAjX117OBpD2hWNudyFO7qnLrZoz0UybqVcv2iwIkLn/cHFxt+GtGgcwq08A5y988ivxfLNbovM B+ZD64efGAmFmG4ny0OndNtwIufiiqKySLjkKaHmJ8IgwBN3pVIwUpdgdK0pl55P0ojj/yW4a2HgG a4eR6svXEXW8yHrPM1ew==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ltETg-002Lml-MC; Tue, 15 Jun 2021 19:12:01 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lt9E0-000ByJ-Vi for linux-arm-kernel@bombadil.infradead.org; Tue, 15 Jun 2021 13:35:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=jrlwSWatHznx383NLiMm7Z2IuN1e5i6noGzyC8CFebk=; b=EUonrcjNUV9uHGoYzorniFdjsq yeNnq/vdUtq+hHneyKyE68BdPWWENLYH8oJhAvjJCPe703KFYZdwtcQO3xCmEXO/3APPuIBPWbZll Vbvt+3jY/NI1p+IHYjPKjMguYDydrJzcFyIdeKDWcL1wgTxLRaEXi3BDiY0yuSiYY2o1XcEEIpN0Z ohWR7DPZL9vm33UJKur0Q/AlmCncCGYF2hGrR7/RwCs8MR8BJXO1iyS5gF2R5paqP7dkGqNRGWzJs u3nsdRvkwsQSqM1HGAe++rZV6Cxwi4DkEie4ltoIit2co9xfxo2X0k/5jBtGjFUESzoMvI1akBJbz gvYIgKKw==; Received: from mail-vs1-f52.google.com ([209.85.217.52]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lt817-007qIX-BP for linux-arm-kernel@lists.infradead.org; Tue, 15 Jun 2021 12:18:14 +0000 Received: by mail-vs1-f52.google.com with SMTP id y207so9638783vsy.12 for ; 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=kQQO7xP0tQwLAYc+HTf1gBvsVLYC9/yIwAFBrWHf54zy5iCxYYvXqSrlFE+5cJzjG2 T5gTNAB/zny28S2WGakITqlxUgIr9jMmg+DQyLcabqyqHaa6hzkX1T8BjyngkxBqxEl1 AzhDXZ8z+xXsydPF2lDK41fgXjgY5kbNAl2pBnZ0zSXA96E5kkTA9KY1jIYfy1E9eGja PS30Y+nXqmG3bvhseN13xA3gTXvTiGJiX9lxC+LJgqJHBSZId1IMxSlrZVwE2MYX66s9 qlDkPXNrp8yCIIqJCr1greUcWO3ock9BgYmIizcE4DPvsMxMyPC4RhzlZcwVGwE5L7yo x+/w== X-Gm-Message-State: AOAM531kqrcuN84tTw2hv8hjFoPb1Mz4JBRILwBfJlJe6l7CIrDab2Po NhEhcKy7yZ+4vz9TmPbGaQndHD8j7Z4goTMPKrg= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210615_131812_353713_C0EBF9B9 X-CRM114-Status: GOOD ( 34.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel