Skip to content

Commit 6fdc348

Browse files
jkoong-fbAlexei Starovoitov
authored andcommitted
bpf: Bloom filter map naming fixups
This patch has two changes in the kernel bloom filter map implementation: 1) Change the names of map-ops functions to include the "bloom_map" prefix. As Martin pointed out on a previous patchset, having generic map-ops names may be confusing in tracing and in perf-report. 2) Drop the "& 0xF" when getting nr_hash_funcs, since we already ascertain that no other bits in map_extra beyond the first 4 bits can be set. Signed-off-by: Joanne Koong <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent f27a6fa commit 6fdc348

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

kernel/bpf/bloom_filter.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static u32 hash(struct bpf_bloom_filter *bloom, void *value,
4040
return h & bloom->bitset_mask;
4141
}
4242

43-
static int peek_elem(struct bpf_map *map, void *value)
43+
static int bloom_map_peek_elem(struct bpf_map *map, void *value)
4444
{
4545
struct bpf_bloom_filter *bloom =
4646
container_of(map, struct bpf_bloom_filter, map);
@@ -55,7 +55,7 @@ static int peek_elem(struct bpf_map *map, void *value)
5555
return 0;
5656
}
5757

58-
static int push_elem(struct bpf_map *map, void *value, u64 flags)
58+
static int bloom_map_push_elem(struct bpf_map *map, void *value, u64 flags)
5959
{
6060
struct bpf_bloom_filter *bloom =
6161
container_of(map, struct bpf_bloom_filter, map);
@@ -72,12 +72,12 @@ static int push_elem(struct bpf_map *map, void *value, u64 flags)
7272
return 0;
7373
}
7474

75-
static int pop_elem(struct bpf_map *map, void *value)
75+
static int bloom_map_pop_elem(struct bpf_map *map, void *value)
7676
{
7777
return -EOPNOTSUPP;
7878
}
7979

80-
static struct bpf_map *map_alloc(union bpf_attr *attr)
80+
static struct bpf_map *bloom_map_alloc(union bpf_attr *attr)
8181
{
8282
u32 bitset_bytes, bitset_mask, nr_hash_funcs, nr_bits;
8383
int numa_node = bpf_map_attr_numa_node(attr);
@@ -90,11 +90,13 @@ static struct bpf_map *map_alloc(union bpf_attr *attr)
9090
attr->max_entries == 0 ||
9191
attr->map_flags & ~BLOOM_CREATE_FLAG_MASK ||
9292
!bpf_map_flags_access_ok(attr->map_flags) ||
93+
/* The lower 4 bits of map_extra (0xF) specify the number
94+
* of hash functions
95+
*/
9396
(attr->map_extra & ~0xF))
9497
return ERR_PTR(-EINVAL);
9598

96-
/* The lower 4 bits of map_extra specify the number of hash functions */
97-
nr_hash_funcs = attr->map_extra & 0xF;
99+
nr_hash_funcs = attr->map_extra;
98100
if (nr_hash_funcs == 0)
99101
/* Default to using 5 hash functions if unspecified */
100102
nr_hash_funcs = 5;
@@ -150,46 +152,47 @@ static struct bpf_map *map_alloc(union bpf_attr *attr)
150152
return &bloom->map;
151153
}
152154

153-
static void map_free(struct bpf_map *map)
155+
static void bloom_map_free(struct bpf_map *map)
154156
{
155157
struct bpf_bloom_filter *bloom =
156158
container_of(map, struct bpf_bloom_filter, map);
157159

158160
bpf_map_area_free(bloom);
159161
}
160162

161-
static void *lookup_elem(struct bpf_map *map, void *key)
163+
static void *bloom_map_lookup_elem(struct bpf_map *map, void *key)
162164
{
163165
/* The eBPF program should use map_peek_elem instead */
164166
return ERR_PTR(-EINVAL);
165167
}
166168

167-
static int update_elem(struct bpf_map *map, void *key,
168-
void *value, u64 flags)
169+
static int bloom_map_update_elem(struct bpf_map *map, void *key,
170+
void *value, u64 flags)
169171
{
170172
/* The eBPF program should use map_push_elem instead */
171173
return -EINVAL;
172174
}
173175

174-
static int check_btf(const struct bpf_map *map, const struct btf *btf,
175-
const struct btf_type *key_type,
176-
const struct btf_type *value_type)
176+
static int bloom_map_check_btf(const struct bpf_map *map,
177+
const struct btf *btf,
178+
const struct btf_type *key_type,
179+
const struct btf_type *value_type)
177180
{
178181
/* Bloom filter maps are keyless */
179182
return btf_type_is_void(key_type) ? 0 : -EINVAL;
180183
}
181184

182-
static int bpf_bloom_btf_id;
185+
static int bpf_bloom_map_btf_id;
183186
const struct bpf_map_ops bloom_filter_map_ops = {
184187
.map_meta_equal = bpf_map_meta_equal,
185-
.map_alloc = map_alloc,
186-
.map_free = map_free,
187-
.map_push_elem = push_elem,
188-
.map_peek_elem = peek_elem,
189-
.map_pop_elem = pop_elem,
190-
.map_lookup_elem = lookup_elem,
191-
.map_update_elem = update_elem,
192-
.map_check_btf = check_btf,
188+
.map_alloc = bloom_map_alloc,
189+
.map_free = bloom_map_free,
190+
.map_push_elem = bloom_map_push_elem,
191+
.map_peek_elem = bloom_map_peek_elem,
192+
.map_pop_elem = bloom_map_pop_elem,
193+
.map_lookup_elem = bloom_map_lookup_elem,
194+
.map_update_elem = bloom_map_update_elem,
195+
.map_check_btf = bloom_map_check_btf,
193196
.map_btf_name = "bpf_bloom_filter",
194-
.map_btf_id = &bpf_bloom_btf_id,
197+
.map_btf_id = &bpf_bloom_map_btf_id,
195198
};

0 commit comments

Comments
 (0)