From: Joanne Koong <joannekoong@fb.com>
To: <bpf@vger.kernel.org>
Cc: <andrii@kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>,
<kafai@fb.com>, <Kernel-team@fb.com>,
Joanne Koong <joannekoong@fb.com>
Subject: [PATCH bpf-next 1/3] bpf: Bloom filter map naming fixups
Date: Fri, 29 Oct 2021 10:01:24 -0700 [thread overview]
Message-ID: <20211029170126.4189338-2-joannekoong@fb.com> (raw)
In-Reply-To: <20211029170126.4189338-1-joannekoong@fb.com>
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 <joannekoong@fb.com>
---
kernel/bpf/bloom_filter.c | 49 +++++++++++++++++++++------------------
1 file changed, 26 insertions(+), 23 deletions(-)
diff --git a/kernel/bpf/bloom_filter.c b/kernel/bpf/bloom_filter.c
index 7c50232b7571..073c2f2cab8b 100644
--- a/kernel/bpf/bloom_filter.c
+++ b/kernel/bpf/bloom_filter.c
@@ -40,7 +40,7 @@ static u32 hash(struct bpf_bloom_filter *bloom, void *value,
return h & bloom->bitset_mask;
}
-static int peek_elem(struct bpf_map *map, void *value)
+static int bloom_map_peek_elem(struct bpf_map *map, void *value)
{
struct bpf_bloom_filter *bloom =
container_of(map, struct bpf_bloom_filter, map);
@@ -55,7 +55,7 @@ static int peek_elem(struct bpf_map *map, void *value)
return 0;
}
-static int push_elem(struct bpf_map *map, void *value, u64 flags)
+static int bloom_map_push_elem(struct bpf_map *map, void *value, u64 flags)
{
struct bpf_bloom_filter *bloom =
container_of(map, struct bpf_bloom_filter, map);
@@ -72,12 +72,12 @@ static int push_elem(struct bpf_map *map, void *value, u64 flags)
return 0;
}
-static int pop_elem(struct bpf_map *map, void *value)
+static int bloom_map_pop_elem(struct bpf_map *map, void *value)
{
return -EOPNOTSUPP;
}
-static struct bpf_map *map_alloc(union bpf_attr *attr)
+static struct bpf_map *bloom_map_alloc(union bpf_attr *attr)
{
u32 bitset_bytes, bitset_mask, nr_hash_funcs, nr_bits;
int numa_node = bpf_map_attr_numa_node(attr);
@@ -90,11 +90,13 @@ static struct bpf_map *map_alloc(union bpf_attr *attr)
attr->max_entries == 0 ||
attr->map_flags & ~BLOOM_CREATE_FLAG_MASK ||
!bpf_map_flags_access_ok(attr->map_flags) ||
+ /* The lower 4 bits of map_extra (0xF) specify the number
+ * of hash functions
+ */
(attr->map_extra & ~0xF))
return ERR_PTR(-EINVAL);
- /* The lower 4 bits of map_extra specify the number of hash functions */
- nr_hash_funcs = attr->map_extra & 0xF;
+ nr_hash_funcs = attr->map_extra;
if (nr_hash_funcs == 0)
/* Default to using 5 hash functions if unspecified */
nr_hash_funcs = 5;
@@ -150,7 +152,7 @@ static struct bpf_map *map_alloc(union bpf_attr *attr)
return &bloom->map;
}
-static void map_free(struct bpf_map *map)
+static void bloom_map_free(struct bpf_map *map)
{
struct bpf_bloom_filter *bloom =
container_of(map, struct bpf_bloom_filter, map);
@@ -158,38 +160,39 @@ static void map_free(struct bpf_map *map)
bpf_map_area_free(bloom);
}
-static void *lookup_elem(struct bpf_map *map, void *key)
+static void *bloom_map_lookup_elem(struct bpf_map *map, void *key)
{
/* The eBPF program should use map_peek_elem instead */
return ERR_PTR(-EINVAL);
}
-static int update_elem(struct bpf_map *map, void *key,
- void *value, u64 flags)
+static int bloom_map_update_elem(struct bpf_map *map, void *key,
+ void *value, u64 flags)
{
/* The eBPF program should use map_push_elem instead */
return -EINVAL;
}
-static int check_btf(const struct bpf_map *map, const struct btf *btf,
- const struct btf_type *key_type,
- const struct btf_type *value_type)
+static int bloom_map_check_btf(const struct bpf_map *map,
+ const struct btf *btf,
+ const struct btf_type *key_type,
+ const struct btf_type *value_type)
{
/* Bloom filter maps are keyless */
return btf_type_is_void(key_type) ? 0 : -EINVAL;
}
-static int bpf_bloom_btf_id;
+static int bpf_bloom_map_btf_id;
const struct bpf_map_ops bloom_filter_map_ops = {
.map_meta_equal = bpf_map_meta_equal,
- .map_alloc = map_alloc,
- .map_free = map_free,
- .map_push_elem = push_elem,
- .map_peek_elem = peek_elem,
- .map_pop_elem = pop_elem,
- .map_lookup_elem = lookup_elem,
- .map_update_elem = update_elem,
- .map_check_btf = check_btf,
+ .map_alloc = bloom_map_alloc,
+ .map_free = bloom_map_free,
+ .map_push_elem = bloom_map_push_elem,
+ .map_peek_elem = bloom_map_peek_elem,
+ .map_pop_elem = bloom_map_pop_elem,
+ .map_lookup_elem = bloom_map_lookup_elem,
+ .map_update_elem = bloom_map_update_elem,
+ .map_check_btf = bloom_map_check_btf,
.map_btf_name = "bpf_bloom_filter",
- .map_btf_id = &bpf_bloom_btf_id,
+ .map_btf_id = &bpf_bloom_map_btf_id,
};
--
2.30.2
next prev parent reply other threads:[~2021-10-29 17:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-29 17:01 [PATCH bpf-next 0/3] "map_extra" and bloom filter fixups Joanne Koong
2021-10-29 17:01 ` Joanne Koong [this message]
2021-10-29 21:28 ` [PATCH bpf-next 1/3] bpf: Bloom filter map naming fixups Yonghong Song
2021-10-29 17:01 ` [PATCH bpf-next 2/3] bpf: Add alignment padding for "map_extra" + consolidate holes Joanne Koong
2021-10-29 21:29 ` Yonghong Song
2021-10-29 17:01 ` [PATCH bpf-next 3/3] selftests/bpf: Add bloom map success test for userspace calls Joanne Koong
2021-10-29 22:04 ` Yonghong Song
2021-10-29 22:30 ` Joanne Koong
2021-10-29 22:49 [PATCH bpf-next 0/3] "map_extra" and bloom filter fixups Joanne Koong
2021-10-29 22:49 ` [PATCH bpf-next 1/3] bpf: Bloom filter map naming fixups Joanne Koong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211029170126.4189338-2-joannekoong@fb.com \
--to=joannekoong@fb.com \
--cc=Kernel-team@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).