Skip to content
Permalink
Browse files
dyndbg+module: expose ddebug_sites to modules
In order to drop the pointer connecting _ddebug's to _ddebug_sites,
we need to elevate the latter; we need to track it in (internal)
ddebug_tables, and set it in ddebug_add_module.  That last part
exposes it by interface to module.c, so we add a field to load_info,
and adjust load_module to initialize it from the elf section.

Its possible that this closes a "hole" created when __dyndbg_sites
section was added, in that the section wasn't "managed" directly, and
could conceivably get lost later.  I never saw any misbehavior loading
i915.ko into a vm, but still..

TBD/RFC:

these 2 vectors should be in a single struct.  if this struct can have
ddebugs[], ie a flex-array, then container_of can get us to the
sites*, yielding &ddebug_sites[N], and allowing to drop _ddebug.site

The trouble with this is that ddebugs* now points to someone elses
memory, and we cant just steal it and stomp on the memory just in
front of it (for the sites ptr).

rename n to numdbgs

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
  • Loading branch information
jimc authored and intel-lab-lkp committed Mar 17, 2021
1 parent 7791d5e commit 5e967879ab4f65ac82fbc4ee3593aa31c801cc84
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
@@ -70,8 +70,8 @@ struct _ddebug {
/* exported for module authors to exercise >control */
int dynamic_debug_exec_queries(const char *query, const char *modname);

int ddebug_add_module(struct _ddebug *tab, unsigned int n,
const char *modname);
int ddebug_add_module(struct _ddebug *tab, struct _ddebug_site *sites,
unsigned int numdbgs, const char *modname);
extern int ddebug_remove_module(const char *mod_name);
extern __printf(2, 3)
void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
@@ -18,6 +18,7 @@ struct load_info {
char *secstrings, *strtab;
unsigned long symoffs, stroffs, init_typeoffs, core_typeoffs;
struct _ddebug *debug;
struct _ddebug_site *sites;
unsigned int num_debug;
bool sig_ok;
#ifdef CONFIG_KALLSYMS
@@ -2780,11 +2780,12 @@ static void add_kallsyms(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)
static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug,
struct _ddebug_site *sites, unsigned int num)
{
if (!debug)
return;
ddebug_add_module(debug, num, mod->name);
ddebug_add_module(debug, sites, num, mod->name);
}

static void dynamic_debug_remove(struct module *mod, struct _ddebug *debug)
@@ -3333,6 +3334,8 @@ static int find_module_sections(struct module *mod, struct load_info *info)

info->debug = section_objs(info, "__dyndbg",
sizeof(*info->debug), &info->num_debug);
info->sites = section_objs(info, "__dyndbg_sites",
sizeof(*info->sites), &info->num_debug);

return 0;
}
@@ -4004,7 +4007,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
goto free_arch_cleanup;
}

dynamic_debug_setup(mod, info->debug, info->num_debug);
dynamic_debug_setup(mod, info->debug, info->sites, info->num_debug);

/* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
ftrace_module_init(mod);
@@ -49,6 +49,7 @@ struct ddebug_table {
const char *mod_name;
unsigned int num_ddebugs;
struct _ddebug *ddebugs;
struct _ddebug_site *sites;
};

struct ddebug_query {
@@ -1014,14 +1015,14 @@ static const struct proc_ops proc_fops = {
* Allocate a new ddebug_table for the given module
* and add it to the global list.
*/
int ddebug_add_module(struct _ddebug *tab, unsigned int n,
const char *name)
int ddebug_add_module(struct _ddebug *tab, struct _ddebug_site *sites,
unsigned int numdbgs, const char *modname)
{
struct ddebug_table *dt;

dt = kzalloc(sizeof(*dt), GFP_KERNEL);
if (dt == NULL) {
pr_err("error adding module: %s\n", name);
pr_err("error adding module: %s\n", modname);
return -ENOMEM;
}
/*
@@ -1030,15 +1031,16 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
* member of struct module, which lives at least as long as
* this struct ddebug_table.
*/
dt->mod_name = name;
dt->num_ddebugs = n;
dt->mod_name = modname;
dt->num_ddebugs = numdbgs;
dt->ddebugs = tab;
dt->sites = sites;

mutex_lock(&ddebug_lock);
list_add(&dt->link, &ddebug_tables);
mutex_unlock(&ddebug_lock);

v2pr_info("%3u debug prints in module %s\n", n, dt->mod_name);
v2pr_info("%3u debug prints in module %s\n", numdbgs, modname);
return 0;
}

@@ -1178,7 +1180,9 @@ static int __init dynamic_debug_init(void)

if (strcmp(modname, site->modname)) {
modct++;
ret = ddebug_add_module(iter_mod_start, site_ct, modname);

ret = ddebug_add_module(iter_mod_start, site_mod_start,
site_ct, modname);
if (ret)
goto out_err;
site_ct = 0;
@@ -1188,7 +1192,7 @@ static int __init dynamic_debug_init(void)
}
site_ct++;
}
ret = ddebug_add_module(iter_mod_start, site_ct, modname);
ret = ddebug_add_module(iter_mod_start, site_mod_start, site_ct, modname);
if (ret)
goto out_err;

0 comments on commit 5e96787

Please sign in to comment.