From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mail.toke.dk (Postfix) with ESMTPS id 5F7B299DD5C for ; Wed, 7 Sep 2022 17:45:50 +0200 (CEST) Authentication-Results: mail.toke.dk; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Gl3BES11 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662565549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=e8qzYn67mc0YUjcpq2BNfwdPV/CrkwgKNBPhMy5km50=; b=Gl3BES11wsvmxDSplomKB4HoNYNFthve83k4YFLBkB9l9LdgRWkx+HuXQTV5g+Ca0dNTD+ o69ANH4b0Ipuda/ELeZrEmf+TgELA2k6UyjSze8OWaKFxeUj57us1tndjeAR/azFOlMvAu kjF/jDXY5XyM/71ZyUDk3utslLlRL/A= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-412-P7_TQDObNXik3CSFnSY3QQ-1; Wed, 07 Sep 2022 11:45:48 -0400 X-MC-Unique: P7_TQDObNXik3CSFnSY3QQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1BE0D811E90; Wed, 7 Sep 2022 15:45:47 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.40.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id D37234C816; Wed, 7 Sep 2022 15:45:46 +0000 (UTC) Received: from [192.168.42.3] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 27C7C30721A6C; Wed, 7 Sep 2022 17:45:46 +0200 (CEST) From: Jesper Dangaard Brouer To: bpf@vger.kernel.org Date: Wed, 07 Sep 2022 17:45:46 +0200 Message-ID: <166256554611.1434226.15342391322311314838.stgit@firesoul> In-Reply-To: <166256538687.1434226.15760041133601409770.stgit@firesoul> References: <166256538687.1434226.15760041133601409770.stgit@firesoul> User-Agent: StGit/1.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 Message-ID-Hash: ZJG2A6VMFJJLGZBSJURPTC4XY7W4QMR4 X-Message-ID-Hash: ZJG2A6VMFJJLGZBSJURPTC4XY7W4QMR4 X-MailFrom: brouer@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Jesper Dangaard Brouer , netdev@vger.kernel.org, xdp-hints@xdp-project.net, larysa.zaremba@intel.com, memxor@gmail.com, Lorenzo Bianconi , mtahhan@redhat.com, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , dave@dtucker.co.uk, Magnus Karlsson , bjorn@kernel.org X-Mailman-Version: 3.3.5 Precedence: list Subject: [xdp-hints] [PATCH RFCv2 bpf-next 09/18] bpf: export btf functions for modules List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This allows modules to lookup their own module BTF info. These are get and set operations that bump the refcount. Thus, modules can use this to control the lifetime. Suggested-by: Kumar Kartikeya Dwivedi Signed-off-by: Jesper Dangaard Brouer --- include/linux/btf.h | 2 ++ kernel/bpf/btf.c | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/btf.h b/include/linux/btf.h index ad93c2d9cc1c..a66266c00c04 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -148,6 +148,8 @@ u32 btf_obj_id(const struct btf *btf); bool btf_is_kernel(const struct btf *btf); bool btf_is_module(const struct btf *btf); struct module *btf_try_get_module(const struct btf *btf); +struct btf *btf_get_module_btf(const struct module *module); +void btf_put_module_btf(struct btf *btf); u32 btf_nr_types(const struct btf *btf); bool btf_member_is_reg_int(const struct btf *btf, const struct btf_type *s, const struct btf_member *m, diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 903719b89238..1e95391e0ca1 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -534,6 +534,7 @@ s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind) return -ENOENT; } +EXPORT_SYMBOL_GPL(btf_find_by_name_kind); static s32 bpf_find_btf_id(const char *name, u32 kind, struct btf **btf_p) { @@ -1673,6 +1674,15 @@ void btf_put(struct btf *btf) } } +void btf_put_module_btf(struct btf *btf) +{ + if (!btf_is_module(btf)) + return; + + btf_put(btf); +} +EXPORT_SYMBOL_GPL(btf_put_module_btf); + static int env_resolve_init(struct btf_verifier_env *env) { struct btf *btf = env->btf; @@ -7051,7 +7061,7 @@ struct module *btf_try_get_module(const struct btf *btf) /* Returns struct btf corresponding to the struct module. * This function can return NULL or ERR_PTR. */ -static struct btf *btf_get_module_btf(const struct module *module) +struct btf *btf_get_module_btf(const struct module *module) { #ifdef CONFIG_DEBUG_INFO_BTF_MODULES struct btf_module *btf_mod, *tmp; @@ -7080,6 +7090,7 @@ static struct btf *btf_get_module_btf(const struct module *module) return btf; } +EXPORT_SYMBOL_GPL(btf_get_module_btf); BPF_CALL_4(bpf_btf_find_by_name_kind, char *, name, int, name_sz, u32, kind, int, flags) {