]>
git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - include/linux/instrumented.h
1 /* SPDX-License-Identifier: GPL-2.0 */
4 * This header provides generic wrappers for memory access instrumentation that
5 * the compiler cannot emit for: KASAN, KCSAN.
7 #ifndef _LINUX_INSTRUMENTED_H
8 #define _LINUX_INSTRUMENTED_H
10 #include <linux/compiler.h>
11 #include <linux/kasan-checks.h>
12 #include <linux/kcsan-checks.h>
13 #include <linux/types.h>
16 * instrument_read - instrument regular read access
18 * Instrument a regular read access. The instrumentation should be inserted
19 * before the actual read happens.
21 * @ptr address of access
22 * @size size of access
24 static __always_inline
void instrument_read(const volatile void *v
, size_t size
)
26 kasan_check_read(v
, size
);
27 kcsan_check_read(v
, size
);
31 * instrument_write - instrument regular write access
33 * Instrument a regular write access. The instrumentation should be inserted
34 * before the actual write happens.
36 * @ptr address of access
37 * @size size of access
39 static __always_inline
void instrument_write(const volatile void *v
, size_t size
)
41 kasan_check_write(v
, size
);
42 kcsan_check_write(v
, size
);
46 * instrument_atomic_read - instrument atomic read access
48 * Instrument an atomic read access. The instrumentation should be inserted
49 * before the actual read happens.
51 * @ptr address of access
52 * @size size of access
54 static __always_inline
void instrument_atomic_read(const volatile void *v
, size_t size
)
56 kasan_check_read(v
, size
);
57 kcsan_check_atomic_read(v
, size
);
61 * instrument_atomic_write - instrument atomic write access
63 * Instrument an atomic write access. The instrumentation should be inserted
64 * before the actual write happens.
66 * @ptr address of access
67 * @size size of access
69 static __always_inline
void instrument_atomic_write(const volatile void *v
, size_t size
)
71 kasan_check_write(v
, size
);
72 kcsan_check_atomic_write(v
, size
);
76 * instrument_copy_to_user - instrument reads of copy_to_user
78 * Instrument reads from kernel memory, that are due to copy_to_user (and
79 * variants). The instrumentation must be inserted before the accesses.
81 * @to destination address
82 * @from source address
83 * @n number of bytes to copy
85 static __always_inline
void
86 instrument_copy_to_user(void __user
*to
, const void *from
, unsigned long n
)
88 kasan_check_read(from
, n
);
89 kcsan_check_read(from
, n
);
93 * instrument_copy_from_user - instrument writes of copy_from_user
95 * Instrument writes to kernel memory, that are due to copy_from_user (and
96 * variants). The instrumentation should be inserted before the accesses.
98 * @to destination address
99 * @from source address
100 * @n number of bytes to copy
102 static __always_inline
void
103 instrument_copy_from_user(const void *to
, const void __user
*from
, unsigned long n
)
105 kasan_check_write(to
, n
);
106 kcsan_check_write(to
, n
);
109 #endif /* _LINUX_INSTRUMENTED_H */