Re: [PATCH bpf-next 05/11] bpf: initialize/free array of btf_field(s).

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

 



On Tue, 2024-04-09 at 17:41 -0700, Kui-Feng Lee wrote:
[...]

> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index f397ccdc6d4b..ee53dcd14bd4 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -390,6 +390,9 @@ static inline u32 btf_field_type_align(enum btf_field_type type)
>  
>  static inline void bpf_obj_init_field(const struct btf_field *field, void *addr)
>  {
> +	u32 elem_size;
> +	int i;
> +
>  	memset(addr, 0, field->size);
>  
>  	switch (field->type) {
> @@ -400,6 +403,10 @@ static inline void bpf_obj_init_field(const struct btf_field *field, void *addr)
>  		RB_CLEAR_NODE((struct rb_node *)addr);
>  		break;
>  	case BPF_LIST_HEAD:
> +		elem_size = field->size / field->nelems;
> +		for (i = 0; i < field->nelems; i++, addr += elem_size)
> +			INIT_LIST_HEAD((struct list_head *)addr);
> +		break;

In btf_find_datasec_var() nelem > 1 is allowed for the following types:
- BPF_LIST_{NODE,HEAD}
- BPF_KPTR_{REF,UNREF,PERCPU}:
- BPF_RB_{NODE,ROOT}

Of these types bpf_obj_init_field() handles in a special way
BPF_RB_NODE, BPF_LIST_HEAD and BPF_LIST_NODE.
However, only BPF_LIST_HEAD handling is adjusted in this patch.
Is there a reason to omit BPF_RB_NODE and BPF_LIST_NODE?

>  	case BPF_LIST_NODE:
>  		INIT_LIST_HEAD((struct list_head *)addr);
>  		break;

[...]






[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