bpf: Fix memlock accounting for sock_hash
Subsystems (4)
PATCH 1/1 bpf: Fix memlock accounting for sock_hash
Add missed bpf_map_charge_init() in sock_hash_alloc() and correspondingly bpf_map_charge_finish() on ENOMEM.
It was found accidentally while working on unrelated selftest that checks "map->memory.pages > 0" is true for all map types.
Before:
# bpftool m l ... 3692: sockhash name m_sockhash flags 0x0 key 4B value 4B max_entries 8 memlock 0B
After:
# bpftool m l ... 84: sockmap name m_sockmap flags 0x0 key 4B value 4B max_entries 8 memlock 4096B
Fixes 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by Andrey Ignatov <[email protected]>
--- net/core/sock_map.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/sock_map.c +4 -0
@@ -989,11 +989,15 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr) err = -EINVAL ; goto free_htab; } + err =bpf_map_charge_init (&htab->map.memory, cost); +if (err) + goto free_htab; htab->buckets =bpf_map_area_alloc (htab->buckets_num *sizeof (struct bpf_htab_bucket ), htab->map.numa_node);if (!htab->buckets) { +bpf_map_charge_finish (&htab->map.memory); err = -ENOMEM ; goto free_htab; }
Signature · 1 line
2.24.1
Quoted 13 lines · Andrey Ignatov
Add missed
bpf_map_charge_init()insock_hash_alloc()and correspondinglybpf_map_charge_finish()on ENOMEM.It was found accidentally while working on unrelated selftest that checks "
map->memory.pages> 0" is true for all map types.Before:
# bpftool m l ... 3692: sockhash name m_sockhash flags 0x0 key 4B value 4B max_entries 8 memlock 0B
Quoted 8 lines
After:
# bpftool m l ... 84: sockmap name m_sockmap flags 0x0 key 4B value 4B max_entries 8 memlock 4096BFixes 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface")Signed-off-by Andrey Ignatov <[email protected]>
That's a nasty one. Good catch.
Applied.