Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Add bpf object kern_version attribute setter

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@ubuntu.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20210323040952.2118241-1-rafaeldtinoco@ubuntu.com

authored by

Rafael David Tinoco and committed by
Alexei Starovoitov
155f556d 3ac3f314

+12
+10
tools/lib/bpf/libbpf.c
··· 8270 8270 return obj->btf ? btf__fd(obj->btf) : -1; 8271 8271 } 8272 8272 8273 + int bpf_object__set_kversion(struct bpf_object *obj, __u32 kern_version) 8274 + { 8275 + if (obj->loaded) 8276 + return -EINVAL; 8277 + 8278 + obj->kern_version = kern_version; 8279 + 8280 + return 0; 8281 + } 8282 + 8273 8283 int bpf_object__set_priv(struct bpf_object *obj, void *priv, 8274 8284 bpf_object_clear_priv_t clear_priv) 8275 8285 {
+1
tools/lib/bpf/libbpf.h
··· 143 143 144 144 LIBBPF_API const char *bpf_object__name(const struct bpf_object *obj); 145 145 LIBBPF_API unsigned int bpf_object__kversion(const struct bpf_object *obj); 146 + LIBBPF_API int bpf_object__set_kversion(struct bpf_object *obj, __u32 kern_version); 146 147 147 148 struct btf; 148 149 LIBBPF_API struct btf *bpf_object__btf(const struct bpf_object *obj);
+1
tools/lib/bpf/libbpf.map
··· 359 359 bpf_linker__finalize; 360 360 bpf_linker__free; 361 361 bpf_linker__new; 362 + bpf_object__set_kversion; 362 363 } LIBBPF_0.3.0;