From: Dave Marchevsky <davemarchevsky@fb.com>
To: <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Kernel Team <kernel-team@fb.com>, Yonghong Song <yhs@fb.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Dave Marchevsky <davemarchevsky@fb.com>
Subject: [PATCH v5 bpf-next 1/4] bpf: Allow ringbuf memory to be used as map key
Date: Thu, 20 Oct 2022 09:07:18 -0700 [thread overview]
Message-ID: <20221020160721.4030492-1-davemarchevsky@fb.com> (raw)
This patch adds support for the following pattern:
struct some_data *data = bpf_ringbuf_reserve(&ringbuf, sizeof(struct some_data, 0));
if (!data)
return;
bpf_map_lookup_elem(&another_map, &data->some_field);
bpf_ringbuf_submit(data);
Currently the verifier does not consider bpf_ringbuf_reserve's
PTR_TO_MEM | MEM_ALLOC ret type a valid key input to bpf_map_lookup_elem.
Since PTR_TO_MEM is by definition a valid region of memory, it is safe
to use it as a key for lookups.
Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
---
v2->v3: lore.kernel.org/bpf/20220914123600.927632-1-davemarchevsky@fb.com
* Add Yonghong ack, rebase
v1->v2: lore.kernel.org/bpf/20220912101106.2765921-1-davemarchevsky@fb.com
* Move test changes into separate patch - patch 2 in this series.
(Kumar, Yonghong). That patch's changelog enumerates specific
changes from v1
* Remove PTR_TO_MEM addition from this patch - patch 1 (Yonghong)
* I don't have a usecase for PTR_TO_MEM w/o MEM_ALLOC
* Add "if (!data)" error check to example pattern in this patch
(Yonghong)
* Remove patch 2 from v1's series, which removed map_key_value_types
as it was more-or-less duplicate of mem_types
* Now that PTR_TO_MEM isn't added here, more differences between
map_key_value_types and mem_types, and no usecase for PTR_TO_BUF,
so drop for now.
kernel/bpf/verifier.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 6f6d2d511c06..97351ae3e7a7 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -5641,6 +5641,7 @@ static const struct bpf_reg_types map_key_value_types = {
PTR_TO_PACKET_META,
PTR_TO_MAP_KEY,
PTR_TO_MAP_VALUE,
+ PTR_TO_MEM | MEM_ALLOC,
},
};
--
2.30.2
next reply other threads:[~2022-10-20 16:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-20 16:07 Dave Marchevsky [this message]
2022-10-20 16:07 ` [PATCH v5 bpf-next 2/4] bpf: Consider all mem_types compatible for map_{key,value} args Dave Marchevsky
2022-10-21 23:04 ` Andrii Nakryiko
2022-10-22 2:26 ` Alexei Starovoitov
2022-10-20 16:07 ` [PATCH v5 bpf-next 3/4] selftests/bpf: Add test verifying bpf_ringbuf_reserve retval use in map ops Dave Marchevsky
2022-10-21 23:04 ` Andrii Nakryiko
2022-10-20 16:07 ` [PATCH v5 bpf-next 4/4] selftests/bpf: Add write to hashmap to array_map iter test Dave Marchevsky
2022-10-21 23:04 ` Andrii Nakryiko
2022-10-21 23:04 ` [PATCH v5 bpf-next 1/4] bpf: Allow ringbuf memory to be used as map key Andrii Nakryiko
2022-10-22 2:30 ` patchwork-bot+netdevbpf
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=20221020160721.4030492-1-davemarchevsky@fb.com \
--to=davemarchevsky@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=memxor@gmail.com \
--cc=yhs@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