Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32034201rwd; Fri, 7 Jul 2023 07:51:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlFHRsdTHL/wOTr6DT01NYrJm/50H1DOE60zuQhI04PQvhbbn74vfFAfmKCRCgbM/WYxYKuV X-Received: by 2002:a05:6a20:157:b0:12c:1193:a563 with SMTP id 23-20020a056a20015700b0012c1193a563mr3210404pzs.58.1688741461948; Fri, 07 Jul 2023 07:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688741461; cv=none; d=google.com; s=arc-20160816; b=L5LiAjm1unhuY7B7DdBrexrZWyu/OqoG9XddezjQirxrlh9PuadPF/qMqPUJicNb4s ghihwGX7WxD5zzlK0rjOc2q368xUderlhMh0hP7FhJLiWuV+S8pSgQgUCAKSPIBfMaeI wZ6OQIKDPqfiNkMQBNrB5O+5EnudI1dAqPpNe2RSSF/76EUvDmNl10KpvNxvbsArtm36 nWOmJDGa5b5eJvCFa/37dTAnMZtwex86F1hqxd64ooNpNB5gaRjcREJ8SqOSt+rfzXB7 eOrcHyhK3cuAUBFvwzD6jX2Ou5v+adwpiesqLIZc4OfXd590WBwJG/s+TDp6oBBfWRAu eBNQ== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=vqKhUFD8AXtT1AF5JXxPNWIctIX3YNzRAJPIgUW4grY=; fh=fQ26dWUyqM8VZbAJ7SIpJl6wQn5cnWW0/2Awg4c/+Ug=; b=T+uvyv+KaZ8U1XPATuY3QWWGKGceYWLB24kCNpRiOYJlV7kuaGxLUH2XOHT+f6WZTv lHAkIoyWrWqgTulWAtY3qCSmZDnec6BlYK0zqBB4YaGDu8S2c9SpzCT44eShS9JNt3AV 8ta4cjvs44o7oHum+i1ZxszCTnCkcF8zhIdUVM56QODEeM9uDa4thbmcD5mHW6DVONcV MrHlZQmqjckjPsvUxaeLE4Ewo8rsuW+ATAORzxsvT7PZUs6tWN6A1T5bshdmdlmOCEMm aENtT4uyf/1ene0eeG9XR3zVClrhDYc6rsk7LljgDdJcmXDg81/3aMrsDhaF5twyM/h+ b5ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=F0IdHISG; 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 h16-20020a056a00171000b006749ad285e8si3664333pfc.97.2023.07.07.07.50.42; Fri, 07 Jul 2023 07:51:01 -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=F0IdHISG; 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 S232055AbjGGOMo (ORCPT + 99 others); Fri, 7 Jul 2023 10:12:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbjGGOMm (ORCPT ); Fri, 7 Jul 2023 10:12:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 549802114; Fri, 7 Jul 2023 07:12:22 -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 8D684619CC; Fri, 7 Jul 2023 14:12:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E90D7C433C7; Fri, 7 Jul 2023 14:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688739141; bh=xKI4tJjFwB2inCEEimsopT5TgiFdgHAOO7kacDEX0Zo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=F0IdHISGjGsWRx49yYNiXBaeszm77RxZs94VsAK1AjPyUQt7kYJ43l7l1XQIC6cw4 F/N+9Jt6YLXBOcqaiEIU4wQOhEssDB8HLzOb4TeBD8AZKYDco8m8tDQqwf0tuZj7Ob aMF6QUip7T+DfTIlrBkQEmIoeArHXnBOhyeT9MH7X2WPPALZLbUR+CW4o07pQg8cYm YvDQApfh0vMoGCuq3olqv6uKf+EJ69ra5/4uKCpR9WT0SVq20rGQY6UJ6+InHznhZw jXP1LK2FEqUnT3plEtSo5vEsk8dd797RVC/wypoGsNcgTdoVKAHeZ4HHjdgmomLzSd UXD4/N60w5IkQ== Date: Fri, 7 Jul 2023 23:12:14 +0900 From: Masami Hiramatsu (Google) To: Donglin Peng Cc: linux-kernel@vger.kernel.org, Steven Rostedt , Florent Revest , Mark Rutland , Will Deacon , Mathieu Desnoyers , Martin KaFai Lau , bpf@vger.kernel.org, Bagas Sanjaya , linux-trace-kernel@vger.kernel.org, Ding Hui , huangcun@sangfor.com.cn Subject: Re: [PATCH v13 09/12] tracing/probes: Add BTF retval type support Message-Id: <20230707231214.2787a24ac36d41f7edc5e94a@kernel.org> In-Reply-To: References: <168507466597.913472.10572827237387849017.stgit@mhiramat.roam.corp.google.com> <168507476195.913472.16290308831790216609.stgit@mhiramat.roam.corp.google.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, 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 On Mon, 12 Jun 2023 15:29:00 +0800 Donglin Peng wrote: > On 2023/5/26 12:19, Masami Hiramatsu (Google) wrote: > > From: Masami Hiramatsu (Google) > > > > Check the target function has non-void retval type and set the correct > > fetch type if user doesn't specify it. > > If the function returns void, $retval is rejected as below; > > > > # echo 'f unregister_kprobes%return $retval' >> dynamic_events > > sh: write error: No such file or directory > > # cat error_log > > [ 37.488397] trace_fprobe: error: This function returns 'void' type > > Command: f unregister_kprobes%return $retval > > ^ > > > > Signed-off-by: Masami Hiramatsu (Google) > > --- > > Changes in v8: > > - Fix wrong indentation. > > Changes in v7: > > - Introduce this as a new patch. > > --- > > kernel/trace/trace_probe.c | 69 ++++++++++++++++++++++++++++++++++++++++---- > > kernel/trace/trace_probe.h | 1 + > > 2 files changed, 63 insertions(+), 7 deletions(-) > > > > diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c > > index 7318642aceb3..dfe3e1823eec 100644 > > --- a/kernel/trace/trace_probe.c > > +++ b/kernel/trace/trace_probe.c > > @@ -371,15 +371,13 @@ static const char *type_from_btf_id(struct btf *btf, s32 id) > > return NULL; > > } > > > > -static const struct btf_param *find_btf_func_param(const char *funcname, s32 *nr, > > - bool tracepoint) > > +static const struct btf_type *find_btf_func_proto(const char *funcname) > > { > > struct btf *btf = traceprobe_get_btf(); > > - const struct btf_param *param; > > const struct btf_type *t; > > s32 id; > > > > - if (!btf || !funcname || !nr) > > + if (!btf || !funcname) > > return ERR_PTR(-EINVAL); > > > > id = btf_find_by_name_kind(btf, funcname, BTF_KIND_FUNC); > > @@ -396,6 +394,22 @@ static const struct btf_param *find_btf_func_param(const char *funcname, s32 *nr > > if (!btf_type_is_func_proto(t)) > > return ERR_PTR(-ENOENT); > > > > + return t; > > +} > > + > > +static const struct btf_param *find_btf_func_param(const char *funcname, s32 *nr, > > + bool tracepoint) > > +{ > > + const struct btf_param *param; > > + const struct btf_type *t; > > + > > + if (!funcname || !nr) > > + return ERR_PTR(-EINVAL); > > + > > + t = find_btf_func_proto(funcname); > > + if (IS_ERR(t)) > > + return (const struct btf_param *)t; > > + > > *nr = btf_type_vlen(t); > > param = (const struct btf_param *)(t + 1); > > > > @@ -462,6 +476,32 @@ static const struct fetch_type *parse_btf_arg_type(int arg_idx, > > return find_fetch_type(typestr, ctx->flags); > > } > > > > +static const struct fetch_type *parse_btf_retval_type( > > + struct traceprobe_parse_context *ctx) > > +{ > > Can we make this a common interface so that the funcgraph-retval can > also use it to get the return type? It is possible to expose BTF part as an independent file so that other ftrace tracers reuse it. But you might need to store the result for each function somewhere in the kernel. Would you have any idea? Thank you, > > -- Donglin Peng > > > + struct btf *btf = traceprobe_get_btf(); > > + const char *typestr = NULL; > > + const struct btf_type *t; > > + > > + if (btf && ctx->funcname) { > > + t = find_btf_func_proto(ctx->funcname); > > + if (!IS_ERR(t)) > > + typestr = type_from_btf_id(btf, t->type); > > + } > > + > > + return find_fetch_type(typestr, ctx->flags); > > +} > > + > > +static bool is_btf_retval_void(const char *funcname) > > +{ > > + const struct btf_type *t; > > + > > + t = find_btf_func_proto(funcname); > > + if (IS_ERR(t)) > > + return false; > > + > > + return t->type == 0; > > +} > > #else > > static struct btf *traceprobe_get_btf(void) > > { > > @@ -480,8 +520,15 @@ static int parse_btf_arg(const char *varname, struct fetch_insn *code, > > trace_probe_log_err(ctx->offset, NOSUP_BTFARG); > > return -EOPNOTSUPP; > > } > > + > > #define parse_btf_arg_type(idx, ctx) \ > > find_fetch_type(NULL, ctx->flags) > > + > > +#define parse_btf_retval_type(ctx) \ > > + find_fetch_type(NULL, ctx->flags) > > + > > +#define is_btf_retval_void(funcname) (false) > > + > > #endif > > > > #define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long)) > > @@ -512,6 +559,11 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t, > > > > if (strcmp(arg, "retval") == 0) { > > if (ctx->flags & TPARG_FL_RETURN) { > > + if ((ctx->flags & TPARG_FL_KERNEL) && > > + is_btf_retval_void(ctx->funcname)) { > > + err = TP_ERR_NO_RETVAL; > > + goto inval; > > + } > > code->op = FETCH_OP_RETVAL; > > return 0; > > } > > @@ -912,9 +964,12 @@ static int traceprobe_parse_probe_arg_body(const char *argv, ssize_t *size, > > goto fail; > > > > /* Update storing type if BTF is available */ > > - if (IS_ENABLED(CONFIG_PROBE_EVENTS_BTF_ARGS) && > > - !t && code->op == FETCH_OP_ARG) > > - parg->type = parse_btf_arg_type(code->param, ctx); > > + if (IS_ENABLED(CONFIG_PROBE_EVENTS_BTF_ARGS) && !t) { > > + if (code->op == FETCH_OP_ARG) > > + parg->type = parse_btf_arg_type(code->param, ctx); > > + else if (code->op == FETCH_OP_RETVAL) > > + parg->type = parse_btf_retval_type(ctx); > > + } > > > > ret = -EINVAL; > > /* Store operation */ > > diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h > > index c864e6dea10f..eb43bea5c168 100644 > > --- a/kernel/trace/trace_probe.h > > +++ b/kernel/trace/trace_probe.h > > @@ -449,6 +449,7 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call, > > C(BAD_EVENT_NAME, "Event name must follow the same rules as C identifiers"), \ > > C(EVENT_EXIST, "Given group/event name is already used by another event"), \ > > C(RETVAL_ON_PROBE, "$retval is not available on probe"), \ > > + C(NO_RETVAL, "This function returns 'void' type"), \ > > C(BAD_STACK_NUM, "Invalid stack number"), \ > > C(BAD_ARG_NUM, "Invalid argument number"), \ > > C(BAD_VAR, "Invalid $-valiable specified"), \ > > > > > > > -- Masami Hiramatsu (Google)