From patchwork Wed Jul 14 14:15:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 477892 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, URIBL_BLOCKED, 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 A72EAC11F66 for ; Wed, 14 Jul 2021 14:15:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8ABA9613C3 for ; Wed, 14 Jul 2021 14:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239418AbhGNOSm (ORCPT ); Wed, 14 Jul 2021 10:18:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232170AbhGNOSj (ORCPT ); Wed, 14 Jul 2021 10:18:39 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D125C061760 for ; Wed, 14 Jul 2021 07:15:47 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id l17-20020a05600c1d11b029021f84fcaf75so4021122wms.1 for ; Wed, 14 Jul 2021 07:15:46 -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=2e9bWP8sof1c4hjxI9a8uAGITp4HXNPUGK5CMz0uo/c=; b=AD9P7dIbeC/tvILoqAn/ihGMgFSzgIQk9U4kBgDLGnGk2rxQs034kvv53QS/2jiQTP whKo8jaRXRJlISw0LiXB87hE0eUb6Pp6+ii/W0JrkZvKordFmbt/NnfZ8e1VAfUyaQp7 ZMgF5m5zX1yfj60svjvB1e8NqKxZLZ0eBhABFBOJqsmjVBWqp1UpcYaznOUvBo10Cdcb MRlY9NDSw2izpQ8YYny050IQN3Mv1SKdpmF/xH0C6F3pNRUqNUag9TPBIPV+gtMyYuL9 Y6C2rYvcvfjtfuNI5d0pffAGEGqoFxRRH1bqxEuYU7PjCEsTv66ZtGkS6H7M8CXLeYHB zgyw== 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=2e9bWP8sof1c4hjxI9a8uAGITp4HXNPUGK5CMz0uo/c=; b=ZoNiJeKGEFJidR0WZiZmw2OX2gbOvLr8xGdr3wBtzk3optFzbIDIWM7W7h1iv9U8Pe VwJLsrElcHxivLFfHSKX6u7GfKIBMK75rh0/cO5WfEWOumZspL05Akwc6i8b8D7PwCzp OKPG3HsFvRBjpIYqgennr8quCobHhtPOZ56Hegj/Mpl0q418WLPcQFsShQNJCkez9L/a HF7xLiTYXUm816Qz90DsRXLjlSKRL0JHD2Buc9xcvHJJi6C4LbZWUX7ss8/HI7omVL+z sQkzZeKmofVDQmAiweRQsO9tTPVYx2POeRzN0GE1D0NkvyTk57wpU+r2xq1eAACBOFKE 5FDA== X-Gm-Message-State: AOAM530VLqh51FGvfEIR5FBPrX6bJMch2D+/C6DNY+T8lD+IWlMCGEd3 wbZgtxOwTTDajVub777QgnEv/g== X-Google-Smtp-Source: ABdhPJx5CkeJ9H0z8Qc+tCY1bKPlX17dD3iuZG5n2melu/9cHOpMMLlMIgbFAgtz9VETXLUsNLjDcQ== X-Received: by 2002:a7b:c346:: with SMTP id l6mr11315586wmj.109.1626272145603; Wed, 14 Jul 2021 07:15:45 -0700 (PDT) Received: from localhost.localdomain ([149.86.90.174]) by smtp.gmail.com with ESMTPSA id a207sm6380037wme.27.2021.07.14.07.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 07:15:45 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Quentin Monnet Subject: [PATCH bpf-next 1/6] libbpf: rename btf__load() as btf__load_into_kernel() Date: Wed, 14 Jul 2021 15:15:27 +0100 Message-Id: <20210714141532.28526-2-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714141532.28526-1-quentin@isovalent.com> References: <20210714141532.28526-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, and rename it instead as btf__load_into_kernel(). This new name better reflects what the function does, and should be less confusing. References: - https://github.com/libbpf/libbpf/issues/278 - https://github.com/libbpf/libbpf/wiki/Libbpf:-the-road-to-v1.0#btfh-apis Signed-off-by: Quentin Monnet --- tools/lib/bpf/btf.c | 3 ++- tools/lib/bpf/btf.h | 1 + tools/lib/bpf/libbpf.c | 2 +- tools/lib/bpf/libbpf.map | 5 +++++ 4 files changed, 9 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 b54f1c3ebd57..b36f1b2805dc 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 88b99401040c..d8b7c7750402 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -2768,7 +2768,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 944c99d1ded3..d42f20b0e9e4 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -375,3 +375,8 @@ LIBBPF_0.5.0 { bpf_object__gen_loader; libbpf_set_strict_mode; } LIBBPF_0.4.0; + +LIBBPF_0.6.0 { + global: + btf__load_into_kernel; +} LIBBPF_0.5.0; From patchwork Wed Jul 14 14:15:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 477289 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, URIBL_BLOCKED, 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 7E802C11F68 for ; Wed, 14 Jul 2021 14:15:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B983613C3 for ; Wed, 14 Jul 2021 14:15:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239440AbhGNOSn (ORCPT ); Wed, 14 Jul 2021 10:18:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232543AbhGNOSj (ORCPT ); Wed, 14 Jul 2021 10:18:39 -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 10888C061764 for ; Wed, 14 Jul 2021 07:15:48 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id v5so3436721wrt.3 for ; Wed, 14 Jul 2021 07:15:47 -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=CSW+B8YeFefYH1Ir/Q2pn5cgLIgymPkcnV1aC48t328=; b=jcYB+fAnFlM89GbF6jSoChSI1X8hpt0qa1TkLBTjktSG14qYVAUiI1YlTBShihuN6/ bX4tKst7U92Z6Ah9kM9zUEqr2oGNHOj2f9BgFGcEDB5KGsfNygCNyM3q0xN2qbEWfMUn Z3sRVixnhsFAGftjvIWBc2AhGPPXGQpbaXNSvMYJ9lmzaFuTB1RivAVVzNeD5ItqCdfs zuLmrxkT/G0BnFnMcKPyNVG/mH4JywJ6cqGi/hGUCetkGTaGRrTJ0+B4KsA4y4VMY+f8 wtqjPgkziTww+vBq/GNVSM6JGh3JSaNX0iBZ0Ee6Fbv+Yx4lpwdJqtFX1+cI5nobwEHy TKbw== 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=CSW+B8YeFefYH1Ir/Q2pn5cgLIgymPkcnV1aC48t328=; b=XPzRs/jboLXTzin0HtSFDFqbxWLbvPv3SLJmfNilvjmCtoOpnCzjeU0WnvhqzSau/L t8mAgGe6O2m+nRcHM0MBFqTPv4yhJG2c9r9lX/gkRNsjtXgPFlqGQcFgngLeL8XMZvAj Mfu1M580KNoiNsqFj2OH5iMcgECep6uEhXH+RUjIewxYkdFONuZlwvK6NlEhvL1gk0Lu UWdZb/0wA6LlLBE8jIgaBmBb3Xv+Ov/wCIjX9YTaswMkjdzQk23H6SbUUMNNgKI3i2xA ofspAaIwa72idY3z8lKJUYUy0yaGJrXpz4rw5x8NDtu7yIbD3q1OPalVz7Zx5wunoR3R os8w== X-Gm-Message-State: AOAM532Om0twrErCBFG8PAWDQSREum93vs8byIX3TeYDrzTep6AsmU1i m/MOt00ziv6ho16Fojm7yi6/UA== X-Google-Smtp-Source: ABdhPJwQ0Mr/d+SVS2DU2E5nwYxhdWCe5g8XJjw6kBoIjdnbYFY4V49UQPqwl9xf8RcZ8nZjw1xKGg== X-Received: by 2002:a05:6000:1c4:: with SMTP id t4mr13400198wrx.181.1626272146728; Wed, 14 Jul 2021 07:15:46 -0700 (PDT) Received: from localhost.localdomain ([149.86.90.174]) by smtp.gmail.com with ESMTPSA id a207sm6380037wme.27.2021.07.14.07.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 07:15:46 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Quentin Monnet Subject: [PATCH bpf-next 2/6] libbpf: rename btf__get_from_id() as btf__load_from_kernel_by_id() Date: Wed, 14 Jul 2021 15:15:28 +0100 Message-Id: <20210714141532.28526-3-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714141532.28526-1-quentin@isovalent.com> References: <20210714141532.28526-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. 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 Signed-off-by: Quentin Monnet --- tools/lib/bpf/btf.c | 4 +++- tools/lib/bpf/btf.h | 1 + tools/lib/bpf/libbpf.c | 2 +- tools/lib/bpf/libbpf.map | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 7e0de560490e..05b63b63083a 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; } -int btf__get_from_id(__u32 id, struct btf **btf) +int btf__load_from_kernel_by_id(__u32 id, struct btf **btf) { struct btf *res; int err, btf_fd; @@ -1404,6 +1404,8 @@ int btf__get_from_id(__u32 id, struct btf **btf) *btf = res; return 0; } +int btf__get_from_id(__u32, struct btf **) + __attribute__((alias("btf__load_from_kernel_by_id"))); 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/btf.h b/tools/lib/bpf/btf.h index b36f1b2805dc..0bd9d3952d19 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 int btf__load_from_kernel_by_id(__u32 id, struct btf **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.c b/tools/lib/bpf/libbpf.c index d8b7c7750402..e54fa1e57d48 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9571,7 +9571,7 @@ 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)) { + if (btf__load_from_kernel_by_id(info->btf_id, &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 d42f20b0e9e4..a687cc63cd80 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -378,5 +378,6 @@ LIBBPF_0.5.0 { LIBBPF_0.6.0 { global: + btf__load_from_kernel_by_id; btf__load_into_kernel; } LIBBPF_0.5.0; From patchwork Wed Jul 14 14:15:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 477891 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, URIBL_BLOCKED, 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 49142C07E9A for ; Wed, 14 Jul 2021 14:15:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30B9E613C3 for ; Wed, 14 Jul 2021 14:15:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239442AbhGNOSp (ORCPT ); Wed, 14 Jul 2021 10:18:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232903AbhGNOSl (ORCPT ); Wed, 14 Jul 2021 10:18:41 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CFD1C061766 for ; Wed, 14 Jul 2021 07:15:49 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id l8-20020a05600c1d08b02902333d79327aso917171wms.3 for ; Wed, 14 Jul 2021 07:15:49 -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=KnV1IxvXRQoR00fEj1yWcBXzpeN1it4YJCVUINfscbk=; b=PLSU9UfQ4FbWS0Zps9YzeqR+qUSHaTWyYhANYa2EQCh1xekU6PbcRRBlLCr/SSlilc i1QHDfWRF86U2OKRmZiChuDFYMtQDvNRoMBRrh8lI2OfgNYjUgziLYgDZANQZlvBA2cY 1YrcSUYj6iLr5GCKS2kpd948q5Xvsvy3gPjtz2WBc9f/aInhTVcBu2uQse6gVU26o4Q1 qqMZ9rh6P6GMKstdnTTRkFlLnqCmdFEuvJ8PfUSzmSwBW13WaZTpEZ6Yy8o5SxVR18s5 miO+kZlsQOSNjifJUHGts79GcnzeG6z8DQbj6ssC3NClhKuHhrNrLuzQyFSau6ONOp5J qJWg== 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=KnV1IxvXRQoR00fEj1yWcBXzpeN1it4YJCVUINfscbk=; b=gzUWEeeOR3oMPzvRbBQ/DP6tlKmikVuOJY8W7wjDbF5WTliJxWHgf2l2Vul8mqsal2 0AOm5N1ocOcIqK7cbBIs8tiESubLg2ukQQZpq0GdxeLB5YEAsHLqf060z4IPxcNudTp6 iHVqnQxUW73Y1YkQB44oyEgI8TDhVDf0roV+BfFSp1YCqW/02/aqqj3XDJ3xgv5eEfuI esBoWI9eDdmL98Z2Ga7qdPDG2qIVaG2ZbNobZmu/sxkewAeQWwC0QQqurp9PXKazoVfz UEUZ4k3grk74nJu7p2Ap2rCGL/SVDGD7aR3gSN7x8ZXiA2WtqMbhsW9ocd3doWBEJjnq 0yxg== X-Gm-Message-State: AOAM532g3QHfU2QpvcYBGXIZ1zjz6N7oOF8AC1Sr7Di1J3zEl0G+hvs+ e7RmO5HZQ1mBwT0LUWyeMBD8AA== X-Google-Smtp-Source: ABdhPJzOo5vmz7mcCJLZ/ajcg6ZW/XTcy/zt2U3R9LVJ4Atwy8Aamfvhpv/Xp/eeD2k/02qEwDbl7w== X-Received: by 2002:a1c:25c6:: with SMTP id l189mr4477132wml.49.1626272148002; Wed, 14 Jul 2021 07:15:48 -0700 (PDT) Received: from localhost.localdomain ([149.86.90.174]) by smtp.gmail.com with ESMTPSA id a207sm6380037wme.27.2021.07.14.07.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 07:15:47 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Quentin Monnet Subject: [PATCH bpf-next 3/6] tools: replace btf__get_from_id() with btf__load_from_kernel_by_id() Date: Wed, 14 Jul 2021 15:15:29 +0100 Message-Id: <20210714141532.28526-4-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714141532.28526-1-quentin@isovalent.com> References: <20210714141532.28526-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). Signed-off-by: Quentin Monnet --- tools/bpf/bpftool/btf.c | 2 +- tools/bpf/bpftool/btf_dumper.c | 2 +- tools/bpf/bpftool/map.c | 4 ++-- tools/bpf/bpftool/prog.c | 6 +++--- tools/perf/util/bpf-event.c | 4 ++-- tools/perf/util/bpf_counter.c | 2 +- tools/testing/selftests/bpf/prog_tests/btf.c | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c index 385d5c955cf3..2296e8eba0ff 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) { - err = btf__get_from_id(btf_id, &btf); + err = btf__load_from_kernel_by_id(btf_id, &btf); if (err) { p_err("get btf by id (%u): %s", btf_id, strerror(err)); goto done; diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c index 7ca54d046362..92db1fccda49 100644 --- a/tools/bpf/bpftool/btf_dumper.c +++ b/tools/bpf/bpftool/btf_dumper.c @@ -65,7 +65,7 @@ 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)) + btf__load_from_kernel_by_id(info->btf_id, &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..69ced1af0ab1 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c @@ -807,7 +807,7 @@ static struct btf *get_map_kv_btf(const struct bpf_map_info *info) } else if (info->btf_value_type_id) { int err; - err = btf__get_from_id(info->btf_id, &btf); + err = btf__load_from_kernel_by_id(info->btf_id, &btf); if (err || !btf) { p_err("failed to get btf"); btf = err ? ERR_PTR(err) : ERR_PTR(-ESRCH); @@ -1042,7 +1042,7 @@ static void print_key_value(struct bpf_map_info *info, void *key, struct btf *btf = NULL; int err; - err = btf__get_from_id(info->btf_id, &btf); + err = btf__load_from_kernel_by_id(info->btf_id, &btf); if (err) { p_err("failed to get btf"); return; diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index cc48726740ad..663828f96358 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -263,7 +263,7 @@ static void show_prog_metadata(int fd, __u32 num_maps) if (!value) return; - err = btf__get_from_id(map_info.btf_id, &btf); + err = btf__load_from_kernel_by_id(map_info.btf_id, &btf); if (err || !btf) goto out_free; @@ -646,7 +646,7 @@ 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)) { + if (info->btf_id && btf__load_from_kernel_by_id(info->btf_id, &btf)) { p_err("failed to get btf"); return -1; } @@ -2013,7 +2013,7 @@ static char *profile_target_name(int tgt_fd) } if (info_linear->info.btf_id == 0 || - btf__get_from_id(info_linear->info.btf_id, &btf)) { + btf__load_from_kernel_by_id(info_linear->info.btf_id, &btf)) { p_err("prog FD %d doesn't have valid btf", tgt_fd); goto out; } diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c index cdecda1ddd36..5e0aa7d379f0 100644 --- a/tools/perf/util/bpf-event.c +++ b/tools/perf/util/bpf-event.c @@ -223,7 +223,7 @@ 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)) { + if (btf__load_from_kernel_by_id(info->btf_id, &btf)) { pr_debug("%s: failed to get BTF of id %u, aborting\n", __func__, info->btf_id); err = -1; btf = NULL; @@ -478,7 +478,7 @@ 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)) { + if (btf__load_from_kernel_by_id(btf_id, &btf)) { pr_debug("%s: failed to get BTF of id %u, aborting\n", __func__, btf_id); goto out; diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c index 5ed674a2f55e..9b9d24016772 100644 --- a/tools/perf/util/bpf_counter.c +++ b/tools/perf/util/bpf_counter.c @@ -85,7 +85,7 @@ static char *bpf_target_prog_name(int tgt_fd) } if (info_linear->info.btf_id == 0 || - btf__get_from_id(info_linear->info.btf_id, &btf)) { + btf__load_from_kernel_by_id(info_linear->info.btf_id, &btf)) { pr_debug("prog FD %d doesn't have valid btf\n", tgt_fd); goto out; } diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c index 857e3f26086f..60e0be02931d 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf.c +++ b/tools/testing/selftests/bpf/prog_tests/btf.c @@ -4350,7 +4350,7 @@ static void do_test_file(unsigned int test_num) goto done; } - err = btf__get_from_id(info.btf_id, &btf); + err = btf__load_from_kernel_by_id(info.btf_id, &btf); if (CHECK(err, "cannot get btf from kernel, err: %d", err)) goto done; From patchwork Wed Jul 14 14:15:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 477288 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, URIBL_BLOCKED, 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 882C7C11F66 for ; Wed, 14 Jul 2021 14:15:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DCF6613D3 for ; Wed, 14 Jul 2021 14:15:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239478AbhGNOSq (ORCPT ); Wed, 14 Jul 2021 10:18:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239429AbhGNOSn (ORCPT ); Wed, 14 Jul 2021 10:18:43 -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 49BB8C06175F for ; Wed, 14 Jul 2021 07:15:51 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id l17-20020a05600c1d11b029021f84fcaf75so4021300wms.1 for ; Wed, 14 Jul 2021 07:15:51 -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=9g7oMOBxjsI3jeOuNMCaoSoX+v79UXg5NQkt+WfPeBE=; b=RagfVc4cz29UZtABpYH5XLJymWhhFKFHhqsVMwsa2WXAEEqlPxcHS5blXMdL6LDS5b 8nZdggt4SnZpunNI1bZuC60yUdnC3P5RLkJyQNsM4M2GUV+M5U/INEcrwqDoQiz2FcbS x30VEzbUM8rtM5Kv38UWd7fDtTJFpwBYCfNgGg+Fw5ZvMxRTLsEFEKsWB85hyFnVDbKk ZpHGG+d+5O+cyv3hP25JY9k3Frr3PXRtaJ5DKbAuSwEoqG90DBVwABiC2oMJGymAxD/y SOsALrHwSUy0RJeJYLfwu6Hr/d22VggS+umUsflKLWMAVKsOrPlummumP3iK10FQTkSv pKBw== 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=9g7oMOBxjsI3jeOuNMCaoSoX+v79UXg5NQkt+WfPeBE=; b=Os04TsshkNK21fueZId+KCOfi7F1f7twpNIdgJ7OeSHQ9CSV9ArWxSeEwDwy1SzZ5G rTT5WoOIy/4hc04vOC/k9tQYf9xeqGV3isJT8ky1JgA0P6VfGLQbYugcXHzthiRnhIo+ GiXD3tiylwVU5wEnHehC5+AtD8ysygcDw8qOWOvRHKNAWEAnJ9757a+7+zCXkf0ORwc3 kN/o1BTHLEoRa/2FjpIaAhBNMfe+OdKaVyjrjwjPCIPz3O8yZZwLu+qXgHU+cQuhGAbF qHPgKxzhYfotsRd/IFwhJpXJ8Z4BX0bllI643KxE4cLVZtzYPGJvHHdLffIqlk6Dlxx+ ktcw== X-Gm-Message-State: AOAM531H27bGXicMDi0oWKiwxBCjsqPi3076xvYtx6igLTvsZ8cID32D vWdTkbimwx3MVKfekVNKGF7VLg== X-Google-Smtp-Source: ABdhPJzoi3IW041Df/KOPi4/TALvaa/DA0LmFOtk5iOIqGcHvlAq5ZFzZEJAE1hoYUfQFMLyN2jO4Q== X-Received: by 2002:a05:600c:2197:: with SMTP id e23mr11457397wme.101.1626272149176; Wed, 14 Jul 2021 07:15:49 -0700 (PDT) Received: from localhost.localdomain ([149.86.90.174]) by smtp.gmail.com with ESMTPSA id a207sm6380037wme.27.2021.07.14.07.15.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 07:15:48 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Quentin Monnet Subject: [PATCH bpf-next 4/6] libbpf: explicitly mark btf__load() and btf__get_from_id() as deprecated Date: Wed, 14 Jul 2021 15:15:30 +0100 Message-Id: <20210714141532.28526-5-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714141532.28526-1-quentin@isovalent.com> References: <20210714141532.28526-1-quentin@isovalent.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Now that we have replacement functions for btf__load() and btf__get_from_id(), with names that better reflect what the functions do, and that we have updated the different tools in the repository calling the legacy functions, let's explicitly mark those as deprecated. References: - https://github.com/libbpf/libbpf/issues/278 - https://github.com/libbpf/libbpf/wiki/Libbpf:-the-road-to-v1.0#btfh-apis Signed-off-by: Quentin Monnet --- tools/lib/bpf/btf.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 0bd9d3952d19..522277b16a88 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -45,7 +45,8 @@ LIBBPF_API struct btf *btf__parse_raw(const char *path); LIBBPF_API struct btf *btf__parse_raw_split(const char *path, struct btf *base_btf); LIBBPF_API int btf__finalize_data(struct bpf_object *obj, struct btf *btf); -LIBBPF_API int btf__load(struct btf *btf); +LIBBPF_API LIBBPF_DEPRECATED("the name was confusing and will be removed in the future libbpf versions, please use btf__load_into_kernel() instead") +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); @@ -67,7 +68,8 @@ LIBBPF_API void btf__set_fd(struct btf *btf, int fd); 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 LIBBPF_DEPRECATED("the name was confusing and will be removed in the future libbpf versions, please use btf__load_from_kernel_by_id() instead") +int btf__get_from_id(__u32 id, struct btf **btf); LIBBPF_API int btf__load_from_kernel_by_id(__u32 id, struct btf **btf); LIBBPF_API int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, __u32 expected_key_size, From patchwork Wed Jul 14 14:15:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 477890 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, URIBL_BLOCKED, 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 9B8E7C11F67 for ; Wed, 14 Jul 2021 14:15:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81C82613CF for ; Wed, 14 Jul 2021 14:15:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239479AbhGNOSr (ORCPT ); Wed, 14 Jul 2021 10:18:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239445AbhGNOSn (ORCPT ); Wed, 14 Jul 2021 10:18:43 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 893ADC061764 for ; Wed, 14 Jul 2021 07:15:51 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id b14-20020a1c1b0e0000b02901fc3a62af78so4010931wmb.3 for ; Wed, 14 Jul 2021 07:15:51 -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=2fjmBoiBuTHHSOG8QbLHOu0AmN8x1dRxJVG9Qi9Evvo=; b=K+FIJQ6iPKBsM2PKaE5Hrwf75+Z8Tjs+fvChg4WHywd7BzucRYhZf9HqNiUsb3SX9d GGyn0YRdRQdU6mnYaizkUxTbkMApnB4EnZkzDZIYkgBHwyZI6JU6/1e6V5MvTvvGKFty dzNch8XxxIRO7WuDw95GtMocrFb7JBT9z/rGtceSBcgX3ZV9nRzY9BtgVsJ17OOgAFTj qIbFxdQDp/Q1GMjilDBPvCxIRmHDWxaVRBOEXHyXUMsqXEE60JU0uL4VR5inhcmBRova faFPETtT2MeToOfF8NEuDb2b5FsS1/zQBO+JUXnIHQt1ZRtWt9Fvab794I5K4tmU09gJ xilA== 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=2fjmBoiBuTHHSOG8QbLHOu0AmN8x1dRxJVG9Qi9Evvo=; b=AC5bUwr6UIFe5Gp9cYKLbLRtjeby2H6OKlFeCsW7GXN/iY2db2QkQx2L3yc25KBnKs Zovn9pDZywhPmp44uiWtdljV4b9E+jrFbyvC5kmJ8mzZuv6x/Da+amgv6f7Ghs7fgY60 6OSF/2k4Gw0Z2uYZIygQGVaKljfsPko5CpPlId5GBQ+OtyY6mq4/mGH4e0KRwxX0B+9g Buo4tF4nhf5LS6IxPevBzpSFETtVcyUCLqj2cC7L9Ym8jOirDndVEkZxnT0VCqpAUpR4 pFVD3ztUG+gIpuUNH9dyoO8CmqKqr/9YvKIp/PW3S7SxwlNSljidpHGQsgU8N0H+/4tq 5M5g== X-Gm-Message-State: AOAM530SYcmPdT8s+/cMLQacaD//W4ytSdzwHKsLbHo8ZoRhafo+MIpj 2D0e0jKRguh7zo2boXgQg9qKPA== X-Google-Smtp-Source: ABdhPJxi+X4Uch5463AWnLf6YB2IWCQDTHY9O6teuJIqKNcdqi6eTSEJ2dsK8uMHBC0h064SrRIFvw== X-Received: by 2002:a1c:c91a:: with SMTP id f26mr11598264wmb.162.1626272150180; Wed, 14 Jul 2021 07:15:50 -0700 (PDT) Received: from localhost.localdomain ([149.86.90.174]) by smtp.gmail.com with ESMTPSA id a207sm6380037wme.27.2021.07.14.07.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 07:15:49 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Quentin Monnet Subject: [PATCH bpf-next 5/6] libbpf: add split BTF support for btf__load_from_kernel_by_id() Date: Wed, 14 Jul 2021 15:15:31 +0100 Message-Id: <20210714141532.28526-6-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714141532.28526-1-quentin@isovalent.com> References: <20210714141532.28526-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 --- tools/lib/bpf/btf.c | 10 ++++++++-- tools/lib/bpf/btf.h | 2 ++ tools/lib/bpf/libbpf.map | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 05b63b63083a..15967dd80ffb 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -1383,7 +1383,8 @@ struct btf *btf_get_from_fd(int btf_fd, struct btf *base_btf) return btf; } -int btf__load_from_kernel_by_id(__u32 id, struct btf **btf) +int btf__load_from_kernel_by_id_split(__u32 id, struct btf **btf, + struct btf *base_btf) { struct btf *res; int err, btf_fd; @@ -1393,7 +1394,7 @@ int btf__load_from_kernel_by_id(__u32 id, struct btf **btf) if (btf_fd < 0) return libbpf_err(-errno); - res = btf_get_from_fd(btf_fd, NULL); + res = btf_get_from_fd(btf_fd, base_btf); err = libbpf_get_error(res); close(btf_fd); @@ -1407,6 +1408,11 @@ int btf__load_from_kernel_by_id(__u32 id, struct btf **btf) int btf__get_from_id(__u32, struct btf **) __attribute__((alias("btf__load_from_kernel_by_id"))); +int btf__load_from_kernel_by_id(__u32 id, struct btf **btf) +{ + return btf__load_from_kernel_by_id_split(id, btf, NULL); +} + int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, __u32 expected_key_size, __u32 expected_value_size, __u32 *key_type_id, __u32 *value_type_id) diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 522277b16a88..62291d3cc9c6 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -71,6 +71,8 @@ LIBBPF_API const char *btf__str_by_offset(const struct btf *btf, __u32 offset); LIBBPF_API LIBBPF_DEPRECATED("the name was confusing and will be removed in the future libbpf versions, please use btf__load_from_kernel_by_id() instead") int btf__get_from_id(__u32 id, struct btf **btf); LIBBPF_API int btf__load_from_kernel_by_id(__u32 id, struct btf **btf); +LIBBPF_API int btf__load_from_kernel_by_id_split(__u32 id, struct btf **btf, + 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 a687cc63cd80..f8420a6d7872 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -379,5 +379,6 @@ LIBBPF_0.5.0 { LIBBPF_0.6.0 { global: btf__load_from_kernel_by_id; + btf__load_from_kernel_by_id_split; btf__load_into_kernel; } LIBBPF_0.5.0; From patchwork Wed Jul 14 14:15:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 477287 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, URIBL_BLOCKED, 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 923FAC07E9A for ; Wed, 14 Jul 2021 14:15:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AAAC61183 for ; Wed, 14 Jul 2021 14:15:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239490AbhGNOSu (ORCPT ); Wed, 14 Jul 2021 10:18:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239449AbhGNOSo (ORCPT ); Wed, 14 Jul 2021 10:18:44 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACEAEC061762 for ; Wed, 14 Jul 2021 07:15:52 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id y21-20020a7bc1950000b02902161fccabf1so4020876wmi.2 for ; Wed, 14 Jul 2021 07:15:52 -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=mUCBpk5CyiIy6Bvb2NbvqDJflK7m0z2f3UFX/XqbowU=; b=RAYn8/FyE0vDqn1+um4/dz8OvsCxr3xK8V0y/cH7AFK8aH+gE18yp3X0EcDEfpSPoc KTky/k9y28lPJmzcxhzKgAi8aJUsdbOLvGAVl6MnEMEB1Btovt0aGlKZYMQBXsQHVG2g Q/zTCmD1iytWlKFNoCsm0zOzBxqDLR88Z0uZJmWdxCMK+DujzcTCA566SpjqTBHxUqsI cKHXwn97FRXHi7+T4zBYII3biel0jV0TizP04thyvHsHeGWuctfdMr5pCJOdWamJgwn1 wntfJYFam8/DLeKRtRtpk94h3nbCDC9ehAQvzAB3RctJBt/znjQPu3nKlErKEi7mvDq7 4cFA== 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=mUCBpk5CyiIy6Bvb2NbvqDJflK7m0z2f3UFX/XqbowU=; b=F0dKDRUHyp01cGjVz3sVq+MTn1ZTzVahG4DhyDUG5U3a/ktW/KOCo72Ksl22HQpyBB GaCtHkmhdBOzZbAfZwuXLpGWWM3WqfGexjIV0n6JGVuCq7+4YnnmS/xW1H1DvjhE5oLS RR2DGQAYpVwAo39Nn9S+fsjvGTNwukunIgUYWgsdjp2jPHjp6XQlPWN0F8QMrjSfzmZN 1CiU6ETjspd6eLYy5cL70y+OlUuIxiJdJu4e/yrA1etEWggcBVwY7K9PMjEsnrhol2P3 4Lc+rZToVOpIsqinWgyLaf2X53bKBD/oaMv1NhQlZ+sl7eSOTj4/lD2Tt+rm2hj2w3A4 Jm3Q== X-Gm-Message-State: AOAM531kMPcxhGzvBCcgJMPRPvD0FHl4/wB7EulwdifNaTwwsvTqj4aS A0b8O7RkOiEEw4FpPsYskpruCqoJNMisEA== X-Google-Smtp-Source: ABdhPJyj3j4nBjWxbdPwSLusLHVQgftz8JotKj/8bOPJqJh0mVBKnenv5b0+bmlA5F65Nne5T1f5vA== X-Received: by 2002:a7b:c147:: with SMTP id z7mr2175067wmi.110.1626272151231; Wed, 14 Jul 2021 07:15:51 -0700 (PDT) Received: from localhost.localdomain ([149.86.90.174]) by smtp.gmail.com with ESMTPSA id a207sm6380037wme.27.2021.07.14.07.15.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 07:15:50 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Quentin Monnet Subject: [PATCH bpf-next 6/6] tools: bpftool: support dumping split BTF by id Date: Wed, 14 Jul 2021 15:15:32 +0100 Message-Id: <20210714141532.28526-7-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210714141532.28526-1-quentin@isovalent.com> References: <20210714141532.28526-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 deprecated in favour of 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 --- 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 2296e8eba0ff..b77a59225f5b 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) { - err = btf__load_from_kernel_by_id(btf_id, &btf); + err = btf__load_from_kernel_by_id_split(btf_id, &btf, base_btf); if (err) { p_err("get btf by id (%u): %s", btf_id, strerror(err)); goto done;