dyndbg: gather __dyndbg[] state into struct _ddebug_info

This new struct composes the linker provided (vector,len) section,
and provides a place to add other __dyndbg[] state-data later:

  descs - the vector of descriptors in __dyndbg section.
  num_descs - length of the data/section.

Use it, in several different ways, as follows:

In lib/dynamic_debug.c:

ddebug_add_module(): Alter params-list, replacing 2 args (array,index)
with a struct _ddebug_info * containing them both, with room for
expansion.  This helps future-proof the function prototype against the
looming addition of class-map info into the dyndbg-state, by providing
a place to add more member fields later.

NB: later add static struct _ddebug_info builtins_state declaration,
not needed yet.

ddebug_add_module() is called in 2 contexts:

In dynamic_debug_init(), declare, init a struct _ddebug_info di
auto-var to use as a cursor.  Then iterate over the prdbg blocks of
the builtin modules, and update the di cursor before calling
_add_module for each.

Its called from kernel/module/main.c:load_info() for each loaded
module:

In internal.h, alter struct load_info, replacing the dyndbg array,len
fields with an embedded _ddebug_info containing them both; and
populate its members in find_module_sections().

The 2 calling contexts differ in that _init deals with contiguous
subranges of __dyndbgs[] section, packed together, while loadable
modules are added one at a time.

So rename ddebug_add_module() into outer/__inner fns, call __inner
from _init, and provide the offset into the builtin __dyndbgs[] where
the module's prdbgs reside.  The cursor provides start, len of the
subrange for each.  The offset will be used later to pack the results
of builtin __dyndbg_sites[] de-duplication, and is 0 and unneeded for
loadable modules,

Note:

kernel/module/main.c includes <dynamic_debug.h> for struct
_ddeubg_info.  This might be prone to include loops, since its also
included by printk.h.  Nothing has broken in robot-land on this.

cc: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
Link: https://lore.kernel.org/r/20220904214134.408619-12-jim.cromie@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Jim Cromie 2022-09-04 15:40:48 -06:00 коммит произвёл Greg Kroah-Hartman
Родитель aa86a15453
Коммит b7b4eebdba
4 изменённых файлов: 50 добавлений и 25 удалений

Просмотреть файл

@ -51,12 +51,16 @@ struct _ddebug {
#endif #endif
} __attribute__((aligned(8))); } __attribute__((aligned(8)));
/* encapsulate linker provided built-in (or module) dyndbg data */
struct _ddebug_info {
struct _ddebug *descs;
unsigned int num_descs;
};
#if defined(CONFIG_DYNAMIC_DEBUG_CORE) #if defined(CONFIG_DYNAMIC_DEBUG_CORE)
int ddebug_add_module(struct _ddebug *tab, unsigned int n, int ddebug_add_module(struct _ddebug_info *dyndbg, const char *modname);
const char *modname);
extern int ddebug_remove_module(const char *mod_name); extern int ddebug_remove_module(const char *mod_name);
extern __printf(2, 3) extern __printf(2, 3)
void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...); void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
@ -184,8 +188,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/printk.h> #include <linux/printk.h>
static inline int ddebug_add_module(struct _ddebug *tab, unsigned int n, static inline int ddebug_add_module(struct _ddebug_info *dinfo, const char *modname)
const char *modname)
{ {
return 0; return 0;
} }

Просмотреть файл

@ -53,6 +53,7 @@ extern const struct kernel_symbol __stop___ksymtab_gpl[];
extern const s32 __start___kcrctab[]; extern const s32 __start___kcrctab[];
extern const s32 __start___kcrctab_gpl[]; extern const s32 __start___kcrctab_gpl[];
#include <linux/dynamic_debug.h>
struct load_info { struct load_info {
const char *name; const char *name;
/* pointer to module in temporary copy, freed at end of load_module() */ /* pointer to module in temporary copy, freed at end of load_module() */
@ -62,8 +63,7 @@ struct load_info {
Elf_Shdr *sechdrs; Elf_Shdr *sechdrs;
char *secstrings, *strtab; char *secstrings, *strtab;
unsigned long symoffs, stroffs, init_typeoffs, core_typeoffs; unsigned long symoffs, stroffs, init_typeoffs, core_typeoffs;
struct _ddebug *debug; struct _ddebug_info dyndbg;
unsigned int num_debug;
bool sig_ok; bool sig_ok;
#ifdef CONFIG_KALLSYMS #ifdef CONFIG_KALLSYMS
unsigned long mod_kallsyms_init_off; unsigned long mod_kallsyms_init_off;

Просмотреть файл

@ -1598,16 +1598,16 @@ static void free_modinfo(struct module *mod)
} }
} }
static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsigned int num) static void dynamic_debug_setup(struct module *mod, struct _ddebug_info *dyndbg)
{ {
if (!debug) if (!dyndbg->num_descs)
return; return;
ddebug_add_module(debug, num, mod->name); ddebug_add_module(dyndbg, mod->name);
} }
static void dynamic_debug_remove(struct module *mod, struct _ddebug *debug) static void dynamic_debug_remove(struct module *mod, struct _ddebug_info *dyndbg)
{ {
if (debug) if (dyndbg->num_descs)
ddebug_remove_module(mod->name); ddebug_remove_module(mod->name);
} }
@ -2111,8 +2111,8 @@ static int find_module_sections(struct module *mod, struct load_info *info)
if (section_addr(info, "__obsparm")) if (section_addr(info, "__obsparm"))
pr_warn("%s: Ignoring obsolete parameters\n", mod->name); pr_warn("%s: Ignoring obsolete parameters\n", mod->name);
info->debug = section_objs(info, "__dyndbg", info->dyndbg.descs = section_objs(info, "__dyndbg",
sizeof(*info->debug), &info->num_debug); sizeof(*info->dyndbg.descs), &info->dyndbg.num_descs);
return 0; return 0;
} }
@ -2807,7 +2807,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
} }
init_build_id(mod, info); init_build_id(mod, info);
dynamic_debug_setup(mod, info->debug, info->num_debug); dynamic_debug_setup(mod, &info->dyndbg);
/* Ftrace init must be called in the MODULE_STATE_UNFORMED state */ /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
ftrace_module_init(mod); ftrace_module_init(mod);
@ -2871,7 +2871,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
ddebug_cleanup: ddebug_cleanup:
ftrace_release_mod(mod); ftrace_release_mod(mod);
dynamic_debug_remove(mod, info->debug); dynamic_debug_remove(mod, &info->dyndbg);
synchronize_rcu(); synchronize_rcu();
kfree(mod->args); kfree(mod->args);
free_arch_cleanup: free_arch_cleanup:

Просмотреть файл

@ -923,14 +923,20 @@ static const struct proc_ops proc_fops = {
* Allocate a new ddebug_table for the given module * Allocate a new ddebug_table for the given module
* and add it to the global list. * and add it to the global list.
*/ */
int ddebug_add_module(struct _ddebug *tab, unsigned int n, static int __ddebug_add_module(struct _ddebug_info *di, unsigned int base,
const char *name) const char *modname)
{ {
struct ddebug_table *dt; struct ddebug_table *dt;
v3pr_info("add-module: %s.%d sites\n", modname, di->num_descs);
if (!di->num_descs) {
v3pr_info(" skip %s\n", modname);
return 0;
}
dt = kzalloc(sizeof(*dt), GFP_KERNEL); dt = kzalloc(sizeof(*dt), GFP_KERNEL);
if (dt == NULL) { if (dt == NULL) {
pr_err("error adding module: %s\n", name); pr_err("error adding module: %s\n", modname);
return -ENOMEM; return -ENOMEM;
} }
/* /*
@ -939,18 +945,25 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
* member of struct module, which lives at least as long as * member of struct module, which lives at least as long as
* this struct ddebug_table. * this struct ddebug_table.
*/ */
dt->mod_name = name; dt->mod_name = modname;
dt->num_ddebugs = n; dt->ddebugs = di->descs;
dt->ddebugs = tab; dt->num_ddebugs = di->num_descs;
INIT_LIST_HEAD(&dt->link);
mutex_lock(&ddebug_lock); mutex_lock(&ddebug_lock);
list_add_tail(&dt->link, &ddebug_tables); list_add_tail(&dt->link, &ddebug_tables);
mutex_unlock(&ddebug_lock); mutex_unlock(&ddebug_lock);
vpr_info("%3u debug prints in module %s\n", n, dt->mod_name); vpr_info("%3u debug prints in module %s\n", di->num_descs, modname);
return 0; return 0;
} }
int ddebug_add_module(struct _ddebug_info *di, const char *modname)
{
return __ddebug_add_module(di, 0, modname);
}
/* helper for ddebug_dyndbg_(boot|module)_param_cb */ /* helper for ddebug_dyndbg_(boot|module)_param_cb */
static int ddebug_dyndbg_param_cb(char *param, char *val, static int ddebug_dyndbg_param_cb(char *param, char *val,
const char *modname, int on_err) const char *modname, int on_err)
@ -1064,6 +1077,11 @@ static int __init dynamic_debug_init(void)
const char *modname; const char *modname;
char *cmdline; char *cmdline;
struct _ddebug_info di = {
.descs = __start___dyndbg,
.num_descs = __stop___dyndbg - __start___dyndbg,
};
if (&__start___dyndbg == &__stop___dyndbg) { if (&__start___dyndbg == &__stop___dyndbg) {
if (IS_ENABLED(CONFIG_DYNAMIC_DEBUG)) { if (IS_ENABLED(CONFIG_DYNAMIC_DEBUG)) {
pr_warn("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n"); pr_warn("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n");
@ -1082,7 +1100,9 @@ static int __init dynamic_debug_init(void)
if (strcmp(modname, iter->modname)) { if (strcmp(modname, iter->modname)) {
mod_ct++; mod_ct++;
ret = ddebug_add_module(iter_mod_start, mod_sites, modname); di.num_descs = mod_sites;
di.descs = iter_mod_start;
ret = __ddebug_add_module(&di, i - mod_sites, modname);
if (ret) if (ret)
goto out_err; goto out_err;
@ -1091,7 +1111,9 @@ static int __init dynamic_debug_init(void)
iter_mod_start = iter; iter_mod_start = iter;
} }
} }
ret = ddebug_add_module(iter_mod_start, mod_sites, modname); di.num_descs = mod_sites;
di.descs = iter_mod_start;
ret = __ddebug_add_module(&di, i - mod_sites, modname);
if (ret) if (ret)
goto out_err; goto out_err;