iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.5k stars 3.87k forks source link

Clarifying BPF map's get_table_offline() atomicity #3493

Open justicezyx opened 3 years ago

justicezyx commented 3 years ago

We uses BPF map to transfer data from BPF to userspace. The code calls get_table_offline() to get all data. But we are concerned about the race condition, between the userspace code and the bpf code, as during the call of get_table_offline(), the bpf map is still being written by BPF code.

But so far we have not observed fatal breakage at all.

We speculated that the race condition might causes we read stale values, or missing values, but the data structure can still be navigated correctly.

Is there more detailed description of the atomicity of get_table_offline()?

davemarchevsky commented 3 years ago

Since different data structures implement the 'BPF map operations' interface, I don't think any atomicity guarantees that are consistent across the board can be made. Is there a specific map type you're interested in?

Regardless, many of these map impls use RCU under the hood to synchronize reads and writes, so your speculation

that the race condition might causes we read stale values, or missing values, but the data structure can still be navigated correctly

sounds correct for these cases.

yzhao1012 commented 3 years ago

Is there a specific map type you're interested in?

I am looking at BPF_HASH().