[PATCH 8/8] dyndbg: add locking around zpool-add loop in zpool-init

From: Jim Cromie
Date: Fri Aug 07 2020 - 16:10:40 EST

summary: no fix here.

Locking review:

ddebug_zpool_init(), like other *_init() routines, does not run under
a lock (that we control). Unlike them, it runs later, at late_init.
I dont know whether this is pertinent to the kernel panic.

ddebug_callsite_get/put() are called as a pair under mutex-lock for
all 3 callsite users; dynamic_emit_prefix() does its own ABBA-ish LGPU
(Lock-Get-Put-Unlock), as does ddebug_change().

ddebug_proc_show() does GP, ddebug_proc_start|stop() wrap it with LU.

ddebug_add_module() does LU to protect list_add(), HEAD~x added
ddebug_zpool_add() inside that protection.

This commit adds locking to ddebug_zpool_init(), around the loop of
ddebug_zpool_add(), to match the locking in ddebug_add_module().

Signed-off-by: Jim Cromie <jim.cromie@xxxxxxxxx>
lib/dynamic_debug.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 9c51f24a9c66..716231a98910 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -1187,8 +1187,10 @@ static void __init ddebug_zpool_init(void)

/* add-module normally does this, but not in time for builtins */
+ mutex_lock(&ddebug_lock);
for (iter = __start___dyndbg; iter < __stop___dyndbg; iter++)
+ mutex_unlock(&ddebug_lock);

v2pr_info("total pages: %lu compaction: %lu\n",
@@ -1285,4 +1287,3 @@ early_initcall(dynamic_debug_init);

/* Debugfs setup must be done later */