Skip to content

Commit 5ff3b30

Browse files
xairytorvalds
authored andcommitted
kcov: collect coverage from interrupts
This change extends kcov remote coverage support to allow collecting coverage from soft interrupts in addition to kernel background threads. To collect coverage from code that is executed in softirq context, a part of that code has to be annotated with kcov_remote_start/stop() in a similar way as how it is done for global kernel background threads. Then the handle used for the annotations has to be passed to the KCOV_REMOTE_ENABLE ioctl. Internally this patch adjusts the __sanitizer_cov_trace_pc() compiler inserted callback to not bail out when called from softirq context. kcov_remote_start/stop() are updated to save/restore the current per task kcov state in a per-cpu area (in case the softirq came when the kernel was already collecting coverage in task context). Coverage from softirqs is collected into pre-allocated per-cpu areas, whose size is controlled by the new CONFIG_KCOV_IRQ_AREA_SIZE. [[email protected]: turn current->kcov_softirq into unsigned int to fix objtool warning] Link: http://lkml.kernel.org/r/841c778aa3849c5cb8c3761f56b87ce653a88671.1585233617.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Reviewed-by: Dmitry Vyukov <[email protected]> Cc: Alan Stern <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Marco Elver <[email protected]> Link: http://lkml.kernel.org/r/469bd385c431d050bc38a593296eff4baae50666.1584655448.git.andreyknvl@google.com Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5fe7042 commit 5ff3b30

File tree

4 files changed

+176
-47
lines changed

4 files changed

+176
-47
lines changed

Documentation/dev-tools/kcov.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,15 @@ This allows to collect coverage from two types of kernel background
217217
threads: the global ones, that are spawned during kernel boot in a limited
218218
number of instances (e.g. one USB hub_event() worker thread is spawned per
219219
USB HCD); and the local ones, that are spawned when a user interacts with
220-
some kernel interface (e.g. vhost workers).
220+
some kernel interface (e.g. vhost workers); as well as from soft
221+
interrupts.
221222

222-
To enable collecting coverage from a global background thread, a unique
223-
global handle must be assigned and passed to the corresponding
224-
kcov_remote_start() call. Then a userspace process can pass a list of such
225-
handles to the KCOV_REMOTE_ENABLE ioctl in the handles array field of the
226-
kcov_remote_arg struct. This will attach the used kcov device to the code
227-
sections, that are referenced by those handles.
223+
To enable collecting coverage from a global background thread or from a
224+
softirq, a unique global handle must be assigned and passed to the
225+
corresponding kcov_remote_start() call. Then a userspace process can pass
226+
a list of such handles to the KCOV_REMOTE_ENABLE ioctl in the handles
227+
array field of the kcov_remote_arg struct. This will attach the used kcov
228+
device to the code sections, that are referenced by those handles.
228229

229230
Since there might be many local background threads spawned from different
230231
userspace processes, we can't use a single global handle per annotation.
@@ -242,7 +243,7 @@ handles as they don't belong to a particular subsystem. The bytes 4-7 are
242243
currently reserved and must be zero. In the future the number of bytes
243244
used for the subsystem or handle ids might be increased.
244245

245-
When a particular userspace proccess collects coverage by via a common
246+
When a particular userspace proccess collects coverage via a common
246247
handle, kcov will collect coverage for each code section that is annotated
247248
to use the common handle obtained as kcov_handle from the current
248249
task_struct. However non common handles allow to collect coverage

include/linux/sched.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,9 @@ struct task_struct {
12471247

12481248
/* KCOV sequence number: */
12491249
int kcov_sequence;
1250+
1251+
/* Collect coverage from softirq context: */
1252+
unsigned int kcov_softirq;
12501253
#endif
12511254

12521255
#ifdef CONFIG_MEMCG

0 commit comments

Comments
 (0)