[PATCH] riscv: Align on L1_CACHE_BYTES when STRICT_KERNEL_RWX

Atish Patra atishp at atishpatra.org
Mon Jan 11 14:40:10 EST 2021


On Sat, Jan 9, 2021 at 1:35 AM Geert Uytterhoeven <geert at linux-m68k.org> wrote:
>
> 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.
>

Technically, Sebastien's patch was an improvement while this one fixes
an issue so that the Fixes tag can be added.
But the original patch was merged in this cycle only. So these changes
can be a single change as long as it is sent as an rc fix.
I am fine with either way.

@Sebastien: Can you send the updated patch soon so that palmer can
pull this one as an RC fix?


> 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



--
Regards,
Atish



More information about the linux-riscv mailing list