From patchwork Wed Jul 21 15:38:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 484369 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19C26C6377E for ; Wed, 21 Jul 2021 15:38:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05A9A61245 for ; Wed, 21 Jul 2021 15:38:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240060AbhGUO5u (ORCPT ); Wed, 21 Jul 2021 10:57:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240041AbhGUO5q (ORCPT ); Wed, 21 Jul 2021 10:57:46 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 658BDC06179B for ; Wed, 21 Jul 2021 08:38:18 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id f17so2666614wrt.6 for ; Wed, 21 Jul 2021 08:38:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j0jhVjo6WTcaDV4uEQGKhqx9NDnOHVKLazidVPgUD5U=; b=lSuS1WXcz2AdA2zaTZWlRHJ5HnWusy+jwTK+/QkRMuwv9GjQXfYbSoO9epZ3LR9fr0 CbILGec66D7YzGZmtWcmj3/rRdVoGUQbs0Z4FVWmtg3vdXdk0j14wisV+3C/v3W7heXk N/n0V7DhESPO9jFxky0Ci7VOBJSPzkyhyE36jZdJCPk3HgInfrruyWmtkT9jrIs3vygd EatJLcYHAbhRn/vMtKuyeEuwtmJAjsYNuNRn/Gu62YXzYZvEGMTIfpqSk92ovfA+wDk+ 4LLoYxsGAtcWyx40iClsper2RD34eLzwd8pxt+VhvzMXnu5MmS17CKpLMUND2TauRaVe JLUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j0jhVjo6WTcaDV4uEQGKhqx9NDnOHVKLazidVPgUD5U=; b=JAuLIlS5XCvCiiULZTWBhwg3UTcPhvQR5AFKgHc/II/I8kbnBH2WvxjWPxRseVkuAI 0+fOhvWIB53IBm9rKWqb7hQltF2myY2Bl8urvjlo74DIcgrNlKH0jE07PSWNB4H82741 p1Wes4Zm9FyFGOIskswuqdlMxVcfZv8Cxmub5upvFmyVru2qA8vF9x4DgkVuhQn1E/Bz RAjMrth8TxPHPilvKCYBPykXrNxaqEEZw5G3hb8zxdiqbpVnkL5E27HX7FJoEqY4i8AE SoAOTjhjrPp4Zb8GqKACxjXr2vInYASB7Vn9kJ1JI4ibBXRh+Utdg/ZqNlJ0U/JbUrQb movw== X-Gm-Message-State: AOAM531bZCfor4Z9kgCop+vv9o+wu18QI1FCE2qaw4r0dsBBODfHInYe DGQ6Leg7EX7LKqM7FBYfHIW/9g== X-Google-Smtp-Source: ABdhPJwIS51VUZdciAOQH8LyHNFdK73sq/xqLzzQGxUQBINXPmfMTJd/PiBPi8+dtDsWQzPjUf/weQ== X-Received: by 2002:a05:6000:1d1:: with SMTP id t17mr42541805wrx.267.1626881897058; Wed, 21 Jul 2021 08:38:17 -0700 (PDT) Received: from localhost.localdomain ([149.86.71.195]) by smtp.gmail.com with ESMTPSA id n18sm26209714wrt.89.2021.07.21.08.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:38:16 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Quentin Monnet , John Fastabend Subject: [PATCH bpf-next v2 5/5] tools: bpftool: support dumping split BTF by id Date: Wed, 21 Jul 2021 16:38:08 +0100 Message-Id: <20210721153808.6902-6-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210721153808.6902-1-quentin@isovalent.com> References: <20210721153808.6902-1-quentin@isovalent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Split BTF objects are typically BTF objects for kernel modules, which are incrementally built on top of kernel BTF instead of redefining all kernel symbols they need. We can use bpftool with its -B command-line option to dump split BTF objects. It works well when the handle provided for the BTF object to dump is a "path" to the BTF object, typically under /sys/kernel/btf, because bpftool internally calls btf__parse_split() which can take a "base_btf" pointer and resolve the BTF reconstruction (although in that case, the "-B" option is unnecessary because bpftool performs autodetection). However, it did not work so far when passing the BTF object through its id, because bpftool would call btf__get_from_id() which did not provide a way to pass a "base_btf" pointer. In other words, the following works: # bpftool btf dump file /sys/kernel/btf/i2c_smbus -B /sys/kernel/btf/vmlinux But this was not possible: # bpftool btf dump id 6 -B /sys/kernel/btf/vmlinux The libbpf API has recently changed, and btf__get_from_id() has been replaced with btf__load_from_kernel_by_id() and its version with support for split BTF, btf__load_from_kernel_by_id_split(). Let's update bpftool to make it able to dump the BTF object in the second case as well. Signed-off-by: Quentin Monnet Acked-by: John Fastabend --- tools/bpf/bpftool/btf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c index 9162a18e84c0..0ce3643278d4 100644 --- a/tools/bpf/bpftool/btf.c +++ b/tools/bpf/bpftool/btf.c @@ -580,7 +580,7 @@ static int do_dump(int argc, char **argv) } if (!btf) { - btf = btf__load_from_kernel_by_id(btf_id); + btf = btf__load_from_kernel_by_id_split(btf_id, base_btf); err = libbpf_get_error(btf); if (err) { p_err("get btf by id (%u): %s", btf_id, strerror(err));