diff options
author | Stanislav Fomichev <sdf@google.com> | 2020-07-15 15:41:07 -0700 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2020-07-16 20:57:09 +0200 |
commit | e81e7a533742c30615f8b15390df6525cef96778 (patch) | |
tree | ecf1d3c7989e38766aab4b931daefdd8062d833c /tools/testing | |
parent | de40a8abf07bfa125b7496b20ce6f92c6370eecd (diff) | |
download | linux-e81e7a533742c30615f8b15390df6525cef96778.tar.gz linux-e81e7a533742c30615f8b15390df6525cef96778.tar.bz2 linux-e81e7a533742c30615f8b15390df6525cef96778.zip |
selftests/bpf: Fix possible hang in sockopt_inherit
Andrii reported that sockopt_inherit occasionally hangs up on 5.5 kernel [0].
This can happen if server_thread runs faster than the main thread.
In that case, pthread_cond_wait will wait forever because
pthread_cond_signal was executed before the main thread was blocking.
Let's move pthread_mutex_lock up a bit to make sure server_thread
runs strictly after the main thread goes to sleep.
(Not sure why this is 5.5 specific, maybe scheduling is less
deterministic? But I was able to confirm that it does indeed
happen in a VM.)
[0] https://lore.kernel.org/bpf/CAEf4BzY0-bVNHmCkMFPgObs=isUAyg-dFzGDY7QWYkmm7rmTSg@mail.gmail.com/
Reported-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200715224107.3591967-1-sdf@google.com
Diffstat (limited to 'tools/testing')
-rw-r--r-- | tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c index 8547ecbdc61f..ec281b0363b8 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c @@ -193,11 +193,10 @@ static void run_test(int cgroup_fd) if (CHECK_FAIL(server_fd < 0)) goto close_bpf_object; + pthread_mutex_lock(&server_started_mtx); if (CHECK_FAIL(pthread_create(&tid, NULL, server_thread, (void *)&server_fd))) goto close_server_fd; - - pthread_mutex_lock(&server_started_mtx); pthread_cond_wait(&server_started, &server_started_mtx); pthread_mutex_unlock(&server_started_mtx); |