linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Nick Kossifidis <mick@ics.forth.gr>
Cc: linux-riscv <linux-riscv@lists.infradead.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 3/5] RISC-V: Improve init_resources
Date: Tue, 6 Apr 2021 09:19:52 +0200	[thread overview]
Message-ID: <CAMuHMdWi+wo0+PCR6B1wyXVesG-kL9NQt8XFBuWhZ3SdVUaLZg@mail.gmail.com> (raw)
In-Reply-To: <20210405085712.1953848-4-mick@ics.forth.gr>

Hi Nick,

Thanks for your patch!

On Mon, Apr 5, 2021 at 10:57 AM Nick Kossifidis <mick@ics.forth.gr> wrote:
> * Kernel region is always present and we know where it is, no
> need to look for it inside the loop, just ignore it like the
> rest of the reserved regions within system's memory.
>
> * Don't call memblock_free inside the loop, if called it'll split
> the region of pre-allocated resources in two parts, messing things
> up, just re-use the previous pre-allocated resource and free any
> unused resources after both loops finish.
>
> * memblock_alloc may add a region when called, so increase the
> number of pre-allocated regions by one to be on the safe side
> (reported and patched by Geert Uytterhoeven)
>
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

Where does this SoB come from?

> Signed-off-by: Nick Kossifidis <mick@ics.forth.gr>

> --- a/arch/riscv/kernel/setup.c
> +++ b/arch/riscv/kernel/setup.c

> @@ -129,53 +139,42 @@ static void __init init_resources(void)
>         struct resource *res = NULL;
>         struct resource *mem_res = NULL;
>         size_t mem_res_sz = 0;
> -       int ret = 0, i = 0;
> -
> -       code_res.start = __pa_symbol(_text);
> -       code_res.end = __pa_symbol(_etext) - 1;
> -       code_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> -
> -       rodata_res.start = __pa_symbol(__start_rodata);
> -       rodata_res.end = __pa_symbol(__end_rodata) - 1;
> -       rodata_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> -
> -       data_res.start = __pa_symbol(_data);
> -       data_res.end = __pa_symbol(_edata) - 1;
> -       data_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> +       int num_resources = 0, res_idx = 0;
> +       int ret = 0;
>
> -       bss_res.start = __pa_symbol(__bss_start);
> -       bss_res.end = __pa_symbol(__bss_stop) - 1;
> -       bss_res.flags = IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY;
> +       /* + 1 as memblock_alloc() might increase memblock.reserved.cnt */
> +       num_resources = memblock.memory.cnt + memblock.reserved.cnt + 1;
> +       res_idx = num_resources - 1;
>
> -       mem_res_sz = (memblock.memory.cnt + memblock.reserved.cnt) * sizeof(*mem_res);

Oh, you incorporated my commit ce989f1472ae350e ("RISC-V: Fix out-of-bounds
accesses in init_resources()") (from v5.12-rc4) into your patch.
Why? This means your patch does not apply against upstream.

> +       mem_res_sz = num_resources * sizeof(*mem_res);
>         mem_res = memblock_alloc(mem_res_sz, SMP_CACHE_BYTES);
>         if (!mem_res)
>                 panic("%s: Failed to allocate %zu bytes\n", __func__, mem_res_sz);

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

  reply	other threads:[~2021-04-06  7:20 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-05  8:57 [PATCH v3 0/5] RISC-V: Add kexec/kdump support Nick Kossifidis
2021-04-05  8:57 ` [PATCH v3 1/5] RISC-V: Add EM_RISCV to kexec UAPI header Nick Kossifidis
2021-04-23  3:30   ` Palmer Dabbelt
2021-04-05  8:57 ` [PATCH v3 2/5] RISC-V: Add kexec support Nick Kossifidis
2021-04-06 18:38   ` Alex Ghiti
2021-04-09 10:19     ` Nick Kossifidis
2021-04-23  3:30   ` Palmer Dabbelt
2021-04-05  8:57 ` [PATCH v3 3/5] RISC-V: Improve init_resources Nick Kossifidis
2021-04-06  7:19   ` Geert Uytterhoeven [this message]
2021-04-06  8:11     ` Nick Kossifidis
2021-04-06  8:22       ` Geert Uytterhoeven
2021-04-09 10:11         ` Nick Kossifidis
2021-04-23  3:30   ` Palmer Dabbelt
2021-04-05  8:57 ` [PATCH v3 4/5] RISC-V: Add kdump support Nick Kossifidis
2021-04-06 18:36   ` Alex Ghiti
2021-04-09 10:21     ` Nick Kossifidis
2021-04-23  3:30   ` Palmer Dabbelt
2021-04-05  8:57 ` [PATCH v3 5/5] RISC-V: Add crash kernel support Nick Kossifidis
2021-04-23  3:30   ` Palmer Dabbelt
2021-04-07  7:45 ` [PATCH v3 0/5] RISC-V: Add kexec/kdump support Yixun Lan
2021-04-07 16:29 ` Rob Herring
2021-04-09 10:02   ` Nick Kossifidis
2021-04-23  3:30 ` Palmer Dabbelt
2021-04-23  3:36   ` Nick Kossifidis
2021-04-23  3:48     ` Palmer Dabbelt
2021-04-23  3:53       ` Nick Kossifidis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMuHMdWi+wo0+PCR6B1wyXVesG-kL9NQt8XFBuWhZ3SdVUaLZg@mail.gmail.com \
    --to=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mick@ics.forth.gr \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).