From: Jim Cromie <jim.cromie@gmail.com>
To: jbaron@akamai.com, gregkh@linuxfoundation.org,
linux-kernel@vger.kernel.org
Cc: Jim Cromie <jim.cromie@gmail.com>
Subject: [RFC PATCH v2 14/19] dyndbg+module: expose ddebug_callsites to modules
Date: Fri, 25 Dec 2020 13:19:39 -0700 [thread overview]
Message-ID: <20201225201944.3701590-15-jim.cromie@gmail.com> (raw)
In-Reply-To: <20201225201944.3701590-1-jim.cromie@gmail.com>
In order to drop the pointer connecting _ddebug records to _callsites,
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_callsites
section was added, and wasnt handled by module load-info. I never saw
any misbehavior loading i915.ko into a vm, but still..
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
include/linux/dynamic_debug.h | 4 ++--
kernel/module-internal.h | 1 +
kernel/module.c | 9 ++++++---
lib/dynamic_debug.c | 12 ++++++++----
4 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 49fa1390d1f8..0fcbe96736f3 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -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_callsite *sites,
+ unsigned int n, 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, ...);
diff --git a/kernel/module-internal.h b/kernel/module-internal.h
index 33783abc377b..920b085d2a1b 100644
--- a/kernel/module-internal.h
+++ b/kernel/module-internal.h
@@ -18,6 +18,7 @@ struct load_info {
char *secstrings, *strtab;
unsigned long symoffs, stroffs, init_typeoffs, core_typeoffs;
struct _ddebug *debug;
+ struct _ddebug_callsite *sites;
unsigned int num_debug;
bool sig_ok;
#ifdef CONFIG_KALLSYMS
diff --git a/kernel/module.c b/kernel/module.c
index a4fa44a652a7..876765bc666a 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2820,11 +2820,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_callsite *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)
@@ -3299,6 +3300,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_callsites",
+ sizeof(*info->sites), &info->num_debug);
return 0;
}
@@ -3937,7 +3940,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);
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index c1a113460637..8ad9be28f38e 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -49,6 +49,7 @@ struct ddebug_table {
const char *mod_name;
unsigned int num_ddebugs;
struct _ddebug *ddebugs;
+ struct _ddebug_callsite *sites;
};
struct ddebug_query {
@@ -1014,8 +1015,8 @@ 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_callsite *sites,
+ unsigned int n, const char *name)
{
struct ddebug_table *dt;
@@ -1033,6 +1034,7 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
dt->mod_name = name;
dt->num_ddebugs = n;
dt->ddebugs = tab;
+ dt->sites = sites;
mutex_lock(&ddebug_lock);
list_add(&dt->link, &ddebug_tables);
@@ -1182,7 +1184,9 @@ static int __init dynamic_debug_init(void)
if (strcmp(modname, iter->site->modname)) {
modct++;
- ret = ddebug_add_module(iter_mod_start, n, modname);
+
+ ret = ddebug_add_module(iter_mod_start, site_mod_start,
+ n, modname);
if (ret)
goto out_err;
n = 0;
@@ -1192,7 +1196,7 @@ static int __init dynamic_debug_init(void)
}
n++;
}
- ret = ddebug_add_module(iter_mod_start, n, modname);
+ ret = ddebug_add_module(iter_mod_start, site_mod_start, n, modname);
if (ret)
goto out_err;
--
2.29.2
next prev parent reply other threads:[~2020-12-25 20:22 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-25 20:19 [RFC PATCH v2 00/19] dynamic debug diet plan Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 01/19] dyndbg: fix use before null check Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 02/19] dyndbg: split struct _ddebug, move display fields to new _ddebug_callsite Jim Cromie
2020-12-31 2:34 ` [dyndbg] e83b4a5011: leaking-addresses.proc.__dyndbg_callsites kernel test robot
2020-12-25 20:19 ` [RFC PATCH v2 03/19] dyndbg: refactor part of ddebug_change to ddebug_match_site Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 04/19] dyndbg: accept null site in ddebug_match_site Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 05/19] dyndbg: hoist ->site out of ddebug_match_site Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 06/19] dyndbg: accept null site in ddebug_change Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 07/19] dyndbg: accept null site in dynamic_emit_prefix Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 08/19] dyndbg: accept null site in ddebug_proc_show Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 09/19] dyndbg: optimize ddebug_emit_prefix Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 10/19] dyndbg: avoid calling dyndbg_emit_prefix when it has no work Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 11/19] dyndbg: refactor ddebug_alter_site out of ddebug_change Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 12/19] dyndbg: allow deleting site info via control interface Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 13/19] dyndbg: verify __dyndbg & __dyndbg_callsite invariant Jim Cromie
2020-12-25 20:19 ` Jim Cromie [this message]
2020-12-25 20:19 ` [RFC PATCH v2 15/19] dyndbg: add ddebug_site_get/put api with pass-thru impl Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 16/19] dyndbg: ddebug_site_get/put api commentary Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 17/19] dyndbg: rearrange struct ddebug_callsites Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 18/19] dyndbg: add module_index to struct _ddebug Jim Cromie
2020-12-25 20:19 ` [RFC PATCH v2 19/19] dyndbg: try DEFINE_DYNAMIC_DEBUG_TABLE Jim Cromie
2020-12-29 18:56 ` [RFC PATCH v2 00/19] dynamic debug diet plan Joe Perches
2021-01-06 17:50 ` jim.cromie
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=20201225201944.3701590-15-jim.cromie@gmail.com \
--to=jim.cromie@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jbaron@akamai.com \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®