mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org, Bill Wendling <morbo@google.com>,
	Chuck Wolber <chuck@wolber.net>,
	Justin Stitt <justinstitt@google.com>,
	llvm@lists.linux.dev, Marco Elver <elver@google.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Thomas Gleixner <tglx@kernel.org>
Subject: Re: [PATCH v2 11/20] objtool: Detect code coverage instrumentation in noinstr code
Date: Mon, 16 Nov 2026 14:39:03 -0500	[thread overview]
Message-ID: <20261116193903.227017-1-sashal@kernel.org> (raw)
In-Reply-To: <avdUyFTijaXU5MwM@jpoimboe>

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@worktop.programming.kicks-ass.net/
[2] https://lore.kernel.org/all/YB0+P3LiduCpWctO@hirez.programming.kicks-ass.net/

-- 
Thanks,
Sasha

  reply	other threads:[~2026-11-16 19:39 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03  1:52 [PATCH v2 00/20] Unify code coverage and add Clang source-based coverage with MC/DC Sasha Levin
2026-11-03  1:52 ` [PATCH v2 01/20] coverage: move gcov and kcov under kernel/coverage/ Sasha Levin
2026-11-05 17:38   ` Peter Oberparleiter
2026-11-13  0:45   ` Nathan Chancellor
2026-11-03  1:52 ` [PATCH v2 02/20] kbuild: unify static coverage instrumentation as COVERAGE_PROFILE Sasha Levin
2026-11-13  0:45   ` Nathan Chancellor
2026-11-03  1:52 ` [PATCH v2 03/20] coverage: add a common debugfs interface Sasha Levin
2026-11-05 17:49   ` Peter Oberparleiter
2026-11-06  1:05     ` Sasha Levin
2026-11-03  1:52 ` [PATCH v2 04/20] compiler_types.h: Don't instrument __always_inline functions for coverage Sasha Levin
2026-11-03  1:52 ` [PATCH v2 05/20] context_tracking: Always inline the empty stubs called from noinstr code Sasha Levin
2026-11-03  1:52 ` [PATCH v2 06/20] lockdep: " Sasha Levin
2026-11-03  1:52 ` [PATCH v2 07/20] perf: Always inline the empty perf_lopwr_cb() stub Sasha Levin
2026-11-03  1:52 ` [PATCH v2 08/20] rseq: Always inline the empty stubs called from noinstr code Sasha Levin
2026-11-03  1:52 ` [PATCH v2 09/20] x86: Always inline " Sasha Levin
2026-11-03  1:52 ` [PATCH v2 10/20] x86/sev: Use non-instrumented bitops in the GHCB accessors Sasha Levin
2026-11-04 13:36   ` Sean Christopherson
2026-11-03  1:52 ` [PATCH v2 11/20] objtool: Detect code coverage instrumentation in noinstr code Sasha Levin
2026-11-12  6:23   ` Josh Poimboeuf
2026-11-12 13:09     ` Sasha Levin
2026-11-12 15:12       ` Peter Zijlstra
2026-11-12 18:41         ` Josh Poimboeuf
2026-11-12 18:51           ` Josh Poimboeuf
2026-11-13 15:09           ` Sasha Levin
2026-11-13 18:22             ` Josh Poimboeuf
2026-11-16 19:39               ` Sasha Levin [this message]
2026-11-03  1:52 ` [PATCH v2 12/20] x86/sev: Stop excluding noinstr.o from code coverage Sasha Levin
2026-11-03  1:52 ` [PATCH v2 13/20] x86/entry: Stop excluding the entry code from KCOV Sasha Levin
2026-11-03  1:52 ` [PATCH v2 14/20] coverage: add Clang's source-based code coverage Sasha Levin
2026-11-03  1:52 ` [PATCH v2 15/20] x86: Enable " Sasha Levin
2026-11-03  1:52 ` [PATCH v2 16/20] coverage: add MC/DC measurement Sasha Levin
2026-11-13  0:45   ` Nathan Chancellor
2026-11-03  1:52 ` [PATCH v2 17/20] gcov: fix gcov_info_add() merge semantics for IOR counters Sasha Levin
2026-11-05 17:50   ` Peter Oberparleiter
2026-11-03  1:52 ` [PATCH v2 18/20] kconfig: add CC_HAS_CONDITION_COVERAGE for MC/DC support detection Sasha Levin
2026-11-13  0:45   ` Nathan Chancellor
2026-11-03  1:52 ` [PATCH v2 19/20] gcov: add MC/DC condition coverage support Sasha Levin
2026-11-05 17:56   ` Peter Oberparleiter
2026-11-06  1:05     ` Sasha Levin
2026-11-03  1:52 ` [PATCH v2 20/20] Documentation: dev-tools: document the common code coverage interface Sasha Levin
2026-11-05 17:36 ` [PATCH v2 00/20] Unify code coverage and add Clang source-based coverage with MC/DC Peter Oberparleiter

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=20261116193903.227017-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=chuck@wolber.net \
    --cc=elver@google.com \
    --cc=jpoimboe@kernel.org \
    --cc=justinstitt@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mhiramat@kernel.org \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=tglx@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®