]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bpf: Factor out timer deletion helper
authorMykyta Yatsenko <yatsenko@meta.com>
Tue, 20 Jan 2026 15:59:10 +0000 (15:59 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 21 Jan 2026 02:12:19 +0000 (18:12 -0800)
Move the timer deletion logic into a dedicated bpf_timer_delete()
helper so it can be reused by later patches.

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Link: https://lore.kernel.org/r/20260120-timer_nolock-v6-1-670ffdd787b4@meta.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/helpers.c

index 4d1af703cfcb28dc2341ee65b4a3a682b02c9b23..fb6f9dbca0848a22a919311885ab050c92156364 100644 (file)
@@ -1558,18 +1558,10 @@ out:
        return cb;
 }
 
-/* This function is called by map_delete/update_elem for individual element and
- * by ops->map_release_uref when the user space reference to a map reaches zero.
- */
-void bpf_timer_cancel_and_free(void *val)
+static void bpf_timer_delete(struct bpf_hrtimer *t)
 {
-       struct bpf_hrtimer *t;
-
-       t = (struct bpf_hrtimer *)__bpf_async_cancel_and_free(val);
-
-       if (!t)
-               return;
-       /* We check that bpf_map_delete/update_elem() was called from timer
+       /*
+        * We check that bpf_map_delete/update_elem() was called from timer
         * callback_fn. In such case we don't call hrtimer_cancel() (since it
         * will deadlock) and don't call hrtimer_try_to_cancel() (since it will
         * just return -1). Though callback_fn is still running on this cpu it's
@@ -1618,6 +1610,21 @@ void bpf_timer_cancel_and_free(void *val)
        }
 }
 
+/*
+ * This function is called by map_delete/update_elem for individual element and
+ * by ops->map_release_uref when the user space reference to a map reaches zero.
+ */
+void bpf_timer_cancel_and_free(void *val)
+{
+       struct bpf_hrtimer *t;
+
+       t = (struct bpf_hrtimer *)__bpf_async_cancel_and_free(val);
+       if (!t)
+               return;
+
+       bpf_timer_delete(t);
+}
+
 /* This function is called by map_delete/update_elem for individual element and
  * by ops->map_release_uref when the user space reference to a map reaches zero.
  */