Home > Software design >  ebpf tail call didn't work even bpf code is loaded successfully
ebpf tail call didn't work even bpf code is loaded successfully

Time:05-11

#include "bpf/bpf_helpers.h"
#include <linux/bpf.h>
char _license[] SEC("license") = "GPL";
struct bpf_map_def SEC("maps") jump_table = {
    .type = BPF_MAP_TYPE_PROG_ARRAY,
    .key_size = sizeof(__u32),
    .value_size = sizeof(__u32),
    .max_entries = 100,
};

SEC("xdp_1")
int test_func(struct xdp_md *ctx) {
  bpf_printk("tail call\n");
  return XDP_PASS;
}

SEC("xdp")
int xdp_pass_func(struct xdp_md *ctx) {
  __u32 zero = 0;
  bpf_tail_call(ctx, &jump_table, zero);
  bpf_printk("tail call failed\n");
  return XDP_PASS;
}

when i look cat /sys/kernel/debug/tracing/trace_pipe, it shows tail call failed,but i don't know whats wrong,here is my load code

func main() {
    if err := rlimit.RemoveMemlock(); err != nil {
        log.Fatal(err)
        return
    }
    var obj aclObjects
    err := loadAclObjects(&obj, nil)
    if err != nil {
        log.Fatal(err)
        return
    }
    err = obj.JumpTable.Put(uint32(0), uint32(obj.TestFunc.FD()))
    if err != nil {
        log.Fatal(err)
        return
    }
    link, err := netlink.LinkByName("ens33")
    if err != nil {
        log.Fatal(err)
        return
    }
    err = netlink.LinkSetXdpFd(link, obj.XdpPassFunc.FD())
    if err != nil {
        log.Fatal(err)
        return
    }
}

the bpf code can be loaded, but it seems some thing wrong with tail_call,i wrote it according to linux source code,someone can help me?

CodePudding user response:

As you realised and mentioned in your answer, the file descriptor referencing the program will indeed be closed when the loader exits.

If nothing else references the program, it is unloaded. What can hold such a reference?

What you want is to pin your program before your loader exits (It seems you use goebpf? Apparently the library has a Pin() function, which should probably help).

CodePudding user response:

i find the problem that prog fd will be closed when loader program exit, so i keep the program blocked and tail call works fine, i don't know why fd closed is a problem, hoping someone can answer

  • Related