selftests/rdma: Add an eBPF-based testcase using netkit for RXE
Subsystems (3)
v5 cover selftests/rdma: Add an eBPF-based testcase using netkit for RXE
Add a new self-test case to verify RXE (Soft-RoCE) traffic using netkit virtual interfaces and an eBPF tcx ingress program to dump and parse RDMA transport headers (BTH, etc.).
The test results:
# make -C tools/testing/selftests/ TARGETS=rdma run_tests make: Entering directory '/root/linux/tools/testing/selftests' clang -g -O2 -target bpf -D__TARGET_ARCH_x86 -I../../../../usr/include -I../../../../include/uapi -I../bpf -I/root/linux/tools/testing/selftests/rdma -c rxe_pkg_kernel_dump.c -o /root/linux/tools/testing/selftests/rdma/rxe_pkg_kernel_dump.o bpftool gen skeleton /root/linux/tools/testing/selftests/rdma/rxe_pkg_kernel_dump.o > /root/linux/tools/testing/selftests/rdma/rxe_pkg_kernel.skel.h gcc -D_GNU_SOURCE= -I/root/linux/tools/testing/selftests/../../../tools/testing/selftests -g -Wall -I../../../../usr/include -I../../../../include/uapi -I../bpf -I/root/linux/tools/testing/selftests/rdma rxe_pkg_user_dump.c -lbpf -lelf -lz -o /root/linux/tools/testing/selftests/rdma/rxe_netkit_dump # timeout set to 45 # selftests: rdma: rxe_rping_between_netns.sh # client DISCONNECT EVENT... ok 1 selftests: rdma: rxe_rping_between_netns.sh # timeout set to 45 # selftests: rdma: rxe_ipv6.sh ok 2 selftests: rdma: rxe_ipv6.sh # timeout set to 45 # selftests: rdma: rxe_socket_with_netns.sh ok 3 selftests: rdma: rxe_socket_with_netns.sh # timeout set to 45 # selftests: rdma: rxe_test_NETDEV_UNREGISTER.sh ok 4 selftests: rdma: rxe_test_NETDEV_UNREGISTER.sh # timeout set to 45 # selftests: rdma: rxe_sent_rcvd_bytes.sh # server DISCONNECT EVENT... # wait for RDMA_READ_ADV state 10 # client DISCONNECT EVENT... ok 5 selftests: rdma: rxe_sent_rcvd_bytes.sh # timeout set to 45 # selftests: rdma: rxe_netns_names.sh # 1..0 # SKIP rdma netns exclusive mode is not supported ok 6 selftests: rdma: rxe_netns_names.sh # SKIP # timeout set to 45 # selftests: rdma: rxe_pkg_netkit.sh # server DISCONNECT EVENT... # wait for RDMA_READ_ADV state 10 # ./rxe_pkg_netkit.sh: line 28: 9866 Killed "$CUR_WD/rxe_netkit_dump" ok 7 selftests: rdma: rxe_pkg_netkit.sh make: Leaving directory '/root/linux/tools/testing/selftests'
---
V4 - > V5: Fix err and length problems
V3 - > V4: Fix problems in user space app
V2 - > V3: Fix problems in user space application
V1 - > V2: Fix problems from sashiko
---
Zhu Yanjun (2):
selftests/rdma: Introduce eBPF kernel and user dump utilities for RXE selftests/rdma: Add netkit-based automated test script for RXE
tools/testing/selftests/rdma/Makefile | 23 +- tools/testing/selftests/rdma/config | 3 + .../selftests/rdma/rxe_pkg_kernel_dump.c | 62 + .../testing/selftests/rdma/rxe_pkg_netkit.sh | 63 + .../selftests/rdma/rxe_pkg_user_dump.c | 1275 +++++++++++++++++ 5 files changed, 1425 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/rdma/rxe_pkg_kernel_dump.c create mode 100755 tools/testing/selftests/rdma/rxe_pkg_netkit.sh create mode 100644 tools/testing/selftests/rdma/rxe_pkg_user_dump.c
Signature · 1 line
2.54.0
PATCH v5 1/2 selftests/rdma: Introduce eBPF kernel and user dump utilities for RXE
Add eBPF-based kernel and user-space packet dump utilities along with a netkit test script (rxe_pkg_netkit.sh) to tools/testing/selftests/rdma/. This enables capturing and parsing Soft-RoCE (RXE) traffic over netkit devices for testing purposes.
--- tools/testing/selftests/rdma/Makefile | 24 +- tools/testing/selftests/rdma/config | 3 + tools/testing/selftests/rdma/rxe_pkg_common.h | 17 + .../selftests/rdma/rxe_pkg_kernel_dump.c | 78 + .../selftests/rdma/rxe_pkg_user_dump.c | 1388 +++++++++++++++++ 5 files changed, 1509 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/rdma/rxe_pkg_common.h create mode 100644 tools/testing/selftests/rdma/rxe_pkg_kernel_dump.c create mode 100644 tools/testing/selftests/rdma/rxe_pkg_user_dump.c
tools/testing/selftests/rdma/Makefile +23 -1
@@ -4,6 +4,28 @@ TEST_PROGS := rxe_rping_between_netns.sh \ rxe_socket_with_netns.sh \ rxe_test_NETDEV_UNREGISTER.sh \ rxe_sent_rcvd_bytes.sh \ - rxe_netns_names.sh + rxe_netns_names.sh \ + rxe_pkg_netkit.sh +TEST_GEN_PROGS_EXTENDED := rxe_netkit_dump include ../lib.mk + +CLANG ?= clang +LLC ?= llc +BPFTOOL ?= bpftool +ARCH ?= $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/' | sed 's/ppc64le/powerpc/') + +INCLUDES := -I../../../../usr/include -I../../../../include/uapi -I../bpf -I$(OUTPUT) +CFLAGS += -g -Wall $(INCLUDES) +LDFLAGS += -lbpf -lelf -lz + +$(OUTPUT)/rxe_netkit_dump: rxe_pkg_user_dump.c $(OUTPUT)/rxe_pkg_kernel.skel.h + $(CC) $(CFLAGS) $< $(LDFLAGS) -o $@ + +$(OUTPUT)/rxe_pkg_kernel_dump.o: rxe_pkg_kernel_dump.c rxe_pkg_common.h + $(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) $(INCLUDES) -c $< -o $@ + +$(OUTPUT)/rxe_pkg_kernel.skel.h: $(OUTPUT)/rxe_pkg_kernel_dump.o + $(BPFTOOL) gen skeleton $< > $@ + +EXTRA_CLEAN := $(OUTPUT)/rxe_pkg_kernel_dump.o $(OUTPUT)/rxe_pkg_kernel.skel.h $(OUTPUT)/rxe_pkg_kernel.skel.h.tmp
tools/testing/selftests/rdma/config +3 -0
@@ -3,3 +3,6 @@ CONFIG_VETH CONFIG_DUMMY CONFIG_NET_NS CONFIG_RDMA_RXE +CONFIG_BPF=y +CONFIG_BPF_SYSCALL=y +CONFIG_NETKIT=y
tools/testing/selftests/rdma/rxe_pkg_common.h new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +/* +* Copyright (c) 2026 Zhu Yanjun <[email protected]> +*/ + +// rxe_pkg_common.h +#ifndef RXE_PKG_COMMON_H +#define RXE_PKG_COMMON_H + +#define MAX_PKT_LEN 512 + +struct pkg_event { +__u32 len; +__u8 data[MAX_PKT_LEN ]; +}; + +#endif
tools/testing/selftests/rdma/rxe_pkg_kernel_dump.c new file +78 -0
78 lines not on this page · raw message
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +1388 -0
1,388 lines not on this page · raw message
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v5 1/2] selftests/rdma: Introduce eBPF kernel and user dump utilities for RXE
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [Medium] selftests/rdma: broken BPF/UAPI include paths, arpa/inet.h, and skel rule - [Medium]…
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [Medium] selftests/rdma: broken BPF/UAPI include paths, arpa/inet.h, and skel rule
- [Medium] selftests/rdma: incompatible callback signature in handle_event() on 32-bit
- [Medium] selftests/rdma: print_bpf_output() includes ICRC and pad bytes in payload
- [Medium] selftests/rdma: fixed IPv4 header size and header loop order in print_bpf_output()
- [Medium] selftests/rdma: missing -mcpu=v3 in Makefile breaks BPF verification
- [Low] selftests/rdma: u64 printf format mismatch and __be32 return in immdt_imm()
- [Low] selftests/rdma: duplicated RXE tables/wrappers and hardcoded nk0 in dump tool --
commit f654ac52160578ed80b6042ffb2064d0f8f8a7d7
Author: Zhu Yanjun <[email protected]>
selftests/rdma: Introduce eBPF kernel and user dump utilities for RXE
This commit adds eBPF-based kernel and user-space packet dump utilities for Soft-RoCE (RXE) traffic over netkit devices in the RDMA selftests.
Quoted 24 lines
tools/testing/selftests/rdma/Makefile +13
-1@@ -4,6 +4,28 @@ TEST_PROGS := rxe_rping_between_netns.sh \ rxe_socket_with_netns.sh \ rxe_test_NETDEV_UNREGISTER.sh \ rxe_sent_rcvd_bytes.sh \ - rxe_netns_names.sh + rxe_netns_names.sh \ + rxe_pkg_netkit.sh +TEST_GEN_PROGS_EXTENDED := rxe_netkit_dump include ../lib.mk + +CLANG ?= clang +LLC ?= llc +BPFTOOL ?= bpftool +ARCH ?= $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/' | sed 's/ppc64le/powerpc/') + +INCLUDES := -I../../../../usr/include -I../../../../include/uapi -I../bpf -I$(OUTPUT) +CFLAGS += -g -Wall $(INCLUDES) +LDFLAGS += -lbpf -lelf -lz +
tools/testing/selftests/rdma/Makefile TEST_PROGS := rxe_rping_between_netns.sh \ · line 31
Quoted 10 lines
tools/testing/selftests/rdma/Makefile +10
-0+$(OUTPUT)/rxe_netkit_dump: rxe_pkg_user_dump.c $(OUTPUT)/rxe_pkg_kernel.skel.h + $(CC) $(CFLAGS) $< $(LDFLAGS) -o $@ + +$(OUTPUT)/rxe_pkg_kernel_dump.o: rxe_pkg_kernel_dump.c rxe_pkg_common.h + $(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) $(INCLUDES) -c $< -o $@ + +$(OUTPUT)/rxe_pkg_kernel.skel.h: $(OUTPUT)/rxe_pkg_kernel_dump.o + $(BPFTOOL) gen skeleton $< > $@ + +EXTRA_CLEAN := $(OUTPUT)/rxe_pkg_kernel_dump.o $(OUTPUT)/rxe_pkg_kernel.skel.h $(OUTPUT)/rxe_pkg_kernel.skel.h.tmp
[Severity: Medium]
Could these Makefile rules and include flags cause build failures across out-of-tree, multiarch, and -Werror environments, or leave a corrupted skeleton header behind if bpftool fails?
In tools/testing/selftests/rdma/Makefile, INCLUDES hardcodes -I../../../../usr/include and -I../../../../include/uapi instead of using $(KHDR_INCLUDES) provided by ../lib.mk. Hardcoding ../../../../usr/include breaks out-of-tree builds (O= or KBUILD_OUTPUT=), and passing the raw unexported -I../../../../include/uapi path to userspace compilation triggers the #warning in include/uapi/linux/types.h when __EXPORTED_HEADERS__ is not defined (failing under USERCFLAGS=-Werror) and fails to resolve generated <asm/types.h> and <asm/byteorder.h> headers when in-tree headers have not been exported.
In addition, the recipe for $(OUTPUT)/rxe_pkg_kernel.skel.h redirects stdout directly to $@:
$(BPFTOOL) gen skeleton $< > $@
If bpftool is missing or returns an error, the shell still creates an empty $(OUTPUT)/rxe_pkg_kernel.skel.h file. Because that empty file satisfies make's timestamp check on subsequent runs, compiling rxe_pkg_user_dump.c then fails with undeclared skeleton symbols (even though EXTRA_CLEAN lists $(OUTPUT)/rxe_pkg_kernel.skel.h.tmp, the rule does not write to [email protected] and mv it into place).
Quoted 7 lines
tools/testing/selftests/rdma/rxe_pkg_kernel_dump.c new file +1
-0@@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
tools/testing/selftests/rdma/rxe_pkg_kernel_dump.c line 11
Quoted 10 lines
tools/testing/selftests/rdma/rxe_pkg_kernel_dump.c new file +10
-0+/* +* Copyright (c) 2026 Zhu Yanjun <[email protected]> +*/ + +#include <linux/bpf.h> +#include <bpf/bpf_helpers.h> +#include <bpf/bpf_endian.h> +#include <linux/if_ether.h> +#include <linux/ip.h> +#include <arpa/inet.h>
[Severity: Medium]
Is <arpa/inet.h> needed in tools/testing/selftests/rdma/rxe_pkg_kernel_dump.c?
Because handle_netkit_ingress() uses bpf_htons() from <bpf/bpf_endian.h>, <arpa/inet.h> is unused. Including a userspace libc header in a translation unit compiled with clang -target bpf drops host architecture macros (such as __x86_64__) and multiarch include paths (/usr/include/<arch>-linux-gnu), which causes glibc headers (<features.h>, <sys/cdefs.h>, <gnu/stubs.h>) to fail to locate <sys/cdefs.h> on multiarch distributions or fall back to <gnu/stubs-32.h> and fail on 64-bit hosts without 32-bit glibc development headers installed.
[ ... ]
Quoted 33 lines
tools/testing/selftests/rdma/rxe_pkg_kernel_dump.c new file +33
-0+SEC("netkit/primary") +int handle_netkit_ingress (struct __sk_buff *skb) +{ +/* Get the header pointer of skb */ +void *data_end = (void *)(long )skb->data_end; +void *data = (void *)(long )skb->data; + +struct ethhdr *eth = data; + +/* Verify the data */ +if (data +sizeof (*eth) > data_end) +return BPF_OK ; + +/* Check if it is IP skb */ +if (eth->h_proto ==bpf_htons (ETH_P_IP )) { +struct iphdr *iph = data +sizeof (*eth); + +if ((void *)iph +sizeof (*iph) <= data_end) { +bpf_printk ("Got IP packet from netkit ingress, %d\n" , skb->len); + +__u32 len = skb->len; + +/* It is a rping test, the size of packets should be +* less than MAX_PKT_LEN +*/ +if (len ==0 || len >MAX_PKT_LEN ) { +bpf_printk ("len is not in 0..MAX_PKT_LEN\n" ); +return BPF_OK ; + } + +struct pkg_event *e; + +/* The len is fixed to MAX_PKT_LEN */
tools/testing/selftests/rdma/rxe_pkg_kernel_dump.c line 62
Quoted 10 lines
tools/testing/selftests/rdma/rxe_pkg_kernel_dump.c new file +10
-0+ e =bpf_ringbuf_reserve (&rb,sizeof (*e),0 ); + +if (!e) { +bpf_printk ("bpf_ringbuf_reserve fails\n" ); +return BPF_OK ; + } + + e->len = len; + +if (bpf_skb_load_bytes (skb,0 , e->data, len) <0 ) {
[Severity: Medium]
Will handle_netkit_ingress() be rejected by the BPF verifier when compiled without -mcpu=v3?
In tools/testing/selftests/rdma/Makefile, $(OUTPUT)/rxe_pkg_kernel_dump.o is built with:
$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) $(INCLUDES) -c $< -o $@
Without -mcpu=v3, clang defaults to the BPF v1 ISA, which lacks 32-bit ALU and JMP32 instructions. At -O2, clang lowers the 32-bit check (if (len == 0 || len > MAX_PKT_LEN)) into a 64-bit addition followed by a 64-bit shift pair to zero-extend the lower 32 bits before the conditional jump:
r1 = r6
r1 += -1
r1 <<= 32
r1 >>= 32
if r1 > 511 goto ...
In the kernel BPF verifier, adjust_reg_min_max_vals() preserves dst_reg->id with BPF_ADD_CONST64 across BPF_ADD and BPF_SUB, but clears dst_reg->id via clear_scalar_id() on BPF_LSH (r1 <<= 32). Because r1->id is 0 at the conditional branch, check_cond_jmp_op() cannot propagate the [1, 512] bounds back to r6 (len), leaving len with its initial umin=0 and umax=U32_MAX bounds. When bpf_skb_load_bytes(skb, 0, e->data, len) is verified, check_mem_size_reg() sees reg_umin(size_reg) == 0 with zero_size_allowed == false (and reg_umax exceeding sizeof(e->data)) and rejects loading the program with -EACCES.
Should the clang invocation in Makefile pass -mcpu=v3 (matching the other BPF selftests)?
Quoted 5 lines
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +0
-0
[ ... ]
Quoted 9 lines
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +9
-0+static inline void print_reth (const struct rxe_reth *reth) +{ +printf ("struct rxe_reth {\n" ); +printf ("\t__be64 va; 0x%llx\n" ,reth_va (reth)); +printf ("\t__be32 rkey; 0x%x\n" ,reth_rkey (reth)); +printf ("\t__be32 len; 0x%x\n" ,reth_len (reth)); + +printf ("};\n" ); +}
[ ... ]
Quoted 21 lines
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +21
-0+static inline void print_atmeth (struct rxe_atmeth *atmeth) +{ +printf ("struct rxe_atmeth {\n" ); +printf ("\t__be64 va; 0x%llx\n" ,atmeth_va (atmeth)); +printf ("\t__be32 rkey; 0x%x\n" ,atmeth_rkey (atmeth)); +printf ("\t__be64 swap_add; 0x%llx\n" ,atmeth_swap_add (atmeth)); +printf ("\t__be64 comp; 0x%llx\n" ,atmeth_comp (atmeth)); +printf ("} __packed;\n" ); +} + +static inline u64 atmack_orig (struct rxe_atmack *atmack) +{ +return be64toh (atmack->orig); +} + +static inline void print_atmack (struct rxe_atmack *atmack) +{ +printf ("struct rxe_atmack {\n" ); +printf ("\t__be64 orig; 0x%llx\n" ,atmack_orig (atmack)); +printf ("};\n" ); +}
[ ... ]
tools/testing/selftests/rdma/rxe_pkg_user_dump.c line 1117
Quoted 4 lines
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +4
-0+static inline __be32 immdt_imm (struct rxe_immdt *immdt) +{ +return ntohl (immdt->imm); +}
[Severity: Low]
Will printing u64 (__u64) values with %llx in print_reth(), print_atmeth(), and print_atmack() produce -Wformat warnings on 64-bit architectures such as ppc64le where __u64 in userspace is unsigned long rather than unsigned long long? Also, should immdt_imm() return u32 instead of __be32 since it converts immdt->imm to host byte order with ntohl()?
[ ... ]
Quoted 39 lines
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +39
-0+static void print_bpf_output (const void *data,__u32 size) +{ +/* Validate size covers IP and UDP headers */ +if (size <sizeof (struct iphdr ) +sizeof (struct udphdr )) +return ; + +const struct iphdr *iph = (const struct iphdr *)data; + +if (iph->protocol !=IPPROTO_UDP ) +return ; + +const struct udphdr *udp_hdr = (const struct udphdr *)(data +sizeof (struct iphdr )); + +if (ntohs (udp_hdr->dest) !=ROCEV2_PORT ) +return ; + +print_ipaddr (iph); +printf ("udp hdr:\n" ); +print_udphdr (udp_hdr); + +size_t base_hdr_size =sizeof (struct iphdr ) +sizeof (struct udphdr ) + +sizeof (struct rxe_bth ); + +if (size < base_hdr_size) +return ; + +const struct rxe_bth *bth = (struct rxe_bth *)(data +sizeof (struct iphdr ) + +sizeof (struct udphdr )); + +/* Validate opcode bounds and ensure name exists to prevent NULL dereference */ +if (bth->opcode >=256 || !rxe_opcode[bth->opcode].name) { +printf ("Unknown or unpopulated opcode: 0x%x\n" , bth->opcode); +return ; + } + +printf ("%s\n" , rxe_opcode[bth->opcode].name); +print_bth (bth); + +for (int i =RXE_BTH +1 ; i <NUM_HDR_TYPES ; i++) {
tools/testing/selftests/rdma/rxe_pkg_user_dump.c line 1214
Quoted 10 lines
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +10
-0+int offset = rxe_opcode[bth->opcode].offset[i]; + +if (offset && (size >=sizeof (struct iphdr ) +sizeof (struct udphdr ) + offset)) { +const unsigned char *cur_p = (const unsigned char *)bth + offset; +size_t remaining_size = size - ((const void *)cur_p - data); + +if (i <ARRAY_SIZE (rxe_hdr_sizes) && rxe_hdr_sizes[i] >0 ) { +if (remaining_size < rxe_hdr_sizes[i]) +break ; + }
[Severity: Medium]
Does print_bpf_output() misparse packets when IPv4 options are present or when headers appear in a different order than enum rxe_hdr_type?
First, print_bpf_output() computes the UDP and BTH offsets using sizeof(struct iphdr) instead of validating iph->ihl >= 5 and advancing by iph->ihl * 4.
Second, the loop iterates i from RXE_BTH + 1 to NUM_HDR_TYPES in enum rxe_hdr_type order (where RXE_RETH = 3 precedes RXE_RDETH = 8 and RXE_DETH = 9) rather than packet offset order. For RD opcodes such as IB_OPCODE_RD_RDMA_WRITE_FIRST, RDETH and DETH are placed before RETH in the packet, so breaking out of the loop when remaining_size < rxe_hdr_sizes[i] skips headers with larger enum values that actually lie earlier in the packet.
Third, bth->opcode is a __u8, so the bth->opcode >= 256 check is always false.
[ ... ]
Quoted 9 lines
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +9
-0+case RXE_PAYLOAD : +printf ("RXE_PAYLOAD\n" ); +int expected_len = (int )ntohs (udp_hdr->len) + - (int )sizeof (struct udphdr ) + - rxe_opcode[bth->opcode].length; +int len = (expected_len < (int )remaining_size) ? + expected_len : (int )remaining_size; + +if (len <0 )
tools/testing/selftests/rdma/rxe_pkg_user_dump.c line 1291
Quoted 10 lines
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +10
-0+ len =0 ; + +for (int j =0 ; j < len; j++) { +if (isprint (cur_p[j])) +printf ("%c" , cur_p[j]); +else +printf ("%02x" , cur_p[j]); + } +printf ("\n" ); +break ;
[Severity: Medium]
Does the RXE_PAYLOAD calculation include the trailing BTH pad bytes and the 4-byte RoCEv2 ICRC as part of the payload?
Every RoCEv2 packet ends with 0..3 BTH pad bytes ((bth->flags & 0x30) >> 4) and a 4-byte Invariant CRC (RXE_ICRC_SIZE, see payload_size() in drivers/infiniband/sw/rxe/rxe_hdr.h). In addition, rxe_opcode[] sets a non-zero .offset[RXE_PAYLOAD] even for opcodes that carry no payload, such as IB_OPCODE_RC_ACKNOWLEDGE and IB_OPCODE_RC_RDMA_READ_REQUEST. Because expected_len and remaining_size do not subtract RXE_ICRC_SIZE (4) and the BTH padding length, print_bpf_output() prints 4 bytes of ICRC as RXE_PAYLOAD on payload-less packets and appends padding and ICRC bytes to actual payloads.
Quoted 24 lines
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +24
-0+default : +break ; + } + } + } + +printf ("\n" ); +} + +static int handle_event (void *ctx,void *data,unsigned long data_sz) +{ +const struct pkg_event *e = data; + +if (data_sz <sizeof (*e)) +return -1 ; + +if (e->len <sizeof (struct ethhdr ) || e->len >sizeof (e->data)) +return -1 ; + +print_bpf_output (e->data +sizeof (struct ethhdr ), + e->len -sizeof (struct ethhdr )); + +return 0 ; +}
[ ... ]
Quoted 7 lines
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +7
-0+int ifindex =if_nametoindex ("nk0" ); + +if (ifindex ==0 ) { +perror ("if_nametoindex nk0 failed" ); + goto cleanup; + } +
tools/testing/selftests/rdma/rxe_pkg_user_dump.c line 1363
Quoted 10 lines
tools/testing/selftests/rdma/rxe_pkg_user_dump.c new file +10
-0+ skel->links.handle_netkit_ingress =bpf_program__attach_netkit ( + skel->progs.handle_netkit_ingress, ifindex,NULL ); + +if (!skel->links.handle_netkit_ingress) { +fprintf (stderr,"Failed to attach to netkit nk0\n" ); + goto cleanup; + } + + ringbuf =ring_buffer__new (bpf_map__fd (skel->maps.rb), + handle_event,NULL ,NULL );
[Severity: Medium]
Will passing handle_event() to ring_buffer__new() fail to build on 32-bit architectures?
In tools/lib/bpf/libbpf.h, ring_buffer_sample_fn is defined as:
typedef int (*ring_buffer_sample_fn)(void *ctx, void *data, size_t size);
However, handle_event() declares its third parameter as unsigned long data_sz. On 32-bit architectures where size_t is unsigned int, passing handle_event to ring_buffer__new() fails compilation with -Wincompatible-pointer-types.
[Severity: Low]
This isn't a bug, but rxe_pkg_user_dump.c duplicates over 1,000 lines of RXE header definitions, IB_OPCODE_* enums, rxe_opcode[] table entries, and trivial wrapper functions (__bth_opcode()/bth_opcode(), etc.) from drivers/infiniband/sw/rxe/, and rxe_opcode[] has already drifted from the kernel table (omitting newer opcodes such as IB_OPCODE_RC_FLUSH and IB_OPCODE_RC_ATOMIC_WRITE). In addition, main() hardcodes the interface name "nk0" in if_nametoindex("nk0"). Could the interface name be passed via command-line arguments (defaulting to "nk0"), and can the duplicated definitions and wrappers in rxe_pkg_user_dump.c be trimmed or shared?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v5 2/2 selftests/rdma: Add netkit-based automated test script for RXE
In reply to Zhu YanjunAdd a shell script to automate functional and tracing tests for the Soft-RoCE (RXE) driver over netkit network interfaces. The script creates an isolated network namespace, sets up a netkit link pair (nk0/nk1), attaches RXE links, and runs an rping client/server verification test along with kernel tracing output collection.
--- .../testing/selftests/rdma/rxe_pkg_netkit.sh | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 tools/testing/selftests/rdma/rxe_pkg_netkit.sh
tools/testing/selftests/rdma/rxe_pkg_netkit.sh new file +91 -0
@@ -0,0 +1,91 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +# Copyright (c) 2026 Zhu Yanjun <[email protected]> +if [ "$(id -u)" -ne 0 ]; then + echo "SKIP: This test must be run as root" + exit 4 +fi + +for cmd in ip rdma rping; do + if ! command -v "$cmd" >/dev/null 2>&1; then + echo "SKIP: Required tool '$cmd' not found" + exit 4 + fi +done + +if ! modprobe -n netkit >/dev/null 2>&1 || ! modprobe -n rdma_rxe >/dev/null 2>&1; then + echo "SKIP: Required kernel modules (netkit or rdma_rxe) are not available" + exit 4 +fi + +exec > /dev/null + +set -e + +CUR_WD="$(dirname "$0")" +[ "$CUR_WD" = "." ] && CUR_WD="$(pwd)" + +cleanup() { + local exit_code=$? + + set +e + [ -n "$RPING_PID" ] && kill -9 "$RPING_PID" 2>/dev/null + unset RPING_PID + + [ -n "$DUMP_PID" ] && kill -9 "$DUMP_PID" 2>/dev/null + unset DUMP_PID + + ip netns exec ns0 rdma link del rxe0 2>/dev/null + + rdma link del rxe1 2>/dev/null + ip link del nk0 2>/dev/null + ip netns delete ns0 2>/dev/null + + exit "$exit_code" +} + +trap cleanup EXIT INT TERM + +# Clear tracing buffer +echo > /sys/kernel/debug/tracing/trace + +# Create network namespace and netkit peer links +ip netns add ns0 +ip link add nk0 type netkit mode l2 peer name nk1 +ip link set nk0 up +ip link set nk1 up + +# Configure namespace interface +ip link set nk1 netns ns0 +ip netns exec ns0 ip addr add 10.0.0.1/24 dev nk1 +ip netns exec ns0 ip link set nk1 up + +# Configure host interface +ip addr add 10.0.0.2/24 dev nk0 + +# Start dump utility in background +"$CUR_WD/rxe_netkit_dump" & +DUMP_PID=$! + +# Add RXE links over netkit devices +ip netns exec ns0 rdma link add rxe0 type rxe netdev nk1 +rdma link add rxe1 type rxe netdev nk0 + +# Start rping server in namespace +ip netns exec ns0 rping -s -a 10.0.0.1 -C 3 & +RPING_PID=$! + +# Add wait time +sleep 1 + +# Run rping client on host +rping -c -a 10.0.0.1 -C 3 + +# Tear down RDMA links and netkit devices +ip netns exec ns0 rdma link del rxe0 +rdma link del rxe1 +ip link del nk0 +ip netns delete ns0 + +# Display kernel trace output +cat /sys/kernel/debug/tracing/trace
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v5 2/2] selftests/rdma: Add netkit-based automated test script for RXE
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [Medium] selftests/rdma: stdout redirected to /dev/null and rxe_netkit_dump unverified - [Medium]…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Medium] selftests/rdma: stdout redirected to /dev/null and rxe_netkit_dump unverified
- [Medium] selftests/rdma: unchecked /sys/kernel/debug/tracing/trace access under set -e
- [Medium] selftests/rdma: double cleanup() and masked signal exit in rxe_pkg_netkit.sh
- [Medium] selftests/rdma: rxe_pkg_netkit.sh tears down links before stopping processes --
commit f5c35de37b8753656d0f89ba368ca5c8470cec1f
Author: Zhu Yanjun <[email protected]>
selftests/rdma: Add netkit-based automated test script for RXE
This commit adds the rxe_pkg_netkit.sh selftest script to automate functional and tracing tests for Soft-RoCE (RXE) over netkit interfaces inside an isolated network namespace.
Quoted 6 lines
tools/testing/selftests/rdma/rxe_pkg_netkit.sh new file +0
-0@@ -0,0 +1,91 @@
[ ... ]
Quoted 17 lines
tools/testing/selftests/rdma/rxe_pkg_netkit.sh new file +17
-0+exec > /dev/null + +set -e + +CUR_WD="$(dirname "$0")" +[ "$CUR_WD" = "." ] && CUR_WD="$(pwd)" + +cleanup() { + local exit_code=$? + + set +e + [ -n "$RPING_PID" ] && kill -9 "$RPING_PID" 2>/dev/null + unset RPING_PID + + [ -n "$DUMP_PID" ] && kill -9 "$DUMP_PID" 2>/dev/null + unset DUMP_PID +
tools/testing/selftests/rdma/rxe_pkg_netkit.sh line 47
Quoted 10 lines
tools/testing/selftests/rdma/rxe_pkg_netkit.sh new file +10
-0+ ip netns exec ns0 rdma link del rxe0 2>/dev/null + + rdma link del rxe1 2>/dev/null + ip link del nk0 2>/dev/null + ip netns delete ns0 2>/dev/null + + exit "$exit_code" +} + +trap cleanup EXIT INT TERM
[Severity: Medium]
As reported by Sashiko on v4 [1], when tools/testing/selftests/rdma/rxe_pkg_netkit.sh receives SIGINT or SIGTERM (for example, on a kselftest timeout or user interruption while waiting in sleep 1), cleanup() captures the status of the previous completed command in exit_code=$?, which is 0 if that command succeeded.
Because cleanup() then calls exit "$exit_code" without resetting the EXIT trap via trap - EXIT, POSIX sh invokes the EXIT trap handler upon exit, running cleanup() a second time and allowing an interrupted or timed-out test to exit with status 0. In addition, the resource deletion commands at the end of the script duplicate the teardown already performed by cleanup() on normal EXIT.
Could cleanup() clear the EXIT trap before exiting and ensure signal-induced termination exits with a non-zero status?
tools/testing/selftests/rdma/rxe_pkg_netkit.sh line 50
Quoted 3 lines
tools/testing/selftests/rdma/rxe_pkg_netkit.sh new file +3
-0+ +# Clear tracing buffer +echo > /sys/kernel/debug/tracing/trace
[Severity: Medium]
As reported by Sashiko on v4 [2], tools/testing/selftests/rdma/rxe_pkg_netkit.sh unconditionally writes to and reads from /sys/kernel/debug/tracing/trace while set -e is active, and tools/testing/selftests/rdma/config does not request CONFIG_TRACING or CONFIG_FTRACE.
If CONFIG_TRACING is disabled, debugfs is not mounted, or tracefs is mounted standalone at /sys/kernel/tracing, this redirection fails under set -e and aborts the test with exit status 1 instead of skipping with exit status 4 as expected by kselftest when a kernel feature or mount is unavailable. Writing to /sys/kernel/debug/tracing/trace also clears the host-wide global trace buffer.
Should the script check that the trace file is available (or skip with exit code 4 if unavailable) before accessing it?
Quoted 28 lines
tools/testing/selftests/rdma/rxe_pkg_netkit.sh new file +28
-0+ +# Create network namespace and netkit peer links +ip netns add ns0 +ip link add nk0 type netkit mode l2 peer name nk1 +ip link set nk0 up +ip link set nk1 up + +# Configure namespace interface +ip link set nk1 netns ns0 +ip netns exec ns0 ip addr add 10.0.0.1/24 dev nk1 +ip netns exec ns0 ip link set nk1 up + +# Configure host interface +ip addr add 10.0.0.2/24 dev nk0 + +# Start dump utility in background +"$CUR_WD/rxe_netkit_dump" & +DUMP_PID=$! + +# Add RXE links over netkit devices +ip netns exec ns0 rdma link add rxe0 type rxe netdev nk1 +rdma link add rxe1 type rxe netdev nk0 + +# Start rping server in namespace +ip netns exec ns0 rping -s -a 10.0.0.1 -C 3 & +RPING_PID=$! + +# Add wait time
tools/testing/selftests/rdma/rxe_pkg_netkit.sh line 88
Quoted 10 lines
tools/testing/selftests/rdma/rxe_pkg_netkit.sh new file +10
-0+sleep 1 + +# Run rping client on host +rping -c -a 10.0.0.1 -C 3 + +# Tear down RDMA links and netkit devices +ip netns exec ns0 rdma link del rxe0 +rdma link del rxe1 +ip link del nk0 +ip netns delete ns0
[Severity: Medium]
As reported by Sashiko on v4 [3], right after rping -c returns, tools/testing/selftests/rdma/rxe_pkg_netkit.sh deletes rxe0, rxe1, nk0, and ns0 under set -e while the background rping -s server (RPING_PID) and rxe_netkit_dump (DUMP_PID) processes may still be running and holding RDMA, BPF netkit link, and network namespace resources.
When cleanup() subsequently runs, it sends SIGKILL (kill -9) to RPING_PID and DUMP_PID without waiting for them to exit. Sending SIGKILL to DUMP_PID bypasses sig_handler() in main() of tools/testing/selftests/rdma/rxe_pkg_user_dump.c, preventing rxe_netkit_dump from cleanly draining ring buffer events and calling ring_buffer__free() and rxe_pkg_kernel_dump__destroy().
Could the script wait for RPING_PID to finish and stop DUMP_PID with SIGINT or SIGTERM (followed by wait) before deleting the RDMA links, netkit devices, and namespace?
tools/testing/selftests/rdma/rxe_pkg_netkit.sh line 91
Quoted 3 lines
tools/testing/selftests/rdma/rxe_pkg_netkit.sh new file +3
-0+ +# Display kernel trace output +cat /sys/kernel/debug/tracing/trace
[Severity: Medium]
As reported by Sashiko on v4 [4], tools/testing/selftests/rdma/rxe_pkg_netkit.sh redirects stdout to /dev/null via exec > /dev/null at the top of the script. Because all child processes inherit this file descriptor, all packet dump output from rxe_netkit_dump and the output of cat /sys/kernel/debug/tracing/trace here are discarded to /dev/null without verifying that any packets or trace entries were captured.
In addition, "$CUR_WD/rxe_netkit_dump" & is launched in the background without checking that the binary exists and without waiting for rxe_pkg_kernel_dump__open_and_load() and bpf_program__attach_netkit() to complete before starting RDMA traffic, and its exit status is never checked via wait.
If rxe_netkit_dump is missing, fails BPF loading or netkit attachment, or captures zero packets, won't the test still report success?
[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
[3] https://lore.kernel.org/r/[email protected]
[4] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2