iovisor / iovisor/bcc

is bcc object initialization thread-safe

Open
#4,500 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

Different errors occur when a process compiles ebpf concurrently using bcc。
e.g.
```
/virtual/include/bcc/helpers.h:50:10: fatal error: 'uapi/linux/bpf.h' file not found
#include
^~~~~~~~~~~~~~~~~~
```
```
In file included from /virtual/main.c:4:
include/net/sock.h:64:10: fatal error: 'linux/filter.h' file not found
#include
```
Sometimes a coredump occurs.
demo.cpp
```
#include
#include
#include
#include
#include
#include
#include
std::string strBPFCode = R"(

#include
#include
#include

struct ipv4_key_t {
u32 pid;
u16 type;
};

BPF_HASH(ipv4_map, struct ipv4_key_t,u64);

int kprobe__tcp_sendmsg(struct pt_regs *ctx, struct sock *sk,
struct msghdr *msg, size_t size)
{

u32 pid = bpf_get_current_pid_tgid() >> 32;

struct ipv4_key_t ipv4_key= {};
ipv4_key.pid = pid;
ipv4_key.type = 1;
ipv4_map.increment(ipv4_key, size);
return 0;
}

int kprobe__tcp_cleanup_rbuf(struct pt_regs *ctx, struct sock *sk, int copied)
{
u32 pid = bpf_get_current_pid_tgid() >> 32;

u64 *val, zero =0;
if (copied <= 0)
return 0;
struct ipv4_key_t ipv4_key = {};
ipv4_key.pid = pid;
ipv4_key.type = 2;
ipv4_map.increment(ipv4_key, copied);
return 0;
}
)";
struct ipv4_key_t {
uint32_t pid;
uint16_t type;
size_t size;
};
void initBPF(){
ebpf::BPF bpf;
auto init_res = bpf.init(strBPFCode);
if(!init_res.ok()) {
std::cout << "init error"<("ipv4_map");
auto table = ipv4_map.get_table_offline();
for (auto &item : table) {
std::cout << item.first.pid< tmp1 = std::async(initBPF);
std::future tmp2 = std::async(initBPF);
/* std::future tmp3 = std::async(initBPF);
std::future tmp4 = std::async(initBPF);
std::future tmp5 = std::async(initBPF);
std::future tmp6 = std::async(initBPF);
std::future tmp7 = std::async(initBPF);
std::future tmp8 = std::async(initBPF);
std::future tmp9 = std::async(initBPF);
std::future tmp10 = std::async(initBPF);
std::future tmp11 = std::async(initBPF);*/
pause();
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the concurrent reproducer in demo.cpp and the ebpf::BPF initialization path exposed by bcc/BPF.h. Run two simultaneous initBPF calls and compare the missing-header failures and core dumps with serial initialization. Done means concurrent initialization no longer produces these failures, with a regression test or documented reproducible verification.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, linux
Domain
devtools, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.