From: Stanislaw Gruszka <stf_xl@wp.pl>
To: Petr Pavlu <petr.pavlu@suse.com>
Cc: linux-modules@vger.kernel.org,
Sami Tolvanen <samitolvanen@google.com>,
Luis Chamberlain <mcgrof@kernel.org>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
live-patching@vger.kernel.org, Daniel Gomez <da.gomez@kernel.org>,
Aaron Tomlin <atomlin@atomlin.com>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Jordan Rome <linux@jordanrome.com>,
Viktor Malik <vmalik@redhat.com>, Petr Mladek <pmladek@suse.com>
Subject: Re: [PATCH v2 2/2] module/kallsyms: sort function symbols and use binary search
Date: Tue, 17 Nov 2026 12:17:52 +0100 [thread overview]
Message-ID: <avw34F1WLGdyYUkN@wp.pl> (raw)
In-Reply-To: <20260428082330.GA2757@wp.pl>
Hi,
My apologies for the very long delay in responding.
I wanted to understand the livepatch relocation issue before getting
back to this patch, but I kept struggling with it and putting it off.
Eventually, I got some help from AI to understand how livepatch
relocations work and why reordering symtab entries breaks them.
On Tue, Apr 28, 2026 at 10:23:30AM +0200, Stanislaw Gruszka wrote:
> > >> I'm not sure if it is ok to limit the search only to function symbols
> > >> when the address lies in MOD_TEXT. The text can theoretically contain
> > >> non-function symbols.
> > >
> > > Yes, the patch assumes that the only valid symbols in the MOD_TEXT
> > > are functions. If there are defined OBJECT symbols in .text, the patch
> > > would break lookup for those.
> > >
> > > While it’s theoretically possible (e.g. hand-written assembly placing
> > > data in .text ?), I’m not sure this is a practical concern. In general,
> > > having data in executable segments is discouraged for security reasons.
> > >
> > >> Could this optimization be adjusted to sort all
> > >> MOD_TEXT symbols (excluding anonymous and mapping symbols) and move them
> > >> to the front of the symbol table?
> > >
> > > That’s possible. We could track .text sections indices in
> > > __layout_sections() and include all valid symbols from those sections,
> > > and also reorder typetab accordingly.
> > >
> > > However, this adds complexity. I would prefer to first confirm whether
> > > OBJECT symbols in MOD_TEXT is a real issue before going in that direction.
It turns out that identifying MOD_TEXT symbols is straightforward.
The section's memory type is already encoded in
sec->sh_entsize >> SH_ENTSIZE_TYPE_SHIFT, where sec is obtained from
the symbol's st_shndx.
> > I'm not aware of specific OBJECT symbols that end up in MOD_TEXT.
> > Nonetheless, it is a valid case and it is preferable that an
> > optimization doesn't break their lookup by address.
> >
> > In general, I'm worried about the several edge cases and inconsistencies
> > that this optimization introduces. This also includes the fact that it
> > doesn't work for livepatch modules.
> >
> > An alternative could be to keep the symbol table untouched and have
> > a separate array with symbol indexes that is sorted by their addresses,
> > but it requires evaluation if the additional memory usage is worth it.
I've implemented this approach. As a bonus, sorting during module
loading is actually faster, since only the indexes need to be moved
instead of entire symbol table entries.
To get a rough estimate of the additional memory usage, I ran the
following command on my system:
awk 'NF == 4 && ($2 == "T" || $2 == "t")' /proc/kallsyms | wc -l
It reports 83593 symbols, which would correspond to roughly 326kB
of additional memory for 32-bit indexes across all loaded modules.
For comparison, the total size of loaded modules on this system is:
lsmod | awk 'NR > 1 { sum += $2 } END { printf "%.2f MB\n", sum / 1024 / 1024 }'
49.74 MB
Thus, the additional index would account for roughly 0.64% of the
total memory occupied by modules.
> I personally prefer not to over-engineer for cases that may never occur.
> That said, your concerns about edge cases, consistency, and livepatch
> handling are valid.
>
> Let me take some time to think this through and experiment with possible
> solutions that handle these cases properly. I can’t work on this
> immediately, but I’ll get back to it.
I'll post v3 shortly.
Regards
Stanislaw
next prev parent reply other threads:[~2026-11-17 11:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 11:00 [PATCH v2 1/2] module/kallsyms: fix nextval for data symbol lookup Stanislaw Gruszka
2026-03-27 11:00 ` [PATCH v2 2/2] module/kallsyms: sort function symbols and use binary search Stanislaw Gruszka
2026-04-23 14:00 ` Petr Pavlu
2026-04-24 9:13 ` Stanislaw Gruszka
2026-04-27 13:51 ` Petr Pavlu
2026-04-28 8:23 ` Stanislaw Gruszka
2026-11-17 11:17 ` Stanislaw Gruszka [this message]
2026-05-05 12:24 ` Petr Mladek
2026-05-05 14:37 ` Petr Pavlu
2026-05-06 8:58 ` Petr Mladek
2026-05-06 9:42 ` Petr Pavlu
2026-11-17 12:12 ` Stanislaw Gruszka
2026-04-08 15:24 ` [PATCH v2 1/2] module/kallsyms: fix nextval for data symbol lookup Petr Pavlu
2026-07-10 12:36 ` Petr Pavlu
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=avw34F1WLGdyYUkN@wp.pl \
--to=stf_xl@wp.pl \
--cc=atomlin@atomlin.com \
--cc=da.gomez@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-modules@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=linux@jordanrome.com \
--cc=live-patching@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=mhiramat@kernel.org \
--cc=petr.pavlu@suse.com \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=samitolvanen@google.com \
--cc=vmalik@redhat.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.