Skip to content

Commit

Permalink
selftests/bpf: Add load_kallsyms_refresh function
Browse files Browse the repository at this point in the history
Adding load_kallsyms_refresh function to re-read symbols from
/proc/kallsyms file.

This will be needed to get proper functions addresses from
bpf_testmod.ko module, which is loaded/unloaded several times
during the tests run, so symbols might be already old when
we need to use them.

Acked-by: Song Liu <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>
  • Loading branch information
olsajiri authored and Alexei Starovoitov committed Oct 25, 2022
1 parent e22061b commit 10705b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tools/testing/selftests/bpf/trace_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,15 @@ static int ksym_cmp(const void *p1, const void *p2)
return ((struct ksym *)p1)->addr - ((struct ksym *)p2)->addr;
}

int load_kallsyms(void)
int load_kallsyms_refresh(void)
{
FILE *f;
char func[256], buf[256];
char symbol;
void *addr;
int i = 0;

/*
* This is called/used from multiplace places,
* load symbols just once.
*/
if (sym_cnt)
return 0;
sym_cnt = 0;

f = fopen("/proc/kallsyms", "r");
if (!f)
Expand All @@ -57,6 +52,17 @@ int load_kallsyms(void)
return 0;
}

int load_kallsyms(void)
{
/*
* This is called/used from multiplace places,
* load symbols just once.
*/
if (sym_cnt)
return 0;
return load_kallsyms_refresh();
}

struct ksym *ksym_search(long key)
{
int start = 0, end = sym_cnt;
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/bpf/trace_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct ksym {
};

int load_kallsyms(void);
int load_kallsyms_refresh(void);

struct ksym *ksym_search(long key);
long ksym_get_addr(const char *name);

Expand Down

0 comments on commit 10705b2

Please sign in to comment.