public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: Update max_entries for array maps
@ 2022-10-25  9:28 Florian Lehner
  2022-10-26  3:35 ` Hou Tao
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Lehner @ 2022-10-25  9:28 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, Florian Lehner

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@der-flo.net>
---
 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);
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-26  3:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-25  9:28 [PATCH bpf-next] bpf: Update max_entries for array maps Florian Lehner
2022-10-26  3:35 ` Hou Tao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox