[PATCH] riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX
Geert Uytterhoeven
geert at linux-m68k.org
Sat Jan 9 04:35:03 EST 2021
Hi Atish,
On Fri, Jan 8, 2021 at 8:12 PM Atish Patra <atishp at atishpatra.org> wrote:
> On Fri, Jan 8, 2021 at 8:37 AM Geert Uytterhoeven <geert at linux-m68k.org> wrote:
> > On Mon, Nov 16, 2020 at 1:59 PM Sebastien Van Cauwenberghe
> > <svancau at gmail.com> wrote:
> > > From 5690c2f91d87a007babb13e2d2c9c45d1ff68b7a Mon Sep 17 00:00:00 2001
> > > From: Sebastien Van Cauwenberghe <svancau at gmail.com>
> > > Date: Mon, 16 Nov 2020 13:37:32 +0100
> > > Subject: [PATCH] riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX is
> > > disabled
> > >
> > > Allows the sections to be aligned on smaller boundaries and
> > > therefore results in a smaller kernel image size.
> > >
> > > Signed-off-by: Sebastien Van Cauwenberghe <svancau at gmail.com>
> >
> > Thanks for your patch!
> >
> > > --- a/arch/riscv/include/asm/set_memory.h
> > > +++ b/arch/riscv/include/asm/set_memory.h
> > > @@ -27,14 +27,14 @@ int set_direct_map_default_noflush(struct page *page);
> > >
> > > #endif /* __ASSEMBLY__ */
> > >
> > > -#ifdef CONFIG_ARCH_HAS_STRICT_KERNEL_RWX
> > > +#ifdef CONFIG_STRICT_KERNEL_RWX
> > > #ifdef CONFIG_64BIT
> > > #define SECTION_ALIGN (1 << 21)
> > > #else
> > > #define SECTION_ALIGN (1 << 22)
> > > #endif
> > > -#else /* !CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
> > > +#else /* !CONFIG_STRICT_KERNEL_RWX */
> > > #define SECTION_ALIGN L1_CACHE_BYTES
> > > -#endif /* CONFIG_ARCH_HAS_STRICT_KERNEL_RWX */
> > > +#endif /* CONFIG_STRICT_KERNEL_RWX */
> > >
> > > #endif /* _ASM_RISCV_SET_MEMORY_H */
> >
> > Since commit 19a00869028f4a28 ("RISC-V: Protect all kernel sections
> > including init early"), you also need (whitespace-damaged-gmail-patch):
> >
> > --- a/arch/riscv/kernel/setup.c
> > +++ b/arch/riscv/kernel/setup.c
> > @@ -293,6 +293,8 @@ void free_initmem(void)
> > unsigned long init_begin = (unsigned long)__init_begin;
> > unsigned long init_end = (unsigned long)__init_end;
> >
> > - set_memory_rw_nx(init_begin, (init_end - init_begin) >> PAGE_SHIFT);
> > + if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
> > + set_memory_rw_nx(init_begin,
> > + (init_end - init_begin) >> PAGE_SHIFT);
> > free_initmem_default(POISON_FREE_INITMEM);
> > }
> >
>
> Thanks for the fix. I guess you need to disable
> CONFIG_STRICT_KERNEL_RWX explicitly
> to notice this issue.
Indeed.
> > Else it crashes here without any kernel output.
> >
> > Feel free to fold this into your patch.
> >
>
> IMO, this can be a separate patch with Fixes tag.
Why? Sebastien's patch (which hasn't been applied yet) no longer works
due to interaction with a commit in v5.11-rc1.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at 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
More information about the linux-riscv
mailing list