Skip to content

Optimize kprobe session#10955

Closed
andrey-grodzovsky wants to merge 3 commits intokernel-patches:bpf-next_basefrom
andrey-grodzovsky:optimize-kprobe-session
Closed

Optimize kprobe session#10955
andrey-grodzovsky wants to merge 3 commits intokernel-patches:bpf-next_basefrom
andrey-grodzovsky:optimize-kprobe-session

Conversation

@andrey-grodzovsky
Copy link
Copy Markdown
Contributor

Implement dual-path optimization in attach_kprobe_session: use fast syms[] array for exact function names, fall back to slow pattern matching only for wildcards. This avoids expensive kallsyms parsing (~150ms) when function names are specified exactly, improving attachment time 50x (~3-5ms).

Add test coverage with kprobe_multi_session_syms test program that exercises the fast path with exact function names

@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot force-pushed the bpf-next_base branch 2 times, most recently from a003c26 to 48fc95a Compare February 4, 2026 18:35
Implement dual-path optimization in attach_kprobe_session():
- Fast path: Use syms[] array for exact function names (no kallsyms parsing)
- Slow path: Use pattern matching with kallsyms only for wildcards

This avoids expensive kallsyms file parsing (~150ms) when function names
are specified exactly, improving attachment time 50x (~3-5ms).

Error code normalization: The fast path returns ESRCH from kernel's
ftrace_lookup_symbols(), while slow path returns ENOENT from userspace
kallsyms parsing. Convert ESRCH to ENOENT in fast path to maintain API
consistency - both paths now return identical error codes for "symbol
not found".

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com>
Add test_session_syms() to verify the optimization works correctly with
exact function names, and test_session_errors() to verify error code
consistency between fast and slow paths.

test_session_syms_skel_api():
- Tests entry/return execution with exact function names
- Verifies return probe suppression works correctly
- Uses kprobe.session/bpf_fentry_test1 (exact name, no wildcards)

test_session_errors():
- Verifies both fast path (exact name) and slow path (wildcard pattern)
  return the same error code (ENOENT) for non-existent functions
- Protects against future kernel or libbpf changes that might alter
  error return values
- Uses impossible function names that cannot exist in kernel code:
  * __impossible_test_func_xyz_wildcard_* for slow path
  * __impossible_test_func_xyz_exact_123 for fast path

Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com>
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot force-pushed the bpf-next_base branch 11 times, most recently from 2294d0a to 254af9f Compare February 11, 2026 20:32
@kernel-patches-daemon-bpf
Copy link
Copy Markdown

Automatically cleaning up stale PR; feel free to reopen if needed

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.

1 participant