Skip to content

Commit

Permalink
selftests/bpf: Make res_spin_lock AA test condition stronger
Browse files Browse the repository at this point in the history
Let's make sure that we see a EDEADLK and ETIMEDOUT whenever checking
for the AA tests (in case of simple AA and AA after exhausting 31
entries).

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20250410170023.2670683-1-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Kumar Kartikeya Dwivedi authored and Alexei Starovoitov committed Apr 10, 2025
1 parent 7bbb38f commit 1ddb9ad
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tools/testing/selftests/bpf/progs/res_spin_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ int res_spin_lock_test(struct __sk_buff *ctx)
r = bpf_res_spin_lock(&elem1->lock);
if (r)
return r;
if (!bpf_res_spin_lock(&elem2->lock)) {
r = bpf_res_spin_lock(&elem2->lock);
if (!r) {
bpf_res_spin_unlock(&elem2->lock);
bpf_res_spin_unlock(&elem1->lock);
return -1;
}
bpf_res_spin_unlock(&elem1->lock);
return 0;
return r != -EDEADLK;
}

SEC("tc")
Expand Down Expand Up @@ -124,12 +125,15 @@ int res_spin_lock_test_held_lock_max(struct __sk_buff *ctx)
/* Trigger AA, after exhausting entries in the held lock table. This
* time, only the timeout can save us, as AA detection won't succeed.
*/
if (!bpf_res_spin_lock(locks[34])) {
ret = bpf_res_spin_lock(locks[34]);
if (!ret) {
bpf_res_spin_unlock(locks[34]);
ret = 1;
goto end;
}

ret = ret != -ETIMEDOUT ? 2 : 0;

end:
for (i = i - 1; i >= 0; i--)
bpf_res_spin_unlock(locks[i]);
Expand Down

0 comments on commit 1ddb9ad

Please sign in to comment.