lists.openwall.net | lists / announce owl-users owl-dev john-users john-dev passwdqc-users yescrypt popa3d-users / oss-security kernel-hardening musl sabotage tlsify passwords / crypt-dev xvendor / Bugtraq Full-Disclosure linux-kernel linux-netdev linux-ext4 linux-hardening PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Fri, 23 Oct 2020 17:21:20 -0700 From: Andrii Nakryiko <andrii.nakryiko@...il.com> To: Hangbin Liu <haliu@...hat.com> Cc: Stephen Hemminger <stephen@...workplumber.org>, Daniel Borkmann <daniel@...earbox.net>, David Ahern <dsahern@...il.com>, Alexei Starovoitov <ast@...nel.org>, Martin KaFai Lau <kafai@...com>, Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>, David Miller <davem@...emloft.net>, Jesper Dangaard Brouer <brouer@...hat.com>, Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>, Jiri Benc <jbenc@...hat.com>, Andrii Nakryiko <andrii@...nel.org>, Toke Høiland-Jørgensen <toke@...hat.com> Subject: Re: [PATCH iproute2-next 3/5] lib: add libbpf support On Thu, Oct 22, 2020 at 8:39 PM Hangbin Liu <haliu@...hat.com> wrote: > > This patch converts iproute2 to use libbpf for loading and attaching > BPF programs when it is available, which is started by Toke's > implementation[1]. With libbpf iproute2 could correctly process BTF > information and support the new-style BTF-defined maps, while keeping > compatibility with the old internal map definition syntax. > > The old iproute2 bpf code is kept and will be used if no suitable libbpf > is available. When using libbpf, wrapper code in bpf_legacy.c ensures that > iproute2 will still understand the old map definition format, including > populating map-in-map and tail call maps before load. > > In bpf_libbpf.c, we init iproute2 ctx and elf info first to check the > legacy bytes. When handling the legacy maps, for map-in-maps, we create > them manually and re-use the fd as they are associated with id/inner_id. > For pin maps, we only set the pin path and let libbp load to handle it. > For tail calls, we find it first and update the element after prog load. I never implemented tail call map initialization using the same approach as declarative map-in-map support in libbpf, because no one asked and/or showed a use case. But all the pieces are there, and if there's interest, we should probably support that in libbpf as well. > > Other maps/progs will be loaded by libbpf directly. > > Note: ip/ipvrf.c is not convert to use libbpf as it only encodes a few > instructions and load directly. > > [1] https://lore.kernel.org/bpf/20190820114706.18546-1-toke@redhat.com/ > > Reviewed-by: Toke Høiland-Jørgensen <toke@...hat.com> > Signed-off-by: Hangbin Liu <haliu@...hat.com> > --- > include/bpf_util.h | 11 ++ > lib/Makefile | 4 + > lib/bpf_legacy.c | 178 ++++++++++++++++++++++++ > lib/bpf_libbpf.c | 338 +++++++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 531 insertions(+) > create mode 100644 lib/bpf_libbpf.c > [...] > + > +static int load_bpf_object(struct bpf_cfg_in *cfg) > +{ > + struct bpf_program *p, *prog = NULL; > + struct bpf_object *obj; > + char root_path[PATH_MAX]; > + struct bpf_map *map; > + int prog_fd, ret = 0; > + > + ret = iproute2_get_root_path(root_path, PATH_MAX); > + if (ret) > + return ret; > + > + DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts, > + .relaxed_maps = true, > + .pin_root_path = root_path, > + ); > + > + obj = bpf_object__open_file(cfg->object, &open_opts); > + if (IS_ERR_OR_NULL(obj)) libbpf defines libbpf_get_error() to check that the returned pointer is not encoding error, you shouldn't need to define your IS_ERR macros. > + return -ENOENT; > + [...]
Powered by blists - more mailing lists