On 24/03/2021 03.04, Stephen Boyd wrote:
> @@ -2778,6 +2793,10 @@ static inline void layout_symtab(struct module *mod, struct load_info *info)
> static void add_kallsyms(struct module *mod, const struct load_info *info)
> {
> }
> +
> +static void init_build_id(struct module *mod, const struct load_info *info)
> +{
> +}
> #endif /* CONFIG_KALLSYMS */
>
> static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsigned int num)
> @@ -4004,6 +4023,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
> goto free_arch_cleanup;
> }
>
> + init_build_id(mod, info);
> dynamic_debug_setup(mod, info->debug, info->num_debug);
>
> /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
> @@ -4235,7 +4255,7 @@ void * __weak dereference_module_function_descriptor(struct module *mod,
> const char *module_address_lookup(unsigned long addr,
> unsigned long *size,
> unsigned long *offset,
> - char **modname,
> + char **modname, unsigned char **modbuildid,
It's an existing defect with modname, but surely this should take a
"const unsigned char **modbuildid", no?
> char *namebuf)
> {
> const char *ret = NULL;
> @@ -4246,6 +4266,8 @@ const char *module_address_lookup(unsigned long addr,
> if (mod) {
> if (modname)
> *modname = mod->name;
> + if (modbuildid)
> + *modbuildid = mod->build_id;
>
> ret = find_kallsyms_symbol(mod, addr, size, offset);
> }
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 41ddc353ebb8..9cd62e84e4aa 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -961,13 +961,15 @@ char *symbol_string(char *buf, char *end, void *ptr,
> char sym[KSYM_SYMBOL_LEN];
> #endif
>
> - if (fmt[1] == 'R')
> + if (fmt[1] == 'R' || fmt[1] == 'r')
> ptr = __builtin_extract_return_addr(ptr);
> value = (unsigned long)ptr;
>
> #ifdef CONFIG_KALLSYMS
> if (*fmt == 'B')
> sprint_backtrace(sym, value);
> + else if (*fmt == 'S' && (fmt[1] == 'b' || fmt[1] == 'r'))
> + sprint_symbol_stacktrace(sym, value);
> else if (*fmt != 's')
> sprint_symbol(sym, value);
> else
> @@ -2129,6 +2131,8 @@ early_param("no_hash_pointers", no_hash_pointers_enable);
> * - 'S' For symbolic direct pointers (or function descriptors) with offset
> * - 's' For symbolic direct pointers (or function descriptors) without offset
> * - '[Ss]R' as above with __builtin_extract_return_addr() translation
> + * - '[Ss]r' as above with __builtin_extract_return_addr() translation and module build ID
> + * - '[Ss]b' as above with module build ID (for use in backtraces)
The code doesn't quite match the comment. The lowercase s is not handled
(i.e., there's no way to say "without offset, with build ID"). You don't
have to fix the code to support that right now, the whole kallsyms
vsprintf code needs to be reworked inside-out anyway (having vsnprint
call sprint_symbol* which builds the output using snprintf() calls makes
me cringe), so please just replace [Ss] by S to make the comment match
the code - I notice that you did only document the S variant in
printk-formats.rst.
Is there any reason you didn't just make b an optional flag that could
be specified with or without R? I suppose the parsing is more difficult
with several orthogonal flags (see escaped_string()), but it's a little
easier to understand. Dunno, it's not like we're gonna think of 10 other
things that could be printed for a symbol, so perhaps it's fine.
Rasmus
Quoting Rasmus Villemoes (2021-03-24 02:57:13)
> On 24/03/2021 03.04, Stephen Boyd wrote:
>
> > @@ -2778,6 +2793,10 @@ static inline void layout_symtab(struct module *mod, struct load_info *info)
> > static void add_kallsyms(struct module *mod, const struct load_info *info)
> > {
> > }
> > +
> > +static void init_build_id(struct module *mod, const struct load_info *info)
> > +{
> > +}
> > #endif /* CONFIG_KALLSYMS */
> >
> > static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsigned int num)
> > @@ -4004,6 +4023,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
> > goto free_arch_cleanup;
> > }
> >
> > + init_build_id(mod, info);
> > dynamic_debug_setup(mod, info->debug, info->num_debug);
> >
> > /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
> > @@ -4235,7 +4255,7 @@ void * __weak dereference_module_function_descriptor(struct module *mod,
> > const char *module_address_lookup(unsigned long addr,
> > unsigned long *size,
> > unsigned long *offset,
> > - char **modname,
> > + char **modname, unsigned char **modbuildid,
>
> It's an existing defect with modname, but surely this should take a
> "const unsigned char **modbuildid", no?
Sure.
>
> > char *namebuf)
> > {
> > const char *ret = NULL;
> > @@ -4246,6 +4266,8 @@ const char *module_address_lookup(unsigned long addr,
> > if (mod) {
> > if (modname)
> > *modname = mod->name;
> > + if (modbuildid)
> > + *modbuildid = mod->build_id;
> >
> > ret = find_kallsyms_symbol(mod, addr, size, offset);
> > }
> > diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> > index 41ddc353ebb8..9cd62e84e4aa 100644
> > --- a/lib/vsprintf.c
> > +++ b/lib/vsprintf.c
> > @@ -961,13 +961,15 @@ char *symbol_string(char *buf, char *end, void *ptr,
> > char sym[KSYM_SYMBOL_LEN];
> > #endif
> >
> > - if (fmt[1] == 'R')
> > + if (fmt[1] == 'R' || fmt[1] == 'r')
> > ptr = __builtin_extract_return_addr(ptr);
> > value = (unsigned long)ptr;
> >
> > #ifdef CONFIG_KALLSYMS
> > if (*fmt == 'B')
> > sprint_backtrace(sym, value);
> > + else if (*fmt == 'S' && (fmt[1] == 'b' || fmt[1] == 'r'))
> > + sprint_symbol_stacktrace(sym, value);
> > else if (*fmt != 's')
> > sprint_symbol(sym, value);
> > else
> > @@ -2129,6 +2131,8 @@ early_param("no_hash_pointers", no_hash_pointers_enable);
> > * - 'S' For symbolic direct pointers (or function descriptors) with offset
> > * - 's' For symbolic direct pointers (or function descriptors) without offset
> > * - '[Ss]R' as above with __builtin_extract_return_addr() translation
> > + * - '[Ss]r' as above with __builtin_extract_return_addr() translation and module build ID
> > + * - '[Ss]b' as above with module build ID (for use in backtraces)
>
> The code doesn't quite match the comment. The lowercase s is not handled
> (i.e., there's no way to say "without offset, with build ID"). You don't
> have to fix the code to support that right now, the whole kallsyms
> vsprintf code needs to be reworked inside-out anyway (having vsnprint
> call sprint_symbol* which builds the output using snprintf() calls makes
> me cringe), so please just replace [Ss] by S to make the comment match
> the code - I notice that you did only document the S variant in
> printk-formats.rst.
No problem. Will fix this comment.
>
> Is there any reason you didn't just make b an optional flag that could
> be specified with or without R? I suppose the parsing is more difficult
> with several orthogonal flags (see escaped_string()), but it's a little
> easier to understand. Dunno, it's not like we're gonna think of 10 other
> things that could be printed for a symbol, so perhaps it's fine.
>
I think I follow. So %pSb or %pSRb? If it's easier to understand then
sure. I was trying to avoid checking another character beyond fmt[1] but
it should be fine if fmt[1] is already 'R'.
On 24/03/2021 20.11, Stephen Boyd wrote:
> Quoting Rasmus Villemoes (2021-03-24 02:57:13)
>>
>> Is there any reason you didn't just make b an optional flag that could
>> be specified with or without R? I suppose the parsing is more difficult
>> with several orthogonal flags (see escaped_string()), but it's a little
>> easier to understand. Dunno, it's not like we're gonna think of 10 other
>> things that could be printed for a symbol, so perhaps it's fine.
>>
>
> I think I follow. So %pSb or %pSRb? If it's easier to understand then
> sure. I was trying to avoid checking another character beyond fmt[1] but
> it should be fine if fmt[1] is already 'R'.
>
I don't know. On the one hand, it seems sensible to allow such "flag"
modifiers to appear independently and in any order. Because what if some
day we think of some other property of the symbol we might want to
provide access to via a "z" flag; when to allow all combinations of the
R, b and z functionality we'd have to use four more random letters to
stand for various combinations of those flags. On the other hand,
vsprintf.c is already a complete wild west of odd conventions for
%p<foo>, and it's not like symbol_string() gets extended every other
release, and I can certainly understand the desire to keep the parsing
of fmt minimal. So 'r' to mean 'Rb' is ok by me if you prefer that.
Rasmus
Quoting Rasmus Villemoes (2021-03-24 15:21:34)
> On 24/03/2021 20.11, Stephen Boyd wrote:
> > Quoting Rasmus Villemoes (2021-03-24 02:57:13)
>
> >>
> >> Is there any reason you didn't just make b an optional flag that could
> >> be specified with or without R? I suppose the parsing is more difficult
> >> with several orthogonal flags (see escaped_string()), but it's a little
> >> easier to understand. Dunno, it's not like we're gonna think of 10 other
> >> things that could be printed for a symbol, so perhaps it's fine.
> >>
> >
> > I think I follow. So %pSb or %pSRb? If it's easier to understand then
> > sure. I was trying to avoid checking another character beyond fmt[1] but
> > it should be fine if fmt[1] is already 'R'.
> >
>
> I don't know. On the one hand, it seems sensible to allow such "flag"
> modifiers to appear independently and in any order. Because what if some
> day we think of some other property of the symbol we might want to
> provide access to via a "z" flag; when to allow all combinations of the
> R, b and z functionality we'd have to use four more random letters to
> stand for various combinations of those flags. On the other hand,
> vsprintf.c is already a complete wild west of odd conventions for
> %p<foo>, and it's not like symbol_string() gets extended every other
> release, and I can certainly understand the desire to keep the parsing
> of fmt minimal. So 'r' to mean 'Rb' is ok by me if you prefer that.
I'm inclined to use %pSb and %pSRb. The code looks to simpler and I
suppose we can worry about different ordering/combination problems if it
comes to it.
---8<---
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 41ddc353ebb8..0e94cba5ba20 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -968,6 +968,8 @@ char *symbol_string(char *buf, char *end, void *ptr,
#ifdef CONFIG_KALLSYMS
if (*fmt == 'B')
sprint_backtrace(sym, value);
+ else if (*fmt == 'S' && (fmt[1] == 'b' || (fmt[1] == 'R' && fmt[2] == 'b')))
+ sprint_symbol_stacktrace(sym, value);
else if (*fmt != 's')
sprint_symbol(sym, value);
else
On Wed 2021-03-24 15:28:43, Stephen Boyd wrote:
> Quoting Rasmus Villemoes (2021-03-24 15:21:34)
> > On 24/03/2021 20.11, Stephen Boyd wrote:
> > > Quoting Rasmus Villemoes (2021-03-24 02:57:13)
> >
> > >>
> > >> Is there any reason you didn't just make b an optional flag that could
> > >> be specified with or without R? I suppose the parsing is more difficult
> > >> with several orthogonal flags (see escaped_string()), but it's a little
> > >> easier to understand. Dunno, it's not like we're gonna think of 10 other
> > >> things that could be printed for a symbol, so perhaps it's fine.
> > >>
> > >
> > > I think I follow. So %pSb or %pSRb? If it's easier to understand then
> > > sure. I was trying to avoid checking another character beyond fmt[1] but
> > > it should be fine if fmt[1] is already 'R'.
>
> I'm inclined to use %pSb and %pSRb. The code looks to simpler and I
> suppose we can worry about different ordering/combination problems if it
> comes to it.
>
> ---8<---
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 41ddc353ebb8..0e94cba5ba20 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -968,6 +968,8 @@ char *symbol_string(char *buf, char *end, void *ptr,
> #ifdef CONFIG_KALLSYMS
> if (*fmt == 'B')
> sprint_backtrace(sym, value);
> + else if (*fmt == 'S' && (fmt[1] == 'b' || (fmt[1] == 'R' && fmt[2] == 'b')))
> + sprint_symbol_stacktrace(sym, value);
> else if (*fmt != 's')
> sprint_symbol(sym, value);
> else
I prefer the extra "b" flag as well. It helps me to understand and
memorize[*] the meaning.
[*] at least short-time memorize ;-)
Best Regards,
Petr