xref: /openbmc/linux/include/linux/kcov.h (revision 0ed557aa813922f6f32adec69e266532091c895b)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
25c9a8750SDmitry Vyukov #ifndef _LINUX_KCOV_H
35c9a8750SDmitry Vyukov #define _LINUX_KCOV_H
45c9a8750SDmitry Vyukov 
55c9a8750SDmitry Vyukov #include <uapi/linux/kcov.h>
65c9a8750SDmitry Vyukov 
75c9a8750SDmitry Vyukov struct task_struct;
85c9a8750SDmitry Vyukov 
95c9a8750SDmitry Vyukov #ifdef CONFIG_KCOV
105c9a8750SDmitry Vyukov 
115c9a8750SDmitry Vyukov enum kcov_mode {
125c9a8750SDmitry Vyukov 	/* Coverage collection is not enabled yet. */
135c9a8750SDmitry Vyukov 	KCOV_MODE_DISABLED = 0,
14ded97d2cSVictor Chibotaru 	/* KCOV was initialized, but tracing mode hasn't been chosen yet. */
15ded97d2cSVictor Chibotaru 	KCOV_MODE_INIT = 1,
165c9a8750SDmitry Vyukov 	/*
175c9a8750SDmitry Vyukov 	 * Tracing coverage collection mode.
185c9a8750SDmitry Vyukov 	 * Covered PCs are collected in a per-task buffer.
195c9a8750SDmitry Vyukov 	 */
20ded97d2cSVictor Chibotaru 	KCOV_MODE_TRACE_PC = 2,
21ded97d2cSVictor Chibotaru 	/* Collecting comparison operands mode. */
22ded97d2cSVictor Chibotaru 	KCOV_MODE_TRACE_CMP = 3,
235c9a8750SDmitry Vyukov };
245c9a8750SDmitry Vyukov 
25*0ed557aaSMark Rutland #define KCOV_IN_CTXSW	(1 << 30)
26*0ed557aaSMark Rutland 
27ded97d2cSVictor Chibotaru void kcov_task_init(struct task_struct *t);
28ded97d2cSVictor Chibotaru void kcov_task_exit(struct task_struct *t);
29ded97d2cSVictor Chibotaru 
30*0ed557aaSMark Rutland #define kcov_prepare_switch(t)			\
31*0ed557aaSMark Rutland do {						\
32*0ed557aaSMark Rutland 	(t)->kcov_mode |= KCOV_IN_CTXSW;	\
33*0ed557aaSMark Rutland } while (0)
34*0ed557aaSMark Rutland 
35*0ed557aaSMark Rutland #define kcov_finish_switch(t)			\
36*0ed557aaSMark Rutland do {						\
37*0ed557aaSMark Rutland 	(t)->kcov_mode &= ~KCOV_IN_CTXSW;	\
38*0ed557aaSMark Rutland } while (0)
39*0ed557aaSMark Rutland 
405c9a8750SDmitry Vyukov #else
415c9a8750SDmitry Vyukov 
425c9a8750SDmitry Vyukov static inline void kcov_task_init(struct task_struct *t) {}
435c9a8750SDmitry Vyukov static inline void kcov_task_exit(struct task_struct *t) {}
44*0ed557aaSMark Rutland static inline void kcov_prepare_switch(struct task_struct *t) {}
45*0ed557aaSMark Rutland static inline void kcov_finish_switch(struct task_struct *t) {}
465c9a8750SDmitry Vyukov 
475c9a8750SDmitry Vyukov #endif /* CONFIG_KCOV */
485c9a8750SDmitry Vyukov #endif /* _LINUX_KCOV_H */
49