Commit 06507c75 authored by Alexei Starovoitov's avatar Alexei Starovoitov

Merge branch 'small-api-fix-for-bpf_wq'

Benjamin Tissoires says:

====================
Small API fix for bpf_wq

I realized this while having a map containing both a struct bpf_timer and
a struct bpf_wq: the third argument provided to the bpf_wq callback is
not the struct bpf_wq pointer itself, but the pointer to the value in
the map.

Which means that the users need to double cast the provided "value" as
this is not a struct bpf_wq *.

This is a change of API, but there doesn't seem to be much users of bpf_wq
right now, so we should be able to go with this right now.
Signed-off-by: default avatarBenjamin Tissoires <bentiss@kernel.org>
---
Changes in v2:
- amended the selftests to retrieve something from the third argument of
  the callback
- Link to v1: https://lore.kernel.org/r/20240705-fix-wq-v1-0-91b4d82cd825@kernel.org

---
====================

Link: https://lore.kernel.org/r/20240708-fix-wq-v2-0-667e5c9fbd99@kernel.orgSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents cedc12c5 16e86f2e
...@@ -2734,7 +2734,7 @@ __bpf_kfunc int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) ...@@ -2734,7 +2734,7 @@ __bpf_kfunc int bpf_wq_start(struct bpf_wq *wq, unsigned int flags)
} }
__bpf_kfunc int bpf_wq_set_callback_impl(struct bpf_wq *wq, __bpf_kfunc int bpf_wq_set_callback_impl(struct bpf_wq *wq,
int (callback_fn)(void *map, int *key, struct bpf_wq *wq), int (callback_fn)(void *map, int *key, void *value),
unsigned int flags, unsigned int flags,
void *aux__ign) void *aux__ign)
{ {
......
...@@ -552,7 +552,7 @@ extern void bpf_iter_css_destroy(struct bpf_iter_css *it) __weak __ksym; ...@@ -552,7 +552,7 @@ extern void bpf_iter_css_destroy(struct bpf_iter_css *it) __weak __ksym;
extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym; extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym;
extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym; extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym;
extern int bpf_wq_set_callback_impl(struct bpf_wq *wq, extern int bpf_wq_set_callback_impl(struct bpf_wq *wq,
int (callback_fn)(void *map, int *key, struct bpf_wq *wq), int (callback_fn)(void *map, int *key, void *value),
unsigned int flags__k, void *aux__ign) __ksym; unsigned int flags__k, void *aux__ign) __ksym;
#define bpf_wq_set_callback(timer, cb, flags) \ #define bpf_wq_set_callback(timer, cb, flags) \
bpf_wq_set_callback_impl(timer, cb, flags, NULL) bpf_wq_set_callback_impl(timer, cb, flags, NULL)
......
...@@ -32,6 +32,7 @@ struct { ...@@ -32,6 +32,7 @@ struct {
} hmap_malloc SEC(".maps"); } hmap_malloc SEC(".maps");
struct elem { struct elem {
int ok_offset;
struct bpf_wq w; struct bpf_wq w;
}; };
...@@ -53,7 +54,7 @@ __u32 ok; ...@@ -53,7 +54,7 @@ __u32 ok;
__u32 ok_sleepable; __u32 ok_sleepable;
static int test_elem_callback(void *map, int *key, static int test_elem_callback(void *map, int *key,
int (callback_fn)(void *map, int *key, struct bpf_wq *wq)) int (callback_fn)(void *map, int *key, void *value))
{ {
struct elem init = {}, *val; struct elem init = {}, *val;
struct bpf_wq *wq; struct bpf_wq *wq;
...@@ -70,6 +71,8 @@ static int test_elem_callback(void *map, int *key, ...@@ -70,6 +71,8 @@ static int test_elem_callback(void *map, int *key,
if (!val) if (!val)
return -2; return -2;
val->ok_offset = *key;
wq = &val->w; wq = &val->w;
if (bpf_wq_init(wq, map, 0) != 0) if (bpf_wq_init(wq, map, 0) != 0)
return -3; return -3;
...@@ -84,7 +87,7 @@ static int test_elem_callback(void *map, int *key, ...@@ -84,7 +87,7 @@ static int test_elem_callback(void *map, int *key,
} }
static int test_hmap_elem_callback(void *map, int *key, static int test_hmap_elem_callback(void *map, int *key,
int (callback_fn)(void *map, int *key, struct bpf_wq *wq)) int (callback_fn)(void *map, int *key, void *value))
{ {
struct hmap_elem init = {}, *val; struct hmap_elem init = {}, *val;
struct bpf_wq *wq; struct bpf_wq *wq;
...@@ -114,7 +117,7 @@ static int test_hmap_elem_callback(void *map, int *key, ...@@ -114,7 +117,7 @@ static int test_hmap_elem_callback(void *map, int *key,
} }
/* callback for non sleepable workqueue */ /* callback for non sleepable workqueue */
static int wq_callback(void *map, int *key, struct bpf_wq *work) static int wq_callback(void *map, int *key, void *value)
{ {
bpf_kfunc_common_test(); bpf_kfunc_common_test();
ok |= (1 << *key); ok |= (1 << *key);
...@@ -122,10 +125,16 @@ static int wq_callback(void *map, int *key, struct bpf_wq *work) ...@@ -122,10 +125,16 @@ static int wq_callback(void *map, int *key, struct bpf_wq *work)
} }
/* callback for sleepable workqueue */ /* callback for sleepable workqueue */
static int wq_cb_sleepable(void *map, int *key, struct bpf_wq *work) static int wq_cb_sleepable(void *map, int *key, void *value)
{ {
struct elem *data = (struct elem *)value;
int offset = data->ok_offset;
if (*key != offset)
return 0;
bpf_kfunc_call_test_sleepable(); bpf_kfunc_call_test_sleepable();
ok_sleepable |= (1 << *key); ok_sleepable |= (1 << offset);
return 0; return 0;
} }
......
...@@ -28,14 +28,14 @@ struct { ...@@ -28,14 +28,14 @@ struct {
} lru SEC(".maps"); } lru SEC(".maps");
/* callback for non sleepable workqueue */ /* callback for non sleepable workqueue */
static int wq_callback(void *map, int *key, struct bpf_wq *work) static int wq_callback(void *map, int *key, void *value)
{ {
bpf_kfunc_common_test(); bpf_kfunc_common_test();
return 0; return 0;
} }
/* callback for sleepable workqueue */ /* callback for sleepable workqueue */
static int wq_cb_sleepable(void *map, int *key, struct bpf_wq *work) static int wq_cb_sleepable(void *map, int *key, void *value)
{ {
bpf_kfunc_call_test_sleepable(); bpf_kfunc_call_test_sleepable();
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment