All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 bpf-next 1/2] bpf: Allow ringbuf memory to be used as map key
@ 2022-09-14 12:35 Dave Marchevsky
  2022-09-14 12:36 ` [PATCH v2 bpf-next 2/2] selftests/bpf: Add test verifying bpf_ringbuf_reserve retval use in map ops Dave Marchevsky
  2022-09-14 17:21 ` [PATCH v2 bpf-next 1/2] bpf: Allow ringbuf memory to be used as map key Yonghong Song
  0 siblings, 2 replies; 9+ messages in thread
From: Dave Marchevsky @ 2022-09-14 12:35 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Kernel Team, Kumar Kartikeya Dwivedi, Yonghong Song,
	Dave Marchevsky

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>
---
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 c259d734f863..f6e029780698 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -5626,6 +5626,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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-09-22 17:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14 12:35 [PATCH v2 bpf-next 1/2] bpf: Allow ringbuf memory to be used as map key Dave Marchevsky
2022-09-14 12:36 ` [PATCH v2 bpf-next 2/2] selftests/bpf: Add test verifying bpf_ringbuf_reserve retval use in map ops Dave Marchevsky
2022-09-15 10:24   ` Alexei Starovoitov
2022-09-19 22:53   ` Yonghong Song
2022-09-19 23:22     ` Kumar Kartikeya Dwivedi
2022-09-20  5:50       ` Yonghong Song
2022-09-22 14:27         ` Dave Marchevsky
2022-09-22 16:59           ` Yonghong Song
2022-09-14 17:21 ` [PATCH v2 bpf-next 1/2] bpf: Allow ringbuf memory to be used as map key Yonghong Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.