Re: [PATCH v2 11/20] objtool: Detect code coverage instrumentation in noinstr code
From: Sasha Levin
Date: Mon Nov 16 2026 - 14:39:08 EST
On Fri, Nov 13, 2026 at 10:22:51AM -0800, Josh Poimboeuf wrote:
>That seems circular though, I'm still trying to figure out what the
>actual problem is.
Right, sorry, I'm still trying to piece things together myself :)
>From what I get from Peter[1], a counter update is a store, and a store can
trap:
Because you can get exceptions from memory accesses just fine, which, if
you're inside an exception handler and haven't dealt with recursion
conditions yet, can be fatal.
So if I try to play with it and produce #DB by placing a data breakpoint, I can
observe:
- exc_debug_kernel() bumps __gcov0.local_db_save twice before it reads
DR7. With a write breakpoint on that counter the next kernel #DB
never returns, the CPU spins between asm_exc_debug and
exc_debug_kernel with DR7 still armed.
- exc_page_fault() bumps __gcov0.read_cr2 right before "mov %cr2". If
the breakpoint on it samples user callchains, the #DB handler faults
walking the user frame pointer and CR2 is gone. I tried 300 writes to
freshly mapped pages with %rbp pointing into a PROT_NONE page, and
all 300 got a SIGSEGV for the %rbp address.
I don't think it's a "keep the pieces" thing, since we already refuse
breakpoints on the other data that code touches. So for example,
within_cpu_entry(), and 3943abf2dbfa ("x86/debug: Prevent data breakpoints on
cpu_dr7") is a very similar case I think: something local_db_save() reads
before DR7 is cleared.
It's not only a coverage problem either (I think I just got this as "additional
homework" from Peter :p ). The within_cpu_entry() list is kept by hand (having
objtool enforce it has been on the TODO list since 2021 [2]), and the same
kernel without coverage has holes in it too:
- A read/write breakpoint on cpu_current_top_of_stack gives the same
300 of 300 wrong fault addresses, as sync_regs() reads it before CR2
is read.
- With spectre_v2=ibrs, a read/write breakpoint on
x86_spec_ctrl_current hangs the CPU in paranoid_entry(), which reads
it before DR7 is cleared.
So what coverage adds is thousands more of these in places nobody can list, and
with GCC they're ordinary .data/.bss that can't be blacklisted. That's what the
objtool rewrite gets rid of.
>FYI, a partial objtool port (without the more controversial CFG
>reverse-engineering bits) is likely coming to arm64 soon to support
>klp-build, in which case this should be possible there as well.
Nice. Without the CFG, can it still tell what's inside
instrumentation_begin()/end()? If not it could just drop every counter
in .noinstr.text, I think that's fine.
[1] https://lore.kernel.org/all/20210614190700.GF68749@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
[2] https://lore.kernel.org/all/YB0+P3LiduCpWctO@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
--
Thanks,
Sasha