[PATCH V4 4/8] riscv: traps: Add noinstr to prevent instrumentation inserted
Peter Zijlstra
peterz at infradead.org
Sun Sep 11 08:09:25 PDT 2022
On Sat, Sep 10, 2022 at 05:17:44PM +0800, Guo Ren wrote:
> > > -asmlinkage __visible __trap_section void name(struct pt_regs *regs) \
> > > +asmlinkage __visible __trap_section void noinstr name(struct pt_regs *regs) \
> >
> > But now you have __trap_section and noinstr both adding a section
> > attribute.
>
> Oops, thx for correcting. Here is my solution.
>
> diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
> index 635e6ec26938..eba744caa711 100644
> --- a/arch/riscv/kernel/traps.c
> +++ b/arch/riscv/kernel/traps.c
> @@ -92,9 +92,11 @@ static void do_trap_error(struct pt_regs *regs, int
> signo, int code,
> }
>
> #if defined(CONFIG_XIP_KERNEL) && defined(CONFIG_RISCV_ALTERNATIVE)
> -#define __trap_section __section(".xip.traps")
> +#define __trap_section \
> + noinline notrace __attribute((__section__(".xip.traps"))) \
> + __no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage
> #else
> -#define __trap_section
> +#define __trap_section noinstr
> #endif
This is almost guaranteed to get out of sync when the compiler guys add
yet another sanitizier. Please consider picking up this patch:
https://lore.kernel.org/all/20211110115736.3776-7-jiangshanlai@gmail.com/
and using __noinstr_section(".xip.traps")
More information about the linux-riscv
mailing list