Re: [RFC][PATCH 6/6] x86/mce: Dont use noinstr for now

From: Peter Zijlstra
Date: Fri Jan 08 2021 - 15:44:19 EST


On Thu, Jan 07, 2021 at 11:06:26AM +0100, Borislav Petkov wrote:
> On Wed, Jan 06, 2021 at 03:57:55PM +0100, Boris Petkov wrote:
> > Another thing that we could do is carve out only the stuff which needs
> > to be noinstr into a separate compilation unit and disable tracing
> > only for that while keeping the rest traceable. Need to try it to see
> > how ugly it'll get...
>
> Something like the below, it barely builds.
>
> I haven't found out whether I can even do
>
> ccflags-remove
>
> on a per-file basis, I guess I cannot so that's not there yet.
>
> core_noinstr.c ended up containing all the code needed by the #MC
> handler so that should be ok-ish, carve-out-wise.
>
> Also, I've exported a bunch of functions which are in mce/core.c through
> the internal.h header so that core_noinstr.c can call them. There are
> no more objtool warnings but if it turns out that we have to move those
> functions:
>
> +/* core_noinstr.c */
> +bool mce_check_crashing_cpu(void);
> +void print_mce(struct mce *m);
> +void mce_reset(void);
> +bool whole_page(struct mce *m);
> +u64 mce_rdmsrl(u32 msr);
> +void mce_wrmsrl(u32 msr, u64 v);
> +void mce_read_aux(struct mce *m, int i);
> +void mce_gather_info(struct mce *m, struct pt_regs *regs);
>
> to core_noinstr.c after all, then we can do your solution directly.
>
> Ok, gnight. :-)
>
> ---
> diff --git a/arch/x86/kernel/cpu/mce/Makefile b/arch/x86/kernel/cpu/mce/Makefile
> index 9f020c994154..2fa36118a05f 100644
> --- a/arch/x86/kernel/cpu/mce/Makefile
> +++ b/arch/x86/kernel/cpu/mce/Makefile
> @@ -1,5 +1,10 @@
> # SPDX-License-Identifier: GPL-2.0
> -obj-y = core.o severity.o genpool.o
> +# No instrumentation for #MC handler code
> +KASAN_SANITIZE_core_instr.o := n
> +UBSAN_SANITIZE_core_instr.o := n
> +KCOV_INSTRUMENT_core_instr.o := n

ifdef CONFIG_FUNCTION_TRACER
CFLAGS_REMOVE_core_instr.o = $(CC_FLAGS_FTRACE)
endif

> +
> +obj-y = core.o core_noinstr.o severity.o genpool.o

I'm thinking