mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org,
	linux-kernel@vger.kernel.org, syzkaller@googlegroups.com,
	elver@google.com, glider@google.com, nogikh@google.com,
	tarasmadan@google.com
Subject: Re: [PATCH v2 2/4] kcov: add interrupt handling self test
Date: Wed, 19 Jun 2024 13:26:25 +0200	[thread overview]
Message-ID: <20240619112625.GM31592@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <CACT4Y+bUPsrGpbakLE-yJN8aKE3ODgB7oWHu+cHW2XSoFvJd_g@mail.gmail.com>

On Wed, Jun 19, 2024 at 01:18:52PM +0200, Dmitry Vyukov wrote:
> On Wed, 19 Jun 2024 at 13:13, Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Tue, Jun 11, 2024 at 09:50:31AM +0200, Dmitry Vyukov wrote:
> > > Add a boot self test that can catch sprious coverage from interrupts.
> > > The coverage callback filters out interrupt code, but only after the
> > > handler updates preempt count. Some code periodically leaks out
> > > of that section and leads to spurious coverage.
> > > Add a best-effort (but simple) test that is likely to catch such bugs.
> > > If the test is enabled on CI systems that use KCOV, they should catch
> > > any issues fast.
> > >
> > > Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> > > Reviewed-by: Alexander Potapenko <glider@google.com>
> > > Cc: x86@kernel.org
> > > Cc: linux-kernel@vger.kernel.org
> > > Cc: syzkaller@googlegroups.com
> > >
> > > ---
> > >
> > > Changed since v1:
> > >  - renamed KCOV_TEST to KCOV_SELFTEST
> > >  - improved the config description
> > >  - loop for exactly 300ms in the test
> > >
> > > In my local testing w/o the previous fix,
> > > it immidiatly produced the following splat:
> > >
> > > kcov: running selftest
> > > BUG: TASK stack guard page was hit at ffffc90000147ff8
> > > Oops: stack guard page: 0000 [#1] PREEMPT SMP KASAN PTI
> > > ...
> > >  kvm_set_cpu_l1tf_flush_l1d+0x5/0x20
> > >  sysvec_call_function+0x15/0xb0
> > >  asm_sysvec_call_function+0x1a/0x20
> > >  kcov_init+0xe4/0x130
> > >  do_one_initcall+0xbc/0x470
> > >  kernel_init_freeable+0x4fc/0x930
> > >  kernel_init+0x1c/0x2b0
> >
> > So I'm not entirely sure how the above BUG comes about, nor how this
> > selftest tickles it. Could you elaborate?
> >
> > I've found check_kcov_mode() which has this !in_task() clause, but I'm
> > not entirely sure how failing that leads to the above mentioned failure.
> 
> I've tried to explain it in the test comment, maybe I need to improve it:
> 
> +        * We set kcov_mode to enable tracing, but don't setup the area,
> +        * so any attempt to trace will crash. Note: we must not call any
> +        * potentially traced functions in this region.

Ah, I'm just slow today.. did not connect the dots. No this is fine.

> Basically, we setup current task kcov in a way that any attempt to
> trace in __sanitizer_cov_trace_pc() will crash, and then just loop
> waiting for interrupts.
> 
> A more legit way to achieve the same would be to properly setup kcov
> for tracing from within the kernel, then call outermost interrupt
> entry function, then check we traced nothing. But that would require a
> non-trivial amount of new complex code, and e.g. the top-most
> interrupt entry function is not exported and is arch-specific.

Yeah, polling jiffies should be fine I suppose.

  reply	other threads:[~2024-06-19 11:26 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-11  7:50 [PATCH v2 0/4] KCOV fixes Dmitry Vyukov
2024-06-11  7:50 ` [PATCH v2 1/4] x86/entry: Remove unwanted instrumentation in common_interrupt() Dmitry Vyukov
2024-06-19 11:19   ` Peter Zijlstra
2024-06-19 13:05     ` Dmitry Vyukov
2024-08-08 15:49   ` [tip: x86/build] " tip-bot2 for Dmitry Vyukov
2024-06-11  7:50 ` [PATCH v2 2/4] kcov: add interrupt handling self test Dmitry Vyukov
2024-06-11  9:29   ` Marco Elver
2024-06-13 23:01   ` Andrey Konovalov
2024-06-19 11:13   ` Peter Zijlstra
2024-06-19 11:18     ` Dmitry Vyukov
2024-06-19 11:26       ` Peter Zijlstra [this message]
2024-08-08 15:49   ` [tip: x86/build] kcov: Add " tip-bot2 for Dmitry Vyukov
2024-06-11  7:50 ` [PATCH v2 3/4] module: Fix KCOV-ignored file name Dmitry Vyukov
2024-06-11  9:29   ` Marco Elver
2024-06-13 22:55   ` Andrey Konovalov
2024-08-08 15:49   ` [tip: x86/build] " tip-bot2 for Dmitry Vyukov
2024-06-11  7:50 ` [PATCH v2 4/4] x86: Ignore stack unwinding in KCOV Dmitry Vyukov
2024-06-13 22:51   ` Andrey Konovalov
2024-06-19 11:23   ` Peter Zijlstra
2024-06-19 13:10     ` Dmitry Vyukov
2024-08-08 15:49   ` [tip: x86/build] " tip-bot2 for Dmitry Vyukov
2024-06-11  9:31 ` [PATCH v2 0/4] KCOV fixes Dmitry Vyukov
2024-06-19  5:20   ` Dmitry Vyukov
2024-06-19  8:30     ` Borislav Petkov
2024-08-05 12:52       ` Andrey Konovalov
2024-08-08 15:18         ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240619112625.GM31592@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nogikh@google.com \
    --cc=syzkaller@googlegroups.com \
    --cc=tarasmadan@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®