Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0
  2#include <linux/bpf.h>
  3#include <bpf/bpf_helpers.h>
  4#include <bpf/bpf_tracing.h>
  5#include <stdbool.h>
  6
  7#ifdef ENABLE_ATOMICS_TESTS
  8bool skip_tests __attribute((__section__(".data"))) = false;
  9#else
 10bool skip_tests = true;
 11#endif
 12
 13__u32 pid = 0;
 14
 15__u64 add64_value = 1;
 16__u64 add64_result = 0;
 17__u32 add32_value = 1;
 18__u32 add32_result = 0;
 19__u64 add_stack_value_copy = 0;
 20__u64 add_stack_result = 0;
 21__u64 add_noreturn_value = 1;
 22
 23SEC("raw_tp/sys_enter")
 24int add(const void *ctx)
 25{
 26	if (pid != (bpf_get_current_pid_tgid() >> 32))
 27		return 0;
 28#ifdef ENABLE_ATOMICS_TESTS
 29	__u64 add_stack_value = 1;
 30
 31	add64_result = __sync_fetch_and_add(&add64_value, 2);
 32	add32_result = __sync_fetch_and_add(&add32_value, 2);
 33	add_stack_result = __sync_fetch_and_add(&add_stack_value, 2);
 34	add_stack_value_copy = add_stack_value;
 35	__sync_fetch_and_add(&add_noreturn_value, 2);
 36#endif
 37
 38	return 0;
 39}
 40
 41__s64 sub64_value = 1;
 42__s64 sub64_result = 0;
 43__s32 sub32_value = 1;
 44__s32 sub32_result = 0;
 45__s64 sub_stack_value_copy = 0;
 46__s64 sub_stack_result = 0;
 47__s64 sub_noreturn_value = 1;
 48
 49SEC("raw_tp/sys_enter")
 50int sub(const void *ctx)
 51{
 52	if (pid != (bpf_get_current_pid_tgid() >> 32))
 53		return 0;
 54#ifdef ENABLE_ATOMICS_TESTS
 55	__u64 sub_stack_value = 1;
 56
 57	sub64_result = __sync_fetch_and_sub(&sub64_value, 2);
 58	sub32_result = __sync_fetch_and_sub(&sub32_value, 2);
 59	sub_stack_result = __sync_fetch_and_sub(&sub_stack_value, 2);
 60	sub_stack_value_copy = sub_stack_value;
 61	__sync_fetch_and_sub(&sub_noreturn_value, 2);
 62#endif
 63
 64	return 0;
 65}
 66
 67__u64 and64_value = (0x110ull << 32);
 68__u64 and64_result = 0;
 69__u32 and32_value = 0x110;
 70__u32 and32_result = 0;
 71__u64 and_noreturn_value = (0x110ull << 32);
 72
 73SEC("raw_tp/sys_enter")
 74int and(const void *ctx)
 75{
 76	if (pid != (bpf_get_current_pid_tgid() >> 32))
 77		return 0;
 78#ifdef ENABLE_ATOMICS_TESTS
 79
 80	and64_result = __sync_fetch_and_and(&and64_value, 0x011ull << 32);
 81	and32_result = __sync_fetch_and_and(&and32_value, 0x011);
 82	__sync_fetch_and_and(&and_noreturn_value, 0x011ull << 32);
 83#endif
 84
 85	return 0;
 86}
 87
 88__u64 or64_value = (0x110ull << 32);
 89__u64 or64_result = 0;
 90__u32 or32_value = 0x110;
 91__u32 or32_result = 0;
 92__u64 or_noreturn_value = (0x110ull << 32);
 93
 94SEC("raw_tp/sys_enter")
 95int or(const void *ctx)
 96{
 97	if (pid != (bpf_get_current_pid_tgid() >> 32))
 98		return 0;
 99#ifdef ENABLE_ATOMICS_TESTS
100	or64_result = __sync_fetch_and_or(&or64_value, 0x011ull << 32);
101	or32_result = __sync_fetch_and_or(&or32_value, 0x011);
102	__sync_fetch_and_or(&or_noreturn_value, 0x011ull << 32);
103#endif
104
105	return 0;
106}
107
108__u64 xor64_value = (0x110ull << 32);
109__u64 xor64_result = 0;
110__u32 xor32_value = 0x110;
111__u32 xor32_result = 0;
112__u64 xor_noreturn_value = (0x110ull << 32);
113
114SEC("raw_tp/sys_enter")
115int xor(const void *ctx)
116{
117	if (pid != (bpf_get_current_pid_tgid() >> 32))
118		return 0;
119#ifdef ENABLE_ATOMICS_TESTS
120	xor64_result = __sync_fetch_and_xor(&xor64_value, 0x011ull << 32);
121	xor32_result = __sync_fetch_and_xor(&xor32_value, 0x011);
122	__sync_fetch_and_xor(&xor_noreturn_value, 0x011ull << 32);
123#endif
124
125	return 0;
126}
127
128__u64 cmpxchg64_value = 1;
129__u64 cmpxchg64_result_fail = 0;
130__u64 cmpxchg64_result_succeed = 0;
131__u32 cmpxchg32_value = 1;
132__u32 cmpxchg32_result_fail = 0;
133__u32 cmpxchg32_result_succeed = 0;
134
135SEC("raw_tp/sys_enter")
136int cmpxchg(const void *ctx)
137{
138	if (pid != (bpf_get_current_pid_tgid() >> 32))
139		return 0;
140#ifdef ENABLE_ATOMICS_TESTS
141	cmpxchg64_result_fail = __sync_val_compare_and_swap(&cmpxchg64_value, 0, 3);
142	cmpxchg64_result_succeed = __sync_val_compare_and_swap(&cmpxchg64_value, 1, 2);
143
144	cmpxchg32_result_fail = __sync_val_compare_and_swap(&cmpxchg32_value, 0, 3);
145	cmpxchg32_result_succeed = __sync_val_compare_and_swap(&cmpxchg32_value, 1, 2);
146#endif
147
148	return 0;
149}
150
151__u64 xchg64_value = 1;
152__u64 xchg64_result = 0;
153__u32 xchg32_value = 1;
154__u32 xchg32_result = 0;
155
156SEC("raw_tp/sys_enter")
157int xchg(const void *ctx)
158{
159	if (pid != (bpf_get_current_pid_tgid() >> 32))
160		return 0;
161#ifdef ENABLE_ATOMICS_TESTS
162	__u64 val64 = 2;
163	__u32 val32 = 2;
164
165	xchg64_result = __sync_lock_test_and_set(&xchg64_value, val64);
166	xchg32_result = __sync_lock_test_and_set(&xchg32_value, val32);
167#endif
168
169	return 0;
170}
v5.14.15
  1// SPDX-License-Identifier: GPL-2.0
  2#include <linux/bpf.h>
  3#include <bpf/bpf_helpers.h>
  4#include <bpf/bpf_tracing.h>
  5#include <stdbool.h>
  6
  7#ifdef ENABLE_ATOMICS_TESTS
  8bool skip_tests __attribute((__section__(".data"))) = false;
  9#else
 10bool skip_tests = true;
 11#endif
 12
 
 
 13__u64 add64_value = 1;
 14__u64 add64_result = 0;
 15__u32 add32_value = 1;
 16__u32 add32_result = 0;
 17__u64 add_stack_value_copy = 0;
 18__u64 add_stack_result = 0;
 19__u64 add_noreturn_value = 1;
 20
 21SEC("fentry/bpf_fentry_test1")
 22int BPF_PROG(add, int a)
 23{
 
 
 24#ifdef ENABLE_ATOMICS_TESTS
 25	__u64 add_stack_value = 1;
 26
 27	add64_result = __sync_fetch_and_add(&add64_value, 2);
 28	add32_result = __sync_fetch_and_add(&add32_value, 2);
 29	add_stack_result = __sync_fetch_and_add(&add_stack_value, 2);
 30	add_stack_value_copy = add_stack_value;
 31	__sync_fetch_and_add(&add_noreturn_value, 2);
 32#endif
 33
 34	return 0;
 35}
 36
 37__s64 sub64_value = 1;
 38__s64 sub64_result = 0;
 39__s32 sub32_value = 1;
 40__s32 sub32_result = 0;
 41__s64 sub_stack_value_copy = 0;
 42__s64 sub_stack_result = 0;
 43__s64 sub_noreturn_value = 1;
 44
 45SEC("fentry/bpf_fentry_test1")
 46int BPF_PROG(sub, int a)
 47{
 
 
 48#ifdef ENABLE_ATOMICS_TESTS
 49	__u64 sub_stack_value = 1;
 50
 51	sub64_result = __sync_fetch_and_sub(&sub64_value, 2);
 52	sub32_result = __sync_fetch_and_sub(&sub32_value, 2);
 53	sub_stack_result = __sync_fetch_and_sub(&sub_stack_value, 2);
 54	sub_stack_value_copy = sub_stack_value;
 55	__sync_fetch_and_sub(&sub_noreturn_value, 2);
 56#endif
 57
 58	return 0;
 59}
 60
 61__u64 and64_value = (0x110ull << 32);
 62__u64 and64_result = 0;
 63__u32 and32_value = 0x110;
 64__u32 and32_result = 0;
 65__u64 and_noreturn_value = (0x110ull << 32);
 66
 67SEC("fentry/bpf_fentry_test1")
 68int BPF_PROG(and, int a)
 69{
 
 
 70#ifdef ENABLE_ATOMICS_TESTS
 71
 72	and64_result = __sync_fetch_and_and(&and64_value, 0x011ull << 32);
 73	and32_result = __sync_fetch_and_and(&and32_value, 0x011);
 74	__sync_fetch_and_and(&and_noreturn_value, 0x011ull << 32);
 75#endif
 76
 77	return 0;
 78}
 79
 80__u64 or64_value = (0x110ull << 32);
 81__u64 or64_result = 0;
 82__u32 or32_value = 0x110;
 83__u32 or32_result = 0;
 84__u64 or_noreturn_value = (0x110ull << 32);
 85
 86SEC("fentry/bpf_fentry_test1")
 87int BPF_PROG(or, int a)
 88{
 
 
 89#ifdef ENABLE_ATOMICS_TESTS
 90	or64_result = __sync_fetch_and_or(&or64_value, 0x011ull << 32);
 91	or32_result = __sync_fetch_and_or(&or32_value, 0x011);
 92	__sync_fetch_and_or(&or_noreturn_value, 0x011ull << 32);
 93#endif
 94
 95	return 0;
 96}
 97
 98__u64 xor64_value = (0x110ull << 32);
 99__u64 xor64_result = 0;
100__u32 xor32_value = 0x110;
101__u32 xor32_result = 0;
102__u64 xor_noreturn_value = (0x110ull << 32);
103
104SEC("fentry/bpf_fentry_test1")
105int BPF_PROG(xor, int a)
106{
 
 
107#ifdef ENABLE_ATOMICS_TESTS
108	xor64_result = __sync_fetch_and_xor(&xor64_value, 0x011ull << 32);
109	xor32_result = __sync_fetch_and_xor(&xor32_value, 0x011);
110	__sync_fetch_and_xor(&xor_noreturn_value, 0x011ull << 32);
111#endif
112
113	return 0;
114}
115
116__u64 cmpxchg64_value = 1;
117__u64 cmpxchg64_result_fail = 0;
118__u64 cmpxchg64_result_succeed = 0;
119__u32 cmpxchg32_value = 1;
120__u32 cmpxchg32_result_fail = 0;
121__u32 cmpxchg32_result_succeed = 0;
122
123SEC("fentry/bpf_fentry_test1")
124int BPF_PROG(cmpxchg, int a)
125{
 
 
126#ifdef ENABLE_ATOMICS_TESTS
127	cmpxchg64_result_fail = __sync_val_compare_and_swap(&cmpxchg64_value, 0, 3);
128	cmpxchg64_result_succeed = __sync_val_compare_and_swap(&cmpxchg64_value, 1, 2);
129
130	cmpxchg32_result_fail = __sync_val_compare_and_swap(&cmpxchg32_value, 0, 3);
131	cmpxchg32_result_succeed = __sync_val_compare_and_swap(&cmpxchg32_value, 1, 2);
132#endif
133
134	return 0;
135}
136
137__u64 xchg64_value = 1;
138__u64 xchg64_result = 0;
139__u32 xchg32_value = 1;
140__u32 xchg32_result = 0;
141
142SEC("fentry/bpf_fentry_test1")
143int BPF_PROG(xchg, int a)
144{
 
 
145#ifdef ENABLE_ATOMICS_TESTS
146	__u64 val64 = 2;
147	__u32 val32 = 2;
148
149	xchg64_result = __sync_lock_test_and_set(&xchg64_value, val64);
150	xchg32_result = __sync_lock_test_and_set(&xchg32_value, val32);
151#endif
152
153	return 0;
154}