dyndbg: let's use the module notifier callback
Subsystems (3)
Jason Baron
maintainerv3 cover dyndbg: let's use the module notifier callback
Hi,
Jim Cromie hit a BUG() while toggling jump label branches in a module before they were properly initialized. This isn't currently an issue, but will be as part of his pending classmap series. Seems like we should covert to using module callback notifier for dynamic debug anyways to match other subsystems and remove core module code. First patch is just a cleanup.
I've rebased this series onto modules-next tree. Although the first patch is a cleanup entirely internal to dynamic debug I think it's a nice cleanup to have as part of this series.
Thanks,
-Jason
v3:
-rebased to modules-next tree
-updated changelog as per Luis Chamberlain's suggestions
v2:
-Fix: error: field 'dyndbg_info' has incomplete type
-make ddebug_remove_module() static
Jason Baron (2):
dyndbg: remove unused 'base' arg from __ddebug_add_module()
dyndbg: use the module notifier callbacks
include/linux/dynamic_debug.h | 13 --------- include/linux/module.h | 4 +++ kernel/module/internal.h | 2 -- kernel/module/main.c | 30 ++++++--------------- lib/dynamic_debug.c | 51 ++++++++++++++++++++++++++++------- 5 files changed, 53 insertions(+), 47 deletions(-)
Signature · 1 line
2.17.1
Jason Baron
maintainerPATCH v3 1/2 dyndbg: remove unused 'base' arg from __ddebug_add_module()
The 'base' parameter to __ddebug_add_module() is no longer in use
after: Commit b7b4eebdba7b ("dyndbg: gather __dyndbg[] state into struct _ddebug_info").
--- lib/dynamic_debug.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
lib/dynamic_debug.c +4 -5
@@ -1223,8 +1223,7 @@ static void ddebug_attach_module_classes(struct ddebug_table *dt,* Allocate a new ddebug_table for the given module * and add it to the global list. */ -static int __ddebug_add_module (struct _ddebug_info *di,unsigned int base, -const char *modname) +static int __ddebug_add_module (struct _ddebug_info *di,const char *modname) {struct ddebug_table *dt;
@@ -1265,7 +1264,7 @@ static int __ddebug_add_module(struct _ddebug_info *di, unsigned int base,int ddebug_add_module (struct _ddebug_info *di,const char *modname) { -return __ddebug_add_module (di,0 , modname); +return __ddebug_add_module (di, modname); }/* helper for ddebug_dyndbg_(boot|module)_param_cb */
@@ -1408,7 +1407,7 @@ static int __init dynamic_debug_init(void) mod_ct++; di.num_descs = mod_sites; di.descs = iter_mod_start; - ret =__ddebug_add_module (&di, i - mod_sites, modname); + ret =__ddebug_add_module (&di, modname);if (ret) goto out_err;
@@ -1419,7 +1418,7 @@ static int __init dynamic_debug_init(void) } di.num_descs = mod_sites; di.descs = iter_mod_start; - ret =__ddebug_add_module (&di, i - mod_sites, modname); + ret =__ddebug_add_module (&di, modname);if (ret) goto out_err;
Signature · 1 line
2.17.1
Re: [PATCH v3 1/2] dyndbg: remove unused 'base' arg from __ddebug_add_module()
Quoted 9 lines
The 'base' parameter to
__ddebug_add_module()is no longer in use
after: Commitb7b4eebdba7b("dyndbg: gather __dyndbg[] state into struct_ddebug_info").Cc Jim Cromie <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Tested-by Jim Cromie <[email protected]>Signed-off-by Jason Baron <[email protected]>---
Jason Baron
maintainerPATCH v3 2/2 dyndbg: use the module notifier callbacks
In reply to Jason BaronBring dynamic debug in line with other subsystems by using the module notifier callbacks. This results in a net decrease in core module code.
Additionally, Jim Cromie has a new dynamic debug classmap feature, which requires that jump labels be initialized prior to dynamic debug. Specifically, the new feature toggles a jump label from the existing dynamic_debug_setup() function. However, this does not currently work properly, because jump labels are initialized via the 'module_notify_list' notifier chain, which is invoked after the current call to dynamic_debug_setup(). Thus, this patch ensures that jump labels are initialized prior to dynamic debug by setting the dynamic debug notifier priority to 0, while jump labels have the higher priority of 1.
Tested by Jim using his new test case, and I've verfied the correct printing via: # modprobe test_dynamic_debug dyndbg.
--- include/linux/dynamic_debug.h | 13 --------- include/linux/module.h | 4 +++ kernel/module/internal.h | 2 -- kernel/module/main.c | 30 ++++++--------------- lib/dynamic_debug.c | 50 ++++++++++++++++++++++++++++------- 5 files changed, 53 insertions(+), 46 deletions(-)
include/linux/dynamic_debug.h +0 -13
@@ -130,9 +130,6 @@ struct ddebug_class_param {#if defined(CONFIG_DYNAMIC_DEBUG_CORE ) -int ddebug_add_module (struct _ddebug_info *dyndbg,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, ...);
@@ -304,16 +301,6 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp);#include <linux/errno.h> #include <linux/printk.h> -static inline int ddebug_add_module (struct _ddebug_info *dinfo,const char *modname) -{ -return 0 ; -} - -static inline int ddebug_remove_module (const char *mod) -{ -return 0 ; -} -static inline int ddebug_dyndbg_module_param_cb (char *param,char *val,const char *modname) {
include/linux/module.h +4 -0
@@ -27,6 +27,7 @@#include <linux/tracepoint-defs.h> #include <linux/srcu.h> #include <linux/static_call_types.h> +#include <linux/dynamic_debug.h> #include <linux/percpu.h> #include <asm/module.h>
@@ -579,6 +580,9 @@ struct module {struct error_injection_entry *ei_funcs;unsigned int num_ei_funcs;#endif +#ifdef CONFIG_DYNAMIC_DEBUG_CORE +struct _ddebug_info dyndbg_info; +#endif }____cacheline_aligned __randomize_layout;#ifndef MODULE_ARCH_INIT #define MODULE_ARCH_INIT {}
kernel/module/internal.h +0 -2
@@ -45,7 +45,6 @@ extern const struct kernel_symbol __stop___ksymtab_gpl[];extern const s32 __start___kcrctab[];extern const s32 __start___kcrctab_gpl[]; -#include <linux/dynamic_debug.h> struct load_info {const char *name;/* pointer to module in temporary copy, freed at end of load_module() */
@@ -55,7 +54,6 @@ struct load_info {Elf_Shdr *sechdrs;char *secstrings, *strtab;unsigned long symoffs, stroffs, init_typeoffs, core_typeoffs; -struct _ddebug_info dyndbg;bool sig_ok;#ifdef CONFIG_KALLSYMS unsigned long mod_kallsyms_init_off;
kernel/module/main.c +8 -22
@@ -1216,9 +1216,6 @@ static void free_module(struct module *mod) mod->state =MODULE_STATE_UNFORMED ;mutex_unlock (&module_mutex); -/* Remove dynamic debug info */ -ddebug_remove_module (mod->name); -/* Arch-specific cleanup. */ module_arch_cleanup (mod);
@@ -1619,19 +1616,6 @@ static void free_modinfo(struct module *mod) } } -static void dynamic_debug_setup (struct module *mod,struct _ddebug_info *dyndbg) -{ -if (!dyndbg->num_descs) -return ; -ddebug_add_module (dyndbg, mod->name); -} - -static void dynamic_debug_remove (struct module *mod,struct _ddebug_info *dyndbg) -{ -if (dyndbg->num_descs) -ddebug_remove_module (mod->name); -} -void *__weak module_alloc (unsigned long size) { return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
@@ -2137,10 +2121,14 @@ static int find_module_sections(struct module *mod, struct load_info *info)if (section_addr (info,"__obsparm" ))pr_warn ("%s: Ignoring obsolete parameters\n" , mod->name); - info->dyndbg.descs =section_objs (info,"__dyndbg" , -sizeof (*info->dyndbg.descs), &info->dyndbg.num_descs); - info->dyndbg.classes =section_objs (info,"__dyndbg_classes" , -sizeof (*info->dyndbg.classes), &info->dyndbg.num_classes); +#ifdef CONFIG_DYNAMIC_DEBUG_CORE + mod->dyndbg_info.descs =section_objs (info,"__dyndbg" , +sizeof (*mod->dyndbg_info.descs), + &mod->dyndbg_info.num_descs); + mod->dyndbg_info.classes =section_objs (info,"__dyndbg_classes" , +sizeof (*mod->dyndbg_info.classes), + &mod->dyndbg_info.num_classes); +#endif return 0 ; }
@@ -2824,7 +2812,6 @@ static int load_module(struct load_info *info, const char __user *uargs, }init_build_id (mod, info); -dynamic_debug_setup (mod, &info->dyndbg);/* Ftrace init must be called in the MODULE_STATE_UNFORMED state */ ftrace_module_init (mod);
@@ -2888,7 +2875,6 @@ static int load_module(struct load_info *info, const char __user *uargs, ddebug_cleanup:ftrace_release_mod (mod); -dynamic_debug_remove (mod, &info->dyndbg);synchronize_rcu ();kfree (mod->args); free_arch_cleanup:
lib/dynamic_debug.c +41 -9
96 lines not on this page · raw message
Signature · 1 line
2.17.1
kernel test robot
build botRe: [PATCH v3 2/2] dyndbg: use the module notifier callbacks
I love your patch! Perhaps something to improve:
Hi Jason,
I love your patch! Perhaps something to improve:
[auto build test WARNING on mcgrof/modules-next]
[also build test WARNING on linus/master v6.2 next-20230303] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jason-Baron/dyndbg-remove-unused-base-arg-from-__ddebug_add_module/20230304-005435 base: https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next patch link: https://lore.kernel.org/r/5884c688d10c9703fb0457f8839d6becc8657f8f.1677861177.git.jbaron%40akamai.com patch subject: [PATCH v3 2/2] dyndbg: use the module notifier callbacks config: arm-randconfig-r032-20230302 (https://download.01.org/0day-ci/archive/20230304/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 67409911353323ca5edf2049ef0df54132fa1ca7)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/intel-lab-lkp/linux/commit/0505a1e5b9d22b48fe25399b8013a48cf7f42efb
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jason-Baron/dyndbg-remove-unused-base-arg-from-__ddebug_add_module/20230304-005435 git checkout 0505a1e5b9d22b48fe25399b8013a48cf7f42efb
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/infiniband/ulp/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/infiniband/ulp/srp/ib_srp.c:66:9: warning: 'DEFINE_DYNAMIC_DEBUG_METADATA' macro redefined [-Wmacro-redefined]
#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt)
^
include/linux/dynamic_debug.h:174:9: note: previous definition is here
#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \
^
>> drivers/infiniband/ulp/srp/ib_srp.c:67:9: warning: 'DYNAMIC_DEBUG_BRANCH' macro redefined [-Wmacro-redefined]
#define DYNAMIC_DEBUG_BRANCH(descriptor) false
^
include/linux/dynamic_debug.h:188:9: note: previous definition is here
#define DYNAMIC_DEBUG_BRANCH(descriptor) \
^2 warnings generated.
vim +/DEFINE_DYNAMIC_DEBUG_METADATA +66 drivers/infiniband/ulp/srp/ib_srp.c
aef9ec39c47f0c Roland Dreier 2005-11-02 64
1a1faf7a8a251d Bart Van Assche 2016-11-21 65 #if !defined(CONFIG_DYNAMIC_DEBUG) 1a1faf7a8a251d Bart Van Assche 2016-11-21 @66 #define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) 1a1faf7a8a251d Bart Van Assche 2016-11-21 @67 #define DYNAMIC_DEBUG_BRANCH(descriptor) false 1a1faf7a8a251d Bart Van Assche 2016-11-21 68 #endif
1a1faf7a8a251d Bart Van Assche 2016-11-21 69
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Re: [PATCH v3 2/2] dyndbg: use the module notifier callbacks
In reply to Jason BaronQuoted 18 lines
Bring dynamic debug in line with other subsystems by using the module notifier callbacks. This results in a net decrease in core module code.
Additionally, Jim Cromie has a new dynamic debug classmap feature, which requires that jump labels be initialized prior to dynamic debug. Specifically, the new feature toggles a jump label from the existing
dynamic_debug_setup()function. However, this does not currently work properly, because jump labels are initialized via the 'module_notify_list' notifier chain, which is invoked after the current call todynamic_debug_setup(). Thus, this patch ensures that jump labels are initialized prior to dynamic debug by setting the dynamic debug notifier priority to 0, while jump labels have the higher priority of 1.Tested by Jim using his new test case, and I've verfied the correct printing via: # modprobe
test_dynamic_debugdyndbg.
Quoted 9 lines
Reported-by kernel test robot <[email protected]>Tested-by Jim Cromie <[email protected]>Cc Peter Zijlstra <[email protected]>CC Jim Cromie <[email protected]>Cc Luis Chamberlain <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Jason Baron <[email protected]>
Luis Chamberlain
maintainerRe: [PATCH v3 2/2] dyndbg: use the module notifier callbacks
Quoted 28 lines · Vincenzo Palazzo
Quoted 18 lines
Bring dynamic debug in line with other subsystems by using the module notifier callbacks. This results in a net decrease in core module code.
Additionally, Jim Cromie has a new dynamic debug classmap feature, which requires that jump labels be initialized prior to dynamic debug. Specifically, the new feature toggles a jump label from the existing
dynamic_debug_setup()function. However, this does not currently work properly, because jump labels are initialized via the 'module_notify_list' notifier chain, which is invoked after the current call todynamic_debug_setup(). Thus, this patch ensures that jump labels are initialized prior to dynamic debug by setting the dynamic debug notifier priority to 0, while jump labels have the higher priority of 1.Tested by Jim using his new test case, and I've verfied the correct printing via: # modprobe
test_dynamic_debugdyndbg.Quoted 9 lines
Reported-by kernel test robot <[email protected]>Tested-by Jim Cromie <[email protected]>Cc Peter Zijlstra <[email protected]>CC Jim Cromie <[email protected]>Cc Luis Chamberlain <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Jason Baron <[email protected]>
Quoted 1 line
Reviewed-by Vincenzo Palazzo <[email protected]>
Tag applied too thanks.
Luis
Luis Chamberlain
maintainerQuoted 9 lines · Jason Baron
Hi,
Jim Cromie hit a
BUG()while toggling jump label branches in a module before they were properly initialized. This isn't currently an issue, but will be as part of his pending classmap series. Seems like we should covert to using module callback notifier for dynamic debug anyways to match other subsystems and remove core module code. First patch is just a cleanup.
Quoted 5 lines
I've rebased this series onto modules-next tree. Although the first patch is a cleanup entirely internal to dynamic debug I think it's a nice cleanup to have as part of this series.
Thanks! Queued onto modules-next.
Luis