Repository navigation
Document timer behavior after cancellation - #294
Merged
dylandreimerink merged 1 commit intoSep 7, 2026
Merged
dylandreimerink merged 1 commit into
dylandreimerink merged 1 commit into
Conversation
bpf_timer_cancel detaches the callback from the timer via drop_prog_refcnt, so a subsequent bpf_timer_start fails with -EINVAL until bpf_timer_set_callback has assigned a new callback. The timer stays initialized through all of this, and re-running bpf_timer_init on it returns -EBUSY. None of this was documented. Verified against kernel/bpf/helpers.c on v6.18 and v5.15; the semantics are unchanged since timers were introduced. Fixes isovalent#262 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 7, 2026
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 #262
What
Documents what
bpf_timer_cancelactually does to a timer, and the resulting restart flow, across four pages:bpf_timer_cancel.md: replaces the "Docs could be improved" placeholder with a Usage section: canceling detaches the callback and drops the program reference ([drop_prog_refcnt(https://elixir.bootlin.com/linux/v6.18/source/kernel/bpf/helpers.c#L1457)), the timer stays initialized, and a re-arm needsbpf_timer_set_callbackbeforebpf_timer_start, with a short code sample.bpf_timer_start.md: note that-EINVALalso covers the canceled-timer case.bpf_timer_set_callback.md: note that it must be called again after a cancel, with no re-init.concepts/timers.md: one paragraph on the cancel/restart cycle, next to the existing re-scheduling paragraph.Verified against the kernel
kernel/bpf/helpers.c, checked on both v6.18 and v5.15 (the release that introduced timers) - the semantics are identical:bpf_timer_cancel->drop_prog_refcnt: setsprog = NULLandcallback_fn = NULL, thebpf_hrtimerallocation is untouchedbpf_timer_start->if (!t || !t->cb.prog) return -EINVAL- which is why a canceled timer cannot be started directlybpf_timer_set_callback->_bpf_async_set_callbackonly requires the timer to be initialized, and re-assigns the callback plus program reference__bpf_async_init-> returns-EBUSYwhen the timer is already initialized, so re-initializing is not just unnecessary but impossible