Skip to content
Advertisement

BPF: `bpf_obj_get_info_by_fd` fails with `Invalid argument`

I try to get the fd of the BPF_MAP_TYPE_XSKMAP in my user-space program.

This is the code:

JavaScript

But unfortunately, I get an error for calling bpf_obj_get_info_by_fd(cfg->prog_fd, &prog_info, &prog_info_len): Failed to obtain prog_info 1: Invalid argument.

I don’t know if this is because the XDP-program is loaded from another process? Does the same process have to obtain program information which also loaded the AF-XDP program?

Edit: The only thing I changed in my user-space program was to populate a BPF_MAP_TYPE_HASH via bpf_map_update_elem (the entries are in there, observed with bpftool map dump id <id>) and to use bpf_map_lookup_elem in my XDP-program (same hash map).

And suddenly, the error changes to: Failed to obtain prog_info 1: Bad address

Advertisement

Answer

There is a comment in a function from the kernel code called when you try to retrieve information about your program, stating:

/* If we’re handed a bigger struct than we know of, ensure all the unknown bits are 0 – i.e. new user-space does not rely on any kernel feature extensions we don’t know about yet. […] */

I think this is what you hit in your case. Your libbpf version might use some attributes in struct bpf_prog_info that the kernel is not aware of.

To ensure that the kernel accepts it, simply try to zero-initialise your struct:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement