From eaf2fea0d279c010f8c8ba55dd0a550bbcc6cfe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Thu, 7 Aug 2025 14:28:45 -0700 Subject: [PATCH] bpf_helpers: pass map_flags into DEFINE_LIBBPF_MAP() macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (that this was missing appears to be an oversight) Test: TreeHugger Flag: EXEMPT mainline Signed-off-by: Maciej Żenczykowski Change-Id: Icd424324db11e56f820817f890985155d639175d --- bpf/progs/include/bpf_helpers.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/bpf/progs/include/bpf_helpers.h b/bpf/progs/include/bpf_helpers.h index b68ad2bde7..a140b4a168 100644 --- a/bpf/progs/include/bpf_helpers.h +++ b/bpf/progs/include/bpf_helpers.h @@ -236,11 +236,11 @@ static long (*bpf_sk_storage_delete_unsafe) (const void* sk_storage, #define ABSOLUTE(x) ((x) < 0 ? -(x) : (x)) -#define DEFAULT_BPF_MAP_FLAGS(type, num_entries, mapflags) \ - ( (mapflags) | \ - ((num_entries) < 0 ? BPF_F_NO_PREALLOC : 0) | \ - ( (type == BPF_MAP_TYPE_LPM_TRIE || \ - type == BPF_MAP_TYPE_SK_STORAGE) ? BPF_F_NO_PREALLOC : 0) \ +#define DEFAULT_BPF_MAP_FLAGS(TYPE, num_entries, mapflags) \ + ( (mapflags) | \ + ((num_entries) < 0 ? BPF_F_NO_PREALLOC : 0) | \ + ( (BPF_MAP_TYPE_##TYPE == BPF_MAP_TYPE_LPM_TRIE || \ + BPF_MAP_TYPE_##TYPE == BPF_MAP_TYPE_SK_STORAGE) ? BPF_F_NO_PREALLOC : 0) \ ) #define DEFINE_BPF_MAP_BASE(the_map, TYPE, keysize, valuesize, num_entries, usr, grp, md, \ @@ -252,7 +252,7 @@ static long (*bpf_sk_storage_delete_unsafe) (const void* sk_storage, .key_size = (keysize), \ .value_size = (valuesize), \ .max_entries = ABSOLUTE(num_entries), \ - .map_flags = DEFAULT_BPF_MAP_FLAGS(BPF_MAP_TYPE_##TYPE, num_entries, mapflags), \ + .map_flags = DEFAULT_BPF_MAP_FLAGS(TYPE, num_entries, mapflags), \ .uid = (usr), \ .gid = (grp), \ .mode = (md), \ @@ -268,12 +268,13 @@ static long (*bpf_sk_storage_delete_unsafe) (const void* sk_storage, #define __uint(name, val) int (*name)[val] #define __type(name, val) typeof(val) *name -#define DEFINE_LIBBPF_MAP(the_map, TYPE, KeyType, ValueType, num_entries) \ - struct { \ - __uint(type, BPF_MAP_TYPE_##TYPE); \ - __type(key, KeyType); \ - __type(value, ValueType); \ - __uint(max_entries, ABSOLUTE(num_entries)); \ +#define DEFINE_LIBBPF_MAP(the_map, TYPE, KeyType, ValueType, num_entries, mapflags) \ + struct { \ + __uint(type, BPF_MAP_TYPE_##TYPE); \ + __uint(map_flags, DEFAULT_BPF_MAP_FLAGS(TYPE, num_entries, mapflags)); \ + __type(key, KeyType); \ + __type(value, ValueType); \ + __uint(max_entries, ABSOLUTE(num_entries)); \ } the_map SECTION(".maps"); #define DEFINE_LIBBPF_RINGBUF(the_map, num_entries) \ @@ -329,7 +330,7 @@ static long (*bpf_sk_storage_delete_unsafe) (const void* sk_storage, DEFINE_BPF_MAP_BASE(the_map, SK_STORAGE, sizeof(uint32_t), sizeof(ValueType), \ 0, usr, grp, md, selinux, pindir, \ KVER_5_10, KVER_INF, min_loader, max_loader, mapFlags); \ - DEFINE_LIBBPF_MAP(the_map, SK_STORAGE, uint32_t, ValueType, 0); \ + DEFINE_LIBBPF_MAP(the_map, SK_STORAGE, uint32_t, ValueType, 0, mapFlags); \ BPF_ANNOTATE_KV_PAIR(the_map, uint32_t, ValueType); \ \ static inline __always_inline __unused ValueType* bpf_##the_map##_get( \ @@ -371,7 +372,7 @@ static long (*bpf_sk_storage_delete_unsafe) (const void* sk_storage, DEFINE_BPF_MAP_BASE(the_map, TYPE, sizeof(KeyType), sizeof(ValueType), \ num_entries, usr, grp, md, selinux, pindir, \ KVER_4_9, KVER_INF, min_loader, max_loader, mapFlags); \ - DEFINE_LIBBPF_MAP(the_map, TYPE, KeyType, ValueType, num_entries); \ + DEFINE_LIBBPF_MAP(the_map, TYPE, KeyType, ValueType, num_entries, mapFlags); \ BPF_MAP_ASSERT_OK(BPF_MAP_TYPE_##TYPE, (num_entries), (md)); \ _Static_assert(sizeof(KeyType) < 1024, "aosp/2370288 requires < 1024 byte keys"); \ _Static_assert(sizeof(ValueType) < 65536, "aosp/2370288 requires < 65536 byte values"); \