selftests/bpf: fix task_local_storage/exit_creds rcu usage
authorDelyan Kratunov <delyank@meta.com>
Fri, 21 Oct 2022 19:36:38 +0000 (19:36 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 21 Oct 2022 20:58:09 +0000 (13:58 -0700)
commiteb814cf1adea0ce24413c26c22e9f1a556a45d34
tree57f74ecffec4ad4400e21b78f6afe43007d9d3a9
parent12f96823a9d7724f819424f6232d9e46a56e80d1
selftests/bpf: fix task_local_storage/exit_creds rcu usage

BPF CI has revealed flakiness in the task_local_storage/exit_creds test.
The failure point in CI [1] is that null_ptr_count is equal to 0,
which indicates that the program hasn't run yet. This points to the
kern_sync_rcu (sys_membarrier -> synchronize_rcu underneath) not
waiting sufficiently.

Indeed, synchronize_rcu only waits for read-side sections that started
before the call. If the program execution starts *during* the
synchronize_rcu invocation (due to, say, preemption), the test won't
wait long enough.

As a speculative fix, make the synchornize_rcu calls in a loop until
an explicit run counter has gone up.

  [1]: https://github.com/kernel-patches/bpf/actions/runs/3268263235/jobs/5374940791

Signed-off-by: Delyan Kratunov <delyank@meta.com>
Link: https://lore.kernel.org/r/156d4ef82275a074e8da8f4cffbd01b0c1466493.camel@meta.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/task_local_storage.c
tools/testing/selftests/bpf/progs/task_local_storage_exit_creds.c