From patchwork Mon Jul 17 15:24:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 121431 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp1208453vqt; Mon, 17 Jul 2023 09:15:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlHMDxFYx0qvJbC8HKK+N3xEYmdr7d0UXBMUqJ/Yvr8+3ANK5+3dVksLRGtVbm1AkA48VmU3 X-Received: by 2002:a2e:b710:0:b0:2b9:45d1:da10 with SMTP id j16-20020a2eb710000000b002b945d1da10mr1551839ljo.48.1689610502547; Mon, 17 Jul 2023 09:15:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689610502; cv=none; d=google.com; s=arc-20160816; b=drzytxkK3MP6Hen0jTQyXm62uzWOEijqBmOy4ZvkQPr7uObJ9bPY1xr18LQURTkcWa RqFSSJBpAkJ6da2FfG3qCcOPHeRlK8El7Bit6sqtJ8OXcBQbQLWyT1lLV6mA2XF1+gED D3+YsUM/cluuLVRsnamNOIjlOF4tUrVhkZ+UKSvfa5TlAZ/WoXj23r5QXgMZBTUKm0Ni P+iyzkYMJ8KQ6C8hlczU7Z9iLnXC+XM0eWQ8XXfBw5qyRoKDEVV4x51wPZt6Y+AZiJlQ C81kHps0cXCx+nG7ulNKdK1kSIY1COPNR5XODVqJ1TEuKOLqBjdS1cS4vXvMdwBGQ7Ix /DdQ== 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=QzDZF1cPO+00lSPANv0LA5JA++T/jO9HS1GMBC/nqQY=; fh=raxTTJvC+dSJYbgfX5JG5gvrVjxTZXczN0HF8iDayLY=; b=LJzaQ2SV+RYytXECg4jhV9p7f48mCtsE1gNwG6SVGv+zsjn5tV4xsiJrvTHi6hzhZV 63RJJ64fjSKgHn6UHFj7xGTYqKBgepstEctt44m9oEK5dPJ4QfaYjmiUe+t90ysgAgJv c80bDmMOvSMDpY84qd6CGqWZRltE4yVY1S01fRybzErvASa4LDnC7GTuxlN3qscTXH6U qEFP5LNe2qRfo1mdvBcaBo4z3YxWLT5nf48DjhjrrtQW6BG6JI7vU0L6CNreIQciIudy XfsrU7/huWYBaWFXJAtu+GovFCz1WcuNlhvKVKZvWxaUqpJP2ji26CIiaON+0QcZUGHi BcdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dRLWgmFj; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a1709067cc300b00992c22a6857si13863316ejp.199.2023.07.17.09.14.38; Mon, 17 Jul 2023 09:15:02 -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=dRLWgmFj; 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 S231779AbjGQP0F (ORCPT + 99 others); Mon, 17 Jul 2023 11:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231343AbjGQPZe (ORCPT ); Mon, 17 Jul 2023 11:25:34 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A75F2704; Mon, 17 Jul 2023 08:24:59 -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 B3F5C61123; Mon, 17 Jul 2023 15:24:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 239C4C433C7; Mon, 17 Jul 2023 15:24:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689607472; bh=Ud+/WgVDgP+xcku85SFsEC4AToiKRsKLRxeToviMbLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dRLWgmFjqOYNpjJ7uT98XQf53pRsqoJ4KmYQWSnI4dydNJiKY+NUpsytf0n08osMl bVICQQ33luLAfE1ZmrCsyk8Xbu2GIQanzzFIlTnoi/YVyASFCwDX2OlrfAAp/RNGcu s3JUM/jYOhZyt7JPBTY9K/c48UNAEr9Xz80nb6FVW4FP3ftIqkTyLym+QUvSSs+HMo w6odgw62hH6rmuzXxgGnwOHMUm+GDEWTEf1bQPB7ro8WMzecBIVVoxPZXUSrCQn92U 4inLw+VzOJrEaOP5xrkXWOnF69dfEcUyq34fSbGX4UXG8Na9YBu9YTlqld0wQo1jq/ wX4MzPAn06RvA== 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 v2 7/9] tracing/fprobe-event: Assume fprobe is a return event by $retval Date: Tue, 18 Jul 2023 00:24:27 +0900 Message-Id: <168960746736.34107.3486065330592238119.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <168960739768.34107.15145201749042174448.stgit@devnote2> References: <168960739768.34107.15145201749042174448.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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: INBOX X-GMAIL-THRID: 1771685022342287580 X-GMAIL-MSGID: 1771685022342287580 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. 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 dfe2e546acdc..3ac0e04071aa 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