kfunc-gen: Don't list sleepable kfuncs for non-sleepable program types - #293
Merged
dylandreimerink merged 2 commits intoSep 5, 2026
Merged
Conversation
The kfunc <-> program type references are generated purely from the sets
in data/kfuncs.yaml, without taking the sleepability of a kfunc into
account. A kfunc flagged KF_SLEEPABLE can only be called from a sleepable
program:
sleepable = is_kfunc_sleepable(&meta);
if (sleepable && !in_sleepable(env)) {
verbose(env, "program must be sleepable to call sleepable kfunc %s\n", func_name);
return -EACCES;
}
So listing such a kfunc under a program type that can never be sleepable
is wrong in both directions: the kfunc page offers a program type that
cannot call it, and the program type page lists a kfunc that will always
be rejected by the verifier.
check_attach_btf_id() decides which program types may be sleepable. Every
type has to opt in with BPF_F_SLEEPABLE and pass can_be_sleepable(), except
BPF_PROG_TYPE_SYSCALL which is handled just above it and is always
sleepable. That leaves TRACING (fentry/fexit/fmod_ret/iter), LSM, KPROBE
(uprobes) and STRUCT_OPS, plus SYSCALL.
The set only ever grew: v5.15 allowed TRACING and LSM, v6.1 added KPROBE,
v6.4 added STRUCT_OPS and factored the check into can_be_sleepable(), and
it has been unchanged since. Filtering against the current set therefore
cannot drop a combination that is valid on any supported kernel.
Filtering merged progTypes fixes both directions at once, since the
KFUNC_PROG_REF blocks and the progToKfunc map used for PROG_KFUNC_REF are
both derived from it.
Fixes: isovalent#138
Signed-off-by: Ashwani Yadav <22ashwaniyadav@gmail.com>
Result of the kfunc-gen sleepability filter. Removes 301 kfunc <-> program type combinations the verifier would reject, across 22 kfunc pages and 18 program type pages. No kfunc is left without a program type. Signed-off-by: Ashwani Yadav <22ashwaniyadav@gmail.com>
Contributor
Author
|
@dylandreimerink, could you please review this PR when you have a moment? |
dylandreimerink
approved these changes
Sep 5, 2026
dylandreimerink
left a comment
Collaborator
There was a problem hiding this comment.
This is great, thank you
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #138
What
kfunc-genbuilds the kfunc <-> program type references purely from the sets indata/kfuncs.yaml, without looking at whether a kfunc may sleep. But a kfunc flaggedKF_SLEEPABLEcan only be called from a sleepable program:So listing one under a program type that can never be sleepable is wrong in both directions: the kfunc page offers a program type that cannot call it, and the program type page lists a kfunc the verifier will always reject.
Which program types can be sleepable
check_attach_btf_id()decides this. Every type opts in withBPF_F_SLEEPABLEand has to passcan_be_sleepable(), exceptBPF_PROG_TYPE_SYSCALL, which is handled just above it and is always sleepable. That gives:BPF_PROG_TYPE_TRACINGBPF_PROG_TYPE_LSMBPF_PROG_TYPE_KPROBEBPF_PROG_TYPE_STRUCT_OPSBPF_PROG_TYPE_SYSCALLThe set has only ever grown: v5.15 allowed TRACING and LSM, v6.1 added KPROBE, v6.4 added STRUCT_OPS and factored the check into
can_be_sleepable(), and it has been unchanged since. So filtering against the current set cannot drop acombination that is valid on an older kernel.
Note the filter is per program type, so KPROBE and TRACING stay in the lists even though only some of their attach types can be sleepable. Going finer would need attach-type granularity, which the data file does not carry.
Where the fix goes
One filter on the merged
progTypes, next to the existingExcepthandling. That covers both directions at once, since theKFUNC_PROG_REFblocks and theprogToKfuncmap behindPROG_KFUNC_REFare both derived from it.Impact
301 kfunc <-> program type combinations removed: 22 kfunc pages and 18 program type pages, 583 deletions and no additions.
BPF_PROG_TYPE_PERF_EVENTandBPF_PROG_TYPE_TRACEPOINTlose 23 entries each; the 15 program types reachable throughBPF_PROG_TYPE_UNSPECexpansion (XDP, SCHED_CLS, the CGROUP_* family, LWT_*, NETFILTER, ...) lose 15 each.Four
KF_SLEEPABLEkfuncs are unaffected because they were already correct:bpf_crypto_ctx_create(SYSCALL),bpf_io_uring_submit_sqes(STRUCT_OPS),scx_bpf_create_dsq(STRUCT_OPS + SYSCALL), andcgroup_rstat_flush, which isin
removeKfuncs.Testing
gofmtclean,go vet ./tools/kfunc-gen/cleanwhat the
generate-docsworkflow assertsKF_SLEEPABLEkfunc pages changed, nothing else was touchedlogic over
data/kfuncs.yaml. The only mismatch wasBPF_PROG_TYPE_LWT_SEG6LOCAL, whose page has noPROG_KFUNC_REFmarkers, sothe generator skips it. Pre-existing, left alone.