Re: [PATCH v2 bpf-next] libbpf: add bpf object kern_version attribute setter

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

 



On Sat, Mar 20, 2021 at 1:28 PM Rafael David Tinoco
<rafaeldtinoco@xxxxxxxxxx> wrote:
>
> Unfortunately some distros don't have their kernel version defined
> accurately in <linux/version.h> due to different long term support
> reasons.
>
> It is important to have a way to override the bpf kern_version
> attribute during runtime: some old kernels might still check for
> kern_version attribute during bpf_prog_load().
>
> Signed-off-by: Rafael David Tinoco <rafaeldtinoco@xxxxxxxxxx>
> ---

Ok, getting close, but probably another iteration is needed.

>  src/libbpf.c | 10 ++++++++++
>  src/libbpf.h |  1 +
>  2 files changed, 11 insertions(+)
>
> diff --git a/src/libbpf.c b/src/libbpf.c
> index 2f351d3..3b1c79f 100644
> --- a/src/libbpf.c
> +++ b/src/libbpf.c
> @@ -8278,6 +8278,16 @@ int bpf_object__btf_fd(const struct bpf_object *obj)
>         return obj->btf ? btf__fd(obj->btf) : -1;
>  }
>
> +int bpf_object__set_kversion(struct bpf_object *obj, __u32 kern_version)
> +{
> +       if (obj->loaded)
> +               return -1;

other functions return -EINVAL in such cases. -1 is actually -EPERM,
which is very misleading, please update


> +
> +       obj->kern_version = kern_version;
> +
> +       return 0;
> +}
> +
>  int bpf_object__set_priv(struct bpf_object *obj, void *priv,
>                          bpf_object_clear_priv_t clear_priv)
>  {
> diff --git a/src/libbpf.h b/src/libbpf.h
> index 3c35eb4..f73ec5b 100644
> --- a/src/libbpf.h
> +++ b/src/libbpf.h
> @@ -143,6 +143,7 @@ LIBBPF_API int bpf_object__unload(struct bpf_object *obj);
>
>  LIBBPF_API const char *bpf_object__name(const struct bpf_object *obj);
>  LIBBPF_API unsigned int bpf_object__kversion(const struct bpf_object *obj);
> +LIBBPF_API int bpf_object__set_kversion(struct bpf_object *obj, __u32 kern_version);

have you run libbpf's Makefile? It should have complained about
bpf_object__set_kversion symbol mismatches/etc. That means that this
API needs to be listed in libbpf.map file, please add it there (to
latest version, 0.4, and also preserve alphabetical order). Thanks.

>
>  struct btf;
>  LIBBPF_API struct btf *bpf_object__btf(const struct bpf_object *obj);
> --
> 2.27.0
>



[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