Re: [PATCH v2 bpf-next 07/12] libbpf: Use CO-RE in the kernel in light skeleton.

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

 



On Thu, Nov 11, 2021 at 9:02 PM Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> wrote:
>
> From: Alexei Starovoitov <ast@xxxxxxxxxx>
>
> Without lskel the CO-RE relocations are processed by libbpf before any other
> work is done. Instead, when lksel is needed, remember relocation as RELO_CORE

typo: lskel

> kind. Then when loader prog is generated for a given bpf program pass CO-RE
> relos of that program to gen loader via bpf_gen__record_relo_core(). The gen
> loader will remember them as-is and pass it later as-is into the kernel.
>
> Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx>
> ---
>  tools/lib/bpf/bpf_gen_internal.h |   3 +
>  tools/lib/bpf/gen_loader.c       |  41 +++++++++++-
>  tools/lib/bpf/libbpf.c           | 104 +++++++++++++++++++++++--------
>  3 files changed, 119 insertions(+), 29 deletions(-)
>
> diff --git a/tools/lib/bpf/bpf_gen_internal.h b/tools/lib/bpf/bpf_gen_internal.h
> index 75ca9fb857b2..ed162fdeecf6 100644
> --- a/tools/lib/bpf/bpf_gen_internal.h
> +++ b/tools/lib/bpf/bpf_gen_internal.h
> @@ -39,6 +39,8 @@ struct bpf_gen {
>         int error;
>         struct ksym_relo_desc *relos;
>         int relo_cnt;
> +       struct bpf_core_relo *core_relo;

this is named as a singular pointer to one relocation, core_relos
would be a more natural name for an array?


> +       int core_relo_cnt;
>         char attach_target[128];
>         int attach_kind;
>         struct ksym_desc *ksyms;
> @@ -61,5 +63,6 @@ void bpf_gen__map_freeze(struct bpf_gen *gen, int map_idx);
>  void bpf_gen__record_attach_target(struct bpf_gen *gen, const char *name, enum bpf_attach_type type);
>  void bpf_gen__record_extern(struct bpf_gen *gen, const char *name, bool is_weak,
>                             bool is_typeless, int kind, int insn_idx);

[...]

> @@ -6581,6 +6623,16 @@ static int bpf_program__record_externs(struct bpf_program *prog)
>                                                ext->is_weak, false, BTF_KIND_FUNC,
>                                                relo->insn_idx);
>                         break;
> +               case RELO_CORE: {

This is not an extern, it doesn't make sense to have it here. But I
also don't understand why we need to add RELO_CORE and extend struct
relo_desc in the first place, just to pass it as bpf_core_relo into
gen_loader. Why can't gen_loader just record this directly at the
place of record_relo_core() call?

> +                       struct bpf_core_relo cr = {
> +                               .insn_off = relo->insn_idx * 8,
> +                               .type_id = relo->type_id,
> +                               .access_str_off = relo->access_str_off,
> +                               .kind = relo->kind,
> +                       };
> +                       bpf_gen__record_relo_core(obj->gen_loader, &cr);
> +                       break;
> +               }
>                 default:
>                         continue;
>                 }
> --
> 2.30.2
>



[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