Message ID | 168873727209.2687993.6806850187024303094.stgit@mhiramat.roam.corp.google.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | tracing/probes: Fix bugs in process_fetch_insn | expand |
On Fri, 7 Jul 2023 22:41:12 +0900 "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote: > diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h > index c4e1d4c03a85..6deae2ce34f8 100644 > --- a/kernel/trace/trace_probe_kernel.h > +++ b/kernel/trace/trace_probe_kernel.h > @@ -2,8 +2,6 @@ > #ifndef __TRACE_PROBE_KERNEL_H_ > #define __TRACE_PROBE_KERNEL_H_ > > -#define FAULT_STRING "(fault)" > - Instead of deleting this, why not use it in both places? After applying your patch, we have: $ git grep '(fault)' kernel/trace kernel/trace/trace_events_synth.c: strcpy(str_field, "(fault)"); kernel/trace/trace_probe.c: trace_seq_puts(s, "(fault)"); We could make that consistent with: kernel/trace/trace_events_synth.c: strcpy(str_field, FAULT_STRING); kernel/trace/trace_probe.c: trace_seq_puts(s, FAULT_STRING); -- Steve
On Fri, 7 Jul 2023 10:14:20 -0400 Steven Rostedt <rostedt@goodmis.org> wrote: > On Fri, 7 Jul 2023 22:41:12 +0900 > "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote: > > > diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h > > index c4e1d4c03a85..6deae2ce34f8 100644 > > --- a/kernel/trace/trace_probe_kernel.h > > +++ b/kernel/trace/trace_probe_kernel.h > > @@ -2,8 +2,6 @@ > > #ifndef __TRACE_PROBE_KERNEL_H_ > > #define __TRACE_PROBE_KERNEL_H_ > > > > -#define FAULT_STRING "(fault)" > > - > > Instead of deleting this, why not use it in both places? After applying > your patch, we have: > > $ git grep '(fault)' kernel/trace > kernel/trace/trace_events_synth.c: strcpy(str_field, "(fault)"); > kernel/trace/trace_probe.c: trace_seq_puts(s, "(fault)"); > > We could make that consistent with: > > kernel/trace/trace_events_synth.c: strcpy(str_field, FAULT_STRING); > kernel/trace/trace_probe.c: trace_seq_puts(s, FAULT_STRING); Indeed. So can I tweak the revert patch more for this? I would like to move the definition to trace.h. Thanks, > > -- Steve >
On Sat, 8 Jul 2023 00:46:43 +0900 Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote: > Indeed. So can I tweak the revert patch more for this? > > I would like to move the definition to trace.h. Sure. -- Steve
On Fri, 7 Jul 2023 11:48:17 -0400 Steven Rostedt <rostedt@goodmis.org> wrote: > On Sat, 8 Jul 2023 00:46:43 +0900 > Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote: > > > Indeed. So can I tweak the revert patch more for this? > > > > I would like to move the definition to trace.h. > > Sure. OK, let me update the patch. Thanks! > > -- Steve
diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c index d6a70aff2410..23416ec8e1da 100644 --- a/kernel/trace/trace_events_synth.c +++ b/kernel/trace/trace_events_synth.c @@ -478,7 +478,7 @@ static unsigned int trace_string(struct synth_trace_event *entry, ret = strncpy_from_kernel_nofault(str_field, str_val, STR_VAR_LEN_MAX); if (ret < 0) - strcpy(str_field, FAULT_STRING); + strcpy(str_field, "(fault)"); (*n_u64) += STR_VAR_LEN_MAX / sizeof(u64); } diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h index c4e1d4c03a85..6deae2ce34f8 100644 --- a/kernel/trace/trace_probe_kernel.h +++ b/kernel/trace/trace_probe_kernel.h @@ -2,8 +2,6 @@ #ifndef __TRACE_PROBE_KERNEL_H_ #define __TRACE_PROBE_KERNEL_H_ -#define FAULT_STRING "(fault)" - /* * This depends on trace_probe.h, but can not include it due to * the way trace_probe_tmpl.h is used by trace_kprobe.c and trace_eprobe.c. @@ -15,16 +13,8 @@ static nokprobe_inline int fetch_store_strlen_user(unsigned long addr) { const void __user *uaddr = (__force const void __user *)addr; - int ret; - ret = strnlen_user_nofault(uaddr, MAX_STRING_SIZE); - /* - * strnlen_user_nofault returns zero on fault, insert the - * FAULT_STRING when that occurs. - */ - if (ret <= 0) - return strlen(FAULT_STRING) + 1; - return ret; + return strnlen_user_nofault(uaddr, MAX_STRING_SIZE); } /* Return the length of string -- including null terminal byte */ @@ -44,18 +34,7 @@ fetch_store_strlen(unsigned long addr) len++; } while (c && ret == 0 && len < MAX_STRING_SIZE); - /* For faults, return enough to hold the FAULT_STRING */ - return (ret < 0) ? strlen(FAULT_STRING) + 1 : len; -} - -static nokprobe_inline void set_data_loc(int ret, void *dest, void *__dest, void *base, int len) -{ - if (ret >= 0) { - *(u32 *)dest = make_data_loc(ret, __dest - base); - } else { - strscpy(__dest, FAULT_STRING, len); - ret = strlen(__dest) + 1; - } + return (ret < 0) ? ret : len; } /* @@ -76,7 +55,8 @@ fetch_store_string_user(unsigned long addr, void *dest, void *base) __dest = get_loc_data(dest, base); ret = strncpy_from_user_nofault(__dest, uaddr, maxlen); - set_data_loc(ret, dest, __dest, base, maxlen); + if (ret >= 0) + *(u32 *)dest = make_data_loc(ret, __dest - base); return ret; } @@ -107,7 +87,8 @@ fetch_store_string(unsigned long addr, void *dest, void *base) * probing. */ ret = strncpy_from_kernel_nofault(__dest, (void *)addr, maxlen); - set_data_loc(ret, dest, __dest, base, maxlen); + if (ret >= 0) + *(u32 *)dest = make_data_loc(ret, __dest - base); return ret; }