-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add BPF map reuse function #346
Conversation
c1531f2
to
7ea3e99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @javierhonduco for this contribution. Could you also provide a selftest for this new helper?
dc8d5c1
to
4339c97
Compare
@@ -33,7 +33,7 @@ okcontinue() { okay "$1"; } | |||
kern_version() { | |||
_oper=$1; _version=$2; _notfatal=$3; | |||
_given=$(($(echo $_version | sed 's:\.::g'))) | |||
_current=$(($(uname -r | cut -d'.' -f1,2 | sed 's:\.::g'))) | |||
_current=$(($(uname -r | cut -d'.' -f1,2,3 | sed 's:\.::g'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated this check to make it work with my release 6.3.11-200.fc38.x86_64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo '6.3.11-200.fc38.x86_64' | cut -d'.' -f1,2 | sed 's:\.::g'
63
It seems ok, we need to merge only the first and second field of the numeric version.
Could you please recheck this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On #356
[javierhonduco@fedora reuse-fd]$ ./run.sh
[!] ERROR: kernel 64 not gt than 418
(Now with kernel 6.4.6-200.fc38.x86_64
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, it seems a logic issue. I'm going to take a look at this later. Thanks.
4339c97
to
f0374b4
Compare
Wrap `bpf_map__reuse_fd` to reuse a BPF map accross BPF programs. This is useful in complex programs that long chains of calls, for example, via `bpf_tail_call` that may be loaded in different programs and share state via reused maps. Why is this useful ================= Our global state map, called `heap` is shared by multiple programs. Map reuse will soon become a load loading functionality for Parca Agent. Test Plan ========= Added selftest + ``` [javierhonduco@fedora parca-agent]$ sudo bpftool map | grep heap 3403: percpu_array name heap flags 0x0 ``` ``` 2812: perf_event name walk_user_stacktrace_impl tag 25cb7e352f197144 gpl loaded_at 2023-08-01T16:06:01+0100 uid 0 xlated 7984B jited 4827B memlock 12288B map_ids 3399,3411,3401,3407,3400,3408,3409,3402,3406,3405,3403 btf_id 1993 pids parca-agent(1049424) metadata: name = "parca-agent (https://github.com/parca-dev/parca-agent)" 2814: perf_event name profile_cpu tag 3f2053ff90208ef1 gpl loaded_at 2023-08-01T16:06:02+0100 uid 0 xlated 4368B jited 2850B memlock 8192B map_ids 3411,3404,3399,3401,3408,3409,3405,3407,3403,3402 btf_id 1993 pids parca-agent(1049424) metadata: name = "parca-agent (https://github.com/parca-dev/parca-agent)" 2816: perf_event name walk_ruby_stack tag 97bb3ee23c47e22d gpl loaded_at 2023-08-01T16:06:02+0100 uid 0 xlated 87600B jited 56572B memlock 98304B map_ids 3413,3414,3419,3415,3399,3403,3420,3417,3418 btf_id 1994 pids parca-agent(1049424) ``` We are thoroughly testing it, across multiple kernels and with ASAN enabled, too. If there were any problems in the future we will quickly notice them and will be happy to submit bugfixes. Signed-off-by: Francisco Javier Honduvilla Coto <[email protected]>
f0374b4
to
d668e72
Compare
@javierhonduco I'm going to review this today 👍🏼 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javierhonduco thank your for your changes. As I commented I'll cherry-pick this and line it in with the on going changes.
if errC != 0 { | ||
return fmt.Errorf("could not reuse bpf map fd %d: %w", fd, syscall.Errno(-errC)) | ||
} | ||
b.fd = C.int(fd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fd to be updated is an open/dupped one, not the provided. I also noticed that the map name needs to be updated.
Well, my current work is changing BPFMap to:
As I'm introducing a bunch of changes, I'm going to stop to create conflicts to you 😅, cherry-picking your contribution and doing the required adjustments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking care of this, did not know about the refactor!
@@ -33,7 +33,7 @@ okcontinue() { okay "$1"; } | |||
kern_version() { | |||
_oper=$1; _version=$2; _notfatal=$3; | |||
_given=$(($(echo $_version | sed 's:\.::g'))) | |||
_current=$(($(uname -r | cut -d'.' -f1,2 | sed 's:\.::g'))) | |||
_current=$(($(uname -r | cut -d'.' -f1,2,3 | sed 's:\.::g'))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo '6.3.11-200.fc38.x86_64' | cut -d'.' -f1,2 | sed 's:\.::g'
63
It seems ok, we need to merge only the first and second field of the numeric version.
Could you please recheck this?
Done: 9acf966 Thanks again @javierhonduco. 🚀 |
The `ReuseFD` function links the current BPFMap instance to a provided map file descriptor. This enables the reuse of a map that was initiated by another process. Initial effort: aquasecurity#346 Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
The `ReuseFD` function links the current BPFMap instance to a provided map file descriptor. This enables the reuse of a map that was initiated by another process. Initial effort: aquasecurity#346 Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
The `ReuseFD` function links the current BPFMap instance to a provided map file descriptor. This enables the reuse of a map that was initiated by another process. Initial effort: aquasecurity#346 Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
The `ReuseFD` function links the current BPFMap instance to a provided map file descriptor. This enables the reuse of a map that was initiated by another process. Initial effort: aquasecurity#346 Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
The `ReuseFD` function links the current BPFMap instance to a provided map file descriptor. This enables the reuse of a map that was initiated by another process. Initial effort: aquasecurity#346 Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
The `ReuseFD` function links the current BPFMap instance to a provided map file descriptor. This enables the reuse of a map that was initiated by another process. Initial effort: aquasecurity#346 Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
The `ReuseFD` function links the current BPFMap instance to a provided map file descriptor. This enables the reuse of a map that was initiated by another process. Initial effort: aquasecurity#346 Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
The `ReuseFD` function links the current BPFMap instance to a provided map file descriptor. This enables the reuse of a map that was initiated by another process. Initial effort: aquasecurity#346 Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
The `ReuseFD` function links the current BPFMap instance to a provided map file descriptor. This enables the reuse of a map that was initiated by another process. Initial effort: aquasecurity#346 Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
The `ReuseFD` function links the current BPFMap instance to a provided map file descriptor. This enables the reuse of a map that was initiated by another process. Initial effort: aquasecurity#346 Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
The `ReuseFD` function links the current BPFMap instance to a provided map file descriptor. This enables the reuse of a map that was initiated by another process. Initial effort: #346 Co-authored-by: Francisco Javier Honduvilla Coto <[email protected]>
Wrap
bpf_map__reuse_fd
to reuse a BPF map accross BPF programs. Thisis useful in complex programs that long chains of calls, for example,
via
bpf_tail_call
that may be loaded in different programs and sharestate via reused maps.
Why is this useful
Our global state map, called
heap
is shared by multiple programs.Map reuse will soon become a load loading functionality for Parca Agent.
Test Plan
Added selftest +
We are thoroughly testing it, across multiple kernels and with ASAN
enabled, too.
If there were any problems in the future we will quickly notice them and
will be happy to submit bugfixes.