mapsebpfxdp-bpfxdp-pdf

eBPF XDP - Bad map relocation


I have a short program with two eBPF maps, one used to redirect to an AF_XDP socket, and another to keep track on statistics. However, when trying to load this program, the following error appears: libbpf: prog 'xdp_sock_prog': bad map relo against 'xsks_map' in section '.maps' But, when I comment out the second map (xdp_stats_map), the program loads as usual.

Until a few days ago, this program was able to be loaded normally. But, only after updating the Kernel from 5.12 to 6.5.0 this error started to occur. Would this be related to my problem?

struct {
    __uint(type, BPF_MAP_TYPE_XSKMAP);
    __type(key, __u32);
    __type(value, __u32);
    __uint(max_entries, 64);
} xsks_map SEC(".maps");

struct {
    __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
    __type(key, __u32);
    __type(value, __u32);
    __uint(max_entries, 64);
} xdp_stats_map SEC(".maps");

SEC("xdp")
int xdp_sock_prog(struct xdp_md *ctx)
{
    int index = ctx->rx_queue_index;
    __u32 *pkt_count;

    pkt_count = bpf_map_lookup_elem(&xdp_stats_map, &index);

    //int cpu = bpf_get_smp_processor_id();
    if (bpf_map_lookup_elem(&xsks_map, &index)) {
        //bpf_printk("TEST %d %d", cpu, index);
        return bpf_redirect_map(&xsks_map, index, 0);
    }

    return XDP_PASS;
}

Thanks in advance

In some other XDP programs I have, if it has only one map declared, it loads, but after adding another copy of the map with a different id, this error happens too.


Solution

  • It looks like xdp-tools wasn't compiling correctly due to an older version of clang and llc. So, I updated to clang-16 and llc-16 following this link link, and it worked