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 2/4] selftests/bpf: Fix expired UDP LRU entries in XDP LB benchmark
Date: Tue, 19 May 2026 09:36:30 -0700	[thread overview]
Message-ID: <20260519163632.2220753-3-puranjay@kernel.org> (raw)
In-Reply-To: <20260519163632.2220753-1-puranjay@kernel.org>

populate_lru() inserts LRU entries with atime zero-initialized:

    struct real_pos_lru lru = { .pos = real_idx };

The BPF program's connection_table_lookup() enforces a 30-second timeout
for UDP flows:

    if (cur_time - dst_lru->atime > LRU_UDP_TIMEOUT)
        return NULL;

Since cur_time (system uptime) is always much larger than 30 seconds,
every pre-populated UDP entry is treated as expired on first access.
The lookup returns NULL, counting as an LRU miss.

This is masked by calibration: the BPF program runs during calibration
on one CPU, misses the expired entry, and re-inserts it with a fresh
atime.  But if the scheduler moves the thread to a different CPU for
validation, that CPU still has the atime=0 entry from populate_lru(),
causing intermittent validation failures for UDP LRU-hit scenarios:

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

Fix by initializing atime with the current CLOCK_MONOTONIC time for UDP
flows, matching the clock source used by bpf_ktime_get_ns() in the BPF
program.

Fixes: a4b5ba8187cb ("selftests/bpf: Add XDP load-balancer benchmark driver")
Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
---
 tools/testing/selftests/bpf/benchs/bench_xdp_lb.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tools/testing/selftests/bpf/benchs/bench_xdp_lb.c b/tools/testing/selftests/bpf/benchs/bench_xdp_lb.c
index 0b6709a2b03c..8e25bccbde92 100644
--- a/tools/testing/selftests/bpf/benchs/bench_xdp_lb.c
+++ b/tools/testing/selftests/bpf/benchs/bench_xdp_lb.c
@@ -563,12 +563,23 @@ static void create_per_cpu_lru_maps(struct xdp_lb_bench *skel)
 	nr_inner_maps = nr_cpus;
 }
 
+static __u64 ktime_get_ns(void)
+{
+	struct timespec ts;
+
+	clock_gettime(CLOCK_MONOTONIC, &ts);
+	return (__u64)ts.tv_sec * 1000000000ULL + ts.tv_nsec;
+}
+
 static void populate_lru(const struct test_scenario *sc, __u32 real_idx)
 {
 	struct real_pos_lru lru = { .pos = real_idx };
 	struct flow_key fk;
 	int i, err;
 
+	if (sc->ip_proto == IPPROTO_UDP)
+		lru.atime = ktime_get_ns();
+
 	build_flow_key(&fk, sc);
 
 	/* Insert into every per-CPU inner LRU so the entry is found
-- 
2.53.0-Meta


  parent 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 ` [PATCH bpf-next 1/4] selftests/bpf: Fix cold_lru producing zero batch_hash in XDP LB benchmark Puranjay Mohan
2026-05-19 16:51   ` sashiko-bot
2026-05-19 17:14   ` bot+bpf-ci
2026-05-19 19:25     ` Puranjay Mohan
2026-05-19 16:36 ` Puranjay Mohan [this message]
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-3-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.