lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMuHMdVSuNS4edh-zM0_sbC0i1AAjQ9Y0n_8Mjz=3CALkW4pgg@mail.gmail.com>
Date:   Tue, 15 Jun 2021 14:17:59 +0200
From:   Geert Uytterhoeven <geert@...ux-m68k.org>
To:     Lakshmi Ramasubramanian <nramas@...ux.microsoft.com>,
        Rob Herring <robh@...nel.org>
Cc:     Mimi Zohar <zohar@...ux.ibm.com>,
        Thiago Jung Bauermann <bauerman@...ux.ibm.com>,
        AKASHI Takahiro <takahiro.akashi@...aro.org>,
        Greg KH <gregkh@...uxfoundation.org>,
        Will Deacon <will@...nel.org>, Joe Perches <joe@...ches.com>,
        Catalin Marinas <catalin.marinas@....com>,
        Michael Ellerman <mpe@...erman.id.au>,
        Stephen Rothwell <sfr@...b.auug.org.au>,
        James Morse <james.morse@....com>,
        Sasha Levin <sashal@...nel.org>,
        Benjamin Herrenschmidt <benh@...nel.crashing.org>,
        Paul Mackerras <paulus@...ba.org>,
        Frank Rowand <frowand.list@...il.com>,
        Vincenzo Frascino <vincenzo.frascino@....com>,
        Mark Rutland <mark.rutland@....com>, dmitry.kasatkin@...il.com,
        James Morris <jmorris@...ei.org>,
        "Serge E. Hallyn" <serge@...lyn.com>,
        Pavel Tatashin <pasha.tatashin@...een.com>,
        Allison Randal <allison@...utok.net>,
        Masahiro Yamada <masahiroy@...nel.org>,
        Matthias Brugger <mbrugger@...e.com>,
        Hsin-Yi Wang <hsinyi@...omium.org>, tao.li@...o.com,
        Christophe Leroy <christophe.leroy@....fr>,
        prsriva@...ux.microsoft.com, balajib@...ux.microsoft.com,
        linux-integrity <linux-integrity@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Linux ARM <linux-arm-kernel@...ts.infradead.org>,
        "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" 
        <devicetree@...r.kernel.org>,
        linuxppc-dev <linuxppc-dev@...ts.ozlabs.org>
Subject: Re: [PATCH v19 05/13] of: Add a common kexec FDT setup function

Hi Lakshmi and Rob,

On Sun, Feb 21, 2021 at 6:52 PM Lakshmi Ramasubramanian
<nramas@...ux.microsoft.com> wrote:
> From: Rob Herring <robh@...nel.org>
>
> 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 <robh@...nel.org>
> Signed-off-by: Lakshmi Ramasubramanian <nramas@...ux.microsoft.com>

> --- /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@...ux-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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ