All of lore.kernel.org
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: alex@ghiti.fr
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Damien Le Moal <damien.lemoal@wdc.com>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-riscv <linux-riscv@lists.infradead.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] riscv: Only extend kernel reservation if mapped read-only
Date: Thu, 29 Apr 2021 16:41:21 +0200	[thread overview]
Message-ID: <CAMuHMdWV69hjaja=8YyjuvTUDwrO_oryJzhwgoR4Kfz0esUhZg@mail.gmail.com> (raw)
In-Reply-To: <605dc5e8-0a41-7458-6037-d6263b0ffd59@ghiti.fr>

Hi Alex,

On Thu, Apr 29, 2021 at 4:09 PM Alex Ghiti <alex@ghiti.fr> wrote:
> Le 4/28/21 à 9:45 AM, Geert Uytterhoeven a écrit :
> > When the kernel mapping was moved outside of the linear mapping, the
> > kernel memory reservation was increased, to take into account mapping
> > granularity.  However, this is done unconditionally, regardless of
> > whether the kernel memory is mapped read-only or not.
> >
> > If this extension is not needed, up to 2 MiB may be lost, which has a
> > big impact on e.g. Canaan K210 (64-bit nommu) platforms with only 8 MiB
> > of RAM.
> >
> > Reclaim the lost memory by only extending the reserved region when
> > needed, i.e. matching the conditional logic around the call to
> > protect_kernel_linear_mapping_text_rodata().
> >
> > Fixes: 2bfc6cd81bd17e43 ("riscv: Move kernel mapping outside of linear mapping")
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > ---
> > Only tested on K210 (SiPeed MAIX BiT):
> >
> >      -Memory: 5852K/8192K available (1344K kernel code, 147K rwdata, 272K rodata, 106K init, 72K bss, 2340K reserved, 0K cma-reserved)
> >      +Memory: 5948K/8192K available (1344K kernel code, 147K rwdata, 272K rodata, 106K init, 72K bss, 2244K reserved, 0K cma-reserved)
> >
> > Yes, I was lucky, as only 96 KiB was lost ;-)
> > ---
> >   arch/riscv/mm/init.c | 10 ++++++++--
> >   1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> > index 788eb222deacf994..3439783f26abc488 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -136,11 +136,17 @@ void __init setup_bootmem(void)
> >
> >       /*
> >        * Reserve from the start of the kernel to the end of the kernel
> > -      * and make sure we align the reservation on PMD_SIZE since we will
> > +      */
> > +#if defined(CONFIG_STRICT_KERNEL_RWX) && defined(CONFIG_64BIT) && \
> > +    defined(CONFIG_MMU) && !defined(CONFIG_XIP_KERNEL)
>
> ARCH_HAS_STRICT_KERNEL_RWX depends on MMU and !XIP_KERNEL so I think you
> can get rid of those checks.

Thanks, you're right.  Will simplify in v2.

I'll also clean up the other location where this was copied from.

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

WARNING: multiple messages have this Message-ID (diff)
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: alex@ghiti.fr
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	 Albert Ou <aou@eecs.berkeley.edu>,
	Damien Le Moal <damien.lemoal@wdc.com>,
	 Arnd Bergmann <arnd@arndb.de>,
	linux-riscv <linux-riscv@lists.infradead.org>,
	 Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] riscv: Only extend kernel reservation if mapped read-only
Date: Thu, 29 Apr 2021 16:41:21 +0200	[thread overview]
Message-ID: <CAMuHMdWV69hjaja=8YyjuvTUDwrO_oryJzhwgoR4Kfz0esUhZg@mail.gmail.com> (raw)
In-Reply-To: <605dc5e8-0a41-7458-6037-d6263b0ffd59@ghiti.fr>

Hi Alex,

On Thu, Apr 29, 2021 at 4:09 PM Alex Ghiti <alex@ghiti.fr> wrote:
> Le 4/28/21 à 9:45 AM, Geert Uytterhoeven a écrit :
> > When the kernel mapping was moved outside of the linear mapping, the
> > kernel memory reservation was increased, to take into account mapping
> > granularity.  However, this is done unconditionally, regardless of
> > whether the kernel memory is mapped read-only or not.
> >
> > If this extension is not needed, up to 2 MiB may be lost, which has a
> > big impact on e.g. Canaan K210 (64-bit nommu) platforms with only 8 MiB
> > of RAM.
> >
> > Reclaim the lost memory by only extending the reserved region when
> > needed, i.e. matching the conditional logic around the call to
> > protect_kernel_linear_mapping_text_rodata().
> >
> > Fixes: 2bfc6cd81bd17e43 ("riscv: Move kernel mapping outside of linear mapping")
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> > ---
> > Only tested on K210 (SiPeed MAIX BiT):
> >
> >      -Memory: 5852K/8192K available (1344K kernel code, 147K rwdata, 272K rodata, 106K init, 72K bss, 2340K reserved, 0K cma-reserved)
> >      +Memory: 5948K/8192K available (1344K kernel code, 147K rwdata, 272K rodata, 106K init, 72K bss, 2244K reserved, 0K cma-reserved)
> >
> > Yes, I was lucky, as only 96 KiB was lost ;-)
> > ---
> >   arch/riscv/mm/init.c | 10 ++++++++--
> >   1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> > index 788eb222deacf994..3439783f26abc488 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -136,11 +136,17 @@ void __init setup_bootmem(void)
> >
> >       /*
> >        * Reserve from the start of the kernel to the end of the kernel
> > -      * and make sure we align the reservation on PMD_SIZE since we will
> > +      */
> > +#if defined(CONFIG_STRICT_KERNEL_RWX) && defined(CONFIG_64BIT) && \
> > +    defined(CONFIG_MMU) && !defined(CONFIG_XIP_KERNEL)
>
> ARCH_HAS_STRICT_KERNEL_RWX depends on MMU and !XIP_KERNEL so I think you
> can get rid of those checks.

Thanks, you're right.  Will simplify in v2.

I'll also clean up the other location where this was copied from.

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-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2021-04-29 14:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28 13:45 [PATCH] riscv: Only extend kernel reservation if mapped read-only Geert Uytterhoeven
2021-04-28 13:45 ` Geert Uytterhoeven
2021-04-29 14:09 ` Alex Ghiti
2021-04-29 14:09   ` Alex Ghiti
2021-04-29 14:41   ` Geert Uytterhoeven [this message]
2021-04-29 14:41     ` Geert Uytterhoeven

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='CAMuHMdWV69hjaja=8YyjuvTUDwrO_oryJzhwgoR4Kfz0esUhZg@mail.gmail.com' \
    --to=geert@linux-m68k.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=arnd@arndb.de \
    --cc=damien.lemoal@wdc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.