@@ -32,7 +32,7 @@ struct bpf_struct_ops_value {
32
32
struct bpf_struct_ops_map {
33
33
struct bpf_map map ;
34
34
struct rcu_head rcu ;
35
- const struct bpf_struct_ops * st_ops ;
35
+ const struct bpf_struct_ops_desc * st_ops_desc ;
36
36
/* protect map_update */
37
37
struct mutex lock ;
38
38
/* link has all the bpf_links that is populated
92
92
__NR_BPF_STRUCT_OPS_TYPE ,
93
93
};
94
94
95
- static struct bpf_struct_ops * const bpf_struct_ops [] = {
95
+ static struct bpf_struct_ops_desc bpf_struct_ops [] = {
96
96
#define BPF_STRUCT_OPS_TYPE (_name ) \
97
- [BPF_STRUCT_OPS_TYPE_ ##_name ] = & bpf_ ##_name ,
97
+ [BPF_STRUCT_OPS_TYPE_ ##_name ] = { . st_ops = & bpf_ ##_name } ,
98
98
#include "bpf_struct_ops_types.h"
99
99
#undef BPF_STRUCT_OPS_TYPE
100
100
};
@@ -115,10 +115,11 @@ enum {
115
115
IDX_MODULE_ID ,
116
116
};
117
117
118
- static void bpf_struct_ops_init_one (struct bpf_struct_ops * st_ops ,
119
- struct btf * btf ,
120
- struct bpf_verifier_log * log )
118
+ static void bpf_struct_ops_desc_init (struct bpf_struct_ops_desc * st_ops_desc ,
119
+ struct btf * btf ,
120
+ struct bpf_verifier_log * log )
121
121
{
122
+ struct bpf_struct_ops * st_ops = st_ops_desc -> st_ops ;
122
123
const struct btf_member * member ;
123
124
const struct btf_type * t ;
124
125
s32 type_id , value_id ;
@@ -190,18 +191,18 @@ static void bpf_struct_ops_init_one(struct bpf_struct_ops *st_ops,
190
191
pr_warn ("Error in init bpf_struct_ops %s\n" ,
191
192
st_ops -> name );
192
193
} else {
193
- st_ops -> type_id = type_id ;
194
- st_ops -> type = t ;
195
- st_ops -> value_id = value_id ;
196
- st_ops -> value_type = btf_type_by_id (btf ,
197
- value_id );
194
+ st_ops_desc -> type_id = type_id ;
195
+ st_ops_desc -> type = t ;
196
+ st_ops_desc -> value_id = value_id ;
197
+ st_ops_desc -> value_type = btf_type_by_id (btf ,
198
+ value_id );
198
199
}
199
200
}
200
201
}
201
202
202
203
void bpf_struct_ops_init (struct btf * btf , struct bpf_verifier_log * log )
203
204
{
204
- struct bpf_struct_ops * st_ops ;
205
+ struct bpf_struct_ops_desc * st_ops_desc ;
205
206
u32 i ;
206
207
207
208
/* Ensure BTF type is emitted for "struct bpf_struct_ops_##_name" */
@@ -210,14 +211,14 @@ void bpf_struct_ops_init(struct btf *btf, struct bpf_verifier_log *log)
210
211
#undef BPF_STRUCT_OPS_TYPE
211
212
212
213
for (i = 0 ; i < ARRAY_SIZE (bpf_struct_ops ); i ++ ) {
213
- st_ops = bpf_struct_ops [i ];
214
- bpf_struct_ops_init_one ( st_ops , btf , log );
214
+ st_ops_desc = & bpf_struct_ops [i ];
215
+ bpf_struct_ops_desc_init ( st_ops_desc , btf , log );
215
216
}
216
217
}
217
218
218
219
extern struct btf * btf_vmlinux ;
219
220
220
- static const struct bpf_struct_ops *
221
+ static const struct bpf_struct_ops_desc *
221
222
bpf_struct_ops_find_value (u32 value_id )
222
223
{
223
224
unsigned int i ;
@@ -226,23 +227,23 @@ bpf_struct_ops_find_value(u32 value_id)
226
227
return NULL ;
227
228
228
229
for (i = 0 ; i < ARRAY_SIZE (bpf_struct_ops ); i ++ ) {
229
- if (bpf_struct_ops [i ]-> value_id == value_id )
230
- return bpf_struct_ops [i ];
230
+ if (bpf_struct_ops [i ]. value_id == value_id )
231
+ return & bpf_struct_ops [i ];
231
232
}
232
233
233
234
return NULL ;
234
235
}
235
236
236
- const struct bpf_struct_ops * bpf_struct_ops_find (u32 type_id )
237
+ const struct bpf_struct_ops_desc * bpf_struct_ops_find (u32 type_id )
237
238
{
238
239
unsigned int i ;
239
240
240
241
if (!type_id || !btf_vmlinux )
241
242
return NULL ;
242
243
243
244
for (i = 0 ; i < ARRAY_SIZE (bpf_struct_ops ); i ++ ) {
244
- if (bpf_struct_ops [i ]-> type_id == type_id )
245
- return bpf_struct_ops [i ];
245
+ if (bpf_struct_ops [i ]. type_id == type_id )
246
+ return & bpf_struct_ops [i ];
246
247
}
247
248
248
249
return NULL ;
@@ -302,7 +303,7 @@ static void *bpf_struct_ops_map_lookup_elem(struct bpf_map *map, void *key)
302
303
303
304
static void bpf_struct_ops_map_put_progs (struct bpf_struct_ops_map * st_map )
304
305
{
305
- const struct btf_type * t = st_map -> st_ops -> type ;
306
+ const struct btf_type * t = st_map -> st_ops_desc -> type ;
306
307
u32 i ;
307
308
308
309
for (i = 0 ; i < btf_type_vlen (t ); i ++ ) {
@@ -382,11 +383,12 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
382
383
void * value , u64 flags )
383
384
{
384
385
struct bpf_struct_ops_map * st_map = (struct bpf_struct_ops_map * )map ;
385
- const struct bpf_struct_ops * st_ops = st_map -> st_ops ;
386
+ const struct bpf_struct_ops_desc * st_ops_desc = st_map -> st_ops_desc ;
387
+ const struct bpf_struct_ops * st_ops = st_ops_desc -> st_ops ;
386
388
struct bpf_struct_ops_value * uvalue , * kvalue ;
387
389
const struct btf_type * module_type ;
388
390
const struct btf_member * member ;
389
- const struct btf_type * t = st_ops -> type ;
391
+ const struct btf_type * t = st_ops_desc -> type ;
390
392
struct bpf_tramp_links * tlinks ;
391
393
void * udata , * kdata ;
392
394
int prog_fd , err ;
@@ -399,7 +401,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
399
401
if (* (u32 * )key != 0 )
400
402
return - E2BIG ;
401
403
402
- err = check_zero_holes (st_ops -> value_type , value );
404
+ err = check_zero_holes (st_ops_desc -> value_type , value );
403
405
if (err )
404
406
return err ;
405
407
@@ -492,7 +494,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
492
494
}
493
495
494
496
if (prog -> type != BPF_PROG_TYPE_STRUCT_OPS ||
495
- prog -> aux -> attach_btf_id != st_ops -> type_id ||
497
+ prog -> aux -> attach_btf_id != st_ops_desc -> type_id ||
496
498
prog -> expected_attach_type != i ) {
497
499
bpf_prog_put (prog );
498
500
err = - EINVAL ;
@@ -588,7 +590,7 @@ static long bpf_struct_ops_map_delete_elem(struct bpf_map *map, void *key)
588
590
BPF_STRUCT_OPS_STATE_TOBEFREE );
589
591
switch (prev_state ) {
590
592
case BPF_STRUCT_OPS_STATE_INUSE :
591
- st_map -> st_ops -> unreg (& st_map -> kvalue .data );
593
+ st_map -> st_ops_desc -> st_ops -> unreg (& st_map -> kvalue .data );
592
594
bpf_map_put (map );
593
595
return 0 ;
594
596
case BPF_STRUCT_OPS_STATE_TOBEFREE :
@@ -669,22 +671,22 @@ static int bpf_struct_ops_map_alloc_check(union bpf_attr *attr)
669
671
670
672
static struct bpf_map * bpf_struct_ops_map_alloc (union bpf_attr * attr )
671
673
{
672
- const struct bpf_struct_ops * st_ops ;
674
+ const struct bpf_struct_ops_desc * st_ops_desc ;
673
675
size_t st_map_size ;
674
676
struct bpf_struct_ops_map * st_map ;
675
677
const struct btf_type * t , * vt ;
676
678
struct bpf_map * map ;
677
679
int ret ;
678
680
679
- st_ops = bpf_struct_ops_find_value (attr -> btf_vmlinux_value_type_id );
680
- if (!st_ops )
681
+ st_ops_desc = bpf_struct_ops_find_value (attr -> btf_vmlinux_value_type_id );
682
+ if (!st_ops_desc )
681
683
return ERR_PTR (- ENOTSUPP );
682
684
683
- vt = st_ops -> value_type ;
685
+ vt = st_ops_desc -> value_type ;
684
686
if (attr -> value_size != vt -> size )
685
687
return ERR_PTR (- EINVAL );
686
688
687
- t = st_ops -> type ;
689
+ t = st_ops_desc -> type ;
688
690
689
691
st_map_size = sizeof (* st_map ) +
690
692
/* kvalue stores the
@@ -696,7 +698,7 @@ static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr)
696
698
if (!st_map )
697
699
return ERR_PTR (- ENOMEM );
698
700
699
- st_map -> st_ops = st_ops ;
701
+ st_map -> st_ops_desc = st_ops_desc ;
700
702
map = & st_map -> map ;
701
703
702
704
ret = bpf_jit_charge_modmem (PAGE_SIZE );
@@ -733,8 +735,8 @@ static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr)
733
735
static u64 bpf_struct_ops_map_mem_usage (const struct bpf_map * map )
734
736
{
735
737
struct bpf_struct_ops_map * st_map = (struct bpf_struct_ops_map * )map ;
736
- const struct bpf_struct_ops * st_ops = st_map -> st_ops ;
737
- const struct btf_type * vt = st_ops -> value_type ;
738
+ const struct bpf_struct_ops_desc * st_ops_desc = st_map -> st_ops_desc ;
739
+ const struct btf_type * vt = st_ops_desc -> value_type ;
738
740
u64 usage ;
739
741
740
742
usage = sizeof (* st_map ) +
@@ -808,7 +810,7 @@ static void bpf_struct_ops_map_link_dealloc(struct bpf_link *link)
808
810
/* st_link->map can be NULL if
809
811
* bpf_struct_ops_link_create() fails to register.
810
812
*/
811
- st_map -> st_ops -> unreg (& st_map -> kvalue .data );
813
+ st_map -> st_ops_desc -> st_ops -> unreg (& st_map -> kvalue .data );
812
814
bpf_map_put (& st_map -> map );
813
815
}
814
816
kfree (st_link );
@@ -855,7 +857,7 @@ static int bpf_struct_ops_map_link_update(struct bpf_link *link, struct bpf_map
855
857
if (!bpf_struct_ops_valid_to_reg (new_map ))
856
858
return - EINVAL ;
857
859
858
- if (!st_map -> st_ops -> update )
860
+ if (!st_map -> st_ops_desc -> st_ops -> update )
859
861
return - EOPNOTSUPP ;
860
862
861
863
mutex_lock (& update_mutex );
@@ -868,12 +870,12 @@ static int bpf_struct_ops_map_link_update(struct bpf_link *link, struct bpf_map
868
870
869
871
old_st_map = container_of (old_map , struct bpf_struct_ops_map , map );
870
872
/* The new and old struct_ops must be the same type. */
871
- if (st_map -> st_ops != old_st_map -> st_ops ) {
873
+ if (st_map -> st_ops_desc != old_st_map -> st_ops_desc ) {
872
874
err = - EINVAL ;
873
875
goto err_out ;
874
876
}
875
877
876
- err = st_map -> st_ops -> update (st_map -> kvalue .data , old_st_map -> kvalue .data );
878
+ err = st_map -> st_ops_desc -> st_ops -> update (st_map -> kvalue .data , old_st_map -> kvalue .data );
877
879
if (err )
878
880
goto err_out ;
879
881
@@ -924,7 +926,7 @@ int bpf_struct_ops_link_create(union bpf_attr *attr)
924
926
if (err )
925
927
goto err_out ;
926
928
927
- err = st_map -> st_ops -> reg (st_map -> kvalue .data );
929
+ err = st_map -> st_ops_desc -> st_ops -> reg (st_map -> kvalue .data );
928
930
if (err ) {
929
931
bpf_link_cleanup (& link_primer );
930
932
link = NULL ;
0 commit comments