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: 12377033 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 47B3EC07E9A 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 2B43E613C3 for ; Wed, 14 Jul 2021 14:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233139AbhGNOSl (ORCPT ); Wed, 14 Jul 2021 10:18:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231543AbhGNOSj (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 F3B6FC06175F for ; Wed, 14 Jul 2021 07:15:46 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id g12so1693776wme.2 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=BuqCWLLbJeTDtSOdo2qvQEs00jiO1sG/v+QHGk7Mxv2rIIS3vEmbXpBNIV7HAMUFX7 UcQoOcimV0K9sRNAX2E5dpeD4/kaQ6z8aWR0UNsW0dIbJT/IkJ7b7Z24/RuHUQqibaZ+ 2M3S+Gh9l3vQEu27iLLq9LHn3vBktrRF5ydh879vrNpf7Rt3jWoLMsnbch1IQHakMlk1 uvzAdrGIF0f71zpsmG5UfVIs5flJjy6CG6fuWJcP1EkbpvAs0wUzttarjsB0Iy9i8SNx SSFBROwasSB81q74fuoGV+5OGhfaTx46Qw2cPyDVuklQHCGzqmuCPs9aZAY5NdHqLTkE Rffw== X-Gm-Message-State: AOAM531mHQeki9Yr9M7OjwasWP8TGEPbbk0db9d7FbU5mH2bKl5V67Dv TZQLLjvGBQ2hBBAh1QpY2GkICQ== 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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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: 12377037 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 B9012C07E9C 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 A47C1613D3 for ; Wed, 14 Jul 2021 14:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239399AbhGNOSm (ORCPT ); Wed, 14 Jul 2021 10:18:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232270AbhGNOSj (ORCPT ); Wed, 14 Jul 2021 10:18:39 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EF4FC061762 for ; Wed, 14 Jul 2021 07:15:48 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id i94so3431561wri.4 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=C6dUyHHLlP2RbRYHdRsaQVKQNSfE21u5tYdG/C4mL1m29COAw0hkKfWP12ZeWHaUP3 0ibnF27ASX8U253c3UVB8EZaAYqo2C3S+d1QHUZON/0ke7Lf/cJyt4xVBFOR+Z/Kg8wR Rn8HtsSjmpXDa9mIBAhQs4ONfZ/M676dD3rWLDCwlG6R0YhxcaHOqLej5I3Darum/0ib Opup0Q/Dl4psfPv4KPlUW0XvTW3SLWisrK3/ZlT017b1j/Zz0d77NXKNxa+zsHxaPS6Z 576h8QAW3SrCjT4vPR4JWCp4BiP5iRvqs2bIzdwvKBx9VRS/NJa8sAWs+Jx8X21H3H/P sTyw== X-Gm-Message-State: AOAM533OzpYw4U1ALMSK6Xdhb4vkk6GUahfLQrFr+S90/sUQk5pOR4CL 1QvgCvN0votiOllQXxxghPZ5ww5cF5e9Iw== 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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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: 12377035 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 0E6D9C11F67 for ; Wed, 14 Jul 2021 14:15:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EBEC8613D0 for ; Wed, 14 Jul 2021 14:15:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232270AbhGNOSm (ORCPT ); Wed, 14 Jul 2021 10:18:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232816AbhGNOSl (ORCPT ); Wed, 14 Jul 2021 10:18:41 -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 6BDACC061765 for ; Wed, 14 Jul 2021 07:15:49 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id u8-20020a7bcb080000b02901e44e9caa2aso1524936wmj.4 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=jBIJnWLObNQJs5KDuQTDmK0l1zOL3ZMhoNQzu7u2TIfFCy6bqohzU48P347jdB8+4T a/f6IDoI9McP1PVHgyiKH2Bi2+gaBZ4n3b3sg31O0YLXLUQQlLBez4hpY6AmBx1fdZTg qBTcGsWJeXH3S9PgMO2QKdZiUsmqwHbEsg1iH/1Nm0zXy2SAGgSnknIMKoP2W5web8F9 7WkFxGq/tLKG0e9MVnj7/UlWdav1v0amqlmpETspZ9BB8ZjduPzguE1+Y0DEC7A2hNLz YJwBwJQiOcHR20yJ7CO9+SRGza//haYU9yf2r20/B8mz+51/yS4AYfuRrtcpcaUrQCxP Ujgg== X-Gm-Message-State: AOAM530/1THQhRoHV2Q7EHUV/7Vzy730w8NAxrafM6OiubMIlTOw+SYu b8dMKFoanGrYlJY7/peiQKPbEg== 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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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: 12377041 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 02682C11F6A 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 E19D4613C3 for ; Wed, 14 Jul 2021 14:15:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239425AbhGNOSp (ORCPT ); Wed, 14 Jul 2021 10:18:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239447AbhGNOSn (ORCPT ); Wed, 14 Jul 2021 10:18:43 -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 4AC7CC061760 for ; Wed, 14 Jul 2021 07:15:51 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id q18-20020a1ce9120000b02901f259f3a250so1540536wmc.2 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=giatmN6uQFSKfJ097pKm/4asNYmusBx/zPOxq106UchbTOsUAqEXfs21t07apMGoqP 1swq4uoGc+iCtPtYtwbEyGVocNtylQiw9UTSSiwSb1IS+EnqO/1B318ca2TtnjhUFO2+ PJ+wByy0HxAunMz1ukJQA0n2hw/5LKso06ms+hO1uvCO6VzrLVJDSIUIj8CiBqScovfb oJr3uBXaD91cKgynsrBu25bXFBhoEQ17nY3AjeeDeP2NSZ7msP4Wy+h8IVoAqd6EpnVX zzFoFWq1bF1J+GuQ0/KxfifEEjP0vSKe39i7lCr578oDxKw86ypOz4qD2P5z91lkQZuT ZGKQ== X-Gm-Message-State: AOAM532YmSiDcEckIt+SuIHeah8imDyyYphwaR1MUqgarAQ/qLQUjSex HRJ2zPeXCJxbRpTYG8Z2PE1Uww== 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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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: 12377039 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 6389DC11F69 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 4E290613D0 for ; Wed, 14 Jul 2021 14:15:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239466AbhGNOSo (ORCPT ); Wed, 14 Jul 2021 10:18:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239442AbhGNOSn (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 7FBC9C061762 for ; Wed, 14 Jul 2021 07:15:51 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id w13so1684378wmc.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=d7lwUWwGaL47oyLAeIxdUVnZF/vy/IqEWha9kck1C27DCuFgahT5EjhjQp5zpUEbiU AuLOMNO/pes1f1GDnuZ8V/XiTwIrpg88vnuN+Tw47jJ2Go1t2i0wLMwKSi58G/g8Vkva Jej8Cgy29dcAaRutZGzVCsjHsyXyXFhv1ipvqaL738HZ/JmwgXAOvmfb2HhV/k3TMPrz COhgyq0iIwVRDx/cl+7/5zvv0C2q9lkUL/QdXH50ajj258kAp3SkaevEAxmxZJQiHMdu CygiPt/2xyTVJYHbRDlMAIIcN5Q9xLLgaNRHtX1PsG6IyaRFdHkPnzsiEAUpZsCelYiq Easg== X-Gm-Message-State: AOAM532amywpQ3Wg04pCw1c2dSKHpxRR+G8D+ZcTrV3zpuBpi/r9KLab D4+ilE1z0bBpImF2y+NsJC99Ww== 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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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: 12377043 X-Patchwork-Delegate: bpf@iogearbox.net 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=ham 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 720DCC07E9C 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 5DC48613C3 for ; Wed, 14 Jul 2021 14:15:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239447AbhGNOSp (ORCPT ); Wed, 14 Jul 2021 10:18:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239453AbhGNOSo (ORCPT ); Wed, 14 Jul 2021 10:18:44 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1B37C06175F for ; Wed, 14 Jul 2021 07:15:52 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id l17-20020a05600c1d11b029021f84fcaf75so4021349wms.1 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=XYn0CnUlEPGES5/rSnorat6gX3/nmDiQn96wbKiefwxOO33cO+URiW22BgrQDgMEKR 2+g6rx7sCWHb2EmNXF8AyJVMWJsVyEoOf6q9zdHd+OEDiZ+t9lqCCgxLbxbaLsFazkWS ZzIGdJNZt06ALxsmrU4zXq4yZ1MINAw152MoOhKTxEBxUnl9TdjmYkuWhzmWEWG8X9Q0 XUO+YOSPgwLqkzjFB73IdQpSX9qsWS9j4LnwtQsMyy4B2IyEEh5Hlx4P1nyJpWbgztmf jAz/C3gnfAoPiL4Wi/QJRCgx7eywRzEO3khzZT1AP2//AAdQeEcwnX2naYiYjs145v7W qr4g== X-Gm-Message-State: AOAM532ExvkV84yQz2r0nmhjsr7cOKy7ys6aJ1cC+Hqwhb+hNUhnNOdG qnvlgemCU/GQ5G9/2yZNmtWjGA== 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: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net 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;