bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/5] Introduce bpf_packet_pointer helper
@ 2022-03-06 23:43 Kumar Kartikeya Dwivedi
  2022-03-06 23:43 ` [PATCH bpf-next v1 1/5] bpf: Add ARG_SCALAR and ARG_CONSTANT Kumar Kartikeya Dwivedi
                   ` (5 more replies)
  0 siblings, 6 replies; 24+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2022-03-06 23:43 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Martin KaFai Lau, Toke Høiland-Jørgensen,
	Jesper Dangaard Brouer, Lorenzo Bianconi, John Fastabend,
	Jakub Kicinski, Lorenz Bauer, netdev

Expose existing 'bpf_xdp_pointer' as a BPF helper named 'bpf_packet_pointer'
returning a packet pointer with a fixed immutable range. This can be useful to
enable DPA without having to use memcpy (currently the case in
bpf_xdp_load_bytes and bpf_xdp_store_bytes).

The intended usage to read and write data for multi-buff XDP is:

	int err = 0;
	char buf[N];

	off &= 0xffff;
	ptr = bpf_packet_pointer(ctx, off, sizeof(buf), &err);
	if (unlikely(!ptr)) {
		if (err < 0)
			return XDP_ABORTED;
		err = bpf_xdp_load_bytes(ctx, off, buf, sizeof(buf));
		if (err < 0)
			return XDP_ABORTED;
		ptr = buf;
	}
	...
	// Do some stores and loads in [ptr, ptr + N) region
	...
	if (unlikely(ptr == buf)) {
		err = bpf_xdp_store_bytes(ctx, off, buf, sizeof(buf));
		if (err < 0)
			return XDP_ABORTED;
	}

Note that bpf_packet_pointer returns a PTR_TO_PACKET, not PTR_TO_MEM, because
these pointers need to be invalidated on clear_all_pkt_pointers invocation, and
it is also more meaningful to the user to see return value as R0=pkt.

This series is meant to collect feedback on the approach, next version can
include a bpf_skb_pointer and exposing it as bpf_packet_pointer helper for TC
hooks, and explore not resetting range to zero on r0 += rX, instead check access
like check_mem_region_access (var_off + off < range), since there would be no
data_end to compare against and obtain a new range.

The common name and func_id is supposed to allow writing generic code using
bpf_packet_pointer that works for both XDP and TC programs.

Please see the individual patches for implementation details.

Kumar Kartikeya Dwivedi (5):
  bpf: Add ARG_SCALAR and ARG_CONSTANT
  bpf: Introduce pkt_uid concept for PTR_TO_PACKET
  bpf: Introduce bpf_packet_pointer helper to do DPA
  selftests/bpf: Add verifier tests for pkt pointer with pkt_uid
  selftests/bpf: Update xdp_adjust_frags to use bpf_packet_pointer

 include/linux/bpf.h                           |   4 +
 include/linux/bpf_verifier.h                  |   9 +-
 include/uapi/linux/bpf.h                      |  12 ++
 kernel/bpf/verifier.c                         |  97 ++++++++++--
 net/core/filter.c                             |  48 +++---
 tools/include/uapi/linux/bpf.h                |  12 ++
 .../bpf/prog_tests/xdp_adjust_frags.c         |  46 ++++--
 .../bpf/progs/test_xdp_update_frags.c         |  46 ++++--
 tools/testing/selftests/bpf/verifier/xdp.c    | 146 ++++++++++++++++++
 9 files changed, 358 insertions(+), 62 deletions(-)

-- 
2.35.1


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

end of thread, other threads:[~2022-03-11 17:27 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-06 23:43 [PATCH bpf-next v1 0/5] Introduce bpf_packet_pointer helper Kumar Kartikeya Dwivedi
2022-03-06 23:43 ` [PATCH bpf-next v1 1/5] bpf: Add ARG_SCALAR and ARG_CONSTANT Kumar Kartikeya Dwivedi
2022-03-07 19:28   ` Joanne Koong
2022-03-07 21:22     ` Kumar Kartikeya Dwivedi
2022-03-08  5:42   ` Andrii Nakryiko
2022-03-08  6:26     ` Kumar Kartikeya Dwivedi
2022-03-10 23:05       ` Andrii Nakryiko
2022-03-10 23:09         ` Andrii Nakryiko
2022-03-11  7:31           ` Kumar Kartikeya Dwivedi
2022-03-06 23:43 ` [PATCH bpf-next v1 2/5] bpf: Introduce pkt_uid concept for PTR_TO_PACKET Kumar Kartikeya Dwivedi
2022-03-06 23:43 ` [PATCH bpf-next v1 3/5] bpf: Introduce bpf_packet_pointer helper to do DPA Kumar Kartikeya Dwivedi
2022-03-06 23:43 ` [PATCH bpf-next v1 4/5] selftests/bpf: Add verifier tests for pkt pointer with pkt_uid Kumar Kartikeya Dwivedi
2022-03-06 23:43 ` [PATCH bpf-next v1 5/5] selftests/bpf: Update xdp_adjust_frags to use bpf_packet_pointer Kumar Kartikeya Dwivedi
2022-03-08  5:48 ` [PATCH bpf-next v1 0/5] Introduce bpf_packet_pointer helper Andrii Nakryiko
2022-03-08  7:08   ` Kumar Kartikeya Dwivedi
2022-03-08 13:40     ` Toke Høiland-Jørgensen
2022-03-10 23:12       ` Andrii Nakryiko
2022-03-10 23:30         ` Toke Høiland-Jørgensen
2022-03-10 23:35           ` Alexei Starovoitov
2022-03-11  7:25             ` Kumar Kartikeya Dwivedi
2022-03-11  7:32               ` Kumar Kartikeya Dwivedi
2022-03-11 17:27               ` Alexei Starovoitov
2022-03-11  7:19           ` Kumar Kartikeya Dwivedi
2022-03-11 10:34             ` Toke Høiland-Jørgensen

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).