Re: Ebpf map question

Toke Høiland-Jørgensen <[email protected]> Fri, 28 Apr 2023 12:43:24 +0200
Newsgroups org.kernel.vger.xdp-newbies
Message-ID <[email protected]>
Marco <[email protected]> writes:

> Hi
>
> Assuming to have this struct:
>
> struct hash_elem {
>     int cnt;
>     };
>
> and kernel space program want read cnt value:
>
> struct hash_elem *val = bpf_map_lookup_elem(&hash_map, &key);
>
>     if (val)
>    {
>
> # time fraction
>
>     bpf_printk("My value %d", val->cnt);
>     }
>
> What happens if the hash_map is a pinned map and in the same time
> space of 'time fraction" a user program deletes the element of the
> key?
> What happen at val pointer?

The val pointer is RCU-protected so it will stick around until the end
of your BPF program's execution. However, it's up to your own code to
protect against concurrent *updates* of the value...

-Toke