kcov: update documentation on remote coverage collection
Subsystems (4)
PATCH v2 1/1 kcov: update documentation on remote coverage collection
Adjust the docs on remote coverage collection to reflect the changes made in "kcov: refactor common handle ID into kcov_common_handle_id" and "kcov: allow simultaneous KCOV_ENABLE/KCOV_REMOTE_ENABLE".
---
Changes in v2:
- move and reword sentence on simultaneous normal/remote collection (andreyknvl)
- Link to v1: https://lore.kernel.org/r/[email protected]
--- Documentation/dev-tools/kcov.rst | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/dev-tools/kcov.rst +6 -0
@@ -237,6 +237,9 @@ Both ``kcov_remote_start`` and ``kcov_remote_stop`` annotations and the collection sections. The way a handle is used depends on the context where the matching code section executes. +A thread can use two separate KCOV instances to collect remote coverage and +normal coverage at the same time. + KCOV supports collecting remote coverage from the following contexts: 1. Global kernel background tasks. These are the tasks that are spawned during
@@ -262,6 +265,9 @@ gets saved to the ``kcov_handle`` field in the current ``task_struct`` and needs to be passed to the newly spawned local tasks via custom kernel code modifications. Those tasks should in turn use the passed handle in their ``kcov_remote_start`` and ``kcov_remote_stop`` annotations. +In the kernel, common handles are wrapped in a ``kcov_common_handle_id``, which +consumes no space in builds without ``CONFIG_KCOV``; subsystems that integrate +with this mechanism should not need to use any ``#ifdef CONFIG_KCOV`` or such. KCOV follows a predefined format for both global and common handles. Each handle is a ``u64`` integer. Currently, only the one top and the lower 4 bytes
---
base-commit: ab5fce87a778cb780a05984a2ca448f2b41aafbf
change-id: 20260519-kcov-docs-15feabfb10aa
Signature · 1 line
Jann Horn <[email protected]>
Quoted 3 lines · On Wed, 20 May 2026 20:21:29 +0200 Jann Horn <[email protected]> wrote:
Adjust the docs on remote coverage collection to reflect the changes made in "kcov: refactor common handle ID into
kcov_common_handle_id" and "kcov: allow simultaneous KCOV_ENABLE/KCOV_REMOTE_ENABLE".
This has all become rather confusing, with fixes and new versions of fixes under different titles, etc.
I did my best to piece it all together then I joined everything into a single patch, below. Please check it for accuracy, up-to-dateness and changelog truthfulness, thanks.
From: Jann Horn <[email protected]>
Subject: kcov: allow simultaneous KCOV_ENABLE/KCOV_REMOTE_ENABLE
Date: Tue, 05 May 2026 11:00:46 +0200
Allow the same userspace thread to simultaneously collect normal coverage in syscall context (KCOV_ENABLE) and remote coverage of asynchronous work created by the thread (KCOV_REMOTE_ENABLE). With this, remote KCOV coverage becomes useful for generic fuzzing and not just fuzzing of specific data injection interfaces.
This requires that the task_struct::kcov_* fields are separated into ones that are used by the task that generates coverage, and ones that are used by the task that requested remote coverage. To split this up:
- Split task_struct::kcov into kcov and kcov_remote. kcov_task_exit() now has to clean up both separately.
- Only use task_struct::kcov_mode on the task that generates coverage.
- Only reset task_struct::kcov_handle on the task that requested remote coverage.
After this change, fields used by the task that generates coverage are:
- kcov_mode
- kcov_size
- kcov_area
- kcov
- kcov_sequence
- kcov_softirq
Fields used by the task that requested remote coverage are:
- kcov_remote
- kcov_handle
[[email protected]: move and reword sentence on simultaneous normal/remote collection
---
Documentation/dev-tools/kcov.rst | 6 + include/linux/kcov.h | 2 include/linux/sched.h | 3 kernel/kcov.c | 94 ++++++++++++++++------------- 4 files changed, 61 insertions(+), 44 deletions(-)
include/linux/sched.h renamed from include/linux/sched.h~kcov-allow-simultaneous-kcov_enable-kcov_remote_enable +3 -0
@@ -1517,6 +1517,9 @@ struct task_struct {/* KCOV descriptor wired with this task or NULL: */ struct kcov *kcov; +/* KCOV descriptor for remote coverage collection from other tasks: */ +struct kcov *kcov_remote; +/* KCOV common handle for remote coverage collection: */ u64 kcov_handle;
kernel/kcov.c renamed from kernel/kcov.c~kcov-allow-simultaneous-kcov_enable-kcov_remote_enable +52 -42
150 lines not on this page · raw message
include/linux/kcov.h renamed from include/linux/kcov.h~kcov-allow-simultaneous-kcov_enable-kcov_remote_enable +0 -2
@@ -21,8 +21,6 @@ enum kcov_mode {KCOV_MODE_TRACE_PC =2 ,/* Collecting comparison operands mode. */ KCOV_MODE_TRACE_CMP = 3, -/* The process owns a KCOV remote reference. */ - KCOV_MODE_REMOTE = 4, };#define KCOV_IN_CTXSW (1 << 30)
Documentation/dev-tools/kcov.rst renamed from Documentation/dev-tools/kcov.rst~kcov-allow-simultaneous-kcov_enable-kcov_remote_enable +6 -0
@@ -237,6 +237,9 @@ Both ``kcov_remote_start`` and ``kcov_re collection sections. The way a handle is used depends on the context where the matching code section executes. +A thread can use two separate KCOV instances to collect remote coverage and +normal coverage at the same time. + KCOV supports collecting remote coverage from the following contexts: 1. Global kernel background tasks. These are the tasks that are spawned during
@@ -262,6 +265,9 @@ gets saved to the ``kcov_handle`` field needs to be passed to the newly spawned local tasks via custom kernel code modifications. Those tasks should in turn use the passed handle in their ``kcov_remote_start`` and ``kcov_remote_stop`` annotations. +In the kernel, common handles are wrapped in a ``kcov_common_handle_id``, which +consumes no space in builds without ``CONFIG_KCOV``; subsystems that integrate +with this mechanism should not need to use any ``#ifdef CONFIG_KCOV`` or such. KCOV follows a predefined format for both global and common handles. Each handle is a ``u64`` integer. Currently, only the one top and the lower 4 bytes
_
Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Wed, 20 May 2026 20:21:29 +0200 Jann Horn <[email protected]> wrote:
Adjust the docs on remote coverage collection to reflect the changes made in "kcov: refactor common handle ID into
kcov_common_handle_id" and "kcov: allow simultaneous KCOV_ENABLE/KCOV_REMOTE_ENABLE".This has all become rather confusing, with fixes and new versions of fixes under different titles, etc.
glider@ suggested in
<https://lore.kernel.org/all/CAG_fn=U+V9wzvJJsRh3aB1uCm5zfWTFv3UHeBaPU_E_KXbDKFQ@mail.gmail.com/>:
| Could you also update Documentation/dev-tools/kcov.rst (a separate | commit is also fine - it can cover the kcov_common_handle_id change as | well)?
So that was my intent - to have these three separate patches:
"kcov: refactor common handle ID into kcov_common_handle_id" "kcov: allow simultaneous KCOV_ENABLE/KCOV_REMOTE_ENABLE" "kcov: update documentation on remote coverage collection"
(where the documentation patch covers changes by both the other changes)
All the patches I sent were meant as full patches, not incremental fixups.
Quoted 3 lines
I did my best to piece it all together then I joined everything into a single patch, below. Please check it for accuracy, up-to-dateness and changelog truthfulness, thanks.
Yes, that is an accurate combination of "[PATCH v2] kcov: allow simultaneous KCOV_ENABLE/KCOV_REMOTE_ENABLE" and "[PATCH v2] kcov:
update documentation on remote coverage collection", and it is up-to-date, and the changelog looks accurate.
Quoted 7 lines · Jann Horn
Adjust the docs on remote coverage collection to reflect the changes made in "kcov: refactor common handle ID into
kcov_common_handle_id" and "kcov: allow simultaneous KCOV_ENABLE/KCOV_REMOTE_ENABLE".Suggested-by Alexander Potapenko <[email protected]>Signed-off-by Jann Horn <[email protected]>