All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: sashiko-bot@kernel.org
Cc: sashiko-reviews@lists.linux.dev, bpf@vger.kernel.org
Subject: Re: [PATCH 2/2] kallsyms: Optimise symbol name search
Date: Wed, 30 Sep 2026 19:21:15 +0100	[thread overview]
Message-ID: <20260930192115.491c461a@pumpkin> (raw)
In-Reply-To: <20260930133525.C8CA21F000FF@smtp.kernel.org>

On Wed, 30 Sep 2026 13:35:25 +0000
sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] kallsyms: 32-bit offset truncation in scripts/kallsyms.c causes panic
> - [Medium] kallsyms: off-by-one in get_name_address binary search bounds doubles scan time
> --
> 
> commit aa83959ffd157437ca56938c0da66225c5fc9aaf
> Author: David Laight <david.laight.linux@gmail.com>
> 
> kallsyms: Optimise symbol name search
> 
> Change the alphabetically ordered lookup table (kallsyms_seqs_of_names)
> with one that indexes the table of compressed names rather than the
> array of symbol values. This removes linear scans during the binary search
> for the symbol name.
> 
> > diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
> > index d18d78e626db2..2f39fa850deae 100644
> > --- a/kernel/kallsyms.c
> > +++ b/kernel/kallsyms.c  
> [ ... ]
> > @@ -177,6 +177,36 @@ static unsigned int get_symbol_offset(unsigned long pos)
> >  	return name - kallsyms_names;
> >  }
> >  
> > +/*
> > + * Find the value of a symbol givem the offset in the compressed stream.
> > + */
> > +static unsigned long get_name_address(unsigned int name_offset)
> > +{
> > +	unsigned int low, pos, high;
> > +
> > +	low = 0;
> > +	high = kallsyms_num_syms >> 8;
> > +
> > +	while (high - low > 1) {  
> 
> [Severity: Medium]
> Since high acts as an exclusive upper bound here, doesn't this omit the final
> lookup marker from the search space if kallsyms_num_syms is not an exact
> multiple of 256?
> 
> Any kallsyms lookup for symbols in the last partial block (up to 255 symbols)
> might fall back to the second-to-last marker, unnecessarily doubling the
> linear scan fallback duration.

I'll double check.
This matched one of the other scans.
I did check the first and last symbols (by name and number could be found). 

> 
> > +		pos = low + (high - low) / 2;
> > +		if (name_offset >= kallsyms_markers[pos])
> > +			low = pos;
> > +		else
> > +			high = pos;
> > +	}  
> [ ... ]
> > diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
> > index 494852ade6d87..74264ead1efe1 100644
> > --- a/scripts/kallsyms.c
> > +++ b/scripts/kallsyms.c  
> [ ... ]
> > @@ -448,13 +439,28 @@ static void write_src(void)
> >  	printf("\n");
> >  
> >  	sort_symbols_by_name();
> > -	output_label("kallsyms_seqs_of_names");
> > -	for (i = 0; i < table_cnt; i++)
> > -		printf("\t.byte 0x%02x, 0x%02x, 0x%02x\t/* %s */\n",
> > -			(unsigned char)(table[i]->seq >> 16),
> > -			(unsigned char)(table[i]->seq >> 8),
> > -			(unsigned char)(table[i]->seq >> 0),
> > -		       table[i]->sym);
> > +	if (table_size < (1u << 24)) {
> > +		output_label("kallsyms_off24_of_names");
> > +		for (i = 0; i < table_cnt; i++) {
> > +			printf("\t.byte 0x%02x, 0x%02x, 0x%02x\t/* %s */\n",
> > +#ifdef CONFIG_CPU_BIG_ENDIAN
> > +				(unsigned char)(table[i]->seq >> 16),
> > +				(unsigned char)(table[i]->seq >> 8),
> > +				(unsigned char)(table[i]->seq >> 0),
> > +#else
> > +				(unsigned char)(table[i]->seq >> 0),
> > +				(unsigned char)(table[i]->seq >> 8),
> > +				(unsigned char)(table[i]->seq >> 16),
> > +#endif
> > +			       table[i]->sym);
> > +		}
> > +	} else {
> > +		output_label("kallsyms_off32_of_names");
> > +		for (i = 0; i < table_cnt; i++) {
> > +			printf("\t.long %#04x\t/* %s */\n",
> > +				table[i]->seq >> 16, table[i]->sym);  
> 
> [Severity: High]
> Does this code inadvertently truncate the 32-bit offset?

That is a C&P error :-(

David

> 
> When the compressed symbol table exceeds 16MB (such as in allyesconfig builds),
> this code shifts table[i]->seq right by 16 bits. This unconditionally discards
> the lower 16 bits of the sequence offset.
> 
> Could this corrupt the lookup table kallsyms_off32_of_names and lead to a
> panic during boot when the kernel attempts to look up wild memory addresses?
> 
> > +		}
> > +	}
> >  	printf("\n");
> >  }  
> 


  reply	other threads:[~2026-09-30 18:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 13:21 [PATCH next 0/2] kallsyms: optimise symbol search by name David Laight
2026-09-30 13:21 ` [PATCH 1/2] kallsyms: Match compressed tokens on the fly during binary search David Laight
2026-09-30 13:21 ` [PATCH 2/2] kallsyms: Optimise symbol name search David Laight
2026-09-30 13:35   ` sashiko-bot
2026-09-30 18:21     ` David Laight [this message]
2026-10-01  0:45   ` bot+bpf-ci
2026-10-01  8:21     ` 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=20260930192115.491c461a@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-bot@kernel.org \
    --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 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.