bpf: add bpf_wq_start
authorBenjamin Tissoires <bentiss@kernel.org>
Sat, 20 Apr 2024 09:09:15 +0000 (11:09 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 24 Apr 2024 02:46:57 +0000 (19:46 -0700)
again, copy/paste from bpf_timer_start().

Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
Link: https://lore.kernel.org/r/20240420-bpf_wq-v2-15-6c986a5a741f@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/helpers.c

index dd2eaaf77c939ee558dcfed8525b0b13f7641090..047a21b7e4baf503a31167fd366fd3dcb3e34b32 100644 (file)
@@ -2711,6 +2711,23 @@ __bpf_kfunc int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags)
        return __bpf_async_init(async, map, flags, BPF_ASYNC_TYPE_WQ);
 }
 
+__bpf_kfunc int bpf_wq_start(struct bpf_wq *wq, unsigned int flags)
+{
+       struct bpf_async_kern *async = (struct bpf_async_kern *)wq;
+       struct bpf_work *w;
+
+       if (in_nmi())
+               return -EOPNOTSUPP;
+       if (flags)
+               return -EINVAL;
+       w = READ_ONCE(async->work);
+       if (!w || !READ_ONCE(w->cb.prog))
+               return -EINVAL;
+
+       schedule_work(&w->work);
+       return 0;
+}
+
 __bpf_kfunc int bpf_wq_set_callback_impl(struct bpf_wq *wq,
                                         int (callback_fn)(void *map, int *key, struct bpf_wq *wq),
                                         unsigned int flags,
@@ -2804,6 +2821,7 @@ BTF_ID_FLAGS(func, bpf_dynptr_clone)
 BTF_ID_FLAGS(func, bpf_modify_return_test_tp)
 BTF_ID_FLAGS(func, bpf_wq_init)
 BTF_ID_FLAGS(func, bpf_wq_set_callback_impl)
+BTF_ID_FLAGS(func, bpf_wq_start)
 BTF_KFUNCS_END(common_btf_ids)
 
 static const struct btf_kfunc_id_set common_kfunc_set = {