Skip to content

Commit 13b9b6e

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing: Fix module use of trace_bprintk()
On use of trace_printk() there's a macro that determines if the format is static or a variable. If it is static, it defaults to __trace_bprintk() otherwise it uses __trace_printk(). A while ago, Lai Jiangshan added __trace_bprintk(). In that patch, we discussed a way to allow modules to use it. The difference between __trace_bprintk() and __trace_printk() is that for faster processing, just the format and args are stored in the trace instead of running it through a sprintf function. In order to do this, the format used by the __trace_bprintk() had to be persistent. See commit 1ba28e0 The problem comes with trace_bprintk() where the module is unloaded. The pointer left in the buffer is still pointing to the format. To solve this issue, the formats in the module were copied into kernel core. If the same format was used, they would use the same copy (to prevent memory leak). This all worked well until we tried to merge everything. At the time this was written, Lai Jiangshan, Frederic Weisbecker, Ingo Molnar and myself were all touching the same code. When this was merged, we lost the part of it that was in module.c. This kept out the copying of the formats and unloading the module could cause bad pointers left in the ring buffer. This patch adds back (with updates required for current kernel) the module code that sets up the necessary pointers. Cc: Lai Jiangshan <[email protected]> Cc: Rusty Russell <[email protected]> Signed-off-by: Steven Rostedt <[email protected]>
1 parent 034c6ef commit 13b9b6e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

kernel/module.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,6 +2326,18 @@ static void find_module_sections(struct module *mod, struct load_info *info)
23262326
kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) *
23272327
mod->num_trace_events, GFP_KERNEL);
23282328
#endif
2329+
#ifdef CONFIG_TRACING
2330+
mod->trace_bprintk_fmt_start = section_objs(info, "__trace_printk_fmt",
2331+
sizeof(*mod->trace_bprintk_fmt_start),
2332+
&mod->num_trace_bprintk_fmt);
2333+
/*
2334+
* This section contains pointers to allocated objects in the trace
2335+
* code and not scanning it leads to false positives.
2336+
*/
2337+
kmemleak_scan_area(mod->trace_bprintk_fmt_start,
2338+
sizeof(*mod->trace_bprintk_fmt_start) *
2339+
mod->num_trace_bprintk_fmt, GFP_KERNEL);
2340+
#endif
23292341
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
23302342
/* sechdrs[0].sh_size is always zero */
23312343
mod->ftrace_callsites = section_objs(info, "__mcount_loc",

0 commit comments

Comments
 (0)