Re: [PATCH bpf-next] bpf: Update max_entries for array maps

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

 



Hi,

On 10/25/2022 5:28 PM, Florian Lehner wrote:
> To improve memory handling and alignment max_entries is rounded up
> before using its value to allocate memory.
> This can lead to a situation where more memory is allocated than usable
> if max_entries is no adjusted accordingly. So this change updates
> max_entries in order to make the allocated memory available.
>
> Signed-off-by: Florian Lehner <dev@xxxxxxxxxxx>
> ---
>  kernel/bpf/arraymap.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c
> index 832b2659e96e..9411fa255ccc 100644
> --- a/kernel/bpf/arraymap.c
> +++ b/kernel/bpf/arraymap.c
> @@ -145,6 +145,7 @@ static struct bpf_map *array_map_alloc(union bpf_attr *attr)
>  	/* copy mandatory map attributes */
>  	bpf_map_init_from_attr(&array->map, attr);
>  	array->elem_size = elem_size;
> +	array->map.max_entries = max_entries;
>  
>  	if (percpu && bpf_array_alloc_percpu(array)) {
>  		bpf_map_area_free(array);
The override of max_entries is unnecessary and is also wrong.
bpf_array_alloc_percpu() will use array->map.max_entries to allocate per-cpu
value, and if using the rounded-up max_entries, there will be memory waste
because the extra allocated per-cpu values should not be accessible to bpf
program or user-space program.




[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