Re: [PATCH] kcov: report the first spurious PC in the interrupt selftest
From: Bradley Morgan
Date: Fri Jul 24 2026 - 13:37:03 EST
Hi Karl.
> Use a two-word buffer to record the first spurious PC. Once one is
> recorded, disable KCOV, report the PC, and panic. This preserves the
> selftest's hard failure while avoiding the recursive fault path.
Nice! Way better than fishing the PC out of a stack overflow, heh.
[...]
> + current->kcov_size = ARRAY_SIZE(selftest_area);
> + current->kcov_area = selftest_area;
> + barrier();
> WRITE_ONCE(current->kcov_mode, KCOV_MODE_TRACE_PC);
[...]
> + WRITE_ONCE(current->kcov_mode, KCOV_MODE_DISABLED);
> + barrier();
> + current->kcov_size = 0;
> + current->kcov_area = NULL;
this is kcov_start()/kcov_stop() open coded. mode is still off when
kcov_start() does its kcov_debug() print, so calling the helpers is
safe and the barriers come for free, do e.g:
kcov_start(current, NULL, ARRAY_SIZE(selftest_area),
selftest_area, KCOV_MODE_TRACE_PC, 0);
...
kcov_stop(current);
if youd rather keep it open coded thats ok too, the ordering matches
the helpers exactly.
> + if (selftest_area[0]) {
> + /* PCs are recorded with kaslr_offset() subtracted. */
> + ip = selftest_area[1];
> +#ifdef CONFIG_RANDOMIZE_BASE
> + ip += kaslr_offset();
> +#endif
works, but its canonicalize_ip() inverted by hand and the two can
drift apart. please add the inverse next to canonicalize_ip() and
call that:
static unsigned long decanonicalize_ip(unsigned long ip)
{
#ifdef CONFIG_RANDOMIZE_BASE
ip += kaslr_offset();
#endif
return ip;
}
(Note: pls cc me on V2)
Thanks!