Message ID | 165461826247.280167.11939123218334322352.stgit@devnote2 (mailing list archive) |
---|---|
State | Accepted |
Delegated to: | BPF |
Headers | show |
Series | rethook: Reject getting a rethook if RCU is not watching | expand |
On Wed, 8 Jun 2022 01:11:02 +0900 "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote: > > static void sample_entry_handler(struct fprobe *fp, unsigned long ip, struct pt_regs *regs) > { > - pr_info("Enter <%pS> ip = 0x%p\n", (void *)ip, (void *)ip); > + if (use_trace) > + trace_printk("Enter <%pS> ip = 0x%p\n", (void *)ip, (void *)ip); Could we add a comment stating something like "this is just an example, no kernel code should call trace_printk() except when actively debugging". -- Steve > + else > + pr_info("Enter <%pS> ip = 0x%p\n", (void *)ip, (void *)ip); > + nhit++; > if (stackdump) > show_backtrace(); > } > @@ -49,8 +56,13 @@ static void sample_exit_handler(struct fprobe *fp, unsigned long ip, struct pt_r > { > unsigned long rip = instruction_pointer(regs); > > - pr_info("Return from <%pS> ip = 0x%p to rip = 0x%p (%pS)\n", > - (void *)ip, (void *)ip, (void *)rip, (void *)rip); > + if (use_trace) > + trace_printk("Return from <%pS> ip = 0x%p to rip = 0x%p (%pS)\n", > + (void *)ip, (void *)ip, (void *)rip, (void *)rip); > + else > + pr_info("Return from <%pS> ip = 0x%p to rip = 0x%p (%pS)\n", > + (void *)ip, (void *)ip, (void *)rip, (void *)rip); > + nhit++; > if (stackdump) > show_backtrace();
On Fri, 17 Jun 2022 12:06:51 -0400 Steven Rostedt <rostedt@goodmis.org> wrote: > On Wed, 8 Jun 2022 01:11:02 +0900 > "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote: > > > > > static void sample_entry_handler(struct fprobe *fp, unsigned long ip, struct pt_regs *regs) > > { > > - pr_info("Enter <%pS> ip = 0x%p\n", (void *)ip, (void *)ip); > > + if (use_trace) > > + trace_printk("Enter <%pS> ip = 0x%p\n", (void *)ip, (void *)ip); > > Could we add a comment stating something like "this is just an example, no > kernel code should call trace_printk() except when actively debugging". Indeed. I also add a description for this option so that user can understand this is just a debug option. Thank you,
diff --git a/samples/fprobe/fprobe_example.c b/samples/fprobe/fprobe_example.c index 24d3cf109140..aad5af0278f4 100644 --- a/samples/fprobe/fprobe_example.c +++ b/samples/fprobe/fprobe_example.c @@ -21,6 +21,7 @@ #define BACKTRACE_DEPTH 16 #define MAX_SYMBOL_LEN 4096 struct fprobe sample_probe; +static unsigned long nhit; static char symbol[MAX_SYMBOL_LEN] = "kernel_clone"; module_param_string(symbol, symbol, sizeof(symbol), 0644); @@ -28,6 +29,8 @@ static char nosymbol[MAX_SYMBOL_LEN] = ""; module_param_string(nosymbol, nosymbol, sizeof(nosymbol), 0644); static bool stackdump = true; module_param(stackdump, bool, 0644); +static bool use_trace = false; +module_param(use_trace, bool, 0644); static void show_backtrace(void) { @@ -40,7 +43,11 @@ static void show_backtrace(void) static void sample_entry_handler(struct fprobe *fp, unsigned long ip, struct pt_regs *regs) { - pr_info("Enter <%pS> ip = 0x%p\n", (void *)ip, (void *)ip); + if (use_trace) + trace_printk("Enter <%pS> ip = 0x%p\n", (void *)ip, (void *)ip); + else + pr_info("Enter <%pS> ip = 0x%p\n", (void *)ip, (void *)ip); + nhit++; if (stackdump) show_backtrace(); } @@ -49,8 +56,13 @@ static void sample_exit_handler(struct fprobe *fp, unsigned long ip, struct pt_r { unsigned long rip = instruction_pointer(regs); - pr_info("Return from <%pS> ip = 0x%p to rip = 0x%p (%pS)\n", - (void *)ip, (void *)ip, (void *)rip, (void *)rip); + if (use_trace) + trace_printk("Return from <%pS> ip = 0x%p to rip = 0x%p (%pS)\n", + (void *)ip, (void *)ip, (void *)rip, (void *)rip); + else + pr_info("Return from <%pS> ip = 0x%p to rip = 0x%p (%pS)\n", + (void *)ip, (void *)ip, (void *)rip, (void *)rip); + nhit++; if (stackdump) show_backtrace(); } @@ -112,7 +124,8 @@ static void __exit fprobe_exit(void) { unregister_fprobe(&sample_probe); - pr_info("fprobe at %s unregistered\n", symbol); + pr_info("fprobe at %s unregistered. %ld times hit, %ld times missed\n", + symbol, nhit, sample_probe.nmissed); } module_init(fprobe_init)