bpf: Fix the xdp_adjust_tail sample prog issue
authorYuan Chen <chenyuan@kylinos.cn>
Mon, 30 Sep 2024 02:41:15 +0000 (10:41 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 8 Oct 2024 03:28:40 +0000 (20:28 -0700)
During the xdp_adjust_tail test, probabilistic failure occurs and SKB package
is discarded by the kernel. After checking the issues by tracking SKB package,
it is identified that they were caused by checksum errors. Refer to checksum
of the arch/arm64/include/asm/checksum.h for fixing.

v2: Based on Alexei Starovoitov's suggestions, it is necessary to keep the code
 implementation consistent.

Fixes: c6ffd1ff7856 (bpf: add bpf_xdp_adjust_tail sample prog)
Signed-off-by: Yuan Chen <chenyuan@kylinos.cn>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240930024115.52841-1-chenyuan_fl@163.com
samples/bpf/xdp_adjust_tail_kern.c

index ffdd548627f0a42df9d64e2f7b72ea16957852a5..da67bcad1c63815a48c31e8602b5bb21b00240b9 100644 (file)
@@ -57,6 +57,7 @@ static __always_inline void swap_mac(void *data, struct ethhdr *orig_eth)
 
 static __always_inline __u16 csum_fold_helper(__u32 csum)
 {
+       csum = (csum & 0xffff) + (csum >> 16);
        return ~((csum & 0xffff) + (csum >> 16));
 }