Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-17 Thread Marco Elver
On Wed, Jun 17, 2020 at 06:36PM +0200, Peter Zijlstra wrote: > On Wed, Jun 17, 2020 at 05:55:17PM +0200, Peter Zijlstra wrote: > > On Wed, Jun 17, 2020 at 05:19:59PM +0200, Marco Elver wrote: > > > > > > Does GCC (8, as per the new KASAN thing) have that > > > > __builtin_memcpy_inline() ? > > >

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-17 Thread Peter Zijlstra
On Wed, Jun 17, 2020 at 05:55:17PM +0200, Peter Zijlstra wrote: > On Wed, Jun 17, 2020 at 05:19:59PM +0200, Marco Elver wrote: > > > > Does GCC (8, as per the new KASAN thing) have that > > > __builtin_memcpy_inline() ? > > > > No, sadly it doesn't. Only Clang 11. :-/ > > > > But using a call to

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-17 Thread Peter Zijlstra
On Wed, Jun 17, 2020 at 05:19:59PM +0200, Marco Elver wrote: > > Does GCC (8, as per the new KASAN thing) have that > > __builtin_memcpy_inline() ? > > No, sadly it doesn't. Only Clang 11. :-/ > > But using a call to __memcpy() somehow breaks with Clang+KCSAN. Yet, > it's not the memcpy that BUG

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-17 Thread Marco Elver
On Wed, Jun 17, 2020 at 04:49PM +0200, Peter Zijlstra wrote: > On Wed, Jun 17, 2020 at 04:32:08PM +0200, Marco Elver wrote: > > On Mon, Jun 15, 2020 at 05:20PM +0200, Peter Zijlstra wrote: > > > On Mon, Jun 15, 2020 at 05:03:27PM +0200, Peter Zijlstra wrote: > > > > > > > Yes, I think so. x86_64 n

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-17 Thread Peter Zijlstra
On Wed, Jun 17, 2020 at 04:49:49PM +0200, Peter Zijlstra wrote: > I had the below, except of course that yields another objtool > complaint, and I was still looking at that. This cures it. diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 5fbb90a80d239..fe0d6f1b28d7c 100644 --- a/

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-17 Thread Peter Zijlstra
On Wed, Jun 17, 2020 at 04:32:08PM +0200, Marco Elver wrote: > On Mon, Jun 15, 2020 at 05:20PM +0200, Peter Zijlstra wrote: > > On Mon, Jun 15, 2020 at 05:03:27PM +0200, Peter Zijlstra wrote: > > > > > Yes, I think so. x86_64 needs lib/memcpy_64.S in .noinstr.text then. For > > > i386 it's an __al

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-17 Thread Marco Elver
On Mon, Jun 15, 2020 at 05:20PM +0200, Peter Zijlstra wrote: > On Mon, Jun 15, 2020 at 05:03:27PM +0200, Peter Zijlstra wrote: > > > Yes, I think so. x86_64 needs lib/memcpy_64.S in .noinstr.text then. For > > i386 it's an __always_inline inline-asm thing. > > Bah, I tried writing it without memc

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-15 Thread Peter Zijlstra
On Mon, Jun 15, 2020 at 05:03:27PM +0200, Peter Zijlstra wrote: > Yes, I think so. x86_64 needs lib/memcpy_64.S in .noinstr.text then. For > i386 it's an __always_inline inline-asm thing. Bah, I tried writing it without memcpy, but clang inserts memcpy anyway :/ --- diff --git a/arch/x86/kernel/

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-15 Thread Peter Zijlstra
On Mon, Jun 15, 2020 at 04:53:36PM +0200, Marco Elver wrote: > On Mon, 15 Jun 2020, Peter Zijlstra wrote: > > > On Mon, Jun 15, 2020 at 09:53:06AM +0200, Marco Elver wrote: > > > > > > Disabling KCOV for smp_processor_id now moves the crash elsewhere. In > > > the case of KASAN into its 'memcpy'

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-15 Thread Peter Zijlstra
On Mon, Jun 15, 2020 at 09:53:06AM +0200, Marco Elver wrote: > For KCSAN the crash still happens in check_preemption_disabled, in the > inlined native_save_fl function (apparently on its 'pushf'). If I turn > fixup_bad_iret's __this_cpu_read into a raw_cpu_read (to bypass > check_preemption_disabl

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-15 Thread Marco Elver
On Mon, 15 Jun 2020, Peter Zijlstra wrote: > On Mon, Jun 15, 2020 at 09:53:06AM +0200, Marco Elver wrote: > > > > Disabling KCOV for smp_processor_id now moves the crash elsewhere. In > > the case of KASAN into its 'memcpy' wrapper, called after > > __this_cpu_read in fixup_bad_iret. This is maki

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-15 Thread Peter Zijlstra
On Mon, Jun 15, 2020 at 04:29:50PM +0200, Peter Zijlstra wrote: > Let me go look at your KCSAN thing now... vmlinux.o: warning: objtool: idtentry_enter_cond_rcu()+0x16: call to is_idle_task() leaves .noinstr.text section --- diff --git a/include/linux/sched.h b/include/linux/sched.h index b62e6a

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-15 Thread Peter Zijlstra
On Mon, Jun 15, 2020 at 09:53:06AM +0200, Marco Elver wrote: > > Disabling KCOV for smp_processor_id now moves the crash elsewhere. In > the case of KASAN into its 'memcpy' wrapper, called after > __this_cpu_read in fixup_bad_iret. This is making me suspicious, > because it shouldn't be called fro

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-13 Thread Dmitry Vyukov
On Fri, Jun 12, 2020 at 1:49 PM Marco Elver wrote: > On Fri, 12 Jun 2020, Dmitry Vyukov wrote: > > > On Thu, Jun 11, 2020 at 11:55 PM Peter Zijlstra > > wrote: > > > > > > On Mon, Jun 08, 2020 at 01:01:08PM +0200, Peter Zijlstra wrote: > > > > On Mon, Jun 08, 2020 at 09:57:39AM +0200, Dmitry Vyu

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-12 Thread Marco Elver
On Fri, 12 Jun 2020, Dmitry Vyukov wrote: > On Thu, Jun 11, 2020 at 11:55 PM Peter Zijlstra wrote: > > > > On Mon, Jun 08, 2020 at 01:01:08PM +0200, Peter Zijlstra wrote: > > > On Mon, Jun 08, 2020 at 09:57:39AM +0200, Dmitry Vyukov wrote: > > > > > > > As a crazy idea: is it possible to emplo

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-12 Thread Peter Zijlstra
On Thu, Jun 11, 2020 at 11:58:12PM +0200, Peter Zijlstra wrote: > On Thu, Jun 11, 2020 at 11:55:38PM +0200, Peter Zijlstra wrote: > > I'll have to dig around a little more to see if I can't get rid of the > > relocation entirely. Also, I need to steal better arch_nop_insn() from > > the kernel :-)

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-11 Thread Dmitry Vyukov
On Thu, Jun 11, 2020 at 11:55 PM Peter Zijlstra wrote: > > On Mon, Jun 08, 2020 at 01:01:08PM +0200, Peter Zijlstra wrote: > > On Mon, Jun 08, 2020 at 09:57:39AM +0200, Dmitry Vyukov wrote: > > > > > As a crazy idea: is it possible to employ objtool (linker script?) to > > > rewrite all coverage c

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-11 Thread Peter Zijlstra
On Thu, Jun 11, 2020 at 11:55:38PM +0200, Peter Zijlstra wrote: > On Mon, Jun 08, 2020 at 01:01:08PM +0200, Peter Zijlstra wrote: > > On Mon, Jun 08, 2020 at 09:57:39AM +0200, Dmitry Vyukov wrote: > > > > > As a crazy idea: is it possible to employ objtool (linker script?) to > > > rewrite all cov

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-11 Thread Peter Zijlstra
On Mon, Jun 08, 2020 at 01:01:08PM +0200, Peter Zijlstra wrote: > On Mon, Jun 08, 2020 at 09:57:39AM +0200, Dmitry Vyukov wrote: > > > As a crazy idea: is it possible to employ objtool (linker script?) to > > rewrite all coverage calls to nops in the noinstr section? Or relocate > > to nop functio

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-08 Thread Peter Zijlstra
On Mon, Jun 08, 2020 at 09:57:39AM +0200, Dmitry Vyukov wrote: > As a crazy idea: is it possible to employ objtool (linker script?) to > rewrite all coverage calls to nops in the noinstr section? Or relocate > to nop function? > What we are trying to do is very static, it _should_ have been done >

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-08 Thread Dmitry Vyukov
On Mon, Jun 8, 2020 at 9:49 AM Marco Elver wrote: > > On Fri, Jun 5, 2020 at 3:25 PM 'Andrey Konovalov' via kasan-dev > > wrote: > > > > On Fri, Jun 05, 2020 at 12:57:15PM +0200, Dmitry Vyukov wrote: > > > > > On Fri, Jun 5, 2020 at 10:28 AM Marco Elver wrote: > > > > > > > > > > > > While we la

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-08 Thread Marco Elver
On Sun, 7 Jun 2020 at 11:37, Dmitry Vyukov wrote: > > On Fri, Jun 5, 2020 at 3:25 PM 'Andrey Konovalov' via kasan-dev > wrote: > > > On Fri, Jun 05, 2020 at 12:57:15PM +0200, Dmitry Vyukov wrote: > > > > On Fri, Jun 5, 2020 at 10:28 AM Marco Elver wrote: > > > > > > > > > > While we lack a compi

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-07 Thread Dmitry Vyukov
On Fri, Jun 5, 2020 at 3:25 PM 'Andrey Konovalov' via kasan-dev wrote: > > On Fri, Jun 05, 2020 at 12:57:15PM +0200, Dmitry Vyukov wrote: > > > On Fri, Jun 5, 2020 at 10:28 AM Marco Elver wrote: > > > > > > > > While we lack a compiler attribute to add to noinstr that would disable > > > > KCOV,

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-05 Thread Andrey Konovalov
On Fri, Jun 5, 2020 at 2:04 PM Peter Zijlstra wrote: > > On Fri, Jun 05, 2020 at 12:57:15PM +0200, Dmitry Vyukov wrote: > > On Fri, Jun 5, 2020 at 10:28 AM Marco Elver wrote: > > > > > > While we lack a compiler attribute to add to noinstr that would disable > > > KCOV, make the KCOV runtime func

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-05 Thread Peter Zijlstra
On Fri, Jun 05, 2020 at 12:57:15PM +0200, Dmitry Vyukov wrote: > On Fri, Jun 5, 2020 at 10:28 AM Marco Elver wrote: > > > > While we lack a compiler attribute to add to noinstr that would disable > > KCOV, make the KCOV runtime functions return if the caller is in a > > noinstr section, and mark t

Re: [PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-05 Thread Dmitry Vyukov
On Fri, Jun 5, 2020 at 10:28 AM Marco Elver wrote: > > While we lack a compiler attribute to add to noinstr that would disable > KCOV, make the KCOV runtime functions return if the caller is in a > noinstr section, and mark them noinstr. > > Declare write_comp_data() as __always_inline to ensure i

[PATCH -tip v3 1/2] kcov: Make runtime functions noinstr-compatible

2020-06-05 Thread Marco Elver
While we lack a compiler attribute to add to noinstr that would disable KCOV, make the KCOV runtime functions return if the caller is in a noinstr section, and mark them noinstr. Declare write_comp_data() as __always_inline to ensure it is inlined, which also reduces stack usage and removes one ex