From patchwork Wed May 24 02:11:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 98246 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2544311vqo; Tue, 23 May 2023 19:13:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4MtFHMez5ts7nDPF28Z9OqnWqwotfuJzJYLE0I4yyQ4HDh5VVoAbnzk/vA/h9eME2nFAiz X-Received: by 2002:a17:90b:238f:b0:24d:f77c:71e7 with SMTP id mr15-20020a17090b238f00b0024df77c71e7mr14281325pjb.41.1684894439271; Tue, 23 May 2023 19:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684894439; cv=none; d=google.com; s=arc-20160816; b=Nciv8ZGTPnAnb96qKRtpl+pBJVreQYq4G9OsDiaBjKpl9U+u5M/O6K1WDJEHEIoF41 9hjdcFh2nOTcZ8fvQpuIo4dIzw8LzKA9KymsfQCsz4g3I7p5iuaSAcv6ROwaLSkC0v00 HMV4nP/C1VsmA6z0GFOsdipx5Ou+hnpNqTOJNFJ9hRiWOO7X+zAMLS9qBKMA+WCFlw11 ciF/3Cu+Npy3+cMQbHomQV0lasVwsO9XLpqDgZDd0FiMVRGiH4TUNNrQYP+wB0noMdMn 7TBqcL69/2Ec6gVTIX+VeRUpShNLhNHpl6eUoS2krCxG2MkuIRImkcti5X6MghNMumjX kcVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date; bh=77yJrZLHx/2FwGVsByPfWah4Dq5ugHaK4oD7fB6ohqo=; b=ulz5eNjMEDdjv9QFZ1iJf5LcYnY1ikggqOapl68Z0Mh8fiZJqbUCsOD0dFIP48OfT7 p4hE2X/hgaf1Ekl4Qi4iPPk0TXR/qaznaXfRTeZ+prExxnKIUMVcOxu2BaE/fXYMVVvW iNSGP9NeYL2zHzToSZMqsF/bThKL2SRHgivVK5tkTHNKsxEYeBm7+yWUNPfNhYyNcW5X qrXf/JJJDe1fUbmpT0HMdfSG8+m9v/X2zAxpw3/DH6JTyPTQRgfbiTEv09w8A5xlWx5R OntUsi1UO+WH4BX6m0QUHJf4Wh/9q5o8Uf3K11DdmeQg2cTeUswEFGBd79YXTAVQyHiW ycJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bb18-20020a17090b009200b0024e43558fbdsi379118pjb.129.2023.05.23.19.13.44; Tue, 23 May 2023 19:13:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239085AbjEXCLd (ORCPT + 99 others); Tue, 23 May 2023 22:11:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232367AbjEXCL3 (ORCPT ); Tue, 23 May 2023 22:11:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AE7913E; Tue, 23 May 2023 19:11:28 -0700 (PDT) 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 D8ACB637ED; Wed, 24 May 2023 02:11:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFEC7C433EF; Wed, 24 May 2023 02:11:21 +0000 (UTC) Date: Tue, 23 May 2023 22:11:08 -0400 From: Steven Rostedt To: LKML , Linux trace kernel Cc: Masami Hiramatsu , Tom Zanussi , Mark Rutland Subject: [PATCH] tracing/histograms: Allow variables to have some modifiers Message-ID: <20230523221108.064a5d82@rorschach.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766739871409094699?= X-GMAIL-MSGID: =?utf-8?q?1766739871409094699?= From: "Steven Rostedt (Google)" Modifiers are used to change the behavior of keys. For instance, they can grouped into buckets, converted to syscall names (from the syscall identifier), show task->comm of the current pid, be an array of longs that represent a stacktrace, and more. It was found that nothing stopped a value from taking a modifier. As values are simple counters. If this happened, it would call code that was not expecting a modifier and crash the kernel. This was fixed by having the ___create_val_field() function test if a modifier was present and fail if one was. This fixed the crash. Now there's a problem with variables. Variables are used to pass fields from one event to another. Variables are allowed to have some modifiers, as the processing may need to happen at the time of the event (like stacktraces and comm names of the current pid). The issue is that it too uses __create_val_field(). Now that fails on modifiers, variables can no longer use them (this is a regression). As not all modifiers are for variables, have them use a separate check. Cc: stable@vger.kernel.org Fixes: e0213434fe3e4 ("tracing: Do not let histogram values have some modifiers") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_hist.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 486cca3c2b75..543cb7dc84ad 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -4238,13 +4238,19 @@ static int __create_val_field(struct hist_trigger_data *hist_data, goto out; } - /* Some types cannot be a value */ - if (hist_field->flags & (HIST_FIELD_FL_GRAPH | HIST_FIELD_FL_PERCENT | - HIST_FIELD_FL_BUCKET | HIST_FIELD_FL_LOG2 | - HIST_FIELD_FL_SYM | HIST_FIELD_FL_SYM_OFFSET | - HIST_FIELD_FL_SYSCALL | HIST_FIELD_FL_STACKTRACE)) { - hist_err(file->tr, HIST_ERR_BAD_FIELD_MODIFIER, errpos(field_str)); - ret = -EINVAL; + /* values and variables should not have some modifiers */ + if (hist_field->flags & HIST_FIELD_FL_VAR) { + /* Variable */ + if (hist_field->flags & (HIST_FIELD_FL_GRAPH | HIST_FIELD_FL_PERCENT | + HIST_FIELD_FL_BUCKET | HIST_FIELD_FL_LOG2)) + goto err; + } else { + /* Value */ + if (hist_field->flags & (HIST_FIELD_FL_GRAPH | HIST_FIELD_FL_PERCENT | + HIST_FIELD_FL_BUCKET | HIST_FIELD_FL_LOG2 | + HIST_FIELD_FL_SYM | HIST_FIELD_FL_SYM_OFFSET | + HIST_FIELD_FL_SYSCALL | HIST_FIELD_FL_STACKTRACE)) + goto err; } hist_data->fields[val_idx] = hist_field; @@ -4256,6 +4262,9 @@ static int __create_val_field(struct hist_trigger_data *hist_data, ret = -EINVAL; out: return ret; + err: + hist_err(file->tr, HIST_ERR_BAD_FIELD_MODIFIER, errpos(field_str)); + return -EINVAL; } static int create_val_field(struct hist_trigger_data *hist_data,