~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/kcov.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LINUX_KCOV_H
  3 #define _LINUX_KCOV_H
  4 
  5 #include <linux/sched.h>
  6 #include <uapi/linux/kcov.h>
  7 
  8 struct task_struct;
  9 
 10 #ifdef CONFIG_KCOV
 11 
 12 enum kcov_mode {
 13         /* Coverage collection is not enabled yet. */
 14         KCOV_MODE_DISABLED = 0,
 15         /* KCOV was initialized, but tracing mode hasn't been chosen yet. */
 16         KCOV_MODE_INIT = 1,
 17         /*
 18          * Tracing coverage collection mode.
 19          * Covered PCs are collected in a per-task buffer.
 20          */
 21         KCOV_MODE_TRACE_PC = 2,
 22         /* Collecting comparison operands mode. */
 23         KCOV_MODE_TRACE_CMP = 3,
 24         /* The process owns a KCOV remote reference. */
 25         KCOV_MODE_REMOTE = 4,
 26 };
 27 
 28 #define KCOV_IN_CTXSW   (1 << 30)
 29 
 30 void kcov_task_init(struct task_struct *t);
 31 void kcov_task_exit(struct task_struct *t);
 32 
 33 #define kcov_prepare_switch(t)                  \
 34 do {                                            \
 35         (t)->kcov_mode |= KCOV_IN_CTXSW;        \
 36 } while (0)
 37 
 38 #define kcov_finish_switch(t)                   \
 39 do {                                            \
 40         (t)->kcov_mode &= ~KCOV_IN_CTXSW;       \
 41 } while (0)
 42 
 43 /* See Documentation/dev-tools/kcov.rst for usage details. */
 44 void kcov_remote_start(u64 handle);
 45 void kcov_remote_stop(void);
 46 u64 kcov_common_handle(void);
 47 
 48 static inline void kcov_remote_start_common(u64 id)
 49 {
 50         kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_COMMON, id));
 51 }
 52 
 53 static inline void kcov_remote_start_usb(u64 id)
 54 {
 55         kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_USB, id));
 56 }
 57 
 58 /*
 59  * The softirq flavor of kcov_remote_*() functions is introduced as a temporary
 60  * workaround for KCOV's lack of nested remote coverage sections support.
 61  *
 62  * Adding support is tracked in https://bugzilla.kernel.org/show_bug.cgi?id=210337.
 63  *
 64  * kcov_remote_start_usb_softirq():
 65  *
 66  * 1. Only collects coverage when called in the softirq context. This allows
 67  *    avoiding nested remote coverage collection sections in the task context.
 68  *    For example, USB/IP calls usb_hcd_giveback_urb() in the task context
 69  *    within an existing remote coverage collection section. Thus, KCOV should
 70  *    not attempt to start collecting coverage within the coverage collection
 71  *    section in __usb_hcd_giveback_urb() in this case.
 72  *
 73  * 2. Disables interrupts for the duration of the coverage collection section.
 74  *    This allows avoiding nested remote coverage collection sections in the
 75  *    softirq context (a softirq might occur during the execution of a work in
 76  *    the BH workqueue, which runs with in_serving_softirq() > 0).
 77  *    For example, usb_giveback_urb_bh() runs in the BH workqueue with
 78  *    interrupts enabled, so __usb_hcd_giveback_urb() might be interrupted in
 79  *    the middle of its remote coverage collection section, and the interrupt
 80  *    handler might invoke __usb_hcd_giveback_urb() again.
 81  */
 82 
 83 static inline unsigned long kcov_remote_start_usb_softirq(u64 id)
 84 {
 85         unsigned long flags = 0;
 86 
 87         if (in_serving_softirq()) {
 88                 local_irq_save(flags);
 89                 kcov_remote_start_usb(id);
 90         }
 91 
 92         return flags;
 93 }
 94 
 95 static inline void kcov_remote_stop_softirq(unsigned long flags)
 96 {
 97         if (in_serving_softirq()) {
 98                 kcov_remote_stop();
 99                 local_irq_restore(flags);
100         }
101 }
102 
103 #ifdef CONFIG_64BIT
104 typedef unsigned long kcov_u64;
105 #else
106 typedef unsigned long long kcov_u64;
107 #endif
108 
109 void __sanitizer_cov_trace_pc(void);
110 void __sanitizer_cov_trace_cmp1(u8 arg1, u8 arg2);
111 void __sanitizer_cov_trace_cmp2(u16 arg1, u16 arg2);
112 void __sanitizer_cov_trace_cmp4(u32 arg1, u32 arg2);
113 void __sanitizer_cov_trace_cmp8(kcov_u64 arg1, kcov_u64 arg2);
114 void __sanitizer_cov_trace_const_cmp1(u8 arg1, u8 arg2);
115 void __sanitizer_cov_trace_const_cmp2(u16 arg1, u16 arg2);
116 void __sanitizer_cov_trace_const_cmp4(u32 arg1, u32 arg2);
117 void __sanitizer_cov_trace_const_cmp8(kcov_u64 arg1, kcov_u64 arg2);
118 void __sanitizer_cov_trace_switch(kcov_u64 val, void *cases);
119 
120 #else
121 
122 static inline void kcov_task_init(struct task_struct *t) {}
123 static inline void kcov_task_exit(struct task_struct *t) {}
124 static inline void kcov_prepare_switch(struct task_struct *t) {}
125 static inline void kcov_finish_switch(struct task_struct *t) {}
126 static inline void kcov_remote_start(u64 handle) {}
127 static inline void kcov_remote_stop(void) {}
128 static inline u64 kcov_common_handle(void)
129 {
130         return 0;
131 }
132 static inline void kcov_remote_start_common(u64 id) {}
133 static inline void kcov_remote_start_usb(u64 id) {}
134 static inline unsigned long kcov_remote_start_usb_softirq(u64 id)
135 {
136         return 0;
137 }
138 static inline void kcov_remote_stop_softirq(unsigned long flags) {}
139 
140 #endif /* CONFIG_KCOV */
141 #endif /* _LINUX_KCOV_H */
142 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php