From: sashiko-bot@kernel.org
To: "Jim Cromie" <jim.cromie@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v4 1/4] kallsyms: Add test_kallsyms_perf module to benchmark lookup latency
Date: Tue, 22 Sep 2026 20:18:56 +0000 [thread overview]
Message-ID: <20260922201857.4BC821F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260922-ksyms-tune-v4-1-92acea84b911@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] test_kallsyms: infinite loop on large num_iters due to integer overflow
- [Medium] test_kallsyms: benchmark latency includes preemption sleep time
--
commit 3ac6ce68ed3764cca0a42a3e09873db349d331f2
Author: Jim Cromie <jim.cromie@gmail.com>
kallsyms: Add test_kallsyms_perf module to benchmark lookup latency
This commit adds a lightweight microbenchmark module to evaluate optimizations
and measure performance regressions across kallsyms lookups. It benchmarks
name-to-address, address-to-name, and sequential table scans.
> diff --git a/lib/test_kallsyms_perf.c b/lib/test_kallsyms_perf.c
> new file mode 100644
> index 0000000000000..03ff5f1d51c5d
> --- /dev/null
> +++ b/lib/test_kallsyms_perf.c
[ ... ]
> +static void run_name_lookup_bench(unsigned int iters)
> +{
[ ... ]
> + /* 1. Name search: Existing symbols (Hits) */
> + for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
[Severity: High]
Does this unconditionally add BENCH_CHUNK_SIZE to i in a way that can wrap
around?
If a user sets num_iters via sysfs to a value approaching UINT_MAX
(for example, UINT_MAX - 100), could i wrap around to a small number?
If so, will the termination condition i < iters never be met, causing an
infinite loop that permanently holds bench_lock?
> + unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
> + unsigned int j;
> +
> + cond_resched();
> + t0 = ktime_get_ns();
> + for (j = 0; j < chunk; j++) {
> + const char *sym = hit_symbols[(i + j) % nr_hits];
> +
> + kallsyms_on_each_match_symbol(match_cb, sym, &addr);
[Severity: Medium]
Do these kallsyms traversal APIs inherently invoke cond_resched() within their
internal iteration loops?
If so, does calling them inside the timing bracket (between t0 and t1) defeat
the chunking mitigation? Could this include preemption sleep time in the
measured benchmark latency?
> + OPTIMIZER_HIDE_VAR(addr);
> + }
> + t1 = ktime_get_ns();
> + dt_hit += t1 - t0;
> + }
> +
> + /* 2. Name search: Non-existent symbols (Misses - 17 bsearch probes) */
> + for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
[Severity: High]
Can this loop also suffer from the same integer overflow if num_iters is very
large?
> + unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
> + unsigned int j;
> +
> + cond_resched();
> + t0 = ktime_get_ns();
> + for (j = 0; j < chunk; j++) {
> + const char *sym = miss_symbols[(i + j) % nr_misses];
> +
> + kallsyms_on_each_match_symbol(match_cb, sym, &addr);
> + OPTIMIZER_HIDE_VAR(addr);
> + }
> + t1 = ktime_get_ns();
> + dt_miss += t1 - t0;
> + }
[ ... ]
> +static void run_address_lookup_bench(unsigned int iters)
> +{
[ ... ]
> + /* 1. Address-to-name resolution (sprint_symbol) */
> + for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
[Severity: High]
Is there a similar risk of wrap-around in this loop when num_iters approaches
UINT_MAX?
> + unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
> + unsigned int j;
> +
> + cond_resched();
> + t0 = ktime_get_ns();
> + for (j = 0; j < chunk; j++) {
> + unsigned long addr = addrs[(i + j) % nr_addrs];
> +
> + sprint_symbol(symname, addr);
> + barrier_data(symname);
> + }
> + t1 = ktime_get_ns();
> + dt_sprint += t1 - t0;
> + }
> +
> + /* 2. Address without offset (sprint_symbol_no_offset) */
> + for (i = 0; i < iters; i += BENCH_CHUNK_SIZE) {
[Severity: High]
Could this loop also become infinite due to the same integer overflow
condition?
> + unsigned int chunk = min_t(unsigned int, BENCH_CHUNK_SIZE, iters - i);
> + unsigned int j;
> +
> + cond_resched();
> + t0 = ktime_get_ns();
> + for (j = 0; j < chunk; j++) {
> + unsigned long addr = addrs[(i + j) % nr_addrs];
> +
> + sprint_symbol_no_offset(symname, addr);
> + barrier_data(symname);
> + }
> + t1 = ktime_get_ns();
> + dt_bldid += t1 - t0;
> + }
[ ... ]
> +static void run_table_walk_bench(void)
> +{
[ ... ]
> + for (i = 0; i < iter; i++) {
> + total_symbols = 0;
> + cond_resched();
> + t0 = ktime_get_ns();
> + kallsyms_on_each_symbol(count_cb, &total_symbols);
[Severity: Medium]
Does kallsyms_on_each_symbol() also natively invoke cond_resched() inside its
iteration loop?
If so, could placing this call inside the timing bracket include preemption
sleep time and inflate the measured walk latency?
> + t1 = ktime_get_ns();
> + dt_walk += t1 - t0;
> + }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260922-ksyms-tune-v4-0-92acea84b911@gmail.com?part=1
next prev parent reply other threads:[~2026-09-22 20:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 20:08 [PATCH v4 0/4] kallsyms: Accelerate symbol name lookups by ~19x Jim Cromie
2026-09-22 20:08 ` [PATCH v4 1/4] kallsyms: Add test_kallsyms_perf module to benchmark lookup latency Jim Cromie
2026-09-22 20:18 ` sashiko-bot [this message]
2026-09-22 20:08 ` [PATCH v4 2/4] kallsyms: Match compressed tokens on the fly during binary search Jim Cromie
2026-09-22 20:08 ` [PATCH v4 3/4] kallsyms: Add dynamic lookup index for batch resolution Jim Cromie
2026-09-22 20:08 ` [PATCH v4 4/4] kallsyms: Unroll 24-bit sequence reconstruction in get_symbol_seq() Jim Cromie
2026-09-23 7:12 ` [PATCH v4 0/4] kallsyms: Accelerate symbol name lookups by ~19x Kees Cook
2026-09-23 10:00 ` David Laight
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=20260922201857.4BC821F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jim.cromie@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox