I want to pass data between user/kernel side with BPF_PROG_TYPE_CGROUP_DEVICE
I have defined map as:
struct bpf_map_def SEC("maps") my_map = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(int),
.max_entries = 100,
};
When I execute following in BPF program:
int ret = bpf_map_update_elem(&my_map, &key, &value, BPF_ANY);
void *out = bpf_map_lookup_elem(&my_map, &key);
if (!out)
{
// Never gets in here
}
My code never gets in if statement.
User side
On user side, I get correctly loaded reference to map with helper functions that provide me global arrays like
struct bpf_map_data map_data[MAX_MAPS];
.
I am able to fetch map name with:
printf("Name: %s \n", map_data[0].name);
this means that I am able to correctly parse ELF file for SEC("maps") attribute, and when I try the following:
bpf_map_update_elem(map_data[0].fd, &key, &value, BPF_ANY);
bpf_map_lookup_elem(map_data[0].fd, &key, &value);
Map data is updated and it is visible in user space.
Problem is that I can not see map defined in BPF program inside it self. I have tried with another type of program and it is behaving as expected.
Am I missing something with this type BPF_PROG_TYPE_CGROUP_DEVICE and data sharing with maps ?