All of lore.kernel.org
 help / color / mirror / Atom feed
From: Puranjay Mohan <puranjay@kernel.org>
To: bpf@vger.kernel.org
Cc: Puranjay Mohan <puranjay@kernel.org>,
	Puranjay Mohan <puranjay12@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
	Fei Chen <feichen@meta.com>, Taruna Agrawal <taragrawal@meta.com>,
	Nikhil Dixit Limaye <ndixit@meta.com>,
	"Nikita V. Shirokov" <tehnerd@tehnerd.com>,
	kernel-team@meta.com
Subject: [PATCH bpf-next 1/4] selftests/bpf: Fix cold_lru producing zero batch_hash in XDP LB benchmark
Date: Tue, 19 May 2026 09:36:29 -0700	[thread overview]
Message-ID: <20260519163632.2220753-2-puranjay@kernel.org> (raw)
In-Reply-To: <20260519163632.2220753-1-puranjay@kernel.org>

The cold_lru mechanism generates a per-batch hash to XOR into the source
address, ensuring each batch tests a fresh (uncached) flow:

    batch_hash = (batch_gen ^ cpu_id) * KNUTH_HASH_MULT;
    *saddr ^= batch_hash;

When batch_gen equals the CPU ID, the XOR is zero and batch_hash becomes
zero.  The source address is left unchanged, so every iteration hits the
warm LRU entry instead of testing cold lookups.

During validation, batch_gen is 2 (one increment from seeding, one from
the validation run itself).  If the BPF program happens to execute on
CPU 2, batch_hash is zero and all LRU lookups hit, producing:

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

This fails roughly 50% of the time depending on scheduler placement.

Fix by forcing the multiplier input to be non-zero with | 1.  Since
KNUTH_HASH_MULT (2654435761) is odd, the product of two odd numbers is
always odd, so batch_hash can never be zero.

Fixes: 4b4f2229104c ("selftests/bpf: Add XDP load-balancer BPF program")
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
---
 tools/testing/selftests/bpf/progs/xdp_lb_bench.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/progs/xdp_lb_bench.c b/tools/testing/selftests/bpf/progs/xdp_lb_bench.c
index b9fd848c035d..f40e36aa183e 100644
--- a/tools/testing/selftests/bpf/progs/xdp_lb_bench.c
+++ b/tools/testing/selftests/bpf/progs/xdp_lb_bench.c
@@ -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()) | 1) * KNUTH_HASH_MULT;
 		if ((void *)(saddr + 1) <= data_end)
 			*saddr ^= batch_hash;
 	}
-- 
2.53.0-Meta


  reply	other threads:[~2026-05-19 16:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19 16:36 [PATCH bpf-next 0/4] selftests/bpf: XDP LB benchmark fixes Puranjay Mohan
2026-05-19 16:36 ` Puranjay Mohan [this message]
2026-05-19 16:51   ` [PATCH bpf-next 1/4] selftests/bpf: Fix cold_lru producing zero batch_hash in XDP LB benchmark sashiko-bot
2026-05-19 17:14   ` bot+bpf-ci
2026-05-19 19:25     ` Puranjay Mohan
2026-05-19 16:36 ` [PATCH bpf-next 2/4] selftests/bpf: Fix expired UDP LRU entries " Puranjay Mohan
2026-05-19 16:36 ` [PATCH bpf-next 3/4] selftests/bpf: Cap batch-timing calibration at BPF may_goto loop limit Puranjay Mohan
2026-05-19 17:19   ` sashiko-bot
2026-05-19 19:10   ` Alexei Starovoitov
2026-05-19 19:23     ` Puranjay Mohan
2026-05-19 16:36 ` [PATCH bpf-next 4/4] selftests/bpf: Filter timing outliers with IQR in batch-timing library Puranjay Mohan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260519163632.2220753-2-puranjay@kernel.org \
    --to=puranjay@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=feichen@meta.com \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=ndixit@meta.com \
    --cc=puranjay12@gmail.com \
    --cc=taragrawal@meta.com \
    --cc=tehnerd@tehnerd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.