Skip to content

helper-functions: add newer bpf_base_func_proto helpers to base - #301

Merged
dylandreimerink merged 1 commit into
isovalent:masterfrom
fjvbn2003:base-helpers-newer-kernels
Oct 26, 2026
Merged

dylandreimerink merged 1 commit into
isovalent:masterfrom
fjvbn2003:base-helpers-newer-kernels

Conversation

@fjvbn2003

Copy link
Copy Markdown
Contributor

The base group in data/helpers-functions.yaml mirrors bpf_base_func_proto(), but it is missing helpers that the kernel has handed to every program type for a while. For example, the bpf_get_current_comm page lists only tracing, LSM, syscall and cgroup sock types, while XDP and TC programs can call it since v6.16.

Added to base, with since set to the commit that moved each helper into bpf_base_func_proto():

  • bpf_strtol, bpf_strtoul: v6.1, 8a67f2de9b1d ("bpf: expose bpf_strtol and bpf_strtoul to all program types")
  • bpf_perf_event_read_value: v6.15, ae0a457f5d33
  • bpf_get_current_uid_gid, bpf_current_task_under_cgroup, bpf_get_cgroup_classid, bpf_task_storage_get, bpf_task_storage_delete, bpf_get_current_comm, bpf_perf_event_read, bpf_send_signal, bpf_send_signal_thread, bpf_get_task_stack, bpf_get_branch_snapshot, bpf_find_vma: v6.16, ee971630f20f ("bpf: Allow some trace helpers for all prog types")

cap and kconfig follow the section of bpf_base_func_proto() each helper is in (no capability, CAP_BPF, or CAP_BPF + CAP_PERFMON; CONFIG_CGROUPS / CONFIG_CGROUP_NET_CLASSID). Program types that already list one of these helpers keep their own entry, because the generator lets a parent definition override the base one.

I left out bpf_copy_from_user and bpf_copy_from_user_task. The same v6.16 commit added them to the base set, but they are might_sleep helpers, and the verifier rejects them in non-sleepable programs ("helper call might sleep in a non-sleepable prog"). Of the program types that use the base group, only struct_ops can be sleepable. I can add them for BPF_PROG_TYPE_STRUCT_OPS only if you prefer.

The program type and helper pages were regenerated with tools/helper-ref-gen (built from this repo). No other generated files changed.

How I checked it:

  • I ran bpftool feature probe (bpftool v7.7.0 / libbpf 1.7) on Ubuntu 25.04 (6.14.0-37-generic) and Ubuntu 26.04 (7.0.0-38-generic). On 7.0, the v6.15/v6.16 helpers above show up for socket_filter, sched_cls, sched_act, xdp, cgroup_skb, lwt_*, sock_ops, sk_skb, sk_msg, flow_dissector, sk_reuseport, sk_lookup and netfilter (where the type didn't already have them). On 6.14 they don't. bpf_strtol/bpf_strtoul show up on both kernels.
  • I resolved the YAML per program type the same way the generator does and compared the result with the 7.0 probe output for these 15 helpers. Before this change, 314 (program type, helper) pairs that the kernel reports are missing from the docs. After the change, none are missing, and no pairs are documented that the kernel doesn't report. bpftool cannot probe tracing, LSM or struct_ops, so I did not check those three types this way.
  • bpftool also lists bpf_copy_from_user for XDP etc. on 7.0. That is because its heuristic treats any verifier error other than "unknown func" / "cannot use helper" as supported.

This change was drafted with AI assistance and reviewed by me.

🤖 Generated with Claude Code

The base group was missing helpers that bpf_base_func_proto() has
handed out to every program type for a while:

- bpf_strtol, bpf_strtoul since v6.1 (commit 8a67f2de9b1d, "bpf: expose
  bpf_strtol and bpf_strtoul to all program types")
- bpf_perf_event_read_value since v6.15 (commit ae0a457f5d33)
- bpf_get_current_uid_gid, bpf_current_task_under_cgroup,
  bpf_get_cgroup_classid, bpf_task_storage_{get,delete},
  bpf_get_current_comm, bpf_perf_event_read, bpf_send_signal{,_thread},
  bpf_get_task_stack, bpf_get_branch_snapshot and bpf_find_vma since
  v6.16 (commit ee971630f20f, "bpf: Allow some trace helpers for all
  prog types")

Capabilities and kconfig follow the sections of bpf_base_func_proto()
they sit in. bpf_copy_from_user and bpf_copy_from_user_task were moved
to the base set by the same v6.16 commit but are left out: they are
might_sleep helpers and the verifier rejects them in non-sleepable
programs. Of the program types that use the base group, only struct_ops
can be sleepable, so listing them in base would mostly document helpers
that can't be called. bpftool feature probe does list them for XDP, TC
and friends, because its heuristic treats "helper call might sleep in a
non-sleepable prog" as supported.

Program type and helper pages regenerated with tools/helper-ref-gen.

Signed-off-by: YoungjuKim <[email protected]>
@dylandreimerink
dylandreimerink self-requested a review October 23, 2026 12:25

@dylandreimerink dylandreimerink left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Changes look good to me.

I left out bpf_copy_from_user and bpf_copy_from_user_task. The same v6.16 commit added them to the base set, but they are might_sleep helpers, and the verifier rejects them in non-sleepable programs ("helper call might sleep in a non-sleepable prog"). Of the program types that use the base group, only struct_ops can be sleepable. I can add them for BPF_PROG_TYPE_STRUCT_OPS only if you prefer.

I think this is good for now. We still need to update the tooling to account for sleepable helpers and kfuncs, some way to annotate it and make sure they are only added to program references if program contexts can be sleepable.

I will make a GH issue for that to track that, including the helpers we left out.

@dylandreimerink
dylandreimerink merged commit adc50a3 into isovalent:master Oct 26, 2026
2 checks passed
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.

2 participants