tracing/probes: Cleanup probe event code
Masami Hiramatsu (Google)
maintainercover tracing/probes: Cleanup probe event code
Hi,
Here are a patches to cleanup the probe events related code (kernel/trace/trace_*probe*).
Thank you,
---
base-commit: 1a416ae446afa42d2d8500ce25bd61c564508721
Masami Hiramatsu (Google) (10):
tracing/probes: Remove duplicate MAX_ARRAY_LEN macro definition tracing/probes: Remove redundant boolean conversion in trace_probe_has_single_file() tracing/probes: Remove redundant bounds check in trace_probe_compare_arg_type() tracing/probes: Remove unused parameter from parse_probe_var_retval() tracing/probes: Cleanup pointer arithmetic in store_trace_entry_data() tracing/probes: Simplify BTF_KIND_PTR case in fetch_type_from_btf_type() tracing/fprobe: Remove redundant snprintf in trace_fprobe_match_command_head() tracing/fprobe: Remove redundant memset in fentry_perf_func() tracing/kprobe: Remove redundant memset in kprobe_perf_func() tracing/probes: Fix extra whitespace in trace_probe_kernel.h
kernel/trace/trace_fprobe.c | 6 +----- kernel/trace/trace_kprobe.c | 1 - kernel/trace/trace_probe.c | 18 +++++++----------- kernel/trace/trace_probe.h | 3 +-- kernel/trace/trace_probe_kernel.h | 2 +- 5 files changed, 10 insertions(+), 20 deletions(-)
--
Masami Hiramatsu (Google) <[email protected]>
Masami Hiramatsu (Google)
maintainerPATCH 1/10 tracing/probes: Remove duplicate MAX_ARRAY_LEN macro definition
From: Masami Hiramatsu (Google) <[email protected]>
MAX_ARRAY_LEN is defined twice in trace_probe.h. Remove the redundant definition.
--- kernel/trace/trace_probe.h | 1 - 1 file changed, 1 deletion(-)
kernel/trace/trace_probe.h +0 -1
@@ -220,7 +220,6 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(symbol); _ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, atype)#define ASSIGN_FETCH_TYPE_END {} -#define MAX_ARRAY_LEN 64#ifdef CONFIG_KPROBE_EVENTS bool trace_kprobe_on_func_entry (struct trace_event_call *call);
Masami Hiramatsu (Google)
maintainerPATCH 2/10 tracing/probes: Remove redundant boolean conversion in trace_probe_has_single_file()
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
list_is_singular() returns a boolean value, so the double negation (!!) in trace_probe_has_single_file() is redundant. Remove it.
--- kernel/trace/trace_probe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_probe.h +1 -1
@@ -360,7 +360,7 @@ static inline int trace_probe_unregister_event_call(struct trace_probe *tp)static inline bool trace_probe_has_single_file (struct trace_probe *tp) { -return !!list_is_singular (&tp->event->files); +return list_is_singular (&tp->event->files); } int trace_probe_init(struct trace_probe *tp, const char *event,
Masami Hiramatsu (Google)
maintainerPATCH 3/10 tracing/probes: Remove redundant bounds check in trace_probe_compare_arg_type()
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
In trace_probe_compare_arg_type(), prior to entering the comparison loop, a->nr_args and b->nr_args are checked for equality. Since the loop condition is i < a->nr_args, i is guaranteed to be less than b->nr_args inside the loop.
Remove the redundant (b->nr_args <= i) check.
--- kernel/trace/trace_probe.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/trace/trace_probe.c +3 -4
@@ -2770,10 +2770,9 @@ int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b)return b->nr_args +1 ;for (i =0 ; i < a->nr_args; i++) { -if ((b->nr_args <= i) || - ((a->args[i].type != b->args[i].type) || - (a->args[i].count != b->args[i].count) || -strcmp (a->args[i].name, b->args[i].name))) +if ((a->args[i].type != b->args[i].type) || + (a->args[i].count != b->args[i].count) || +strcmp (a->args[i].name, b->args[i].name))return i +1 ; }
Masami Hiramatsu (Google)
maintainerPATCH 4/10 tracing/probes: Remove unused parameter from parse_probe_var_retval()
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
The parameter 'arg' in parse_probe_var_retval() is unused. Remove it and update its caller accordingly.
--- kernel/trace/trace_probe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_probe.c +2 -2
@@ -1262,7 +1262,7 @@ NOKPROBE_SYMBOL(store_trace_entry_data)#define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long)) -static int parse_probe_var_retval (char *orig_arg,char *arg, +static int parse_probe_var_retval (char *orig_arg,struct fetch_insn **pcode,struct fetch_insn *end,struct traceprobe_parse_context *ctx)
@@ -1415,7 +1415,7 @@ static int parse_probe_vars(char *orig_arg, const struct fetch_type *t, goto inval;if (str_has_prefix (arg,"retval" )) -return parse_probe_var_retval (orig_arg, arg, pcode, end, ctx); +return parse_probe_var_retval (orig_arg, pcode, end, ctx); len =str_has_prefix (arg,"stack" );if (len)
Masami Hiramatsu (Google)
maintainerPATCH 5/10 tracing/probes: Cleanup pointer arithmetic in store_trace_entry_data()
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
In store_trace_entry_data(), edata is cast to unsigned long for pointer offset arithmetic before being cast back to unsigned long *. Cast edata to u8 * instead.
--- kernel/trace/trace_probe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_probe.c +1 -1
@@ -1246,7 +1246,7 @@ void store_trace_entry_data(void *edata, struct trace_probe *tp, struct pt_regs val =regs_get_kernel_argument (regs, code->param);break ;case FETCH_OP_ST_EDATA : - *(unsigned long *)((unsigned long )edata + code->offset) = val; + *(unsigned long *)((u8 *)edata + code->offset) = val;break ;case FETCH_OP_END : goto end;
Masami Hiramatsu (Google)
maintainerPATCH 6/10 tracing/probes: Simplify BTF_KIND_PTR case in fetch_type_from_btf_type()
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Use a ternary operator for checking IS_ENABLED(CONFIG_64BIT) in the BTF_KIND_PTR case of fetch_type_from_btf_type() to simplify the code.
--- kernel/trace/trace_probe.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
kernel/trace/trace_probe.c +1 -4
@@ -495,10 +495,7 @@ static const char *fetch_type_from_btf_type(struct btf *btf,return "s64" ;case BTF_KIND_PTR :/* pointer will be converted to "x??" */ -if (IS_ENABLED (CONFIG_64BIT )) -return "x64" ; -else -return "x32" ; +return IS_ENABLED (CONFIG_64BIT ) ?"x64" :"x32" ;case BTF_KIND_INT : intdata =btf_type_int (type);if (BTF_INT_ENCODING (intdata) &BTF_INT_SIGNED ) {
Masami Hiramatsu (Google)
maintainerPATCH 7/10 tracing/fprobe: Remove redundant snprintf in trace_fprobe_match_command_head()
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
trace_fprobe_match_command_head() copies trace_fprobe_symbol(tf) into a local buffer 'buf' of size MAX_COMMON_HEAD_LEN + 1 using snprintf before comparing with argv[0].
Since trace_fprobe_symbol(tf) already returns a null-terminated string, comparing it directly with argv[0] via strcmp() avoids stack buffer usage and potential symbol truncation at MAX_COMMON_HEAD_LEN.
--- kernel/trace/trace_fprobe.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
kernel/trace/trace_fprobe.c +1 -4
@@ -238,13 +238,10 @@ static bool trace_fprobe_is_busy(struct dyn_event *ev)static bool trace_fprobe_match_command_head (struct trace_fprobe *tf,int argc,const char **argv) { -char buf[MAX_COMMON_HEAD_LEN +1 ]; -if (!argc)return true; -snprintf (buf,sizeof (buf),"%s" ,trace_fprobe_symbol (tf)); -if (strcmp (buf, argv[0 ])) +if (strcmp (trace_fprobe_symbol (tf), argv[0 ]))return false; argc--; argv++;
Masami Hiramatsu (Google)
maintainerPATCH 8/10 tracing/fprobe: Remove redundant memset in fentry_perf_func()
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
fentry_perf_func() calls memset(&entry[1], 0, dsize) prior to calling store_trace_args(). store_trace_args() populates the entry buffer and handles dynamic data fields.
Furthermore, passing dsize (the dynamic data byte length) to memset at &entry[1] (the start of fixed trace arguments) is inaccurate as it zeroes from the fixed args area rather than the dynamic data region.
Remove this redundant memset call to align with fexit_perf_func() and other probe perf functions.
--- kernel/trace/trace_fprobe.c | 1 - 1 file changed, 1 deletion(-)
kernel/trace/trace_fprobe.c +0 -1
@@ -471,7 +471,6 @@ static int fentry_perf_func(struct trace_fprobe *tf, unsigned long entry_ip, regs =ftrace_fill_perf_regs (fregs, regs); entry->ip = entry_ip; -memset (&entry[1 ],0 , dsize);store_trace_args (&entry[1 ], &tf->tp, fregs,NULL ,sizeof (*entry), dsize);perf_trace_buf_submit (entry, size, rctx, call->event.type,1 , regs, head,NULL );
Masami Hiramatsu (Google)
maintainerPATCH 9/10 tracing/kprobe: Remove redundant memset in kprobe_perf_func()
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
kprobe_perf_func() calls memset(&entry[1], 0, dsize) prior to calling store_trace_args(). store_trace_args() populates the entry buffer and handles dynamic data fields.
Remove this redundant memset call to align with kretprobe_perf_func() and other probe perf functions.
--- kernel/trace/trace_kprobe.c | 1 - 1 file changed, 1 deletion(-)
kernel/trace/trace_kprobe.c +0 -1
@@ -1721,7 +1721,6 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)return 0 ; entry->ip = (unsigned long )tk->rp.kp.addr; -memset (&entry[1 ],0 , dsize);store_trace_args (&entry[1 ], &tk->tp, regs,NULL ,sizeof (*entry), dsize);perf_trace_buf_submit (entry, size, rctx, call->event.type,1 , regs, head,NULL );
Masami Hiramatsu (Google)
maintainerPATCH 10/10 tracing/probes: Fix extra whitespace in trace_probe_kernel.h
In reply to Masami Hiramatsu (Google)From: Masami Hiramatsu (Google) <[email protected]>
Clean up extra space after '=' in fetch_store_strlen_user().
--- kernel/trace/trace_probe_kernel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_probe_kernel.h +1 -1
@@ -12,7 +12,7 @@ static nokprobe_inline intfetch_store_strlen_user (unsigned long addr) { -const void __user *uaddr = (__force const void __user *)addr; +const void __user *uaddr = (__force const void __user *)addr;return strnlen_user_nofault (uaddr,MAX_STRING_SIZE ); }