Re: [PATCH bpf-next 5/8] selftests/bpf: Add load_kallsyms_refresh function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Oct 9, 2022 at 3:00 PM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
>
> 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.
>
> Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>

Acked-by: Song Liu <song@xxxxxxxxxx>

> ---
>  tools/testing/selftests/bpf/trace_helpers.c | 20 +++++++++++++-------
>  tools/testing/selftests/bpf/trace_helpers.h |  2 ++
>  2 files changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
> index 9c4be2cdb21a..09a16a77bae4 100644
> --- a/tools/testing/selftests/bpf/trace_helpers.c
> +++ b/tools/testing/selftests/bpf/trace_helpers.c
> @@ -23,7 +23,7 @@ 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];
> @@ -31,12 +31,7 @@ int load_kallsyms(void)
>         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)
> @@ -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;
> diff --git a/tools/testing/selftests/bpf/trace_helpers.h b/tools/testing/selftests/bpf/trace_helpers.h
> index 238a9c98cde2..53efde0e2998 100644
> --- a/tools/testing/selftests/bpf/trace_helpers.h
> +++ b/tools/testing/selftests/bpf/trace_helpers.h
> @@ -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);
>
> --
> 2.37.3
>



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux