From: Masami Hiramatsu (Google) <[email protected]> The +PCPU() dereference operator was introduced in trace probes to access a per-CPU pointer of a CPU local variable. However, kernel developers are more familiar with the "this_cpu_ptr()" macro.
To make trace probe syntax more intuitive and aligned with standard kernel macros, introduce support for "this_cpu_ptr(<fetcharg>)" as a reserved method. Signed-off-by: Masami Hiramatsu (Google) <[email protected]> --- kernel/trace/trace.c | 2 +- kernel/trace/trace_probe.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 2b8c8ac4036a..60ab839d0867 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -4332,7 +4332,7 @@ static const char readme_msg[] = "\t $stack<index>, $stack, $retval, $comm, $current\n" #endif "\t +|-[u]<offset>(<fetcharg>), \\imm-value, \\\"imm-string\"\n" - "\t +CPU(<fetcharg>), +PCPU(<fetcharg>)\n" + "\t +CPU(<fetcharg>), +PCPU(<fetcharg>), this_cpu_ptr(<fetcharg>)\n" "\t kernel return probes support: $retval, $arg<N>, $comm\n" "\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, char, string, symbol,\n" "\t b<bit-width>@<bit-offset>/<container-size>, ustring,\n" diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index fa6757222fe6..27be0664cdf3 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -1315,6 +1315,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type, struct fetch_insn **pcode, struct fetch_insn *end, struct traceprobe_parse_context *ctx) { + static const char *THIS_CPU_PTR_STR = "this_cpu_ptr("; struct fetch_insn *code = *pcode; unsigned long param; int deref = FETCH_OP_DEREF; @@ -1426,6 +1427,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type, ctx->offset += (tmp + 1 - arg) + (arg[0] != '-' ? 1 : 0); arg = tmp + 1; } +handle_deref: tmp = strrchr(arg, ')'); if (!tmp) { trace_probe_log_err(ctx->offset + strlen(arg), @@ -1476,6 +1478,11 @@ parse_probe_arg(char *arg, const struct fetch_type *type, ret = handle_typecast(arg, pcode, end, ctx); break; default: + if (str_has_prefix(arg, THIS_CPU_PTR_STR)) { + arg += strlen(THIS_CPU_PTR_STR); + deref = FETCH_OP_CPU_PTR; + goto handle_deref; + } if (isalpha(arg[0]) || arg[0] == '_') { /* BTF variable */ if (!tparg_is_function_entry(ctx->flags) && !tparg_is_function_return(ctx->flags)) {
