From patchwork Wed Jul 21 15:38:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 483728 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=-19.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,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 2BCA9C636CA for ; Wed, 21 Jul 2021 15:38:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BC6A61221 for ; Wed, 21 Jul 2021 15:38:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240036AbhGUO5l (ORCPT ); Wed, 21 Jul 2021 10:57:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240021AbhGUO5h (ORCPT ); Wed, 21 Jul 2021 10:57:37 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55B69C061757 for ; Wed, 21 Jul 2021 08:38:14 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id y21-20020a7bc1950000b02902161fccabf1so3685965wmi.2 for ; Wed, 21 Jul 2021 08:38:14 -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=P8e81FmVgHT1ooYp1RVWBwSzx74yKgj81vQ/604cq6c=; b=y7VDqgQYzvwGexz+B2URdDKWk+BMFm4tOAj784WhXN4dflBSTx/XmReCxJI+sVgpx8 9ErmSN4/jH8xpz/uS6HZNYeSCS4wBbFX4KdQzo7hCOh+BuyB02P1ZZDxG+MPIwJTs1gT mxWyF1hfT7c3mDszeq84uREkzoAE2lKBoiNdWu0hofQYlZbGXNnFXhFwFrasQLChbNaE +56TQF/SPV/WXZkqaTLj1O1EOPcpVs3tg09uper+rEqlOvmGkI8UYmdLvA+VLfbF+EsW /T04+6SlFfNh9pkIgc6GM7NUZEtRdm85Mn0zak31VVr3LFVJZC3FPt68ARRqWi0+lcUL ks5g== 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=P8e81FmVgHT1ooYp1RVWBwSzx74yKgj81vQ/604cq6c=; b=sLjv3ceSXhEiPBaH3//ccSYcsp/UTykHgWQk7l2ahLALLaON0nS3ixxKvA9MSW8lXu oUPNr98ZrMvblAFtv5eyAr24RWc0sHhzk3Jve09XPf3x/ucuQ2Gtxtr/6GlaoXI5rF0Q rRNaT3YxxvVMMAesQlgJadD6JKmXzPEGegZmragEgOWHfeK8vMSJkIE4jEjJnbh8XX0Y AsZYkbvAXwXXPufOcIrIvAmVC9kBJQZJyju0RvH2lpmf1dowSdsROrPiiiuGeryPIb4U EFkOdRYE2kKAgBklyRQBl0P9SW0hasTdMOiyS0gJNWBSbejBCSnsMxENqW0kPYgnmOOi lodA== X-Gm-Message-State: AOAM533b6kHLRNaT/Rh7YBCOiXpW5woK/A58VGZ0dK9Cf6Ii80G080R0 7y3Xbn19TIDvJYhZ3J7IavS63Q== X-Google-Smtp-Source: ABdhPJzR1j4kVFBfddGNf4girU0lRaR4WWpFTyTmSUL3GfaKPQjhg/61rGOYWwxAZBe0uYES+7+hYw== X-Received: by 2002:a7b:c1cd:: with SMTP id a13mr4615406wmj.75.1626881892925; Wed, 21 Jul 2021 08:38:12 -0700 (PDT) Received: from localhost.localdomain ([149.86.71.195]) by smtp.gmail.com with ESMTPSA id n18sm26209714wrt.89.2021.07.21.08.38.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:38:12 -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 1/5] libbpf: rename btf__load() as btf__load_into_kernel() Date: Wed, 21 Jul 2021 16:38:04 +0100 Message-Id: <20210721153808.6902-2-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 As part of the effort to move towards a v1.0 for libbpf, rename btf__load() function, used to "upload" BTF information into the kernel, as btf__load_into_kernel(). This new name better reflects what the function does. References: - https://github.com/libbpf/libbpf/issues/278 - https://github.com/libbpf/libbpf/wiki/Libbpf:-the-road-to-v1.0#btfh-apis v2: Declare the new symbol in libbpf.map as v0.5.0 API (and not v0.6.0). Signed-off-by: Quentin Monnet Acked-by: John Fastabend --- tools/lib/bpf/btf.c | 3 ++- tools/lib/bpf/btf.h | 1 + tools/lib/bpf/libbpf.c | 2 +- tools/lib/bpf/libbpf.map | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index b46760b93bb4..7e0de560490e 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -1180,7 +1180,7 @@ int btf__finalize_data(struct bpf_object *obj, struct btf *btf) static void *btf_get_raw_data(const struct btf *btf, __u32 *size, bool swap_endian); -int btf__load(struct btf *btf) +int btf__load_into_kernel(struct btf *btf) { __u32 log_buf_size = 0, raw_size; char *log_buf = NULL; @@ -1228,6 +1228,7 @@ int btf__load(struct btf *btf) free(log_buf); return libbpf_err(err); } +int btf__load(struct btf *) __attribute__((alias("btf__load_into_kernel"))); int btf__fd(const struct btf *btf) { diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 374e9f15de2e..fd8a21d936ef 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -46,6 +46,7 @@ LIBBPF_API struct btf *btf__parse_raw_split(const char *path, struct btf *base_b LIBBPF_API int btf__finalize_data(struct bpf_object *obj, struct btf *btf); LIBBPF_API int btf__load(struct btf *btf); +LIBBPF_API int btf__load_into_kernel(struct btf *btf); LIBBPF_API __s32 btf__find_by_name(const struct btf *btf, const char *type_name); LIBBPF_API __s32 btf__find_by_name_kind(const struct btf *btf, diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 4c153c379989..242e97892043 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -2774,7 +2774,7 @@ static int bpf_object__sanitize_and_load_btf(struct bpf_object *obj) */ btf__set_fd(kern_btf, 0); } else { - err = btf__load(kern_btf); + err = btf__load_into_kernel(kern_btf); } if (sanitize) { if (!err) { diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 5bfc10722647..f7d52d76ca3a 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -373,6 +373,7 @@ LIBBPF_0.5.0 { bpf_map__initial_value; bpf_map_lookup_and_delete_elem_flags; bpf_object__gen_loader; + btf__load_into_kernel; btf_dump__dump_type_data; libbpf_set_strict_mode; } LIBBPF_0.4.0; From patchwork Wed Jul 21 15:38:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 484370 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=-21.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, 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 13D60C636CA for ; Wed, 21 Jul 2021 15:38:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF92061208 for ; Wed, 21 Jul 2021 15:38:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240050AbhGUO5s (ORCPT ); Wed, 21 Jul 2021 10:57:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240021AbhGUO5m (ORCPT ); Wed, 21 Jul 2021 10:57:42 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A1D9C061575 for ; Wed, 21 Jul 2021 08:38:15 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id u8-20020a7bcb080000b02901e44e9caa2aso1225211wmj.4 for ; Wed, 21 Jul 2021 08:38:15 -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=YFc+p2CWUZ27INFIKo1iQGYRXr1S7VT4yShsvIVH75w=; b=Edpwi6NgjS5enTGjsxjMTUMSFkA2+pWw1ynvfNeiqi6Ho2iFhN/nQtdC7M9JFWSQ34 AmKB8eUeFhWV5eC/HDGuWoUutH+oWZbFocXJY2GkIkr0TscoQUVTjnVPZhBXDKdj5fUu cNLVv0ikpqMdnYqzeozd3lJzT1XoitngTYOFIgIRzTEgA46Qocj8/kuDCnMiuiFHRYdq dU8H2mWbuK/1f3K9AB0q/trpPmi6I1DiRQPq0mKfuVQzndpLT2TJJiJfTS14Smb7j1cc +yJjPWg/QLhfPeso/2pDgvVkW3ZfkICbhcOv8X0mKfpJx+HEpx1tZAeBDObJpN3wrKy6 oj5g== 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=YFc+p2CWUZ27INFIKo1iQGYRXr1S7VT4yShsvIVH75w=; b=ra4P1x+yB3G7l1ZDq22wTuScs0zMC5hu7Cah39Cb5hFCU/VJH8MQQQfM23pyOvZ0Vc qkb+gJmJo7/6wjNbikrHEPtzHRCfj0brekoNwXyPWwiKF6Eimk/R2vXGsBSJLT8hM+nW w4oW55KLfUyImsJvho0NsrZFkwKaIZDZqDwk1H7KTEmXYnrGsBKqToS2qIJVKLAYZZCy ZbFo/QH0JcHHcmzKaDCQYIPkvyZvUgjf5MwCh5dNWFMq2Vxic6/YcgtHXBrcuwAaHweG KSmpqePcid9IYZBdNYSPpWL/Nxwj6uUdNq6ba7jvxkfo1zbV0kFz6abGuORll8CTv4H0 gkMQ== X-Gm-Message-State: AOAM532mxdAG6xrU8on5VSP34kFB37poKGE6VaIBFo4qIY7yTdeVKWaI QnhvnjuaX3rKiqhvVpb/TrY1KA== X-Google-Smtp-Source: ABdhPJz9Os3rKNk1W8eUTWaqPW0hKizkKc3HSKXdQqXV66JS7rUUXMrARReUKF+MslkNbCpRWrnqyQ== X-Received: by 2002:a05:600c:47c4:: with SMTP id l4mr4662002wmo.125.1626881893946; Wed, 21 Jul 2021 08:38:13 -0700 (PDT) Received: from localhost.localdomain ([149.86.71.195]) by smtp.gmail.com with ESMTPSA id n18sm26209714wrt.89.2021.07.21.08.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:38:13 -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 2/5] libbpf: rename btf__get_from_id() as btf__load_from_kernel_by_id() Date: Wed, 21 Jul 2021 16:38:05 +0100 Message-Id: <20210721153808.6902-3-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 Rename function btf__get_from_id() as btf__load_from_kernel_by_id() to better indicate what the function does. Change the new function so that, instead of requiring a pointer to the pointer to update and returning with an error code, it takes a single argument (the id of the BTF object) and returns the corresponding pointer. This is more in line with the existing constructors. The other tools calling the deprecated btf__get_from_id() function will be updated in a future commit. References: - https://github.com/libbpf/libbpf/issues/278 - https://github.com/libbpf/libbpf/wiki/Libbpf:-the-road-to-v1.0#btfh-apis v2: - Instead of a simple renaming, change the new function to make it return the pointer to the btf struct. - API v0.5.0 instead of v0.6.0. Signed-off-by: Quentin Monnet Acked-by: John Fastabend --- tools/lib/bpf/btf.c | 25 +++++++++++++++++-------- tools/lib/bpf/btf.h | 1 + tools/lib/bpf/libbpf.c | 5 +++-- tools/lib/bpf/libbpf.map | 1 + 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 7e0de560490e..6654bdee7ad7 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -1383,21 +1383,30 @@ struct btf *btf_get_from_fd(int btf_fd, struct btf *base_btf) return btf; } +struct btf *btf__load_from_kernel_by_id(__u32 id) +{ + struct btf *btf; + int btf_fd; + + btf_fd = bpf_btf_get_fd_by_id(id); + if (btf_fd < 0) + return ERR_PTR(-errno); + + btf = btf_get_from_fd(btf_fd, NULL); + close(btf_fd); + + return libbpf_ptr(btf); +} + int btf__get_from_id(__u32 id, struct btf **btf) { struct btf *res; - int err, btf_fd; + int err; *btf = NULL; - btf_fd = bpf_btf_get_fd_by_id(id); - if (btf_fd < 0) - return libbpf_err(-errno); - - res = btf_get_from_fd(btf_fd, NULL); + res = btf__load_from_kernel_by_id(id); err = libbpf_get_error(res); - close(btf_fd); - if (err) return libbpf_err(err); diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index fd8a21d936ef..3db9446bc133 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -68,6 +68,7 @@ LIBBPF_API const void *btf__get_raw_data(const struct btf *btf, __u32 *size); LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset); LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset); LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf); +LIBBPF_API struct btf *btf__load_from_kernel_by_id(__u32 id); LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, __u32 expected_key_size, __u32 expected_value_size, diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 242e97892043..eff005b1eba1 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9576,8 +9576,8 @@ static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd) { struct bpf_prog_info_linear *info_linear; struct bpf_prog_info *info; - struct btf *btf = NULL; int err = -EINVAL; + struct btf *btf; info_linear = bpf_program__get_prog_info_linear(attach_prog_fd, 0); err = libbpf_get_error(info_linear); @@ -9591,7 +9591,8 @@ static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd) pr_warn("The target program doesn't have BTF\n"); goto out; } - if (btf__get_from_id(info->btf_id, &btf)) { + btf = btf__load_from_kernel_by_id(info->btf_id); + if (libbpf_get_error(btf)) { pr_warn("Failed to get BTF of the program\n"); goto out; } diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index f7d52d76ca3a..ca8cc7a7faad 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -373,6 +373,7 @@ LIBBPF_0.5.0 { bpf_map__initial_value; bpf_map_lookup_and_delete_elem_flags; bpf_object__gen_loader; + btf__load_from_kernel_by_id; btf__load_into_kernel; btf_dump__dump_type_data; libbpf_set_strict_mode; From patchwork Wed Jul 21 15:38:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 483726 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 D3831C6377B for ; Wed, 21 Jul 2021 15:38:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9F4C61208 for ; Wed, 21 Jul 2021 15:38:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240045AbhGUO5r (ORCPT ); Wed, 21 Jul 2021 10:57:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240029AbhGUO5k (ORCPT ); Wed, 21 Jul 2021 10:57:40 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C4F2C0613D3 for ; Wed, 21 Jul 2021 08:38:16 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id l17-20020a05600c1d11b029021f84fcaf75so3687404wms.1 for ; Wed, 21 Jul 2021 08:38:16 -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=dEVfozjGZK/3dXowqh2UjKyafiJ11/pLn4v/JLvZ33I=; b=SYO393XMjJOWmHhl4A/je2qayJn67baAap99xgciGM0jVUBSQ6KaVLEW1RZYxXiG3K hXwxPT1FI+GnMxIz8ziNXoXHQqmXrosSUVMqQ9VjuDq0nU5VADvAVekv/MxzuozWACes CDUJzulXKB32msdDORX91hMunLFquMXDGDO9zS9bQDqnWRL7AeZBUr2dZOIvpFVguFSj Z5PO53lwqn1fbCco2FtdIZA3PPgbYL8FwxYxmBJJh5BiZVdJTlAYgpJRffN/kNap+xU2 Dex+h2W40wVcouWVHjrqRvENZ5bmrBxPPES+uEhsYa6LDEo53VsxqWG126FHK3NBd96x ie+A== 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=dEVfozjGZK/3dXowqh2UjKyafiJ11/pLn4v/JLvZ33I=; b=uUKiaSf3u7Pr4/hoi4dMSS8csTsM0p0QV1GeZjhcRvbugpGVXtYWBco3UXo9/F9edf dNe9L/axJIA5piokUebHpM6Bn2PRhS3PnWYFJauGfkcVuwjHO6aYyrIuKoaddayEUrWd 6V10ZKfxyL/FNEh8AD+bnYJhyHiTzd0UnM4pTi/t0SP5dOSCK/13lM7HfhEWiLgH5FPW DIpg7YuWRVP733+oxMNngT8vEAQ46ch1oAH0dR3QsZU6/ooVBXqzlG+4JNmwCF5Q0i+n tmCqKvppdqB8p2yaP/PnXWI0HrXpqENN8oTV8cDJgeArAC0p56NTVlxtMxG8RmUB76MX eECA== X-Gm-Message-State: AOAM5322gYswbm7sNN9m9rtJkpCCN0lnQEKoBR9uPbd77jo72Gh2kBzZ Qzd2Z+7qgIRO4DMluFw6LLg6vg== X-Google-Smtp-Source: ABdhPJydFT/Bb3DVweRNhn4GiJL0rY4pJ7EL4qDmDnOvoFRor1cSBIDu76Se4LhODFWIQTUK9QaA9g== X-Received: by 2002:a7b:c844:: with SMTP id c4mr4715597wml.107.1626881894983; Wed, 21 Jul 2021 08:38:14 -0700 (PDT) Received: from localhost.localdomain ([149.86.71.195]) by smtp.gmail.com with ESMTPSA id n18sm26209714wrt.89.2021.07.21.08.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:38:14 -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 3/5] tools: replace btf__get_from_id() with btf__load_from_kernel_by_id() Date: Wed, 21 Jul 2021 16:38:06 +0100 Message-Id: <20210721153808.6902-4-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 Replace the calls to deprecated function btf__get_from_id() with calls to btf__load_from_kernel_by_id() in tools/ (bpftool, perf, selftests). Update the surrounding code accordingly (instead of passing a pointer to the btf struct, get it as a return value from the function). Also make sure that btf__free() is called on the pointer after use. v2: - Given that btf__load_from_kernel_by_id() has changed since v1, adapt the code accordingly instead of just renaming the function. Also add a few calls to btf__free() when necessary. Signed-off-by: Quentin Monnet Acked-by: John Fastabend --- tools/bpf/bpftool/btf.c | 8 ++---- tools/bpf/bpftool/btf_dumper.c | 6 ++-- tools/bpf/bpftool/map.c | 16 +++++------ tools/bpf/bpftool/prog.c | 29 ++++++++++++++------ tools/perf/util/bpf-event.c | 11 ++++---- tools/perf/util/bpf_counter.c | 12 ++++++-- tools/testing/selftests/bpf/prog_tests/btf.c | 4 ++- 7 files changed, 51 insertions(+), 35 deletions(-) diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c index 385d5c955cf3..9162a18e84c0 100644 --- a/tools/bpf/bpftool/btf.c +++ b/tools/bpf/bpftool/btf.c @@ -580,16 +580,12 @@ static int do_dump(int argc, char **argv) } if (!btf) { - err = btf__get_from_id(btf_id, &btf); + btf = btf__load_from_kernel_by_id(btf_id); + err = libbpf_get_error(btf); if (err) { p_err("get btf by id (%u): %s", btf_id, strerror(err)); goto done; } - if (!btf) { - err = -ENOENT; - p_err("can't find btf with ID (%u)", btf_id); - goto done; - } } if (dump_c) { diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c index 7ca54d046362..9c25286a5c73 100644 --- a/tools/bpf/bpftool/btf_dumper.c +++ b/tools/bpf/bpftool/btf_dumper.c @@ -64,8 +64,10 @@ static int dump_prog_id_as_func_ptr(const struct btf_dumper *d, } info = &prog_info->info; - if (!info->btf_id || !info->nr_func_info || - btf__get_from_id(info->btf_id, &prog_btf)) + if (!info->btf_id || !info->nr_func_info) + goto print; + prog_btf = btf__load_from_kernel_by_id(info->btf_id); + if (libbpf_get_error(prog_btf)) goto print; finfo = u64_to_ptr(info->func_info); func_type = btf__type_by_id(prog_btf, finfo->type_id); diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index 09ae0381205b..12787758ce03 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c @@ -805,12 +805,11 @@ static struct btf *get_map_kv_btf(const struct bpf_map_info *info) } return btf_vmlinux; } else if (info->btf_value_type_id) { - int err; - - err = btf__get_from_id(info->btf_id, &btf); - if (err || !btf) { + btf = btf__load_from_kernel_by_id(info->btf_id); + if (libbpf_get_error(btf)) { p_err("failed to get btf"); - btf = err ? ERR_PTR(err) : ERR_PTR(-ESRCH); + if (!btf) + btf = ERR_PTR(-ESRCH); } } @@ -1039,11 +1038,10 @@ static void print_key_value(struct bpf_map_info *info, void *key, void *value) { json_writer_t *btf_wtr; - struct btf *btf = NULL; - int err; + struct btf *btf; - err = btf__get_from_id(info->btf_id, &btf); - if (err) { + btf = btf__load_from_kernel_by_id(info->btf_id); + if (libbpf_get_error(btf)) { p_err("failed to get btf"); return; } diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index cc48726740ad..b1996b8f1d42 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -249,10 +249,10 @@ static void show_prog_metadata(int fd, __u32 num_maps) struct bpf_map_info map_info; struct btf_var_secinfo *vsi; bool printed_header = false; - struct btf *btf = NULL; unsigned int i, vlen; void *value = NULL; const char *name; + struct btf *btf; int err; if (!num_maps) @@ -263,8 +263,8 @@ static void show_prog_metadata(int fd, __u32 num_maps) if (!value) return; - err = btf__get_from_id(map_info.btf_id, &btf); - if (err || !btf) + btf = btf__load_from_kernel_by_id(map_info.btf_id); + if (libbpf_get_error(btf)) goto out_free; t_datasec = btf__type_by_id(btf, map_info.btf_value_type_id); @@ -646,9 +646,12 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode, member_len = info->xlated_prog_len; } - if (info->btf_id && btf__get_from_id(info->btf_id, &btf)) { - p_err("failed to get btf"); - return -1; + if (info->btf_id) { + btf = btf__load_from_kernel_by_id(info->btf_id); + if (libbpf_get_error(btf)) { + p_err("failed to get btf"); + return -1; + } } func_info = u64_to_ptr(info->func_info); @@ -781,6 +784,8 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode, kernel_syms_destroy(&dd); } + btf__free(btf); + return 0; } @@ -2002,8 +2007,8 @@ static char *profile_target_name(int tgt_fd) struct bpf_prog_info_linear *info_linear; struct bpf_func_info *func_info; const struct btf_type *t; + struct btf *btf = NULL; char *name = NULL; - struct btf *btf; info_linear = bpf_program__get_prog_info_linear( tgt_fd, 1UL << BPF_PROG_INFO_FUNC_INFO); @@ -2012,12 +2017,17 @@ static char *profile_target_name(int tgt_fd) return NULL; } - if (info_linear->info.btf_id == 0 || - btf__get_from_id(info_linear->info.btf_id, &btf)) { + if (info_linear->info.btf_id == 0) { p_err("prog FD %d doesn't have valid btf", tgt_fd); goto out; } + btf = btf__load_from_kernel_by_id(info_linear->info.btf_id); + if (libbpf_get_error(btf)) { + p_err("failed to load btf for prog FD %d", tgt_fd); + goto out; + } + func_info = u64_to_ptr(info_linear->info.func_info); t = btf__type_by_id(btf, func_info[0].type_id); if (!t) { @@ -2027,6 +2037,7 @@ static char *profile_target_name(int tgt_fd) } name = strdup(btf__name_by_offset(btf, t->name_off)); out: + btf__free(btf); free(info_linear); return name; } diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c index cdecda1ddd36..996d025b8ed8 100644 --- a/tools/perf/util/bpf-event.c +++ b/tools/perf/util/bpf-event.c @@ -223,10 +223,10 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session, free(info_linear); return -1; } - if (btf__get_from_id(info->btf_id, &btf)) { + btf = btf__load_from_kernel_by_id(info->btf_id); + if (libbpf_get_error(btf)) { pr_debug("%s: failed to get BTF of id %u, aborting\n", __func__, info->btf_id); err = -1; - btf = NULL; goto out; } perf_env__fetch_btf(env, info->btf_id, btf); @@ -296,7 +296,7 @@ static int perf_event__synthesize_one_bpf_prog(struct perf_session *session, out: free(info_linear); - free(btf); + btf__free(btf); return err ? -1 : 0; } @@ -478,7 +478,8 @@ static void perf_env__add_bpf_info(struct perf_env *env, u32 id) if (btf_id == 0) goto out; - if (btf__get_from_id(btf_id, &btf)) { + btf = btf__load_from_kernel_by_id(btf_id); + if (libbpf_get_error(btf)) { pr_debug("%s: failed to get BTF of id %u, aborting\n", __func__, btf_id); goto out; @@ -486,7 +487,7 @@ static void perf_env__add_bpf_info(struct perf_env *env, u32 id) perf_env__fetch_btf(env, btf_id, btf); out: - free(btf); + btf__free(btf); close(fd); } diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c index 8150e03367bb..ba0f20853651 100644 --- a/tools/perf/util/bpf_counter.c +++ b/tools/perf/util/bpf_counter.c @@ -64,8 +64,8 @@ static char *bpf_target_prog_name(int tgt_fd) struct bpf_prog_info_linear *info_linear; struct bpf_func_info *func_info; const struct btf_type *t; + struct btf *btf = NULL; char *name = NULL; - struct btf *btf; info_linear = bpf_program__get_prog_info_linear( tgt_fd, 1UL << BPF_PROG_INFO_FUNC_INFO); @@ -74,12 +74,17 @@ static char *bpf_target_prog_name(int tgt_fd) return NULL; } - if (info_linear->info.btf_id == 0 || - btf__get_from_id(info_linear->info.btf_id, &btf)) { + if (info_linear->info.btf_id == 0) { pr_debug("prog FD %d doesn't have valid btf\n", tgt_fd); goto out; } + btf = btf__load_from_kernel_by_id(info_linear->info.btf_id); + if (libbpf_get_error(btf)) { + pr_debug("failed to load btf for prog FD %d\n", tgt_fd); + goto out; + } + func_info = u64_to_ptr(info_linear->info.func_info); t = btf__type_by_id(btf, func_info[0].type_id); if (!t) { @@ -89,6 +94,7 @@ static char *bpf_target_prog_name(int tgt_fd) } name = strdup(btf__name_by_offset(btf, t->name_off)); out: + btf__free(btf); free(info_linear); return name; } diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c index 857e3f26086f..649f87382c8d 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf.c +++ b/tools/testing/selftests/bpf/prog_tests/btf.c @@ -4350,7 +4350,8 @@ static void do_test_file(unsigned int test_num) goto done; } - err = btf__get_from_id(info.btf_id, &btf); + btf = btf__load_from_kernel_by_id(info.btf_id); + err = libbpf_get_error(btf); if (CHECK(err, "cannot get btf from kernel, err: %d", err)) goto done; @@ -4386,6 +4387,7 @@ static void do_test_file(unsigned int test_num) fprintf(stderr, "OK"); done: + btf__free(btf); free(func_info); bpf_object__close(obj); } From patchwork Wed Jul 21 15:38:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 483727 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=-19.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,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 C00D9C12002 for ; Wed, 21 Jul 2021 15:38:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A4DAA61003 for ; Wed, 21 Jul 2021 15:38:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240055AbhGUO5t (ORCPT ); Wed, 21 Jul 2021 10:57:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240038AbhGUO5n (ORCPT ); Wed, 21 Jul 2021 10:57:43 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 694D2C061798 for ; Wed, 21 Jul 2021 08:38:17 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id d12so2633458wre.13 for ; Wed, 21 Jul 2021 08:38:17 -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=fnOxE/tjyREC4ZyB6l9KZyxHyA5SXgSGw3IqkFpMRkw=; b=BWy+BqtQHYwnvDrTJ0vM3lU8Rt87nFtAXLqsNZ0m5ThbkImzabkh2c/VpIXLE7BGCN u2ROwRKtxTsPPXGJoOsPhVC09m/lDS2EJy6lXUGM0ZSTsnCz03UYJ14SbdkdzHxbDaXs hIyMPkV0mAmvs2jncDwGaEDo2KyGJx6zh5EqswvxAGWKD9kJpt67SpR60fcHZfmd3pPF fKRwvb8YkhjXex/EGSCOoF2084EH6JdjhBLrYHeDJQhksVYPjBdn0Wrjt61dqtydFN6S 2jc9zcLZy5I1MJbAoO+eYLCveGETpjR4JH+5NmC+YvcYNgYLA7vW5okaDuu/CEnzIlco WIwQ== 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=fnOxE/tjyREC4ZyB6l9KZyxHyA5SXgSGw3IqkFpMRkw=; b=Z4+vZ30EKFFIOJnchN4GUpKkWu9GPt11J7/7XS6Mi8xILITX17CB6mcTpqe0lZApkp G54Eq1nUxXcHvLpC74usJirFHU+vZA6hgTj5lcPCtpoo2GQ6RtlowP1F04m/r0xQJSov Ks07vAQ2CIsatfB2yZsjszlkUiIp62VgP29AW/G5h8vZhQhUCyVVyhs+bHw2rZl5y6f2 dN09T4dgiwdCaWBfmdZomIwSzGssYYYl7tAEiSsVFdBXkIS7Q13vPKpMyQd/x7oHzAYJ SAT/O1JEhi4iL1T/1d0JW//28xHSoOSJdOyCQrhaWWLKTFCzTi5+ZstmK7agbvw8eScD 9m1A== X-Gm-Message-State: AOAM5338UeGmL0E+ygHM2VpN50I0VvbSMg3+6X05UJxXWPO9pm1U6zur ctjFRc3T26Bgf0CnQzoifFdIbw== X-Google-Smtp-Source: ABdhPJz/62r0jFfqQ6sCgbtWSgKcpXV+g9h6K7jglfCXoKIaPf+lKd5OtYK/Mb4d6No2lsPW8Qoz/g== X-Received: by 2002:a5d:65cb:: with SMTP id e11mr45268304wrw.105.1626881896030; Wed, 21 Jul 2021 08:38:16 -0700 (PDT) Received: from localhost.localdomain ([149.86.71.195]) by smtp.gmail.com with ESMTPSA id n18sm26209714wrt.89.2021.07.21.08.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 08:38:15 -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 4/5] libbpf: add split BTF support for btf__load_from_kernel_by_id() Date: Wed, 21 Jul 2021 16:38:07 +0100 Message-Id: <20210721153808.6902-5-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 Add a new API function btf__load_from_kernel_by_id_split(), which takes a pointer to a base BTF object in order to support split BTF objects when retrieving BTF information from the kernel. Reference: https://github.com/libbpf/libbpf/issues/314 Signed-off-by: Quentin Monnet Acked-by: John Fastabend --- tools/lib/bpf/btf.c | 9 +++++++-- tools/lib/bpf/btf.h | 2 ++ tools/lib/bpf/libbpf.map | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 6654bdee7ad7..38a901e3a483 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -1383,7 +1383,7 @@ struct btf *btf_get_from_fd(int btf_fd, struct btf *base_btf) return btf; } -struct btf *btf__load_from_kernel_by_id(__u32 id) +struct btf *btf__load_from_kernel_by_id_split(__u32 id, struct btf *base_btf) { struct btf *btf; int btf_fd; @@ -1392,12 +1392,17 @@ struct btf *btf__load_from_kernel_by_id(__u32 id) if (btf_fd < 0) return ERR_PTR(-errno); - btf = btf_get_from_fd(btf_fd, NULL); + btf = btf_get_from_fd(btf_fd, base_btf); close(btf_fd); return libbpf_ptr(btf); } +struct btf *btf__load_from_kernel_by_id(__u32 id) +{ + return btf__load_from_kernel_by_id_split(id, NULL); +} + int btf__get_from_id(__u32 id, struct btf **btf) { struct btf *res; diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 3db9446bc133..c9407d57d096 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -69,6 +69,8 @@ LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset); LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset); LIBBPF_API int btf__get_from_id(__u32 id, struct btf **btf); LIBBPF_API struct btf *btf__load_from_kernel_by_id(__u32 id); +LIBBPF_API struct btf *btf__load_from_kernel_by_id_split(__u32 id, + struct btf *base_btf); LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, __u32 expected_key_size, __u32 expected_value_size, diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index ca8cc7a7faad..eecf77227aeb 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -374,6 +374,7 @@ LIBBPF_0.5.0 { bpf_map_lookup_and_delete_elem_flags; bpf_object__gen_loader; btf__load_from_kernel_by_id; + btf__load_from_kernel_by_id_split; btf__load_into_kernel; btf_dump__dump_type_data; libbpf_set_strict_mode; 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));