Skip to content

Commit

Permalink
selftests/bpf: trace_helpers.c: Add a global ksyms initialization mutex
Browse files Browse the repository at this point in the history
As Jirka said [0], we just need to make sure that global ksyms
initialization won't race.

[0] https://lore.kernel.org/lkml/ZPCbAs3ItjRd8XVh@krava/

Signed-off-by: Rong Tao <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
Rtoax authored and anakryiko committed Sep 8, 2023
1 parent c698eae commit a28b1ba
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/testing/selftests/bpf/trace_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <pthread.h>
#include <unistd.h>
#include <linux/perf_event.h>
#include <sys/mman.h>
Expand All @@ -26,6 +27,7 @@ struct ksyms {
};

static struct ksyms *ksyms;
static pthread_mutex_t ksyms_mutex = PTHREAD_MUTEX_INITIALIZER;

static int ksyms__add_symbol(struct ksyms *ksyms, const char *name,
unsigned long addr)
Expand Down Expand Up @@ -109,8 +111,10 @@ struct ksyms *load_kallsyms_local(void)

int load_kallsyms(void)
{
pthread_mutex_lock(&ksyms_mutex);
if (!ksyms)
ksyms = load_kallsyms_local();
pthread_mutex_unlock(&ksyms_mutex);
return ksyms ? 0 : 1;
}

Expand Down

0 comments on commit a28b1ba

Please sign in to comment.