Skip to content

Commit 11c511c

Browse files
committed
selftests/bpf: Fix test_verifier atomic test on 32-bit
kernel-patches#20/p Can't use ATM_FETCH_ADD on kernel memory FAIL Unexpected verifier log! EXP: only read is supported RES: FAIL Unexpected error message! EXP: only read is supported RES: 0: R1=ctx() R10=fp0 0: (79) r2 = *(u64 *)(r1 +0) func 'bpf_fentry_test7' arg0 has btf_id 30402 type STRUCT 'bpf_fentry_test_t' 1: R1=ctx() R2_w=ptr_bpf_fentry_test_t() 1: (b7) r3 = 1 ; R3_w=1 2: (db) r3 = atomic64_fetch_add((u64 *)(r2 +0), r3) access beyond struct bpf_fentry_test_t at off 0 size 8 verification time 2173 usec stack depth 0 Fixes: 98d666d ("bpf: Add tests for new BPF atomic operations") Signed-off-by: Tony Ambardar <[email protected]>
1 parent 0aa2393 commit 11c511c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/testing/selftests/bpf/verifier/atomic_fetch_add.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
*/
8282
.errstr = "!read_ok",
8383
},
84+
#define BPF_PTR_SZ (sizeof(void *) == 4 ? BPF_W : BPF_DW)
8485
{
8586
"Can't use ATM_FETCH_ADD on kernel memory",
8687
.insns = {
@@ -93,7 +94,7 @@
9394
* because it's kernel memory.
9495
*/
9596
BPF_MOV64_IMM(BPF_REG_3, 1),
96-
BPF_ATOMIC_OP(BPF_DW, BPF_ADD | BPF_FETCH, BPF_REG_2, BPF_REG_3, 0),
97+
BPF_ATOMIC_OP(BPF_PTR_SZ, BPF_ADD | BPF_FETCH, BPF_REG_2, BPF_REG_3, 0),
9798
/* Done */
9899
BPF_MOV64_IMM(BPF_REG_0, 0),
99100
BPF_EXIT_INSN(),
@@ -104,3 +105,4 @@
104105
.result = REJECT,
105106
.errstr = "only read is supported",
106107
},
108+
#undef BPF_PTR_SZ

0 commit comments

Comments
 (0)