selftests/bpf: Fix cold_lru producing zero batch_hash in XDP LB benchmark

batch_hash = (batch_gen ^ cpu_id) * KNUTH_HASH_MULT;

When batch_gen == cpu_id the XOR produces zero, batch_hash is zero,
and *saddr ^= 0 is a no-op.  Every iteration hits the warm LRU entry.

During validation batch_gen is 2, so running on CPU 2 triggers:

    [udp-v4-lru-miss] COUNTER FAIL: LRU misses=0, expected 1

Replace XOR with addition so the multiplier input is always >= 1.
This also preserves the per-CPU salt for multi-producer runs.

Fixes: 4b4f222910 ("selftests/bpf: Add XDP load-balancer BPF program")
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Link: https://lore.kernel.org/r/20260520133338.3392667-2-puranjay@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Puranjay Mohan 2026-05-20 06:33:30 -07:00 committed by Alexei Starovoitov
parent 523d2f42b4
commit fa747e9f84

View File

@ -618,7 +618,7 @@ int xdp_lb_bench(struct xdp_md *xdp)
__u32 *saddr = data + saddr_off;
batch_gen++;
batch_hash = (batch_gen ^ bpf_get_smp_processor_id()) * KNUTH_HASH_MULT;
batch_hash = (batch_gen + bpf_get_smp_processor_id()) * KNUTH_HASH_MULT;
if ((void *)(saddr + 1) <= data_end)
*saddr ^= batch_hash;
}