]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
libbpf: Remove use of bpf_program__set_priv and bpf_program__priv
authorDavid Ahern <dsahern@kernel.org>
Sat, 23 Apr 2022 15:22:59 +0000 (09:22 -0600)
committerDavid Ahern <dsahern@kernel.org>
Mon, 2 May 2022 21:46:10 +0000 (14:46 -0700)
bpf_program__set_priv and bpf_program__priv are deprecated as of
libbpf v0.7+. Rather than store the map as priv on the program,
change find_legacy_tail_calls to take an argument to return a reference
to the map.

find_legacy_tail_calls is invoked twice from load_bpf_object - the
first time to check for programs that should be loaded. In this case
a reference to the map is not needed, but it does validate the map
exists. The second is invoked from update_legacy_tail_call_maps where
the map pointer is needed.

Signed-off-by: David Ahern <dsahern@kernel.org>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
lib/bpf_libbpf.c

index f723f6310c28efe052a68dc55e69925303d3e846..7dd1faf536f4db7c5b52656ef3ee7a273671399b 100644 (file)
@@ -151,7 +151,8 @@ handle_legacy_map_in_map(struct bpf_object *obj, struct bpf_map *inner_map,
        return ret;
 }
 
-static int find_legacy_tail_calls(struct bpf_program *prog, struct bpf_object *obj)
+static int find_legacy_tail_calls(struct bpf_program *prog, struct bpf_object *obj,
+                                 struct bpf_map **pmap)
 {
        unsigned int map_id, key_id;
        const char *sec_name;
@@ -175,8 +176,8 @@ static int find_legacy_tail_calls(struct bpf_program *prog, struct bpf_object *o
        if (!map)
                return -1;
 
-       /* Save the map here for later updating */
-       bpf_program__set_priv(prog, map, NULL);
+       if (pmap)
+               *pmap = map;
 
        return 0;
 }
@@ -190,8 +191,10 @@ static int update_legacy_tail_call_maps(struct bpf_object *obj)
        struct bpf_map *map;
 
        bpf_object__for_each_program(prog, obj) {
-               map = bpf_program__priv(prog);
-               if (!map)
+               /* load_bpf_object has already verified find_legacy_tail_calls
+                * succeeds when it should
+                */
+               if (find_legacy_tail_calls(prog, obj, &map) < 0)
                        continue;
 
                prog_fd = bpf_program__fd(prog);
@@ -275,7 +278,8 @@ static int load_bpf_object(struct bpf_cfg_in *cfg)
 
                /* Only load the programs that will either be subsequently
                 * attached or inserted into a tail call map */
-               if (find_legacy_tail_calls(p, obj) < 0 && !prog_to_attach) {
+               if (find_legacy_tail_calls(p, obj, NULL) < 0 &&
+                   !prog_to_attach) {
                        ret = bpf_program__set_autoload(p, false);
                        if (ret)
                                return -EINVAL;