Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5246736rwd; Mon, 12 Jun 2023 02:06:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6gyOTmSIk4URBcP5Io04K+U7NqMPTtjHiB+OJDonh4lzhhsP0730/ad+8RbEhXDzCIDCGT X-Received: by 2002:a17:903:120e:b0:1b3:b200:a3d7 with SMTP id l14-20020a170903120e00b001b3b200a3d7mr5590727plh.52.1686560773168; Mon, 12 Jun 2023 02:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686560773; cv=none; d=google.com; s=arc-20160816; b=ZVpJllVI20fJJuvSfj00zuCGkKCmDfFesfaR7NUfov1LcShxdL5dLprowNxjWUKA41 paVfTppZvwFK2Sf6dEd9TG1L1qU0DdWHgpII4TSeeEL1d9AWB6liL8DyhmVfl2w+0I6Y sO5d/7FqlRiNiXowYq2i+m9ICAn7TOtN71ytc5AqiTxn/0/2y4mktXV7kwG7bcZZOHm9 EK6/44qM1gsezzXa/wN6iLq7hBuJsPaxd5kbRMBhiUvW2RS1hZ6uorOhh+Ail9MOsUi9 a9/50uiPDY2e/HC5qIXZvLZzZOrek/yFKNToT68pyVpOgnqfVoPAODUHqh1Xw8hl5oIB VFbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=xCo3XyjpUQZghxdzGPRMHNIksd4gq27q4JKRDLc3OdY=; b=MR2eZ6/ArUIIDHMRBTkrQ8Y8R1wyejYVOntFJkr/BP6qqerYu0cNbDE59oUTv/Jbox 3f2sC4QQTv6rikq63S471I8MD93cHtCBEysWgHkVWH2ulIdtXp66uKVM3xvsWv1hiG8Q m+wDzmx9qG9N3LwkeLmoNq8ZP9T7R+kUXe7Fs1PFdFeFVpkCd0kQ+Sqz8MH9OhGPn6TT IcXZY5v9JC4Cs3OKdYX3+BLT4+ojS92r0gX0RJHlcWkj9E+WMTSaS1MNQtzLswlxlia/ jZkee719uq0DN3UROR4UUHmv7ePUUvkf43H3juVrhwJ1NOusvm5Dr8O/5SjQcIIXyzl0 Fjyw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b19-20020a170902d89300b001adf26b357bsi6509433plz.631.2023.06.12.02.06.00; Mon, 12 Jun 2023 02:06:13 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232365AbjFLIgf (ORCPT + 99 others); Mon, 12 Jun 2023 04:36:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232992AbjFLIgb (ORCPT ); Mon, 12 Jun 2023 04:36:31 -0400 X-Greylist: delayed 2068 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 12 Jun 2023 01:36:24 PDT Received: from mail-m11877.qiye.163.com (mail-m11877.qiye.163.com [115.236.118.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A83419A; Mon, 12 Jun 2023 01:36:23 -0700 (PDT) Received: from [172.23.197.27] (unknown [121.32.254.147]) by mail-m11877.qiye.163.com (Hmail) with ESMTPA id 92F0A40040C; Mon, 12 Jun 2023 15:29:20 +0800 (CST) Message-ID: Date: Mon, 12 Jun 2023 15:29:00 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v13 09/12] tracing/probes: Add BTF retval type support Content-Language: en-US To: "Masami Hiramatsu (Google)" 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 References: <168507466597.913472.10572827237387849017.stgit@mhiramat.roam.corp.google.com> <168507476195.913472.16290308831790216609.stgit@mhiramat.roam.corp.google.com> From: Donglin Peng In-Reply-To: <168507476195.913472.16290308831790216609.stgit@mhiramat.roam.corp.google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlDT0wYVkxKSx9DGUlDQkhCGlUTARMWGhIXJBQOD1 lXWRgSC1lBWUpJSlVISVVJTk9VSk9MWVdZFhoPEhUdFFlBWU9LSFVKSktISkxVSktLVUtZBg++ X-HM-Tid: 0a88ae8264f62eb3kusn92f0a40040c X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PAg6Dxw5PT1IKho*MTQ#QglO LyhPCUJVSlVKTUNNTk5PQk1KTE9OVTMWGhIXVQseFRwfFBUcFxIVOwgaFRwdFAlVGBQWVRgVRVlX WRILWUFZSklKVUhJVUlOT1VKT0xZV1kIAVlBTEJCTzcG X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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 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? -- 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"), \ > > >