Skip to content
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

[Draft] Collect bpf helper arguments related to bpf map #453

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jschwinger233
Copy link
Member

The idea is to identify bpf map-related helpers in userspace, then use kprobe cookie to notify bpf program whether this requires arguments collecting.

There are at least following steps:

  1. collect map->name. We assume bpf_map * is always at PT_REGS_PARM1(ctx).
  2. collect key buffer. Key size can be determined by map->key_size, then we can simply call bpf_probe_read_kernel to collect the buffer. BTW we assume void *key is always at PT_REGS_PRAM2(ctx).
  3. collect value buffer. This is a bit harder because it can be at retval for bpf_map_lookup_elem(). So userspace pwru must tell this info to bpf via cookie:
    a. if value is in the return (bpf_map_lookup): bpf_probe_read_kernel(ctx->rax) at kretprobe to collect it
    b. if value is in the param (bpf_map_update): bpf_probe_read_kernel(PT_REGS_PARM3(ctx)) to collect it
  4. Similar to stack backtrace and shinfo, we'll add a new member print_bpf_map_id to event.

Some unexpected work may happen, such as bpf stack being used up. If that tragedy takes place, I'll use a per-cpu map to save bpf stack.

This doesn't require BTF at all, but if necessary we can extend it to support BTF parsing.

Fixes: #448

@jschwinger233
Copy link
Member Author

I hope this helps me understand how Cilium CT works. Even after 18 months since onboarding, CT is still a mystery to me.

@brb
Copy link
Member

brb commented Nov 11, 2024

👍 the idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve observability of bpf map operations
2 participants