Hello,
this small series aims to increase coverage of xdp features in
test_progs. The initial versions proposed to rework test_xdp_features.sh
to make it fit in test_progs, but some discussions in v1 and v2 showed
that the script is still needed as a standalone tool. So this new
revision lets test_xdp_features.sh as-is, and rather adds missing
coverage in existing test (cpu map). The new revision is now also a
follow-up to the update performed by Florian Kauer in [1] for devmap
programs testing.
[1] https://lore.kernel.org/bpf/20240911-devel-koalo-fix-ingress-ifindex-v4-2-5…
---
Changes in v3:
- Drop xdp_features rework commit
- update xdp_cpumap_attach to extend its coverage
- Link to v2: https://lore.kernel.org/r/20240910-convert_xdp_tests-v2-1-a46367c9d038@boot…
Changes in v2:
- fix endianness management in userspace packet parsing (call htonl on
constant rather than packet part)
The new test has been run in a local x86 environment and in CI:
#560/1 xdp_cpumap_attach/CPUMAP with programs in entries:OK
#560/2 xdp_cpumap_attach/CPUMAP with frags programs in entries:OK
#560/3 xdp_cpumap_attach/CPUMAP attach with programs in entries on veth:OK
#560 xdp_cpumap_attach:OK
Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
---
Alexis Lothoré (eBPF Foundation) (3):
selftests/bpf: fix bpf_map_redirect call for cpu map test
selftests/bpf: make xdp_cpumap_attach keep redirect prog attached
selftests/bpf: check program redirect in xdp_cpumap_attach
.../selftests/bpf/prog_tests/xdp_cpumap_attach.c | 130 +++++++++++++++++++--
.../bpf/progs/test_xdp_with_cpumap_helpers.c | 7 +-
2 files changed, 129 insertions(+), 8 deletions(-)
---
base-commit: 058d7c3d1691e2e4a4963716ec6c047dff778637
change-id: 20240730-convert_xdp_tests-ccd66bfe33db
Best regards,
--
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Currently, sk_lookup allows an ebpf program to run on the ingress socket
lookup path, and accept traffic not only on a range of addresses, but
also on a range of ports. At Cloudflare we use sk_lookup for two main
cases:
1. Sharing a single port between multiple services - i.e. two services
(or more) use disjoint IP ranges but share the same port;
2. Receiving traffic on all ports - i.e. a service which accepts traffic
on specific IP ranges but any port [1].
However, one main challenge we face while using sk_lookup for these use
cases is how to source return UDP traffic:
- On point 1. above, sometimes this range of addresses are not local
(i.e. there's no local routes for these in the server), which means we
need IP_TRANSPARENT set to be able to egress traffic from addresses
we've received traffic on (or simply IP_FREEBIND in the case of IPv6);
- And on point 2. above, allowing traffic to a range of ports means a
service could get traffic on multiple ports, but currently there's no
way to set the source UDP port egress traffic should be sourced from -
it's possible to receive the original destination port using the
IP_ORIGDSTADDR ancilliary message in recvmsg, but not set it in
sendmsg.
Both of these limitations can be worked around, but in a sub-optimal
way. Using IP_TRANSPARENT, for instance, requires special privileges.
And while one could use UDP connected sockets to send return traffic,
creating a connected socket for each different address a UDP traffic is
received on does have performance implications.
Given sk_lookup allows services to accept traffic on a range of
addresses or ports, it seems sensible to also allow return traffic to
proceed through as well, without needing extra configurations / set ups.
This patch set allows to do exactly this by performing a reverse socket
lookup on the egress path - where it looks to see if the egress socket
matches a socket in the attached sk_lookup ebpf program for the traffic
that's being sent. If it does, traffic is allowed to proceed.
The downsides to this is that this runs on the egress hot path, although
this work tries to minimise its impact by only performing the reverse
socket lookup when necessary. Further performance measurements are to be
taken, but we're reaching out early for feedback to see what the
technical concerns are and if we can address them.
[1] https://blog.cloudflare.com/how-we-built-spectrum/
Suggested-by: Jakub Sitnicki <jakub(a)cloudflare.com>
Signed-off-by: Tiago Lam <tiagolam(a)cloudflare.com>
---
Tiago Lam (3):
ipv4: Run a reverse sk_lookup on sendmsg.
ipv6: Run a reverse sk_lookup on sendmsg.
bpf: Add sk_lookup test to use ORIGDSTADDR cmsg.
include/net/ip.h | 1 +
net/ipv4/ip_sockglue.c | 11 ++++
net/ipv4/udp.c | 33 +++++++++-
net/ipv6/datagram.c | 76 ++++++++++++++++++++++
net/ipv6/udp.c | 8 ++-
tools/testing/selftests/bpf/prog_tests/sk_lookup.c | 70 +++++++++++++-------
6 files changed, 174 insertions(+), 25 deletions(-)
---
base-commit: da3ea35007d0af457a0afc87e84fddaebc4e0b63
change-id: 20240909-reverse-sk-lookup-f7bf36292bc4
Best regards,
--
Tiago Lam <tiagolam(a)cloudflare.com>
Hi all,
This is part of a hackathon organized by LKCAMP [1], focused on writing
tests using KUnit. We reached out a while ago asking for advice on what would
be a useful contribution [2] and ended up choosing data structures that did
not yet have tests.
This patch series depends on the patch that moves the KUnit tests on lib/
into lib/tests/ [3].
This patch adds tests for the kfifo data structure, defined in
include/linux/kfifo.h, and is inspired by the KUnit tests for the doubly
linked list in lib/tests/list-test.c (previously at lib/list-test.c) [4].
[1] https://lkcamp.dev/about/
[2] https://lore.kernel.org/all/Zktnt7rjKryTh9-N@arch/
[3] https://lore.kernel.org/all/20240720181025.work.002-kees@kernel.org/
[4] https://elixir.bootlin.com/linux/latest/source/lib/list-test.c
---
Changes in v2:
- Add MODULE_DESCRIPTION()
- Move the tests from lib/kfifo-test.c to lib/tests/kfifo_kunit.c
Diego Vieira (1):
lib/tests/kfifo_kunit.c: add tests for the kfifo structure
lib/Kconfig.debug | 14 +++
lib/tests/Makefile | 1 +
lib/tests/kfifo_kunit.c | 224 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 239 insertions(+)
create mode 100644 lib/tests/kfifo_kunit.c
--
2.34.1
The BPF testing framework has evolved significantly over time. However,
some legacy tests in the samples/bpf directory have not kept up with
these changes. These outdated tests can cause confusion and increase
maintenance efforts.
This patchset focuses on migrating outdated cgroup and tracing-related
tests from samples/bpf to selftests/bpf, ensuring the BPF test suite
remains current and efficient. Tests that are already covered by
selftests/bpf are removed, while those not yet covered are migrated.
This includes cgroup sock create tests for setting socket attributes
and blocking socket creation, as well as the removal of redundant
cgroup and tracing tests that have been replaced by newer tests.
This patchset covers the following cgroup/tracing tests:
- test_overhead: tests the overhead of BPF programs with task_rename,
now covered by selftests and benchmark tests (rename-*). [1]
- test_override_return: tests the return override functionality, now
handled by kprobe_multi_override in selftests.
- test_probe_write_user: tests the probe_write_user functionality,
now replaced by the probe_user test in selftests.
- test_cgrp2_sock: tests cgroup BPF's ability to set sk_bound_dev_if,
mark, and priority during socket creation. Migrated to selftests as
'sock_create' since no existing tests fully cover this.
- test_cgrp2_sock2: tests blocking socket creation for specific types
(AF_INET{6}, SOCK_DGRAM, IPPROTO_ICMP{V6}). Migrated to selftests
in 'sock_create' test for coverage.
- test_current_task_under_cgroup: tests bpf_current_task_under_cgroup()
to check if a task belongs to a cgroup. Already covered by
task_under_cgroup at selftest and other cgroup ID tests.
- test_cgrp2_tc: tests bpf_skb_under_cgroup() to filter packets based
on cgroup. This behavior is now validated by cgroup_skb_sk_lookup,
which uses bpf_skb_cgroup_id, making this test redundant.
[1]: https://patchwork.kernel.org/cover/13759916
Daniel T. Lee (4):
selftests/bpf: migrate cgroup sock create test for setting
iface/mark/prio
selftests/bpf: migrate cgroup sock create tests for prohibitig sockets
samples/bpf: remove obsolete cgroup related tests
samples/bpf: remove obsolete tracing related tests
---
Changes in v2:
- commit message fix
samples/bpf/Makefile | 24 --
samples/bpf/sock_flags.bpf.c | 47 ---
samples/bpf/test_cgrp2_array_pin.c | 106 ------
samples/bpf/test_cgrp2_attach.c | 177 ----------
samples/bpf/test_cgrp2_sock.c | 296 ----------------
samples/bpf/test_cgrp2_sock.sh | 137 -------
samples/bpf/test_cgrp2_sock2.c | 95 -----
samples/bpf/test_cgrp2_sock2.sh | 103 ------
samples/bpf/test_cgrp2_tc.bpf.c | 56 ---
samples/bpf/test_cgrp2_tc.sh | 187 ----------
.../bpf/test_current_task_under_cgroup.bpf.c | 43 ---
.../bpf/test_current_task_under_cgroup_user.c | 115 ------
samples/bpf/test_overhead_kprobe.bpf.c | 41 ---
samples/bpf/test_overhead_raw_tp.bpf.c | 17 -
samples/bpf/test_overhead_tp.bpf.c | 23 --
samples/bpf/test_overhead_user.c | 225 ------------
samples/bpf/test_override_return.sh | 16 -
samples/bpf/test_probe_write_user.bpf.c | 52 ---
samples/bpf/test_probe_write_user_user.c | 108 ------
samples/bpf/tracex7.bpf.c | 15 -
samples/bpf/tracex7_user.c | 56 ---
.../selftests/bpf/prog_tests/sock_create.c | 333 ++++++++++++++++++
22 files changed, 333 insertions(+), 1939 deletions(-)
delete mode 100644 samples/bpf/sock_flags.bpf.c
delete mode 100644 samples/bpf/test_cgrp2_array_pin.c
delete mode 100644 samples/bpf/test_cgrp2_attach.c
delete mode 100644 samples/bpf/test_cgrp2_sock.c
delete mode 100755 samples/bpf/test_cgrp2_sock.sh
delete mode 100644 samples/bpf/test_cgrp2_sock2.c
delete mode 100755 samples/bpf/test_cgrp2_sock2.sh
delete mode 100644 samples/bpf/test_cgrp2_tc.bpf.c
delete mode 100755 samples/bpf/test_cgrp2_tc.sh
delete mode 100644 samples/bpf/test_current_task_under_cgroup.bpf.c
delete mode 100644 samples/bpf/test_current_task_under_cgroup_user.c
delete mode 100644 samples/bpf/test_overhead_kprobe.bpf.c
delete mode 100644 samples/bpf/test_overhead_raw_tp.bpf.c
delete mode 100644 samples/bpf/test_overhead_tp.bpf.c
delete mode 100644 samples/bpf/test_overhead_user.c
delete mode 100755 samples/bpf/test_override_return.sh
delete mode 100644 samples/bpf/test_probe_write_user.bpf.c
delete mode 100644 samples/bpf/test_probe_write_user_user.c
delete mode 100644 samples/bpf/tracex7.bpf.c
delete mode 100644 samples/bpf/tracex7_user.c
create mode 100644 tools/testing/selftests/bpf/prog_tests/sock_create.c
--
2.43.0
The BPF testing framework has evolved significantly over time. However,
some legacy tests in the samples/bpf directory have not kept up with
these changes. These outdated tests can cause confusion and increase
maintenance efforts.
This patchset focuses on migrating outdated cgroup and tracing-related
tests from samples/bpf to selftests/bpf, ensuring the BPF test suite
remains current and efficient. Tests that are already covered by
selftests/bpf are removed, while those not yet covered are migrated.
This includes cgroup sock create tests for setting socket attributes
and blocking socket creation, as well as the removal of redundant
cgroup and tracing tests that have been replaced by newer tests.
This patchset covers the following cgroup/tracing tests:
- test_overhead: tests the overhead of BPF programs with task_rename,
now covered by selftests and benchmark tests (rename-*). [1]
- test_override_return: tests the return override functionality, now
handled by kprobe_multi_override in selftests.
- test_probe_write_user: tests the probe_write_user functionality,
now replaced by the probe_user test in selftests.
- test_cgrp2_sock: tests cgroup BPF's ability to set sk_bound_dev_if,
mark, and priority during socket creation. Migrated to selftests as
'sock_create' since no existing tests fully cover this.
- test_cgrp2_sock2: tests blocking socket creation for specific types
(AF_INET{6}, SOCK_DGRAM, IPPROTO_ICMP{V6}). Migrated to selftests
in 'sock_create' test for coverage.
- test_current_task_under_cgroup: tests bpf_current_task_under_cgroup()
to check if a task belongs to a cgroup. Already covered by
task_under_cgroup at selftest and other cgroup ID tests.
- test_cgrp2_tc: tests bpf_skb_under_cgroup() to filter packets based
on cgroup. This behavior is now validated by cgroup_skb_sk_lookup,
which uses bpf_skb_cgroup_id, making this test redundant.
Daniel T. Lee (4):
selftests/bpf: migrate cgroup sock create test for setting
iface/mark/prio
selftests/bpf: migrate sock create tests for prohibitig sockets
samples/bpf: remove obsolete cgroup related tests
samples/bpf: remove obsolete tracing related tests
samples/bpf/Makefile | 24 --
samples/bpf/sock_flags.bpf.c | 47 ---
samples/bpf/test_cgrp2_array_pin.c | 106 ------
samples/bpf/test_cgrp2_attach.c | 177 ----------
samples/bpf/test_cgrp2_sock.c | 296 ----------------
samples/bpf/test_cgrp2_sock.sh | 137 -------
samples/bpf/test_cgrp2_sock2.c | 95 -----
samples/bpf/test_cgrp2_sock2.sh | 103 ------
samples/bpf/test_cgrp2_tc.bpf.c | 56 ---
samples/bpf/test_cgrp2_tc.sh | 187 ----------
.../bpf/test_current_task_under_cgroup.bpf.c | 43 ---
.../bpf/test_current_task_under_cgroup_user.c | 115 ------
samples/bpf/test_overhead_kprobe.bpf.c | 41 ---
samples/bpf/test_overhead_raw_tp.bpf.c | 17 -
samples/bpf/test_overhead_tp.bpf.c | 23 --
samples/bpf/test_overhead_user.c | 225 ------------
samples/bpf/test_override_return.sh | 16 -
samples/bpf/test_probe_write_user.bpf.c | 52 ---
samples/bpf/test_probe_write_user_user.c | 108 ------
samples/bpf/tracex7.bpf.c | 15 -
samples/bpf/tracex7_user.c | 56 ---
.../selftests/bpf/prog_tests/sock_create.c | 333 ++++++++++++++++++
22 files changed, 333 insertions(+), 1939 deletions(-)
delete mode 100644 samples/bpf/sock_flags.bpf.c
delete mode 100644 samples/bpf/test_cgrp2_array_pin.c
delete mode 100644 samples/bpf/test_cgrp2_attach.c
delete mode 100644 samples/bpf/test_cgrp2_sock.c
delete mode 100755 samples/bpf/test_cgrp2_sock.sh
delete mode 100644 samples/bpf/test_cgrp2_sock2.c
delete mode 100755 samples/bpf/test_cgrp2_sock2.sh
delete mode 100644 samples/bpf/test_cgrp2_tc.bpf.c
delete mode 100755 samples/bpf/test_cgrp2_tc.sh
delete mode 100644 samples/bpf/test_current_task_under_cgroup.bpf.c
delete mode 100644 samples/bpf/test_current_task_under_cgroup_user.c
delete mode 100644 samples/bpf/test_overhead_kprobe.bpf.c
delete mode 100644 samples/bpf/test_overhead_raw_tp.bpf.c
delete mode 100644 samples/bpf/test_overhead_tp.bpf.c
delete mode 100644 samples/bpf/test_overhead_user.c
delete mode 100755 samples/bpf/test_override_return.sh
delete mode 100644 samples/bpf/test_probe_write_user.bpf.c
delete mode 100644 samples/bpf/test_probe_write_user_user.c
delete mode 100644 samples/bpf/tracex7.bpf.c
delete mode 100644 samples/bpf/tracex7_user.c
create mode 100644 tools/testing/selftests/bpf/prog_tests/sock_create.c
--
2.43.0
Linking of urandom_read and liburandom_read.so prefers LLVM's 'ld.lld' but
falls back to using 'ld' if unsupported. However, this fallback discards
any existing makefile macro for LD and can break cross-compilation.
Fix by changing the fallback to use the target linker $(LD), passed via
'-fuse-ld=' using an absolute path rather than a linker "flavour".
Fixes: 08c79c9cd67f ("selftests/bpf: Don't force lld on non-x86 architectures")
Signed-off-by: Tony Ambardar <tony.ambardar(a)gmail.com>
---
tools/testing/selftests/bpf/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 5e366f2fc02a..f2a0f912e038 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -263,7 +263,7 @@ $(OUTPUT)/%:%.c
ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 riscv))
LLD := lld
else
-LLD := ld
+LLD := $(shell command -v $(LD))
endif
# Filter out -static for liburandom_read.so and its dependent targets so that static builds
--
2.34.1