]> git.hungrycats.org Git - linux/commit
selftests/bpf: Test timer field on recycled rhtab element
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Fri, 4 Sep 2026 10:41:53 +0000 (12:41 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 4 Sep 2026 19:24:24 +0000 (12:24 -0700)
commitdbf6806dc81553edbab72fcec9a6d637dedff2f4
treed7a697d4afd93b07d0b85168ac62792089556446
parent5df46ddcb7b36878c1b691e9057a0509042a2567
selftests/bpf: Test timer field on recycled rhtab element

Exercise the rhtab special-field lifecycle with the sequence from the
original report. A bpf_for_each_map_elem() callback deletes the sole
element, then initializes and arms a timer through the callback value
pointer while it remains valid.

Use a one-element map and pin userspace and BPF execution to one CPU.
Repeated delete-and-replace cycles drain the per-CPU allocator cache, and
periodic RCU synchronization makes the deleted units available for
recycling.

After each replacement, a second BPF program calls bpf_timer_cancel()
on its value. A successful cancellation proves both that a timer-bearing
unit was recycled and that insertion preserved the timer field. Without
the fix, insertion clears that field and cancellation keeps returning
-EINVAL. A long expiration keeps the timer callback out of the test, so
the regression is detected without accessing freed memory.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20260904104203.345917-3-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/rhash_timer.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/rhash_timer.c [new file with mode: 0644]