From patchwork Mon Jan 31 16:36:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 12730877 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7EC8C433FE for ; Mon, 31 Jan 2022 16:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349716AbiAaQgv (ORCPT ); Mon, 31 Jan 2022 11:36:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380521AbiAaQgu (ORCPT ); Mon, 31 Jan 2022 11:36:50 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28707C06173B for ; Mon, 31 Jan 2022 08:36:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EA91BB82BA1 for ; Mon, 31 Jan 2022 16:36:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C64FDC340F0; Mon, 31 Jan 2022 16:36:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.95) (envelope-from ) id 1nEZfa-00BYaj-QF; Mon, 31 Jan 2022 11:36:46 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 1/4] libtracefs: Initialized func_list in tracefs_filter_functions() Date: Mon, 31 Jan 2022 11:36:39 -0500 Message-Id: <20220131163642.2754485-2-rostedt@goodmis.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220131163642.2754485-1-rostedt@goodmis.org> References: <20220131163642.2754485-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" The variable func_list is used to create a link list and it is expected to be NULL. This causes a crash because of the logic checks it before it gets initialized. Initialize func_list to NULL. This was found by valgrind after a crash. Fixes: c1606fb72264a ("libtracefs: Implement tracefs_filter_functions()") Signed-off-by: Steven Rostedt (Google) --- src/tracefs-tools.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c index ae85444b67dd..489be28a3b94 100644 --- a/src/tracefs-tools.c +++ b/src/tracefs-tools.c @@ -1237,7 +1237,7 @@ void tracefs_trace_pipe_stop(struct tracefs_instance *instance) int tracefs_filter_functions(const char *filter, const char *module, char ***list) { struct func_filter func_filter; - struct func_list *func_list, *f; + struct func_list *func_list = NULL, *f; char **funcs = NULL; int ret; From patchwork Mon Jan 31 16:36:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 12730876 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72E59C433F5 for ; Mon, 31 Jan 2022 16:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380523AbiAaQgu (ORCPT ); Mon, 31 Jan 2022 11:36:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349716AbiAaQgu (ORCPT ); Mon, 31 Jan 2022 11:36:50 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EED16C061714 for ; Mon, 31 Jan 2022 08:36:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BAC54B82B88 for ; Mon, 31 Jan 2022 16:36:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93575C340E8; Mon, 31 Jan 2022 16:36:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.95) (envelope-from ) id 1nEZfa-00BYam-Qy; Mon, 31 Jan 2022 11:36:46 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 2/4] libtracefs: Fix tracefs_synth_echo_cmd() Date: Mon, 31 Jan 2022 11:36:40 -0500 Message-Id: <20220131163642.2754485-3-rostedt@goodmis.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220131163642.2754485-1-rostedt@goodmis.org> References: <20220131163642.2754485-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" The update to use dynamic_events instead of synthetic_events for echoing the synthetic event missed out on adding the colon, and made the output incorrect for the new format. Fixes: d7c5dbb7a231e ("libtracefs: Use the internal dynamic events API when creating synthetic events") Signed-off-by: Steven Rostedt (Google) --- src/tracefs-hist.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 8d99492c84a7..622fe5c98c41 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -2155,8 +2155,10 @@ int tracefs_synth_echo_cmd(struct trace_seq *seq, if (!path) goto out_free; - trace_seq_printf(seq, "echo '%s%s %s' > %s/%s\n", - synth->dyn_event->prefix, synth->dyn_event->event, + trace_seq_printf(seq, "echo '%s%s%s %s' > %s/%s\n", + synth->dyn_event->prefix, + strlen(synth->dyn_event->prefix) ? ":" : "", + synth->dyn_event->event, synth->dyn_event->format, path, synth->dyn_event->trace_file); tracefs_put_tracing_file(path); From patchwork Mon Jan 31 16:36:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 12730875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61D34C433F5 for ; Mon, 31 Jan 2022 16:36:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380512AbiAaQgs (ORCPT ); Mon, 31 Jan 2022 11:36:48 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:46956 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349716AbiAaQgs (ORCPT ); Mon, 31 Jan 2022 11:36:48 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 623F4608C1 for ; Mon, 31 Jan 2022 16:36:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1208C340EE; Mon, 31 Jan 2022 16:36:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.95) (envelope-from ) id 1nEZfa-00BYap-Ra; Mon, 31 Jan 2022 11:36:46 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 3/4] libtracefs: Check README to know if we should do old onmatch format Date: Mon, 31 Jan 2022 11:36:41 -0500 Message-Id: <20220131163642.2754485-4-rostedt@goodmis.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220131163642.2754485-1-rostedt@goodmis.org> References: <20220131163642.2754485-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" Older kernels use: onmatch(..).synth_event(...) Where the "synth_event" is the synthetic event that was created. The new format uses: onmatch(..).trace(synth_event,...) Where it uses the new "trace" command and the synthetic event is the first parameter. The tracefs README can determine which format is used. Search the README and if the string "trace(,param list)" is found, then we know that the kernel uses the new format. Yes, the README in the tracefs file system *is* an ABI. Fixes: 7c9000c7495b9 ("libtracefs: Create a way to create a synthetic event") Signed-off-by: Steven Rostedt (Google) --- src/tracefs-hist.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 622fe5c98c41..ec63b88a0bca 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -674,6 +674,7 @@ struct action { * @end_filters: The fields in the end event to record * @start_parens: Current parenthesis level for start event * @end_parens: Current parenthesis level for end event + * @new_format: onmatch().trace(synth_event,..) or onmatch().synth_event(...) */ struct tracefs_synth { struct tracefs_instance *instance; @@ -702,6 +703,7 @@ struct tracefs_synth { int *start_type; char arg_name[16]; int arg_cnt; + bool new_format; }; /* @@ -949,6 +951,26 @@ static int alloc_synthetic_event(struct tracefs_synth *synth) return synth->dyn_event ? 0 : -1; } +/* + * See if it is onmatch().trace(synth_event,...) or + * onmatch().synth_event(...) + */ +static bool has_new_format() +{ + char *readme; + char *p; + int size; + + readme = tracefs_instance_file_read(NULL, "README", &size); + if (!readme) + return false; + + p = strstr(readme, "trace(,param list)"); + free(readme); + + return p != NULL; +} + /** * tracefs_synth_alloc - create a new tracefs_synth instance * @tep: The tep handle that holds the events to work on @@ -1037,6 +1059,8 @@ struct tracefs_synth *tracefs_synth_alloc(struct tep_handle *tep, synth = NULL; } + synth->new_format = has_new_format(); + return synth; } @@ -1730,13 +1754,21 @@ static char *create_trace(char *hist, struct tracefs_synth *synth) char *name; int i; - hist = append_string(hist, NULL, ".trace("); - hist = append_string(hist, NULL, synth->name); + if (synth->new_format) { + hist = append_string(hist, NULL, ".trace("); + hist = append_string(hist, NULL, synth->name); + hist = append_string(hist, NULL, ","); + } else { + hist = append_string(hist, NULL, "."); + hist = append_string(hist, NULL, synth->name); + hist = append_string(hist, NULL, "("); + } for (i = 0; synth->synthetic_args && synth->synthetic_args[i]; i++) { name = synth->synthetic_args[i]; - hist = append_string(hist, NULL, ","); + if (i) + hist = append_string(hist, NULL, ","); hist = append_string(hist, NULL, name); } From patchwork Mon Jan 31 16:36:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 12730878 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9F78C4332F for ; Mon, 31 Jan 2022 16:36:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380522AbiAaQgw (ORCPT ); Mon, 31 Jan 2022 11:36:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380516AbiAaQgu (ORCPT ); Mon, 31 Jan 2022 11:36:50 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C84AC06173E for ; Mon, 31 Jan 2022 08:36:50 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0E165B82B9E for ; Mon, 31 Jan 2022 16:36:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1282C340F2; Mon, 31 Jan 2022 16:36:47 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.95) (envelope-from ) id 1nEZfa-00BYas-SE; Mon, 31 Jan 2022 11:36:46 -0500 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: "Steven Rostedt (Google)" Subject: [PATCH 4/4] libtracefs: Have synthetic events use types pid_t, gfp_t and bool Date: Mon, 31 Jan 2022 11:36:42 -0500 Message-Id: <20220131163642.2754485-5-rostedt@goodmis.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220131163642.2754485-1-rostedt@goodmis.org> References: <20220131163642.2754485-1-rostedt@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (Google)" The synthetic events understand pid_t, gfp_t and bool, and it is better to use them, as some kernels have bugs where a field with one of the above types may not match the raw format they are. That is, pid_t may not match s32, even though they are the same type! Fixes: 7c9000c7495b9 ("libtracefs: Create a way to create a synthetic event") Signed-off-by: Steven Rostedt (Google) --- src/tracefs-hist.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index ec63b88a0bca..e7dd279ae3f9 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -841,6 +841,15 @@ static char *add_synth_field(const struct tep_format_field *field, return append_string(str, NULL, "];"); } + /* Synthetic events understand pid_t, gfp_t and bool */ + if (strcmp(field->type, "pid_t") == 0 || + strcmp(field->type, "gfp_t") == 0 || + strcmp(field->type, "bool") == 0) { + str = strdup(field->type); + str = append_string(str, " ", name); + return append_string(str, NULL, ";"); + } + sign = field->flags & TEP_FIELD_IS_SIGNED; switch (field->size) {