[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH0uvohNO517GAD7XH-VvUvU+dPdeZBKDw0Teij50sAPSe9sCQ@mail.gmail.com>
Date: Fri, 1 Nov 2024 14:00:46 -0700
From: Howard Chu <howardchu95@...il.com>
To: Benjamin Peterson <benjamin@...flow.com>
Cc: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>,
Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>,
"Liang, Kan" <kan.liang@...ux.intel.com>,
"open list:PERFORMANCE EVENTS SUBSYSTEM" <linux-perf-users@...r.kernel.org>,
"open list:PERFORMANCE EVENTS SUBSYSTEM" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] perf trace: avoid garbage when not printing a trace
event's arguments
Hello Benjamin,
Before your patch:
perf $ ./perf trace -e net:netif_rx_exit
0.000 irq/79-brcmf_p/1694977 net:netif_rx_exit(6n<)
28.153 irq/79-brcmf_p/1694977 net:netif_rx_exit(6n<)
36.429 irq/79-brcmf_p/1694977 net:netif_rx_exit(6n<)
36.461 irq/79-brcmf_p/1694977 net:netif_rx_exit(6n<)
After:
perf $ ./perf trace -e net:netif_rx_exit
0.000 irq/79-brcmf_p/1694977 net:netif_rx_exit()
7.352 irq/79-brcmf_p/1694977 net:netif_rx_exit()
30.232 irq/79-brcmf_p/1694977 net:netif_rx_exit()
37.529 irq/79-brcmf_p/1694977 net:netif_rx_exit()
It works beautifully, but I'm thinking can we simplify it by just doing:
+ char bf[2048] = { 0 };
size_t size = sizeof(bf);
That being said, trace__fprintf_tp_fields() should return void because
currently its return value is not used by any other functions, plus
this line:
return printed + fprintf(trace->output, "%s", bf);
in trace__fprintf_tp_fields() does not make much sense, since that
will be 2 * printed. So I'm thinking maybe:
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 748b061f8678..8a628d1e80f3 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3021,10 +3021,10 @@ static void bpf_output__fprintf(struct trace *trace,
++trace->nr_events_printed;
}
-static size_t trace__fprintf_tp_fields(struct trace *trace, struct
evsel *evsel, struct perf_sample *sample,
+static void trace__fprintf_tp_fields(struct trace *trace, struct
evsel *evsel, struct perf_sample *sample,
struct thread *thread, void
*augmented_args, int augmented_args_size)
{
- char bf[2048];
+ char bf[2048] = { 0 };
size_t size = sizeof(bf);
struct tep_format_field *field = evsel->tp_format->format.fields;
struct syscall_arg_fmt *arg = __evsel__syscall_arg_fmt(evsel);
@@ -3087,7 +3087,7 @@ static size_t trace__fprintf_tp_fields(struct
trace *trace, struct evsel *evsel,
printed += syscall_arg_fmt__scnprintf_val(arg, bf +
printed, size - printed, &syscall_arg, val);
}
- return printed + fprintf(trace->output, "%s", bf);
+ fprintf(trace->output, "%s", bf);
}
static int trace__event_handler(struct trace *trace, struct evsel *evsel,
Then this will be one more diff line than yours.
But that's just my opinion, yours works just fine, thank you :).
Arnaldo, what do you think?
Tested-by: Howard Chu <howardchu95@...il.com>
Thanks,
Howard
On Fri, Nov 1, 2024 at 10:27 AM Benjamin Peterson <benjamin@...flow.com> wrote:
>
> trace__fprintf_tp_fields may not print any tracepoint arguments. E.g., if the
> argument values are all zero. Previously, this would result in a totally
> uninitialized buffer being passed to fprintf, which could lead to garbage on the
> console. Fix the problem by passing the number of initialized bytes fprintf.
>
> Remove the return value of trace__fprintf_tp_fields, since it was meaningless
> and ignored.
>
> Fixes: f11b2803bb88 ("perf trace: Allow choosing how to augment the tracepoint arguments")
> Signed-off-by: Benjamin Peterson <benjamin@...flow.com>
> ---
> tools/perf/builtin-trace.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index d3f11b90d025..4e785ea29df6 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -3021,7 +3021,7 @@ static void bpf_output__fprintf(struct trace *trace,
> ++trace->nr_events_printed;
> }
>
> -static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample *sample,
> +static void trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel, struct perf_sample *sample,
> struct thread *thread, void *augmented_args, int augmented_args_size)
> {
> char bf[2048];
> @@ -3087,7 +3087,7 @@ static size_t trace__fprintf_tp_fields(struct trace *trace, struct evsel *evsel,
> printed += syscall_arg_fmt__scnprintf_val(arg, bf + printed, size - printed, &syscall_arg, val);
> }
>
> - return printed + fprintf(trace->output, "%s", bf);
> + fprintf(trace->output, "%.*s", (int)printed, bf);
> }
>
> static int trace__event_handler(struct trace *trace, struct evsel *evsel,
> --
> 2.39.5
>
Powered by blists - more mailing lists