Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1027919rwb; Wed, 26 Jul 2023 06:39:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlGVbToaifFLY5+LlpP+Eg9prhWjt/lwff4m2EHbsNmhbWMhCkozDzsvXlhF7vQYHqQZ5Aum X-Received: by 2002:a05:6a20:3c8d:b0:130:835b:e260 with SMTP id b13-20020a056a203c8d00b00130835be260mr2067550pzj.52.1690378776898; Wed, 26 Jul 2023 06:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690378776; cv=none; d=google.com; s=arc-20160816; b=G0EfOxJPVyZCnTq2Ou8kcDSCkLmU482GuPFL6pYQ6s7sznOOdL/X240W/c2WHUU5vx My72YRhrgkFKNOvLs4Z4cwhfwJXLY5la6IVoPTvkVD3VOlsLoncxwTOGeOclnAlRb5/H vt326a2X66m4yTkKiN0WWebaMBb3FVpY4s+9Mz6XMwbxdNS67M09FXDKSeF+FB9O0Cpp cyn9LZ2HEKDHWj6zJvYlU9DpJdoIqwsNImmGmMk4vjJBoP4HNgjTCOIrzAl04NWFgE9n uhizLKWZE6k6RA+Ztn/MSsjRbHlpN1l7LbI5QCENcOZHHwX0usKRiTEiZDpycXp9vrFa 759g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=N0VZdmIcCwbsUXtz78ks4IDAk2qeba7vipWibt19+c4=; fh=raxTTJvC+dSJYbgfX5JG5gvrVjxTZXczN0HF8iDayLY=; b=CYLtu2atnVZd21MiiTJJdvw6ssQvwwRszP//CgU2zAgCyLWG+d54bNY2wiCqK9ozbP 8cQjYL0RcrHQ7l7/+C6bQOIR/2Qm/3ooBfiErZS8H4ASOPKaRVIgXdBFEt/dE2HbBRKD SqROF7iGSuCWxeitxtRXcm4nTYG4U0qIbjfSbPzyjHrzDwPuE4e0ODqwlPOUFZ7tBFwl x3ePGmMl/JudOoUP4Yed4W+HVOLGZuhtKbkPjJVJVThqp2OCL17nAxlUxgDnn8y7tp1k 3lJ7umyENWtKecSN3FT81uH546EBS2TU6SIKFKBbEWU5VWYB8egVDdfGmIAo2+uXVN6m rrsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K36bqciP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w8-20020a63f508000000b0056379ae7b03si13372768pgh.71.2023.07.26.06.39.23; Wed, 26 Jul 2023 06:39:36 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=K36bqciP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232951AbjGZNBZ (ORCPT + 99 others); Wed, 26 Jul 2023 09:01:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233325AbjGZNBV (ORCPT ); Wed, 26 Jul 2023 09:01:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F16F52D79; Wed, 26 Jul 2023 06:01:06 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8A09A617A7; Wed, 26 Jul 2023 13:01:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DB2DC433C7; Wed, 26 Jul 2023 13:01:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690376466; bh=gcAsXcNpHr2neQoiFwF9exmEBvK8RQO7NJB0uoPDuFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K36bqciPpGfZqDLISnjK8YpjO3u9WX+y4Q2K2wfIHLNHdo7BJ6AWECehxAoGz+Vwb HaeRETXihrtizo48sWTenh/8lRhOWSrKzYXiunoqBqwnT3S9zn763/fnGrIiLU0HFw RPgSSqsTwbliIdO9ovmXY60DcWg24ojpOZRQhu8aGn7hdZ5OeGkkBUb6F+SPBUQ5Xw nbpGCLhVykyo954j9hVNBWaE9tVy20h51SGpcAhIfAdRn0cuQ1YjXi2p1AdUEpnLIw NlG0nR7kBDHrAlZTRofsGG/fjfwVtDuJgi+JLmOFI7VQundl/Z3IQ2cf3xnNi1FWuj 3EzsxKruCDT4Q== From: "Masami Hiramatsu (Google)" To: linux-trace-kernel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Steven Rostedt , mhiramat@kernel.org, Martin KaFai Lau , bpf@vger.kernel.org, Sven Schnelle , Alexei Starovoitov Subject: [PATCH v3 7/9] tracing/fprobe-event: Assume fprobe is a return event by $retval Date: Wed, 26 Jul 2023 22:01:01 +0900 Message-Id: <169037646179.607919.1122940594695749798.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169037639315.607919.2613476171148037242.stgit@devnote2> References: <169037639315.607919.2613476171148037242.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 From: Masami Hiramatsu (Google) Assume the fprobe event is a return event if there is $retval is used in the probe's argument without %return. e.g. echo 'f:myevent vfs_read $retval' >> dynamic_events then 'myevent' is a return probe event. Suggested-by: Steven Rostedt Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace_fprobe.c | 58 +++++++++++++++----- .../ftrace/test.d/dynevent/fprobe_syntax_errors.tc | 2 - 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/kernel/trace/trace_fprobe.c b/kernel/trace/trace_fprobe.c index 8f43f1f65b1b..8bfe23af9c73 100644 --- a/kernel/trace/trace_fprobe.c +++ b/kernel/trace/trace_fprobe.c @@ -898,6 +898,46 @@ static struct tracepoint *find_tracepoint(const char *tp_name) return data.tpoint; } +static int parse_symbol_and_return(int argc, const char *argv[], + char **symbol, bool *is_return, + bool is_tracepoint) +{ + char *tmp = strchr(argv[1], '%'); + int i; + + if (tmp) { + int len = tmp - argv[1]; + + if (!is_tracepoint && !strcmp(tmp, "%return")) { + *is_return = true; + } else { + trace_probe_log_err(len, BAD_ADDR_SUFFIX); + return -EINVAL; + } + *symbol = kmemdup_nul(argv[1], len, GFP_KERNEL); + } else + *symbol = kstrdup(argv[1], GFP_KERNEL); + if (!*symbol) + return -ENOMEM; + + if (*is_return) + return 0; + + /* If there is $retval, this should be a return fprobe. */ + for (i = 2; i < argc; i++) { + tmp = strstr(argv[i], "$retval"); + if (tmp && !isalnum(tmp[7]) && tmp[7] != '_') { + *is_return = true; + /* + * NOTE: Don't check is_tracepoint here, because it will + * be checked when the argument is parsed. + */ + break; + } + } + return 0; +} + static int __trace_fprobe_create(int argc, const char *argv[]) { /* @@ -927,7 +967,7 @@ static int __trace_fprobe_create(int argc, const char *argv[]) struct trace_fprobe *tf = NULL; int i, len, new_argc = 0, ret = 0; bool is_return = false; - char *symbol = NULL, *tmp = NULL; + char *symbol = NULL; const char *event = NULL, *group = FPROBE_EVENT_SYSTEM; const char **new_argv = NULL; int maxactive = 0; @@ -983,20 +1023,10 @@ static int __trace_fprobe_create(int argc, const char *argv[]) trace_probe_log_set_index(1); /* a symbol(or tracepoint) must be specified */ - symbol = kstrdup(argv[1], GFP_KERNEL); - if (!symbol) - return -ENOMEM; + ret = parse_symbol_and_return(argc, argv, &symbol, &is_return, is_tracepoint); + if (ret < 0) + goto parse_error; - tmp = strchr(symbol, '%'); - if (tmp) { - if (!is_tracepoint && !strcmp(tmp, "%return")) { - *tmp = '\0'; - is_return = true; - } else { - trace_probe_log_err(tmp - symbol, BAD_ADDR_SUFFIX); - goto parse_error; - } - } if (!is_return && maxactive) { trace_probe_log_set_index(0); trace_probe_log_err(1, BAD_MAXACT_TYPE); diff --git a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc index 812f5b3f6055..72563b2e0812 100644 --- a/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc +++ b/tools/testing/selftests/ftrace/test.d/dynevent/fprobe_syntax_errors.tc @@ -30,11 +30,11 @@ check_error 'f:^ vfs_read' # NO_EVENT_NAME check_error 'f:foo/^12345678901234567890123456789012345678901234567890123456789012345 vfs_read' # EVENT_TOO_LONG check_error 'f:foo/^bar.1 vfs_read' # BAD_EVENT_NAME -check_error 'f vfs_read ^$retval' # RETVAL_ON_PROBE check_error 'f vfs_read ^$stack10000' # BAD_STACK_NUM check_error 'f vfs_read ^$arg10000' # BAD_ARG_NUM +check_error 'f vfs_read $retval ^$arg1' # BAD_VAR check_error 'f vfs_read ^$none_var' # BAD_VAR check_error 'f vfs_read ^'$REG # BAD_VAR