From patchwork Mon Aug 7 02:55:38 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: 131650 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1209827vqr; Sun, 6 Aug 2023 20:50:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFYMhXRtZvIM/FvHujIvstb1e+TbFSIPmV23+L4APlY47UFwuLIr9ScQAQP9SNVNx4wWqC2 X-Received: by 2002:a17:906:e:b0:99c:7134:ab6d with SMTP id 14-20020a170906000e00b0099c7134ab6dmr7029421eja.41.1691380237538; Sun, 06 Aug 2023 20:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691380237; cv=none; d=google.com; s=arc-20160816; b=GFRlejjOAfrerJsImyol6aiqEed0zgHE9sWFr1Qq6WyIU8FM9jYPyGvU55+oCwmfSV vVKdNoAv1Fi1xpSfvbqGCP+jbVnt8bw5Lrkvrbu6se2o/2ztUjcll9i3aqX6KDI3OCWi i3HMdwdyPanVHd8I/yUAwT5Xi0ySQzqmyK+xptqxU4UDbvDcyaENQSZasWbQG/HCaI7g 1+ci8s/2y3KjxgspESsMZiw9x+5igyQk3ZOTJbfwXIcb0NIk+f4quy5W3SV4mK5b6Pq1 qk550dj8DHQoxjcxODx+6u52iqJqTpCm6BFyfjHQsSozrRa7hGJ6tNSv2YnCuVAVb/l1 d60A== 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=ITdXGOXFMHJxvQnxrnRMWa60CeNHQLyP3VTWz/0KXQ59nP02BeFCSG0qr9oRnHSru6 iJnaVpP52pjbidbHfCU0GUmeiDYnlqR2Amq32hnioLIqFn2z3wUblmj7mVbRSo9fybkb LWZ+wMzaBW1wIpgF13s6+vsCikH36XEpa0Q7NfS3D9d+s+eGAnoFL7Yj1N54h5dIGQk9 8NGiqDO+4aTSy4DPVepLvXsPNtVUfy7kvQVDoQNFZFH+y8haTD9Kxh62GK/6rQHOTgXL vjxgpw1n2WaBKD5rVqF2vr7PO2+9HeeZ38u3fUiJu+3Ws2yfP6y9KPTWfLwSRBmKhOWM zX0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m8kJkHWo; 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 k5-20020a1709063fc500b0098d52a2bc16si5510705ejj.438.2023.08.06.20.50.04; Sun, 06 Aug 2023 20:50:37 -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=m8kJkHWo; 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 S229690AbjHGC4W (ORCPT + 99 others); Sun, 6 Aug 2023 22:56:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbjHGC4T (ORCPT ); Sun, 6 Aug 2023 22:56:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD8431BDA; Sun, 6 Aug 2023 19:55:44 -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 8DBFF60A4B; Mon, 7 Aug 2023 02:55:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FDA7C433C8; Mon, 7 Aug 2023 02:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691376943; bh=gcAsXcNpHr2neQoiFwF9exmEBvK8RQO7NJB0uoPDuFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m8kJkHWo1ZCZN67vC77Y1xjVj/QZdd7HEOmFmNVl7MijaFHWbLZcKL+dqdDstAalz 8alWXxiJoI7N4Zl+6ArHCH8sFfKRsNjzNBNUQoiT5i+RdsoBYwZGffZtIfwM0mv53C P1wYK7TvF5qDSa7CDpm8juPvvAKCYrUDFwbN4rtLHyj7hPt1HGqxr7iXrXweE2GAZM tGxkCbK+y7WrGleUzkjx0aaz+Cvb8OeR2zqiK07ZRFc0m372nYKOrt1C8Bqu0+KP+k KHEJ44pJHWFAONwnDfeapJZdHZKlJotNoYHzgmF05rx1gyM9+6Sgld7rsQW44ljPpH zR8YOVkhRZkpg== 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 v5 7/9] tracing/fprobe-event: Assume fprobe is a return event by $retval Date: Mon, 7 Aug 2023 11:55:38 +0900 Message-Id: <169137693852.271367.5757753088603858125.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169137686814.271367.11218568219311636206.stgit@devnote2> References: <169137686814.271367.11218568219311636206.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 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: 1773540723921081246 X-GMAIL-MSGID: 1773540723921081246 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