Race Condition between BPF_MAP_UPDATE_ELEM and BPF_MAP_LOOKUP_ELEM for BPF_MAP_TYPE_HASH_OF_MAPS?

Cody Haas <[email protected]> Wed, 15 Jan 2025 12:51:51 -0800
Newsgroups org.kernel.vger.xdp-newbies
Message-ID <CAH7f-ULFTwKdoH_t2SFc5rWCVYLEg-14d1fBYWH2eekudsnTRg@mail.gmail.com>
Hey everyone,

I've got a question. I've got an eBPF map that's a
BPF_MAP_TYPE_HASH_OF_MAPS where user space updates elements in the
map, user space will create a new inner map to do map-in-map swapping
in order to update the outer map's values.  My XDP program will then
read the inner maps by using BPF_MAP_LOOKUP_ELEM on the outer map.
Does this create a potential race condition between
BPF_MAP_LOOKUP_ELEM and BPF_MAP_UPDATE_ELEM when one thread is trying
to lookup an existing element while another thread is trying to update
the same existing element? I'm expecting to see either the old value
or the new value, however I'm occasionally seeing the element does not
exist when looking up the element from the eBPF program. Is this
expected?

Thanks,

Cody Haas