1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <uapi/linux/kcov.h>
12 /* Coverage collection is not enabled yet. */
13 KCOV_MODE_DISABLED = 0,
14 /* KCOV was initialized, but tracing mode hasn't been chosen yet. */
17 * Tracing coverage collection mode.
18 * Covered PCs are collected in a per-task buffer.
20 KCOV_MODE_TRACE_PC = 2,
21 /* Collecting comparison operands mode. */
22 KCOV_MODE_TRACE_CMP = 3,
25 #define KCOV_IN_CTXSW (1 << 30)
27 void kcov_task_init(struct task_struct *t);
28 void kcov_task_exit(struct task_struct *t);
30 #define kcov_prepare_switch(t) \
32 (t)->kcov_mode |= KCOV_IN_CTXSW; \
35 #define kcov_finish_switch(t) \
37 (t)->kcov_mode &= ~KCOV_IN_CTXSW; \
40 /* See Documentation/dev-tools/kcov.rst for usage details. */
41 void kcov_remote_start(u64 handle);
42 void kcov_remote_stop(void);
43 u64 kcov_common_handle(void);
45 static inline void kcov_remote_start_common(u64 id)
47 kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_COMMON, id));
50 static inline void kcov_remote_start_usb(u64 id)
52 kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_USB, id));
56 * The softirq flavor of kcov_remote_*() functions is introduced as a temporary
57 * work around for kcov's lack of nested remote coverage sections support in
58 * task context. Adding suport for nested sections is tracked in:
59 * https://bugzilla.kernel.org/show_bug.cgi?id=210337
62 static inline void kcov_remote_start_usb_softirq(u64 id)
64 if (in_serving_softirq())
65 kcov_remote_start_usb(id);
68 static inline void kcov_remote_stop_softirq(void)
70 if (in_serving_softirq())
76 static inline void kcov_task_init(struct task_struct *t) {}
77 static inline void kcov_task_exit(struct task_struct *t) {}
78 static inline void kcov_prepare_switch(struct task_struct *t) {}
79 static inline void kcov_finish_switch(struct task_struct *t) {}
80 static inline void kcov_remote_start(u64 handle) {}
81 static inline void kcov_remote_stop(void) {}
82 static inline u64 kcov_common_handle(void)
86 static inline void kcov_remote_start_common(u64 id) {}
87 static inline void kcov_remote_start_usb(u64 id) {}
88 static inline void kcov_remote_start_usb_softirq(u64 id) {}
89 static inline void kcov_remote_stop_softirq(void) {}
91 #endif /* CONFIG_KCOV */
92 #endif /* _LINUX_KCOV_H */