Skip to content

Commit

Permalink
selftests/bpf: Add send_signal_sched_switch test
Browse files Browse the repository at this point in the history
Added one test, send_signal_sched_switch, to test bpf_send_signal()
helper triggered by sched/sched_switch tracepoint. This test can be used
to verify kernel deadlocks fixed by the previous commit. The test itself
is heavily borrowed from Commit eac9153 ("bpf/stackmap: Fix deadlock
with rq_lock in bpf_get_stack()").

Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Cc: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20200304191105.2796601-1-yhs@fb.com
  • Loading branch information
Yonghong Song authored and Alexei Starovoitov committed Mar 5, 2020
1 parent 1bc7896 commit c4ef2f3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/send_signal_sched_switch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "test_send_signal_kern.skel.h"

static void sigusr1_handler(int signum)
{
}

#define THREAD_COUNT 100

static void *worker(void *p)
{
int i;

for ( i = 0; i < 1000; i++)
usleep(1);

return NULL;
}

void test_send_signal_sched_switch(void)
{
struct test_send_signal_kern *skel;
pthread_t threads[THREAD_COUNT];
u32 duration = 0;
int i, err;

signal(SIGUSR1, sigusr1_handler);

skel = test_send_signal_kern__open_and_load();
if (CHECK(!skel, "skel_open_and_load", "skeleton open_and_load failed\n"))
return;

skel->bss->pid = getpid();
skel->bss->sig = SIGUSR1;

err = test_send_signal_kern__attach(skel);
if (CHECK(err, "skel_attach", "skeleton attach failed\n"))
goto destroy_skel;

for (i = 0; i < THREAD_COUNT; i++) {
err = pthread_create(threads + i, NULL, worker, NULL);
if (CHECK(err, "pthread_create", "Error creating thread, %s\n",
strerror(errno)))
goto destroy_skel;
}

for (i = 0; i < THREAD_COUNT; i++)
pthread_join(threads[i], NULL);

destroy_skel:
test_send_signal_kern__destroy(skel);
}
6 changes: 6 additions & 0 deletions tools/testing/selftests/bpf/progs/test_send_signal_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ int send_signal_tp(void *ctx)
return bpf_send_signal_test(ctx);
}

SEC("tracepoint/sched/sched_switch")
int send_signal_tp_sched(void *ctx)
{
return bpf_send_signal_test(ctx);
}

SEC("perf_event")
int send_signal_perf(void *ctx)
{
Expand Down

0 comments on commit c4ef2f3

Please sign in to comment.