Re: [PATCH bpf-next v1 3/8] libbpf: honor autocreate flag for struct_ops maps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 27, 2024 at 10:45:51PM +0200, Eduard Zingerman wrote:
> Skip load steps for struct_ops maps not marked for automatic creation.
> This should allow to load bpf object in situations like below:
> 
>     SEC("struct_ops/foo") int BPF_PROG(foo) { ... }
>     SEC("struct_ops/bar") int BPF_PROG(bar) { ... }
> 
>     struct test_ops___v1 {
>     	int (*foo)(void);
>     };
> 
>     struct test_ops___v2 {
>     	int (*foo)(void);
>     	int (*does_not_exist)(void);
>     };
> 
>     SEC(".struct_ops.link")
>     struct test_ops___v1 map_for_old = {
>     	.test_1 = (void *)foo
>     };
> 
>     SEC(".struct_ops.link")
>     struct test_ops___v2 map_for_new = {
>     	.test_1 = (void *)foo,
>     	.does_not_exist = (void *)bar
>     };
> 
> Suppose program is loaded on old kernel that does not have definition
> for 'does_not_exist' struct_ops member. After this commit it would be
> possible to load such object file after the following tweaks:
> 
>     bpf_program__set_autoload(skel->progs.bar, false);
>     bpf_map__set_autocreate(skel->maps.map_for_new, false);
> 
> Signed-off-by: Eduard Zingerman <eddyz87@xxxxxxxxx>

Is this technically a bug fix? We were already skipping creating the map in
bpf_object__create_maps(), so initializing the struct_ops map even when
autocreate isn't set just seems like an oversight.

Either way:

Acked-by: David Vernet <void@xxxxxxxxxxxxx>

> ---
>  tools/lib/bpf/libbpf.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index c239b75d5816..b39d3f2898a1 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -1192,7 +1192,7 @@ static int bpf_object__init_kern_struct_ops_maps(struct bpf_object *obj)
>  	for (i = 0; i < obj->nr_maps; i++) {
>  		map = &obj->maps[i];
>  
> -		if (!bpf_map__is_struct_ops(map))
> +		if (!bpf_map__is_struct_ops(map) || !map->autocreate)
>  			continue;
>  
>  		err = bpf_map__init_kern_struct_ops(map);
> @@ -8114,7 +8114,7 @@ static int bpf_object_prepare_struct_ops(struct bpf_object *obj)
>  	int i;
>  
>  	for (i = 0; i < obj->nr_maps; i++)
> -		if (bpf_map__is_struct_ops(&obj->maps[i]))
> +		if (bpf_map__is_struct_ops(&obj->maps[i]) && obj->maps[i].autocreate)
>  			bpf_map_prepare_vdata(&obj->maps[i]);
>  
>  	return 0;
> -- 
> 2.43.0
> 

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux