@@ -312,6 +312,20 @@ static int check_zero_holes(const struct btf_type *t, void *data)
312
312
return 0 ;
313
313
}
314
314
315
+ int bpf_struct_ops_prepare_trampoline (struct bpf_tramp_progs * tprogs ,
316
+ struct bpf_prog * prog ,
317
+ const struct btf_func_model * model ,
318
+ void * image , void * image_end )
319
+ {
320
+ u32 flags ;
321
+
322
+ tprogs [BPF_TRAMP_FENTRY ].progs [0 ] = prog ;
323
+ tprogs [BPF_TRAMP_FENTRY ].nr_progs = 1 ;
324
+ flags = model -> ret_size > 0 ? BPF_TRAMP_F_RET_FENTRY_RET : 0 ;
325
+ return arch_prepare_bpf_trampoline (NULL , image , image_end ,
326
+ model , flags , tprogs , NULL );
327
+ }
328
+
315
329
static int bpf_struct_ops_map_update_elem (struct bpf_map * map , void * key ,
316
330
void * value , u64 flags )
317
331
{
@@ -323,7 +337,7 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
323
337
struct bpf_tramp_progs * tprogs = NULL ;
324
338
void * udata , * kdata ;
325
339
int prog_fd , err = 0 ;
326
- void * image ;
340
+ void * image , * image_end ;
327
341
u32 i ;
328
342
329
343
if (flags )
@@ -363,12 +377,12 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
363
377
udata = & uvalue -> data ;
364
378
kdata = & kvalue -> data ;
365
379
image = st_map -> image ;
380
+ image_end = st_map -> image + PAGE_SIZE ;
366
381
367
382
for_each_member (i , t , member ) {
368
383
const struct btf_type * mtype , * ptype ;
369
384
struct bpf_prog * prog ;
370
385
u32 moff ;
371
- u32 flags ;
372
386
373
387
moff = btf_member_bit_offset (t , member ) / 8 ;
374
388
ptype = btf_type_resolve_ptr (btf_vmlinux , member -> type , NULL );
@@ -430,14 +444,9 @@ static int bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
430
444
goto reset_unlock ;
431
445
}
432
446
433
- tprogs [BPF_TRAMP_FENTRY ].progs [0 ] = prog ;
434
- tprogs [BPF_TRAMP_FENTRY ].nr_progs = 1 ;
435
- flags = st_ops -> func_models [i ].ret_size > 0 ?
436
- BPF_TRAMP_F_RET_FENTRY_RET : 0 ;
437
- err = arch_prepare_bpf_trampoline (NULL , image ,
438
- st_map -> image + PAGE_SIZE ,
439
- & st_ops -> func_models [i ],
440
- flags , tprogs , NULL );
447
+ err = bpf_struct_ops_prepare_trampoline (tprogs , prog ,
448
+ & st_ops -> func_models [i ],
449
+ image , image_end );
441
450
if (err < 0 )
442
451
goto reset_unlock ;
443
452
0 commit comments