mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Chuck Wolber" <chuck@wolber.net>
To: "Peter Zijlstra" <peterz@infradead.org>,
	"Sasha Levin" <sashal@kernel.org>
Cc: <nathan@kernel.org>, <Matt.Kelly2@boeing.com>,
	<akpm@linux-foundation.org>, <andrew.j.oppelt@boeing.com>,
	<anton.ivanov@cambridgegreys.com>, <ardb@kernel.org>,
	<arnd@arndb.de>, <bhelgaas@google.com>, <bp@alien8.de>,
	<chuck.wolber@boeing.com>, <dave.hansen@linux.intel.com>,
	<dvyukov@google.com>, <hpa@zytor.com>, <jinghao7@illinois.edu>,
	<johannes@sipsolutions.net>, <jpoimboe@kernel.org>,
	<justinstitt@google.com>, <kees@kernel.org>,
	<kent.overstreet@linux.dev>, <linux-arch@vger.kernel.org>,
	<linux-efi@vger.kernel.org>, <linux-kbuild@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-trace-kernel@vger.kernel.org>,
	<linux-um@lists.infradead.org>, <llvm@lists.linux.dev>,
	<luto@kernel.org>, <marinov@illinois.edu>, <masahiroy@kernel.org>,
	<maskray@google.com>, <mathieu.desnoyers@efficios.com>,
	<matthew.l.weber3@boeing.com>, <mhiramat@kernel.org>,
	<mingo@redhat.com>, <morbo@google.com>, <ndesaulniers@google.com>,
	<oberpar@linux.ibm.com>, <paulmck@kernel.org>, <richard@nod.at>,
	<rostedt@goodmis.org>, <samitolvanen@google.com>,
	<samuel.sarkisian@boeing.com>, <steven.h.vanderleest@boeing.com>,
	<tglx@linutronix.de>, <tingxur@illinois.edu>, <tyxu@illinois.edu>,
	<wentaoz5@illinois.edu>, <x86@kernel.org>
Subject: Re: [RFC PATCH 0/4] Enable Clang's Source-based Code Coverage and MC/DC for x86-64
Date: Wed, 15 Oct 2025 08:26:50 +0000	[thread overview]
Message-ID: <DDIR4HE5C74G.1U5TA0KDN9O5J@wolber.net> (raw)
In-Reply-To: <20251015073701.GZ3419281@noisy.programming.kicks-ass.net>

On Wed Oct 15, 2025 at 7:41 AM UTC, Peter Zijlstra wrote:
> On Tue, Oct 14, 2025 at 07:26:35PM -0400, Sasha Levin wrote:
>> This series adds support for Clang's Source-based Code Coverage to the
>> Linux kernel, enabling more accurate coverage measurement at the source
>> level compared to gcov. This is particularly valuable for safety-critical
>> use cases (automotive, medical, aerospace) where MC/DC coverage is required
>> for certification.
>> 
>> Changes since previous patchset [1]:
>> - Rebased on v6.18-rc1
>> - Adapted to lib/crypto reorganization (curve25519 exclusion moved to
>>   lib/crypto/Makefile)
>> - Minor correctness fixes throughout the codebase
>> 
>> The implementation has been tested with a kernel build using Clang 18+ and
>> boots successfully in a KVM environment with instrumentation enabled.
>> 
>> [1] https://lore.kernel.org/all/20240905043245.1389509-1-wentaoz5@illinois.edu/
>> 
>> Wentao Zhang (4):
>>   llvm-cov: add Clang's Source-based Code Coverage support
>>   llvm-cov: add Clang's MC/DC support
>>   x86: disable llvm-cov instrumentation
>>   x86: enable llvm-cov support
>> 
>>  Makefile                          |   9 ++
>>  arch/Kconfig                      |   1 +
>>  arch/x86/Kconfig                  |   2 +
>>  arch/x86/crypto/Makefile          |   1 +
>>  arch/x86/kernel/vmlinux.lds.S     |   2 +
>>  include/asm-generic/vmlinux.lds.h |  36 +++++
>>  kernel/Makefile                   |   1 +
>>  kernel/llvm-cov/Kconfig           | 121 ++++++++++++++
>>  kernel/llvm-cov/Makefile          |   8 +
>>  kernel/llvm-cov/fs.c              | 253 ++++++++++++++++++++++++++++++
>>  kernel/llvm-cov/llvm-cov.h        | 157 ++++++++++++++++++
>>  lib/crypto/Makefile               |   3 +-
>>  scripts/Makefile.lib              |  23 +++
>>  scripts/mod/modpost.c             |   2 +
>
> I'm thinking I'm going to NAK this based on the fact that I'm not
> interested in playing file based games. As long as this thing doesn't
> honour noinstr I don't want this near x86.

I am working on a noinstr patchset that will precede this pachset. As it turns
out there are several areas of the kernel (128 that I have found so far) that
are missing the noinstr attribute macro.

Example:

kernel/locking/lockdep.c:
	void noinstr lockdep_hardirqs_off(unsigned long ip)
include/linux/irqflags.h:
	static inline void lockdep_hardirqs_off(unsigned long ip) { }

The latter version is intended to be optimized out if the kernel is not
configured to use this feature. However when the kernel is instrumented for
profiling, the stub is not optimized out and ends up in the .text section
rather than the .noinstr.text section.


> And we have kcov support, and gcov and now llvm-cov, surely 3 coverage
> solutions is like 2 too many?

Optimization makes it nearly impossible to correlate GCov results back to
actual lines of source. llvm-cov instruments at the AST level which enables
precise mapping back to source code regardless of optimization level.


A detailed rundown on this issue can be found here[1], with the most relevant
excerpt reproduced here:

> In the following gcov example from drivers/firmware/dmi_scan.c, an
> expression with four conditions is reported to have six branch outcomes,
> which is not ideally informative in many safety related use cases, such as
> automotive, medical, and aerospace.
> 
>         5: 1068:	if (s == e || *e != '/' || !month || month > 12) {
> branch  0 taken 5 (fallthrough)
> branch  1 taken 0
> branch  2 taken 5 (fallthrough)
> branch  3 taken 0
> branch  4 taken 0 (fallthrough)
> branch  5 taken 5
> 
> On the other hand, Clang's Source-based Code Coverage instruments at the
> compiler frontend which maintains an accurate mapping from coverage
> measurement to source code location. Coverage reports reflect exactly how
> the code is written regardless of optimization and can present advanced
> metrics like branch coverage and MC/DC in a clearer way. Coverage report
> for the same snippet by llvm-cov would look as follows:
> 
>  1068|      5|	if (s == e || *e != '/' || !month || month > 12) {
>   ------------------
>   |  Branch (1068:6): [True: 0, False: 5]
>   |  Branch (1068:16): [True: 0, False: 5]
>   |  Branch (1068:29): [True: 0, False: 5]
>   |  Branch (1068:39): [True: 0, False: 5]
>   ------------------


..Ch:W..



[1] https://lore.kernel.org/llvm/20240905043245.1389509-1-wentaoz5@illinois.edu/



  reply	other threads:[~2025-10-15  8:26 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-24 23:06 [RFC PATCH 0/3] Enable measuring the kernel's Source-based Code Coverage and MC/DC with Clang Wentao Zhang
2024-08-24 23:06 ` [RFC PATCH 1/3] llvm-cov: add Clang's Source-based Code Coverage support Wentao Zhang
2024-08-25 11:52   ` Thomas Gleixner
2024-08-24 23:06 ` [RFC PATCH 2/3] kbuild, llvm-cov: disable instrumentation in odd or sensitive code Wentao Zhang
2024-08-25 12:12   ` Thomas Gleixner
2024-08-24 23:06 ` [RFC PATCH 3/3] llvm-cov: add Clang's MC/DC support Wentao Zhang
2024-09-05  4:32 ` [PATCH v2 0/4] Enable measuring the kernel's Source-based Code Coverage and MC/DC with Clang Wentao Zhang
2024-09-05  4:32   ` [PATCH v2 1/4] llvm-cov: add Clang's Source-based Code Coverage support Wentao Zhang
2024-10-02  0:30     ` Nathan Chancellor
2024-09-05  4:32   ` [PATCH v2 2/4] llvm-cov: add Clang's MC/DC support Wentao Zhang
2024-10-02  1:10     ` Nathan Chancellor
2024-10-03  3:14       ` Wentao Zhang
2024-09-05  4:32   ` [PATCH v2 3/4] x86: disable llvm-cov instrumentation Wentao Zhang
2024-10-02  1:17     ` Nathan Chancellor
2024-09-05  4:32   ` [PATCH v2 4/4] x86: enable llvm-cov support Wentao Zhang
2024-10-02  1:18     ` Nathan Chancellor
2024-09-05 11:41   ` [PATCH v2 0/4] Enable measuring the kernel's Source-based Code Coverage and MC/DC with Clang Peter Zijlstra
     [not found]     ` <BN0P110MB1785427A8771BD53DADB2E4DAB9DA@BN0P110MB1785.NAMP110.PROD.OUTLOOK.COM>
     [not found]       ` <BN0P110MB1785CA856C1898EEC22ACD7EAB9DA@BN0P110MB1785.NAMP110.PROD.OUTLOOK.COM>
2024-09-05 12:24         ` FW: [EXTERNAL] " Steve VanderLeest
2024-09-05 18:07     ` Wentao Zhang
2024-10-02  4:53   ` Nathan Chancellor
2024-10-02  6:42     ` Wentao Zhang
2024-10-03 23:29       ` Nathan Chancellor
2024-10-09  3:17         ` Wentao Zhang
2024-11-22  5:05         ` Jinghao Jia
2024-11-23  4:39           ` Nathan Chancellor
2025-08-29 18:10           ` Nathan Chancellor
2025-10-14 23:26             ` [RFC PATCH 0/4] Enable Clang's Source-based Code Coverage and MC/DC for x86-64 Sasha Levin
2025-10-14 23:26               ` [RFC PATCH 1/4] llvm-cov: add Clang's Source-based Code Coverage support Sasha Levin
2025-10-14 23:26               ` [RFC PATCH 2/4] llvm-cov: add Clang's MC/DC support Sasha Levin
2025-10-14 23:26               ` [RFC PATCH 3/4] x86: disable llvm-cov instrumentation Sasha Levin
2025-10-14 23:26               ` [RFC PATCH 4/4] x86: enable llvm-cov support Sasha Levin
2025-10-15  7:37               ` [RFC PATCH 0/4] Enable Clang's Source-based Code Coverage and MC/DC for x86-64 Peter Zijlstra
2025-10-15  8:26                 ` Chuck Wolber [this message]
2025-10-15  9:21                   ` Peter Zijlstra
2026-03-15 14:15                     ` Sasha Levin
2024-11-22 12:27         ` [PATCH v2 0/4] Enable measuring the kernel's Source-based Code Coverage and MC/DC with Clang Peter Zijlstra
2024-11-22 19:28           ` [EXTERNAL] " Wolber (US), Chuck
2024-11-23  3:09           ` Nathan Chancellor

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=DDIR4HE5C74G.1U5TA0KDN9O5J@wolber.net \
    --to=chuck@wolber.net \
    --cc=Matt.Kelly2@boeing.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrew.j.oppelt@boeing.com \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=bhelgaas@google.com \
    --cc=bp@alien8.de \
    --cc=chuck.wolber@boeing.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dvyukov@google.com \
    --cc=hpa@zytor.com \
    --cc=jinghao7@illinois.edu \
    --cc=johannes@sipsolutions.net \
    --cc=jpoimboe@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=llvm@lists.linux.dev \
    --cc=luto@kernel.org \
    --cc=marinov@illinois.edu \
    --cc=masahiroy@kernel.org \
    --cc=maskray@google.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=matthew.l.weber3@boeing.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=oberpar@linux.ibm.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=richard@nod.at \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=samuel.sarkisian@boeing.com \
    --cc=sashal@kernel.org \
    --cc=steven.h.vanderleest@boeing.com \
    --cc=tglx@linutronix.de \
    --cc=tingxur@illinois.edu \
    --cc=tyxu@illinois.edu \
    --cc=wentaoz5@illinois.edu \
    --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®