[RFC PATCH v2 13/19] dyndbg: verify __dyndbg & __dyndbg_callsite invariant

From: Jim Cromie
Date: Fri Dec 25 2020 - 15:21:51 EST


Prove that linker + DECLARE_DYNAMIC_DEBUG_METADATA reliably place the
2 related struct _ddebug* initializations into parallel/ordered slots
in the __dyndbg_* sections.

This is a step towards dropping the pointer between the 2 structs;
maybe the 2 vectors stay ordered, and we can deduce and use N. Of
course this test won't survive, since it needs the pointer we seek to
drop, but its a start.

0- iterate over __dyndbg_callsite in parallel with __dyndbg
rename var: s/iter_start/iter_mod_start/ for clarity, consistency.

I disregarded a checkpatch warning about externs in c-files, staying
consistent with long-standing code seemed better.

1- prove that iter->site == site_iter.
DECLARE_DYNAMIC_DEBUG_METADATA + linker insure this now
Maybe we can drop pointer, still get order.

WRT the debug-printing, its noisy, but only with verbose=3.
It warrants trimming later.

The offset grows smoothly, because it is N * sizeof(structs), which
differ. It looks reliable. Amend later to do math, converge on
truth. If numbers are stable after stripping pointer, we have N.

rec ptr mod-ptr N (void*)p
[ 1.929072] dyndbg: 2828: ffffffff82b32f28 ffffffff82b32f10 1 24 40
[ 1.929326] dyndbg: 2829: ffffffff82b32f40 ffffffff82b32f10 2 48 80
[ 1.930209] dyndbg: 2 debug prints in module i386

We have N (col 4), and N * structsize (col 5). I feel like it still
needs more staring at.

Signed-off-by: Jim Cromie <jim.cromie@xxxxxxxxx>
---
lib/dynamic_debug.c | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 2d10fc1e16cd..c1a113460637 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -41,6 +41,8 @@

extern struct _ddebug __start___dyndbg[];
extern struct _ddebug __stop___dyndbg[];
+extern struct _ddebug_callsite __start___dyndbg_callsites[];
+extern struct _ddebug_callsite __stop___dyndbg_callsites[];

struct ddebug_table {
struct list_head link;
@@ -119,6 +121,7 @@ do { \

#define vpr_info(fmt, ...) vnpr_info(1, fmt, ##__VA_ARGS__)
#define v2pr_info(fmt, ...) vnpr_info(2, fmt, ##__VA_ARGS__)
+#define v3pr_info(fmt, ...) vnpr_info(2, fmt, ##__VA_ARGS__)

static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
{
@@ -1147,7 +1150,8 @@ static int __init dynamic_debug_init_control(void)

static int __init dynamic_debug_init(void)
{
- struct _ddebug *iter, *iter_start;
+ struct _ddebug *iter, *iter_mod_start;
+ struct _ddebug_callsite *site, *site_mod_start;
const char *modname = NULL;
char *cmdline;
int ret = 0;
@@ -1162,23 +1166,33 @@ static int __init dynamic_debug_init(void)
ddebug_init_success = 1;
return 0;
}
- iter = __start___dyndbg;
+
+ iter = iter_mod_start = __start___dyndbg;
+ site = site_mod_start = __start___dyndbg_callsites;
modname = iter->site->modname;
- iter_start = iter;
- for (; iter < __stop___dyndbg; iter++) {
+
+ for (; iter < __stop___dyndbg; iter++, site++) {
+
+ BUG_ON(site != iter->site);
+ v3pr_info("%u: %px %ld %ld %ld\n", entries, site,
+ site - site_mod_start,
+ ((void *)site - (void *)site_mod_start),
+ ((void *)iter - (void *)iter_mod_start));
entries++;
+
if (strcmp(modname, iter->site->modname)) {
modct++;
- ret = ddebug_add_module(iter_start, n, modname);
+ ret = ddebug_add_module(iter_mod_start, n, modname);
if (ret)
goto out_err;
n = 0;
modname = iter->site->modname;
- iter_start = iter;
+ iter_mod_start = iter;
+ site_mod_start = site;
}
n++;
}
- ret = ddebug_add_module(iter_start, n, modname);
+ ret = ddebug_add_module(iter_mod_start, n, modname);
if (ret)
goto out_err;

--
2.29.2