Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp195866rdg; Tue, 10 Oct 2023 07:53:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG00GIgVTWjzBRn5ekMgvuIN4JNk9CPj21lb6WQRo2OAjmqze4RjHT3OUnMyAFumTQvu0eW X-Received: by 2002:a17:90a:94c8:b0:274:bdcc:85b1 with SMTP id j8-20020a17090a94c800b00274bdcc85b1mr22087726pjw.12.1696949626980; Tue, 10 Oct 2023 07:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696949626; cv=none; d=google.com; s=arc-20160816; b=pSbhN/bDQwha0VWXDDrBwRy0MkmXoebzkMYmaTXlRAdfZMZPAapIcdkO+6FhmK7k27 DgsNY2W7n2YOsuRreKy9TekFhWSFGXSZHMifKX5OdojlFHe60RBBD3TkRcajvJnhckvb k4B9W/QXQi7R13LbJHPqKK8JK84Bx0MmpFmf7kjDdNKyFqWG8gHsrngOAQDqtO+Pce11 ALfARlf0+DP5/ArdpLuO5ubAjfQayOR68On5ANoga/NAp5d1ghN1rJuitNUM0tzN3uVa DhrwxIp3BtTU7AviTXZ6A6t0CCCXwyYwOoUl0D6GzZBuHXEs9SiUuo20QYRLxamQdN+4 39GQ== 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; bh=ZWLtmN/AWM0FZWGHpJ6gztqcOkANQsd5L3REzCbKgAQ=; fh=PY7o0xYhzx4eEevxl/HkEFM6wpNe57LO+5Q47zwbwT0=; b=AXdeW9M8b+6JEWdAEpn4Ow3qJi28ns/rY108YO1b5WilU53F6uvaTr0Jf8hf3hDrw/ RWCeqvk5tnaN5J6CTaWJMOBnV1C+/DAoFspl8/NPOyUnlsmBr/MSa8LPw62g3MEfci84 OqQyrAh6ysN9Y4JSjn4h7jlZqFU0gcUUmN5q1jbejy1ttSgw2qeZwS3IjNTUdPHkvKLh 7QN6OCStCtPDpmw9qjBd7TyLLPR1rEt1O06U4hnnKojeBfziAq2a7qRk5W6lwJd0mTT9 5B1JeXLc7U2NCXDAhXXiD3dcBNZOIIkgli1rsBGZxBbU/XJpaJ3edGDPw0TnnXLEy/vm N+KQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id c18-20020a17090a8d1200b002743b58483asi11574066pjo.66.2023.10.10.07.53.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 07:53:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id F002E80B2D46; Tue, 10 Oct 2023 07:53:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232993AbjJJOxc (ORCPT + 99 others); Tue, 10 Oct 2023 10:53:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233249AbjJJOxZ (ORCPT ); Tue, 10 Oct 2023 10:53:25 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A0A4D7 for ; Tue, 10 Oct 2023 07:53:24 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 252DAC433C8; Tue, 10 Oct 2023 14:53:23 +0000 (UTC) Date: Tue, 10 Oct 2023 10:54:43 -0400 From: Steven Rostedt To: "Masami Hiramatsu (Google)" Cc: Martin KaFai Lau , Alexei Starovoitov , linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] bpf/btf: Move tracing BTF APIs to the BTF library Message-ID: <20231010105443.7ed2a2a8@gandalf.local.home> In-Reply-To: <169694605862.516358.5321950027838863987.stgit@devnote2> References: <169694605862.516358.5321950027838863987.stgit@devnote2> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; 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=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 10 Oct 2023 07:53:42 -0700 (PDT) X-Spam-Level: ** On Tue, 10 Oct 2023 22:54:19 +0900 "Masami Hiramatsu (Google)" wrote: > --- a/kernel/bpf/btf.c > +++ b/kernel/bpf/btf.c > @@ -912,6 +912,121 @@ static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf, > return t; > } > > +/* > + * Find a function proto type by name, and return the btf_type with its btf > + * in *@btf_p. Return NULL if not found. > + * Note that caller has to call btf_put(*@btf_p) after using the btf_type. > + */ If these functions are going to be available via include/linux/*.h then they really should have kerneldoc comments attached to them. -- Steve > +const struct btf_type *btf_find_func_proto(const char *func_name, struct btf **btf_p) > +{ > + const struct btf_type *t; > + s32 id; > + > + id = bpf_find_btf_id(func_name, BTF_KIND_FUNC, btf_p); > + if (id < 0) > + return NULL; > + > + /* Get BTF_KIND_FUNC type */ > + t = btf_type_by_id(*btf_p, id); > + if (!t || !btf_type_is_func(t)) > + goto err; > + > + /* The type of BTF_KIND_FUNC is BTF_KIND_FUNC_PROTO */ > + t = btf_type_by_id(*btf_p, t->type); > + if (!t || !btf_type_is_func_proto(t)) > + goto err; > + > + return t; > +err: > + btf_put(*btf_p); > + return NULL; > +} > + > +/* > + * Get function parameter with the number of parameters. > + * This can return NULL if the function has no parameters. > + * It can return -EINVAL if the @func_proto is not a function proto type. > + */ > +const struct btf_param *btf_get_func_param(const struct btf_type *func_proto, s32 *nr) > +{ > + if (!btf_type_is_func_proto(func_proto)) > + return ERR_PTR(-EINVAL); > + > + *nr = btf_type_vlen(func_proto); > + if (*nr > 0) > + return (const struct btf_param *)(func_proto + 1); > + else > + return NULL; > +} > + > +#define BTF_ANON_STACK_MAX 16 > + > +struct btf_anon_stack { > + u32 tid; > + u32 offset; > +}; > + > +/* > + * Find a member of data structure/union by name and return it. > + * Return NULL if not found, or -EINVAL if parameter is invalid. > + * If the member is an member of anonymous union/structure, the offset > + * of that anonymous union/structure is stored into @anon_offset. Caller > + * can calculate the correct offset from the root data structure by > + * adding anon_offset to the member's offset. > + */ > +const struct btf_member *btf_find_struct_member(struct btf *btf, > + const struct btf_type *type, > + const char *member_name, > + u32 *anon_offset) > +{