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 D07CB99DD83 for ; Wed, 7 Sep 2022 17:45:57 +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=QQMd6ppM DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662565556; 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=Nj5BlWEjHAbOxvMpguL3MAZX7qC3A5IN2hGEHZzAY40=; b=QQMd6ppMThSwvUEmXv0tZsCFI3D4NlpxqyBz/b9BYG1+9KZ6nXUX/TxzZnLdDFRqmiOjj0 0AIFdSO+yOQkUdeake9sp00Pp3MH1uDzfZCu5fvZMltOEkOrcQpMLcMGwjVRLUJOxYOANB eLhFrAYS7H9IdAXduDiDnVj/dLX759w= 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-436-z2XTngRQPGGugyPz_uhMmg-1; Wed, 07 Sep 2022 11:45:53 -0400 X-MC-Unique: z2XTngRQPGGugyPz_uhMmg-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 7425D80A0B9; Wed, 7 Sep 2022 15:45:52 +0000 (UTC) Received: from firesoul.localdomain (unknown [10.40.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A29790A04; Wed, 7 Sep 2022 15:45:52 +0000 (UTC) Received: from [192.168.42.3] (localhost [IPv6:::1]) by firesoul.localdomain (Postfix) with ESMTP id 35B0330721A6C; Wed, 7 Sep 2022 17:45:51 +0200 (CEST) From: Jesper Dangaard Brouer To: bpf@vger.kernel.org Date: Wed, 07 Sep 2022 17:45:51 +0200 Message-ID: <166256555117.1434226.17491394872817800182.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: TLZCTJTV2ETD2OJ74XU7N7D2VZ6DNV2O X-Message-ID-Hash: TLZCTJTV2ETD2OJ74XU7N7D2VZ6DNV2O 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 10/18] btf: Add helper for kernel modules to lookup full BTF ID List-Id: XDP hardware hints design discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: NIC driver modules need to store the full BTF ID as the last member in metadata area usually written as xdp_hints_common->btf_full_id. This full BTF ID is a 64-bit value, encoding the modules own BTF object ID as the high 32-bit and specific struct BTF type ID as lower 32-bit. Drivers should invoke this once at init time and cache this BTF ID for runtime usage. Signed-off-by: Jesper Dangaard Brouer --- include/linux/btf.h | 1 + kernel/bpf/btf.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/btf.h b/include/linux/btf.h index a66266c00c04..b8f7c92b6767 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -150,6 +150,7 @@ 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); +u64 btf_get_module_btf_full_id(struct btf *btf, const char *name); 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 1e95391e0ca1..10a859943a49 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -7092,6 +7092,29 @@ struct btf *btf_get_module_btf(const struct module *module) } EXPORT_SYMBOL_GPL(btf_get_module_btf); +u64 btf_get_module_btf_full_id(struct btf *btf, const char *name) +{ + s32 type_id; + u64 obj_id; + + if (IS_ERR_OR_NULL(btf)) + return 0; + + obj_id = btf_obj_id(btf); + type_id = btf_find_by_name_kind(btf, name, BTF_KIND_STRUCT); + if (type_id < 0) { + pr_warn("Module %s(ID:%d): BTF cannot find struct %s", + btf->name, (u32)obj_id, name); + return 0; + } + + pr_info("Module %s(ID:%d): BTF type id %d for struct %s", + btf->name, (u32)obj_id, type_id, name); + + return type_id | (obj_id << 32); +} +EXPORT_SYMBOL_GPL(btf_get_module_btf_full_id); + BPF_CALL_4(bpf_btf_find_by_name_kind, char *, name, int, name_sz, u32, kind, int, flags) { struct btf *btf = NULL;