Skip to content

Commit 06507c7

Browse files
author
Alexei Starovoitov
committed
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: Benjamin Tissoires <[email protected]> --- Changes in v2: - amended the selftests to retrieve something from the third argument of the callback - Link to v1: https://lore.kernel.org/r/[email protected] --- ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents cedc12c + 16e86f2 commit 06507c7

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

kernel/bpf/helpers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2734,7 +2734,7 @@ __bpf_kfunc int bpf_wq_start(struct bpf_wq *wq, unsigned int flags)
27342734
}
27352735

27362736
__bpf_kfunc int bpf_wq_set_callback_impl(struct bpf_wq *wq,
2737-
int (callback_fn)(void *map, int *key, struct bpf_wq *wq),
2737+
int (callback_fn)(void *map, int *key, void *value),
27382738
unsigned int flags,
27392739
void *aux__ign)
27402740
{

tools/testing/selftests/bpf/bpf_experimental.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ extern void bpf_iter_css_destroy(struct bpf_iter_css *it) __weak __ksym;
552552
extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym;
553553
extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym;
554554
extern int bpf_wq_set_callback_impl(struct bpf_wq *wq,
555-
int (callback_fn)(void *map, int *key, struct bpf_wq *wq),
555+
int (callback_fn)(void *map, int *key, void *value),
556556
unsigned int flags__k, void *aux__ign) __ksym;
557557
#define bpf_wq_set_callback(timer, cb, flags) \
558558
bpf_wq_set_callback_impl(timer, cb, flags, NULL)

tools/testing/selftests/bpf/progs/wq.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct {
3232
} hmap_malloc SEC(".maps");
3333

3434
struct elem {
35+
int ok_offset;
3536
struct bpf_wq w;
3637
};
3738

@@ -53,7 +54,7 @@ __u32 ok;
5354
__u32 ok_sleepable;
5455

5556
static int test_elem_callback(void *map, int *key,
56-
int (callback_fn)(void *map, int *key, struct bpf_wq *wq))
57+
int (callback_fn)(void *map, int *key, void *value))
5758
{
5859
struct elem init = {}, *val;
5960
struct bpf_wq *wq;
@@ -70,6 +71,8 @@ static int test_elem_callback(void *map, int *key,
7071
if (!val)
7172
return -2;
7273

74+
val->ok_offset = *key;
75+
7376
wq = &val->w;
7477
if (bpf_wq_init(wq, map, 0) != 0)
7578
return -3;
@@ -84,7 +87,7 @@ static int test_elem_callback(void *map, int *key,
8487
}
8588

8689
static int test_hmap_elem_callback(void *map, int *key,
87-
int (callback_fn)(void *map, int *key, struct bpf_wq *wq))
90+
int (callback_fn)(void *map, int *key, void *value))
8891
{
8992
struct hmap_elem init = {}, *val;
9093
struct bpf_wq *wq;
@@ -114,18 +117,24 @@ static int test_hmap_elem_callback(void *map, int *key,
114117
}
115118

116119
/* callback for non sleepable workqueue */
117-
static int wq_callback(void *map, int *key, struct bpf_wq *work)
120+
static int wq_callback(void *map, int *key, void *value)
118121
{
119122
bpf_kfunc_common_test();
120123
ok |= (1 << *key);
121124
return 0;
122125
}
123126

124127
/* callback for sleepable workqueue */
125-
static int wq_cb_sleepable(void *map, int *key, struct bpf_wq *work)
128+
static int wq_cb_sleepable(void *map, int *key, void *value)
126129
{
130+
struct elem *data = (struct elem *)value;
131+
int offset = data->ok_offset;
132+
133+
if (*key != offset)
134+
return 0;
135+
127136
bpf_kfunc_call_test_sleepable();
128-
ok_sleepable |= (1 << *key);
137+
ok_sleepable |= (1 << offset);
129138
return 0;
130139
}
131140

tools/testing/selftests/bpf/progs/wq_failures.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ struct {
2828
} lru SEC(".maps");
2929

3030
/* callback for non sleepable workqueue */
31-
static int wq_callback(void *map, int *key, struct bpf_wq *work)
31+
static int wq_callback(void *map, int *key, void *value)
3232
{
3333
bpf_kfunc_common_test();
3434
return 0;
3535
}
3636

3737
/* callback for sleepable workqueue */
38-
static int wq_cb_sleepable(void *map, int *key, struct bpf_wq *work)
38+
static int wq_cb_sleepable(void *map, int *key, void *value)
3939
{
4040
bpf_kfunc_call_test_sleepable();
4141
return 0;

0 commit comments

Comments
 (0)