On Tue, Mar 10, 2026 at 04:20:32PM +0100, Petr Mladek wrote:
On Fri 2026-03-06 12:14:45, Sasha Levin wrote:On Fri, Mar 06, 2026 at 05:36:36PM +0100, Petr Mladek wrote: > On Tue 2026-03-03 13:21:01, Sasha Levin wrote: > > Add CONFIG_KALLSYMS_LINEINFO, which embeds a compact address-to-line > > lookup table in the kernel image so stack traces directly print source > > file and line number information: > > > > --- a/include/linux/kallsyms.h > > +++ b/include/linux/kallsyms.h > > @@ -16,10 +16,19 @@ > > #include <asm/sections.h> > > > > #define KSYM_NAME_LEN 512 > > + > > +#ifdef CONFIG_KALLSYMS_LINEINFO > > +/* Extra space for " (path/to/file.c:12345)" suffix */ > > +#define KSYM_LINEINFO_LEN 128 > > +#else > > +#define KSYM_LINEINFO_LEN 0 > > +#endif > > + > > #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s %s]") + \ > > I guess that this is used also in ftrace where there formatting > is delayed. We might want: > > #define KSYM_SYMBOL_LEN (sizeof("%s+%#lx/%#lx [%s %s] (%s:%u)") + \KSYM_LINEINFO_LEN already covers the full expansion of the path and line number, not just the literal format characters. ftrace stores raw addresses and formats via %pS at print time into a KSYM_SYMBOL_LEN-sized buffer, so there shouldn't be an issue here.I was curious why the sizeof("%s+%#lx/%#lx [%s %s]") was there. It did not make much sense to count some "random" part of the format string. I expected that it was related to the ftrace delayed formatting. But they are written to the tracing buffer, see trace_vbprintk(). But I believe that it does not need to be counted. It seems to be some cargo-cult programming. The size has been counted first by the commit d069cf94ca296b7fb ("kallsyms for new modules") back in v2.6.12-rc2, see https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=d069cf94ca296b7fb4c7e362e8f27e2c8aca70f1 And it seems that it was not needed there. That said, we could not simply remove it witout revisiting the rest of the computation. Especilly, we need to make sure that it counts all extra characters, like spaces, brackets, and the trailing '\0'. Ideally, we should replace the unsafe sprintf() with snprintf() in all users. (>> TODO ;-)
Yeah, good catch. The sizeof() counts the format specifiers too which never end up in the output since their expansions are already covered by the other terms. I'd rather not poke that bear as part of this series, we can try it in a follow up and see if anything explodes? -- Thanks, Sasha

