From patchwork Wed Apr 5 13:21:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 13201746 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C543C77B60 for ; Wed, 5 Apr 2023 13:21:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237944AbjDENVl (ORCPT ); Wed, 5 Apr 2023 09:21:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238215AbjDENVj (ORCPT ); Wed, 5 Apr 2023 09:21:39 -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 C989926B8 for ; Wed, 5 Apr 2023 06:21:25 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id v14-20020a05600c470e00b003f06520825fso1071745wmo.0 for ; Wed, 05 Apr 2023 06:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1680700884; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OzTnYTzHXCMtnD4fBRvpMdVZR/0u4+xwq2ZcAsfEd4Q=; b=YqRe9t40x9LMUeIwhC7rLF2ubu1tfu2uHWidiHIn4WGf3uFePP0AbI/hfcpyDx8nWT PMGh2ePXaEkTNxTVfm/rWWohPP+YdVbe12bO3hMmA7UzjZdrfBu9++kNXrMgLLpmZ04t +gsIScjttRzg+2Bir2eJ3uwpWAtM4sJym3Ip7mIBUujKQ9EiC/mW0OD4WVMtHLqkhPJE I4jzu2UYdoTiE5hXmmOjAJ4+ff73RdieF2bh/1OHgCHlhlJT6Jjzr1de3OZknzveMgm0 n6GxZv4CdxZzn1D4xmInblUu8jLPuZ8BB8PfA5JRE5PY45cF01QvC0e51MSdsqL7kkXa ARzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680700884; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OzTnYTzHXCMtnD4fBRvpMdVZR/0u4+xwq2ZcAsfEd4Q=; b=E/MoLI+bqxhNIUGRzSu+PCfHyGWNBnlA8+bpCwBKsEenNXHSm7j34WUb649R3Y0/wg 74BWKbd7Zpiw4l/uc5UPwjD5XKZ2CbMPn3Qb4MgLXv7EP9yeU5rSAToAvEFo7H9jKxJc NLoA8gj0Xr0kUaPW41KvbE8mLX/bIIsB7nGYHw2gBgaFu/ImeXcJowM37WVlpIrjmqym h6pzjTx4MpgyjcOFPTWDC5Lnw/Qm9laEH/cu4nmZiynUUMTW0kV2mbr/FgqsnJoeVRw5 VC2E9LyHMx2yAR3Jrjd6w0/3nGavfedKFxZKsZvPPNP/1MNtuuQb+MUaZ61mscyKuhn8 9gYg== X-Gm-Message-State: AAQBX9ciPVpenHvYWfiywnJijypIUoWd6SeoZWfkmMQgme94861nn8v8 6eRw2GulqigjF4RZQVSFwhQXHg== X-Google-Smtp-Source: AKy350atBpdQ+uY6z/dKh9wDwWdKcoCK8ww1Ae7PCOIyRffKayoqNJOh7SkyhyrV9DsBwYao2Py64A== X-Received: by 2002:a1c:7309:0:b0:3ed:ec34:f1 with SMTP id d9-20020a1c7309000000b003edec3400f1mr4588576wmb.35.1680700884425; Wed, 05 Apr 2023 06:21:24 -0700 (PDT) Received: from harfang.fritz.box ([2a02:8011:e80c:0:8147:b5f5:f4cc:b39b]) by smtp.gmail.com with ESMTPSA id c22-20020a05600c0ad600b003ed243222adsm2147306wmr.42.2023.04.05.06.21.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 06:21:24 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Eduard Zingerman , Quentin Monnet Subject: [PATCH bpf-next v3 1/7] bpftool: Fix documentation about line info display for prog dumps Date: Wed, 5 Apr 2023 14:21:14 +0100 Message-Id: <20230405132120.59886-2-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405132120.59886-1-quentin@isovalent.com> References: <20230405132120.59886-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 The documentation states that when line_info is available when dumping a program, the source line will be displayed "by default". There is no notion of "default" here: the line is always displayed if available, there is no way currently to turn it off. In the next sentence, the documentation states that if "linum" is used on the command line, the relevant filename, line, and column will be displayed "on top of the source line". This is incorrect, as they are currently displayed on the right side of the source line (or on top of the eBPF instruction, not the source). This commit fixes the documentation to address these points. Signed-off-by: Quentin Monnet --- tools/bpf/bpftool/Documentation/bpftool-prog.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tools/bpf/bpftool/Documentation/bpftool-prog.rst b/tools/bpf/bpftool/Documentation/bpftool-prog.rst index 14de72544995..06d1e4314406 100644 --- a/tools/bpf/bpftool/Documentation/bpftool-prog.rst +++ b/tools/bpf/bpftool/Documentation/bpftool-prog.rst @@ -106,9 +106,8 @@ DESCRIPTION CFG in DOT format, on standard output. If the programs have line_info available, the source line will - be displayed by default. If **linum** is specified, - the filename, line number and line column will also be - displayed on top of the source line. + be displayed. If **linum** is specified, the filename, line + number and line column will also be displayed. **bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** | **linum** }] Dump jited image (host machine code) of the program. @@ -120,9 +119,8 @@ DESCRIPTION **opcodes** controls if raw opcodes will be printed. If the prog has line_info available, the source line will - be displayed by default. If **linum** is specified, - the filename, line number and line column will also be - displayed on top of the source line. + be displayed. If **linum** is specified, the filename, line + number and line column will also be displayed. **bpftool prog pin** *PROG* *FILE* Pin program *PROG* as *FILE*. From patchwork Wed Apr 5 13:21:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 13201745 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E011C77B6C for ; Wed, 5 Apr 2023 13:21:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238215AbjDENVl (ORCPT ); Wed, 5 Apr 2023 09:21:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238246AbjDENVk (ORCPT ); Wed, 5 Apr 2023 09:21:40 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB78A2D6D for ; Wed, 5 Apr 2023 06:21:26 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id he13so1255354wmb.2 for ; Wed, 05 Apr 2023 06:21:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1680700885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zS+xWbkCiPppB/CJ9sjpe+C+S3vg5aSapcI3Dhq8vzc=; b=BifcG5zy4GGAjCuNWb/AYY+IWFHJelXK/aZKWEm8QTXycusVUbMSDwBIN9mBbo3Q45 NBzuncKVGxCtWH8DmTjQrfSOh0I9P3JeMm36JLgm9Sqxz46yNc5mZTmqINdgLiGoh6so ya7jefq0dn06PFYvpjw5j/Mx/cfaoFGUXEWPzc5QDxHHBuMtNIYN2qMvEP8/Z1wnvdU5 eM9G74XXcpudUyyJ3o7guLGsoVXFdQ1qI8M+7afHDID7mmSFAPlkN0zTjgpwNCeGSjJS vkNuyNNJzoS3ELMGkPlwvYWxVn4+xzl6rglhu+ZSJrfJHd8aAGzbgQuZuuX5oUKl7VLc u+oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680700885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zS+xWbkCiPppB/CJ9sjpe+C+S3vg5aSapcI3Dhq8vzc=; b=RKytLoIopHoCGmLwYvWGj4+NUzPSttDQQu/+vOkB5bKB2sUmMqvJ5BhG8u6+1gW85w ZWJMtFfDwJtyGNO90UreAWPPnsXgv/OGtHqxq7uoUauSsL2aMCzTs+q7HkJTc5+MAN8D HLUV1lrJfWOYzxtiCgYOHtAijMmItq1gZCdINpS9Dxqz6hN4bwKM+5fSiYQFd9Lqnvsm TBXfCHSOWYx3VLfFo/kHXNM40ueVpoivX34OEbUK3753ey7bXd3AELysl5yZyTvKeg+5 zTSgySbNfUk3Sz333jWsbud+EJIPu0+JxHsk29FwiYgLhKVde+ZssZ76SNqRinDD0BTd G7QA== X-Gm-Message-State: AAQBX9cHuQcos6Yh8Wd3TlMKPJeL6cc4o2+RsLjaKRXdCrFOxiTNXA+F UoeJF3fvbQpjkxK5k6Hmpeeeng== X-Google-Smtp-Source: AKy350bgHvf35niW2VQ1cjnzQ4DScCXmyoaoMJwxEvLcdZbuMTYWLzWjTUlHkBNdBLnO1f9/g2h4SQ== X-Received: by 2002:a05:600c:288:b0:3ea:d620:570a with SMTP id 8-20020a05600c028800b003ead620570amr4708733wmk.38.1680700885279; Wed, 05 Apr 2023 06:21:25 -0700 (PDT) Received: from harfang.fritz.box ([2a02:8011:e80c:0:8147:b5f5:f4cc:b39b]) by smtp.gmail.com with ESMTPSA id c22-20020a05600c0ad600b003ed243222adsm2147306wmr.42.2023.04.05.06.21.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 06:21:24 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Eduard Zingerman , Quentin Monnet Subject: [PATCH bpf-next v3 2/7] bpftool: Fix bug for long instructions in program CFG dumps Date: Wed, 5 Apr 2023 14:21:15 +0100 Message-Id: <20230405132120.59886-3-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405132120.59886-1-quentin@isovalent.com> References: <20230405132120.59886-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 When dumping the control flow graphs for programs using the 16-byte long load instruction, we need to skip the second part of this instruction when looking for the next instruction to process. Otherwise, we end up printing "BUG_ld_00" from the kernel disassembler in the CFG. Fixes: efcef17a6d65 ("tools: bpftool: generate .dot graph from CFG information") Signed-off-by: Quentin Monnet --- tools/bpf/bpftool/xlated_dumper.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c index 6fe3134ae45d..3daa05d9bbb7 100644 --- a/tools/bpf/bpftool/xlated_dumper.c +++ b/tools/bpf/bpftool/xlated_dumper.c @@ -372,8 +372,15 @@ void dump_xlated_for_graph(struct dump_data *dd, void *buf_start, void *buf_end, struct bpf_insn *insn_start = buf_start; struct bpf_insn *insn_end = buf_end; struct bpf_insn *cur = insn_start; + bool double_insn = false; for (; cur <= insn_end; cur++) { + if (double_insn) { + double_insn = false; + continue; + } + double_insn = cur->code == (BPF_LD | BPF_IMM | BPF_DW); + printf("% 4d: ", (int)(cur - insn_start + start_idx)); print_bpf_insn(&cbs, cur, true); if (cur != insn_end) From patchwork Wed Apr 5 13:21:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 13201747 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7624C7619A for ; Wed, 5 Apr 2023 13:21:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238250AbjDENVm (ORCPT ); Wed, 5 Apr 2023 09:21:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238247AbjDENVk (ORCPT ); Wed, 5 Apr 2023 09:21:40 -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 8D6D43C0E for ; Wed, 5 Apr 2023 06:21:27 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id l15-20020a05600c4f0f00b003ef6d684102so18418791wmq.3 for ; Wed, 05 Apr 2023 06:21:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1680700886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GaMSq/BrjIsLAsM8tt3GL2gZ/xQ+n5MJCeoPoGN8oJc=; b=TADt5n86cet+PRbtp1K/Qqg0BOL9EfjZzjCStYLY0ieKxJDCHhMHkWNkAceO4RIpUx Vprrfeuhkc5sf8gMeb4IbviyRzJDs8Cpd4JFaFTEwqZGqgZ1xKme//9H9nQbEWgOkuRl oyP1zp6Cr1Lj0VFcGEKK7EWgGiVPXh0YE/1kKG3aI6x69sDnvsE1UuOdn9FRPR13Y/Hw AAu/PTNS5GjeiaZ9qf3peCT+AcvI0dZnz2yg357ov+TTPoqtSzTWTFgbNZa6icH1jGg1 0CCZdqYeqLTXbqmdqsS7YNxtHilur88FvsYJ+gtiy4kYNyxM0r4AKKbHgulwupVwBC5H xEOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680700886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GaMSq/BrjIsLAsM8tt3GL2gZ/xQ+n5MJCeoPoGN8oJc=; b=wMp1v8aetM6nktG0BqA2EtvIQz8LTXcgkfpXpvWV7NT9mjpMuT9sD3pD5ci8OoWNP6 OL+hbi/A8WJc+rK5QznJBdtpbppmJjvczhnjvC23leYJJjfp89jY14XiF5XNi0jFV+5W Tkb9Ujzm2jxxYsNOMgslHRrmYoOiwg512wO/kgMohWSpyti/aenmcBFJNje39JhDNt6r ewjkjCUtACAiEIWz4w5sIEDfXJf1CoJ1LAQNsf3EwE2/rJbKMwlhGTZdqLiiXaLd5ci6 17aVRXGMkDcshti6FCAjVUkOgRjnZaUvj4XgMQOG8yK6H8nTe1oxdQ79uRv6+cmr1yYZ FkJQ== X-Gm-Message-State: AAQBX9dj3oq1Id826K9mSX8W8UF6JH8jwadgVn9gXDgxGWPY1zcfExLY 7E4pAUO/WhAqGZwNVfpfoI1KUw== X-Google-Smtp-Source: AKy350bxnyU2I7pVJiEd8x84r5NdSxqsiY2jpk1Q9g1t4Ty7M73T/EG0d9eXLuV+d/8kkbTJ8XHKNA== X-Received: by 2002:a7b:c455:0:b0:3ee:1afc:c15 with SMTP id l21-20020a7bc455000000b003ee1afc0c15mr4390309wmi.33.1680700885969; Wed, 05 Apr 2023 06:21:25 -0700 (PDT) Received: from harfang.fritz.box ([2a02:8011:e80c:0:8147:b5f5:f4cc:b39b]) by smtp.gmail.com with ESMTPSA id c22-20020a05600c0ad600b003ed243222adsm2147306wmr.42.2023.04.05.06.21.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 06:21:25 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Eduard Zingerman , Quentin Monnet Subject: [PATCH bpf-next v3 3/7] bpftool: Support inline annotations when dumping the CFG of a program Date: Wed, 5 Apr 2023 14:21:16 +0100 Message-Id: <20230405132120.59886-4-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405132120.59886-1-quentin@isovalent.com> References: <20230405132120.59886-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 We support dumping the control flow graph of loaded programs to the DOT format with bpftool, but so far this feature wouldn't display the source code lines available through BTF along with the eBPF bytecode. Let's add support for these annotations, to make it easier to read the graph. In prog.c, we move the call to dump_xlated_cfg() in order to pass and use the full struct dump_data, instead of creating a minimal one in draw_bb_node(). We pass the pointer to this struct down to dump_xlated_for_graph() in xlated_dumper.c, where most of the logics is added. We deal with BTF mostly like we do for plain or JSON output, except that we cannot use a "nr_skip" value to skip a given number of linfo records (we don't process the BPF instructions linearly, and apart from the root of the graph we don't know how many records we should skip, so we just store the last linfo and make sure the new one we find is different before printing it). When printing the source instructions to the label of a DOT graph node, there are a few subtleties to address. We want some special newline markers, and there are some characters that we must escape. To deal with them, we introduce a new dedicated function btf_dump_linfo_dotlabel() in btf_dumper.c. We'll reuse this function in a later commit to format the filepath, line, and column references as well. Signed-off-by: Quentin Monnet --- tools/bpf/bpftool/btf_dumper.c | 34 +++++++++++++++++++++++++++++++ tools/bpf/bpftool/cfg.c | 23 +++++++++------------ tools/bpf/bpftool/cfg.h | 4 +++- tools/bpf/bpftool/main.h | 2 ++ tools/bpf/bpftool/prog.c | 17 +++++++--------- tools/bpf/bpftool/xlated_dumper.c | 34 +++++++++++++++++++++++++++++-- 6 files changed, 88 insertions(+), 26 deletions(-) diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c index e7f6ec3a8f35..583aa843df92 100644 --- a/tools/bpf/bpftool/btf_dumper.c +++ b/tools/bpf/bpftool/btf_dumper.c @@ -821,3 +821,37 @@ void btf_dump_linfo_json(const struct btf *btf, BPF_LINE_INFO_LINE_COL(linfo->line_col)); } } + +static void dotlabel_puts(const char *s) +{ + for (; *s; ++s) { + switch (*s) { + case '\\': + case '"': + case '{': + case '}': + case '<': + case '>': + case '|': + case ' ': + putchar('\\'); + __fallthrough; + default: + putchar(*s); + } + } +} + +void btf_dump_linfo_dotlabel(const struct btf *btf, + const struct bpf_line_info *linfo) +{ + const char *line = btf__name_by_offset(btf, linfo->line_off); + + if (!line || !strlen(line)) + return; + line = ltrim(line); + + printf("; "); + dotlabel_puts(line); + printf("\\l\\\n"); +} diff --git a/tools/bpf/bpftool/cfg.c b/tools/bpf/bpftool/cfg.c index 1951219a9af7..9fdc1f0cdd6e 100644 --- a/tools/bpf/bpftool/cfg.c +++ b/tools/bpf/bpftool/cfg.c @@ -380,7 +380,8 @@ static void cfg_destroy(struct cfg *cfg) } } -static void draw_bb_node(struct func_node *func, struct bb_node *bb) +static void +draw_bb_node(struct func_node *func, struct bb_node *bb, struct dump_data *dd) { const char *shape; @@ -398,13 +399,9 @@ static void draw_bb_node(struct func_node *func, struct bb_node *bb) printf("EXIT"); } else { unsigned int start_idx; - struct dump_data dd = {}; - - printf("{"); - kernel_syms_load(&dd); + printf("{\\\n"); start_idx = bb->head - func->start; - dump_xlated_for_graph(&dd, bb->head, bb->tail, start_idx); - kernel_syms_destroy(&dd); + dump_xlated_for_graph(dd, bb->head, bb->tail, start_idx); printf("}"); } @@ -430,12 +427,12 @@ static void draw_bb_succ_edges(struct func_node *func, struct bb_node *bb) } } -static void func_output_bb_def(struct func_node *func) +static void func_output_bb_def(struct func_node *func, struct dump_data *dd) { struct bb_node *bb; list_for_each_entry(bb, &func->bbs, l) { - draw_bb_node(func, bb); + draw_bb_node(func, bb, dd); } } @@ -455,7 +452,7 @@ static void func_output_edges(struct func_node *func) func_idx, ENTRY_BLOCK_INDEX, func_idx, EXIT_BLOCK_INDEX); } -static void cfg_dump(struct cfg *cfg) +static void cfg_dump(struct cfg *cfg, struct dump_data *dd) { struct func_node *func; @@ -463,14 +460,14 @@ static void cfg_dump(struct cfg *cfg) list_for_each_entry(func, &cfg->funcs, l) { printf("subgraph \"cluster_%d\" {\n\tstyle=\"dashed\";\n\tcolor=\"black\";\n\tlabel=\"func_%d ()\";\n", func->idx, func->idx); - func_output_bb_def(func); + func_output_bb_def(func, dd); func_output_edges(func); printf("}\n"); } printf("}\n"); } -void dump_xlated_cfg(void *buf, unsigned int len) +void dump_xlated_cfg(struct dump_data *dd, void *buf, unsigned int len) { struct bpf_insn *insn = buf; struct cfg cfg; @@ -479,7 +476,7 @@ void dump_xlated_cfg(void *buf, unsigned int len) if (cfg_build(&cfg, insn, len)) return; - cfg_dump(&cfg); + cfg_dump(&cfg, dd); cfg_destroy(&cfg); } diff --git a/tools/bpf/bpftool/cfg.h b/tools/bpf/bpftool/cfg.h index e144257ea6d2..909d17e6d4c2 100644 --- a/tools/bpf/bpftool/cfg.h +++ b/tools/bpf/bpftool/cfg.h @@ -4,6 +4,8 @@ #ifndef __BPF_TOOL_CFG_H #define __BPF_TOOL_CFG_H -void dump_xlated_cfg(void *buf, unsigned int len); +#include "xlated_dumper.h" + +void dump_xlated_cfg(struct dump_data *dd, void *buf, unsigned int len); #endif /* __BPF_TOOL_CFG_H */ diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h index 0ef373cef4c7..e9ee514b22d4 100644 --- a/tools/bpf/bpftool/main.h +++ b/tools/bpf/bpftool/main.h @@ -229,6 +229,8 @@ void btf_dump_linfo_plain(const struct btf *btf, const char *prefix, bool linum); void btf_dump_linfo_json(const struct btf *btf, const struct bpf_line_info *linfo, bool linum); +void btf_dump_linfo_dotlabel(const struct btf *btf, + const struct bpf_line_info *linfo); struct nlattr; struct ifinfomsg; diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index afbe3ec342c8..d855118f0d96 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -840,11 +840,6 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode, false)) goto exit_free; } - } else if (visual) { - if (json_output) - jsonw_null(json_wtr); - else - dump_xlated_cfg(buf, member_len); } else { kernel_syms_load(&dd); dd.nr_jited_ksyms = info->nr_jited_ksyms; @@ -854,12 +849,14 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode, dd.finfo_rec_size = info->func_info_rec_size; dd.prog_linfo = prog_linfo; - if (json_output) - dump_xlated_json(&dd, buf, member_len, opcodes, - linum); + if (json_output && visual) + jsonw_null(json_wtr); + else if (json_output) + dump_xlated_json(&dd, buf, member_len, opcodes, linum); + else if (visual) + dump_xlated_cfg(&dd, buf, member_len); else - dump_xlated_plain(&dd, buf, member_len, opcodes, - linum); + dump_xlated_plain(&dd, buf, member_len, opcodes, linum); kernel_syms_destroy(&dd); } diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c index 3daa05d9bbb7..2ee83561b945 100644 --- a/tools/bpf/bpftool/xlated_dumper.c +++ b/tools/bpf/bpftool/xlated_dumper.c @@ -369,21 +369,51 @@ void dump_xlated_for_graph(struct dump_data *dd, void *buf_start, void *buf_end, .cb_imm = print_imm, .private_data = dd, }; + const struct bpf_prog_linfo *prog_linfo = dd->prog_linfo; + const struct bpf_line_info *last_linfo = NULL; + struct bpf_func_info *record = dd->func_info; struct bpf_insn *insn_start = buf_start; struct bpf_insn *insn_end = buf_end; struct bpf_insn *cur = insn_start; + struct btf *btf = dd->btf; bool double_insn = false; + char func_sig[1024]; for (; cur <= insn_end; cur++) { + unsigned int insn_off; + if (double_insn) { double_insn = false; continue; } double_insn = cur->code == (BPF_LD | BPF_IMM | BPF_DW); - printf("% 4d: ", (int)(cur - insn_start + start_idx)); + insn_off = (unsigned int)(cur - insn_start + start_idx); + if (btf && record) { + if (record->insn_off == insn_off) { + btf_dumper_type_only(btf, record->type_id, + func_sig, + sizeof(func_sig)); + if (func_sig[0] != '\0') + printf("; %s:\\l\\\n", func_sig); + record = (void *)record + dd->finfo_rec_size; + } + } + + if (prog_linfo) { + const struct bpf_line_info *linfo; + + linfo = bpf_prog_linfo__lfind(prog_linfo, insn_off, 0); + if (linfo && linfo != last_linfo) { + btf_dump_linfo_dotlabel(btf, linfo); + last_linfo = linfo; + } + } + + printf("%d: ", insn_off); print_bpf_insn(&cbs, cur, true); + if (cur != insn_end) - printf(" | "); + printf("| "); } } From patchwork Wed Apr 5 13:21:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 13201748 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FAF6C76188 for ; Wed, 5 Apr 2023 13:21:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238251AbjDENVn (ORCPT ); Wed, 5 Apr 2023 09:21:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238096AbjDENVl (ORCPT ); Wed, 5 Apr 2023 09:21:41 -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 5D55626A4 for ; Wed, 5 Apr 2023 06:21:28 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id m8so9965828wmq.5 for ; Wed, 05 Apr 2023 06:21:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1680700887; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M1ibP54UBIFDrVN+8ZpyYzPy2B5kwF7GB0WoEFOJNkQ=; b=I7IsV/X31tR0Ira2FwARXcW5Yy4cOrX6CENASdwbcU+LAsHnf+1wZFV7iTWz9W6t4B TV760CvU5UUBTa8ZZTyK26RA7hBDUrP/TSw+WDsk51GDYkEr/eQMq1S97i/e0foBGrnL 3TPLMd1sEGmDWQZDzKo9bB5jcajDaAQYOd1tOwvVoCQ3Qvwc5d9baUgYmBGdbPQm9OWg XPpAvbDUBBkyHV7dbyIQT+n13gX7p/ssKJ1pegGLQJpESfJTUleVl4EDqYN4zUEEZiHh j1YLMWLxRknyNtEak/aF6cHtbyajtbDcFKhBRExfhLqXLGiFZXTw0+VlQs7DHzP5QTDU dRmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680700887; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M1ibP54UBIFDrVN+8ZpyYzPy2B5kwF7GB0WoEFOJNkQ=; b=46caajUYTlInqjyuJ7LHfuVr60tPecwbJ3ldf7BnCWk2KwKGGy4woeffJ6cVGq2WjO PjcK+ZPl5w+EERX0zcF1Nr7e+qzEttUrQRLX6Yze1CJNF/b2NFlDn5jgNOGiUxto0G13 I6fjWcyCdx3aZ2D0NlUPdr6X74DcPCWeVPF24IiEm7tudiV9VI8siUmKLBA0gIa4xzgH SVVu1XvaEBSgjJSyosiPuKnVQsVxVuYrM1510gOANYEEzgWeQFhawJwlQiHWCdVH7lUa 7Dv2zrF8GRK0G/RTKv2MrurrdA6Qb4najyzZ0seTJE6gE8T2/aDIhkSyWiOhyGze4djM xKDA== X-Gm-Message-State: AAQBX9cF+5KVHJeCg0KEAMKphNUCT66G+phZIyuKR/8feM3R20d5sW43 uIR+OthcY95a5UAGL16f82VM5Q== X-Google-Smtp-Source: AKy350YDEAfZJOHHN580cBgXMrp6M1p+q9347mSFKNTLaLzsJwhCBNc+SXl+2p3MK5nHY+siYaFVdA== X-Received: by 2002:a05:600c:b4f:b0:3ed:d64f:ec30 with SMTP id k15-20020a05600c0b4f00b003edd64fec30mr4516051wmr.33.1680700886823; Wed, 05 Apr 2023 06:21:26 -0700 (PDT) Received: from harfang.fritz.box ([2a02:8011:e80c:0:8147:b5f5:f4cc:b39b]) by smtp.gmail.com with ESMTPSA id c22-20020a05600c0ad600b003ed243222adsm2147306wmr.42.2023.04.05.06.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 06:21:26 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Eduard Zingerman , Quentin Monnet Subject: [PATCH bpf-next v3 4/7] bpftool: Return an error on prog dumps if both CFG and JSON are required Date: Wed, 5 Apr 2023 14:21:17 +0100 Message-Id: <20230405132120.59886-5-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405132120.59886-1-quentin@isovalent.com> References: <20230405132120.59886-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 We do not support JSON output for control flow graphs of programs with bpftool. So far, requiring both the CFG and JSON output would result in producing a null JSON object. It makes more sense to raise an error directly when parsing command line arguments and options, so that users know they won't get any output they might expect. If JSON is required for the graph, we leave it to Graphviz instead: # bpftool prog dump xlated visual | dot -Tjson Suggested-by: Eduard Zingerman Signed-off-by: Quentin Monnet --- tools/bpf/bpftool/bash-completion/bpftool | 9 ++++++--- tools/bpf/bpftool/prog.c | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool index 35f26f7c1124..a3cb07172789 100644 --- a/tools/bpf/bpftool/bash-completion/bpftool +++ b/tools/bpf/bpftool/bash-completion/bpftool @@ -255,16 +255,19 @@ _bpftool_map_update_get_name() _bpftool() { - local cur prev words objword + local cur prev words objword json=0 _init_completion || return # Deal with options if [[ ${words[cword]} == -* ]]; then local c='--version --json --pretty --bpffs --mapcompat --debug \ - --use-loader --base-btf' + --use-loader --base-btf' COMPREPLY=( $( compgen -W "$c" -- "$cur" ) ) return 0 fi + if _bpftool_search_list -j --json -p --pretty; then + json=1 + fi # Deal with simplest keywords case $prev in @@ -367,7 +370,7 @@ _bpftool() ;; *) _bpftool_once_attr 'file' - if _bpftool_search_list 'xlated'; then + if _bpftool_search_list 'xlated' && [[ "$json" == 0 ]]; then COMPREPLY+=( $( compgen -W 'opcodes visual linum' -- \ "$cur" ) ) else diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index d855118f0d96..736defc6e5d0 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -849,9 +849,7 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode, dd.finfo_rec_size = info->func_info_rec_size; dd.prog_linfo = prog_linfo; - if (json_output && visual) - jsonw_null(json_wtr); - else if (json_output) + if (json_output) dump_xlated_json(&dd, buf, member_len, opcodes, linum); else if (visual) dump_xlated_cfg(&dd, buf, member_len); @@ -940,6 +938,10 @@ static int do_dump(int argc, char **argv) usage(); goto exit_close; } + if (json_output && visual) { + p_err("'visual' is not compatible with JSON output"); + goto exit_close; + } if (json_output && nb_fds > 1) jsonw_start_array(json_wtr); /* root array */ From patchwork Wed Apr 5 13:21:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 13201749 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55339C761A6 for ; Wed, 5 Apr 2023 13:21:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238247AbjDENVn (ORCPT ); Wed, 5 Apr 2023 09:21:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238017AbjDENVl (ORCPT ); Wed, 5 Apr 2023 09:21:41 -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 852305FE1 for ; Wed, 5 Apr 2023 06:21:29 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id n19-20020a05600c501300b003f064936c3eso1167590wmr.0 for ; Wed, 05 Apr 2023 06:21:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1680700888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FlKuJWoo+oat+6Ri8hbb8nnQs7jMNtjJLEl9nvYjQQc=; b=VVO7metP3EazRtQYvF0Say76ghZpzK19RqxFKmCTp47swub06ByA4w5c2LYt+8w19+ 88LgTx+n4vEiGuODSc44r4JGIZNf7rA6eSh+Ijx+jFsFGN6JqZwhsc7epqU0ik4jN6PP KKvj64nYVf+JYEsK9mCABe6mWIom80vdrueHukRweWG2cYKXuBvT/muXj7kFPLHSkAUi GqtTjakWyf02WzYok3I6jkMqKEhnY2niOVc0VK7lxeVTsOFv+uBBYUmY+OLLdAjFiq2/ dqjomatspvC7PQKrXU2a6nkkR9enSg2ACYw+3tvBgfDtTq9RzBZvIW3M0Jk6RJN0L85h pHMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680700888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FlKuJWoo+oat+6Ri8hbb8nnQs7jMNtjJLEl9nvYjQQc=; b=TLZYS6GRxh5xDLF8BtYJd3CVCmIJB2EtwiRwzzTngMKZonm6Ipocdc1wPNusX/QLq0 oiNkYEnzaQd6qCiRd9tHQ44dT/dUXL3aw8I6xz2xRuGVYk1idzDlWy+DKh3+c7nLNmDZ t2MwRG8oReqoj77RiHS3Zo+Q9LspkVF71oa8VrDzZTeX/9UDdv5yQl6Vfv7WoKC81dqN 6UCY7nAmnRvYdSBGyG80xuVZptvY8n9fts0TpBFL1xWEbGO3rma2HoZG1KRaBXmpGYWg cYwzIJNIotfBZvx0YAlj7xzj2uXcCFVPus5Wk/WJvBffgd3m+ckpQxzgHK7aKKvXCwmm R4fg== X-Gm-Message-State: AAQBX9eEVfRE341Ainjg8dzLsSThpNGP8BbnUSqwwyTNYGVcQZvIo1nB 6Uln3T1VGStzGOK4BP0G5lT+eA== X-Google-Smtp-Source: AKy350bzut10FsYN2k+tUnJegTgPO7sEAJhBsqRuOf711wxqiWozwvFnkgENd7nhu2wGJB/rWGgh/A== X-Received: by 2002:a05:600c:b91:b0:3ed:bfb4:ad9f with SMTP id fl17-20020a05600c0b9100b003edbfb4ad9fmr1819042wmb.2.1680700887937; Wed, 05 Apr 2023 06:21:27 -0700 (PDT) Received: from harfang.fritz.box ([2a02:8011:e80c:0:8147:b5f5:f4cc:b39b]) by smtp.gmail.com with ESMTPSA id c22-20020a05600c0ad600b003ed243222adsm2147306wmr.42.2023.04.05.06.21.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 06:21:27 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Eduard Zingerman , Quentin Monnet Subject: [PATCH bpf-next v3 5/7] bpftool: Support "opcodes", "linum", "visual" simultaneously Date: Wed, 5 Apr 2023 14:21:18 +0100 Message-Id: <20230405132120.59886-6-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405132120.59886-1-quentin@isovalent.com> References: <20230405132120.59886-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 When dumping a program, the keywords "opcodes" (for printing the raw opcodes), "linum" (for displaying the filename, line number, column number along with the source code), and "visual" (for generating the control flow graph for translated programs) are mutually exclusive. But there's no reason why they should be. Let's make it possible to pass several of them at once. The "file FILE" option, which makes bpftool output a binary image to a file, remains incompatible with the others. Signed-off-by: Quentin Monnet --- .../bpftool/Documentation/bpftool-prog.rst | 8 +-- tools/bpf/bpftool/bash-completion/bpftool | 17 +++--- tools/bpf/bpftool/prog.c | 61 ++++++++++--------- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/tools/bpf/bpftool/Documentation/bpftool-prog.rst b/tools/bpf/bpftool/Documentation/bpftool-prog.rst index 06d1e4314406..9443c524bb76 100644 --- a/tools/bpf/bpftool/Documentation/bpftool-prog.rst +++ b/tools/bpf/bpftool/Documentation/bpftool-prog.rst @@ -28,8 +28,8 @@ PROG COMMANDS ============= | **bpftool** **prog** { **show** | **list** } [*PROG*] -| **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes** | **visual** | **linum**}] -| **bpftool** **prog dump jited** *PROG* [{**file** *FILE* | **opcodes** | **linum**}] +| **bpftool** **prog dump xlated** *PROG* [{ **file** *FILE* | [**opcodes**] [**linum**] [**visual**] }] +| **bpftool** **prog dump jited** *PROG* [{ **file** *FILE* | [**opcodes**] [**linum**] }] | **bpftool** **prog pin** *PROG* *FILE* | **bpftool** **prog** { **load** | **loadall** } *OBJ* *PATH* [**type** *TYPE*] [**map** {**idx** *IDX* | **name** *NAME*} *MAP*] [**dev** *NAME*] [**pinmaps** *MAP_DIR*] [**autoattach**] | **bpftool** **prog attach** *PROG* *ATTACH_TYPE* [*MAP*] @@ -88,7 +88,7 @@ DESCRIPTION programs. On such kernels bpftool will automatically emit this information as well. - **bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** | **linum** }] + **bpftool prog dump xlated** *PROG* [{ **file** *FILE* | [**opcodes**] [**linum**] [**visual**] }] Dump eBPF instructions of the programs from the kernel. By default, eBPF will be disassembled and printed to standard output in human-readable format. In this case, **opcodes** @@ -109,7 +109,7 @@ DESCRIPTION be displayed. If **linum** is specified, the filename, line number and line column will also be displayed. - **bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** | **linum** }] + **bpftool prog dump jited** *PROG* [{ **file** *FILE* | [**opcodes**] [**linum**] }] Dump jited image (host machine code) of the program. If *FILE* is specified image will be written to a file, diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool index a3cb07172789..69c64dc18b1d 100644 --- a/tools/bpf/bpftool/bash-completion/bpftool +++ b/tools/bpf/bpftool/bash-completion/bpftool @@ -271,7 +271,7 @@ _bpftool() # Deal with simplest keywords case $prev in - help|hex|opcodes|visual|linum) + help|hex) return 0 ;; tag) @@ -369,13 +369,16 @@ _bpftool() return 0 ;; *) - _bpftool_once_attr 'file' + # "file" is not compatible with other keywords here + if _bpftool_search_list 'file'; then + return 0 + fi + if ! _bpftool_search_list 'linum opcodes visual'; then + _bpftool_once_attr 'file' + fi + _bpftool_once_attr 'linum opcodes' if _bpftool_search_list 'xlated' && [[ "$json" == 0 ]]; then - COMPREPLY+=( $( compgen -W 'opcodes visual linum' -- \ - "$cur" ) ) - else - COMPREPLY+=( $( compgen -W 'opcodes linum' -- \ - "$cur" ) ) + _bpftool_once_attr 'visual' fi return 0 ;; diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 736defc6e5d0..092525a6933a 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -905,37 +905,42 @@ static int do_dump(int argc, char **argv) if (nb_fds < 1) goto exit_free; - if (is_prefix(*argv, "file")) { - NEXT_ARG(); - if (!argc) { - p_err("expected file path"); - goto exit_close; - } - if (nb_fds > 1) { - p_err("several programs matched"); - goto exit_close; - } + while (argc) { + if (is_prefix(*argv, "file")) { + NEXT_ARG(); + if (!argc) { + p_err("expected file path"); + goto exit_close; + } + if (nb_fds > 1) { + p_err("several programs matched"); + goto exit_close; + } + + filepath = *argv; + NEXT_ARG(); + } else if (is_prefix(*argv, "opcodes")) { + opcodes = true; + NEXT_ARG(); + } else if (is_prefix(*argv, "visual")) { + if (nb_fds > 1) { + p_err("several programs matched"); + goto exit_close; + } - filepath = *argv; - NEXT_ARG(); - } else if (is_prefix(*argv, "opcodes")) { - opcodes = true; - NEXT_ARG(); - } else if (is_prefix(*argv, "visual")) { - if (nb_fds > 1) { - p_err("several programs matched"); + visual = true; + NEXT_ARG(); + } else if (is_prefix(*argv, "linum")) { + linum = true; + NEXT_ARG(); + } else { + usage(); goto exit_close; } - - visual = true; - NEXT_ARG(); - } else if (is_prefix(*argv, "linum")) { - linum = true; - NEXT_ARG(); } - if (argc) { - usage(); + if (filepath && (opcodes || visual || linum)) { + p_err("'file' is not compatible with 'opcodes', 'visual', or 'linum'"); goto exit_close; } if (json_output && visual) { @@ -2419,8 +2424,8 @@ static int do_help(int argc, char **argv) fprintf(stderr, "Usage: %1$s %2$s { show | list } [PROG]\n" - " %1$s %2$s dump xlated PROG [{ file FILE | opcodes | visual | linum }]\n" - " %1$s %2$s dump jited PROG [{ file FILE | opcodes | linum }]\n" + " %1$s %2$s dump xlated PROG [{ file FILE | [opcodes] [linum] [visual] }]\n" + " %1$s %2$s dump jited PROG [{ file FILE | [opcodes] [linum] }]\n" " %1$s %2$s pin PROG FILE\n" " %1$s %2$s { load | loadall } OBJ PATH \\\n" " [type TYPE] [dev NAME] \\\n" From patchwork Wed Apr 5 13:21:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 13201750 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BC06C77B60 for ; Wed, 5 Apr 2023 13:21:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238096AbjDENVo (ORCPT ); Wed, 5 Apr 2023 09:21:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238110AbjDENVl (ORCPT ); Wed, 5 Apr 2023 09:21:41 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 399F35B87 for ; Wed, 5 Apr 2023 06:21:30 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id j1-20020a05600c1c0100b003f04da00d07so2094699wms.1 for ; Wed, 05 Apr 2023 06:21:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1680700888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3Rt5aDcXQLaaDyJ0K5Mqzee6WsTmFbybk17U/ISZxVw=; b=A7RyUVJ9sRIlYtIrXLU2FycKCBDrqvi4SXrT75E/q8LwI2l39KPmxKRk+tyb9Vj6qv D0DejYxlgzgVk76KqLvNyu/DqNY58jqyEAwcR3K+Fb7E5PES2qCnvFjCWA+ODj9wR6LC xNPdMfDSl586pmXA+gktb7Mp/+tCJtr1Zo7/lPHnSZNDI89o41pPWfSenMcD2Ja+ihmW 0SPVgE3r8p41YRCyubmeh8zgtrqPO0fw69XQNmKx+SM9MAXz5JWZW3RBXNFavbANo0z0 +KL/0C2y1j0OguscAv5OJHvawngqXv7D0jH4TTQWvGeBQPrJg0xsWo239X3C1MtmuwOU Hr+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680700888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3Rt5aDcXQLaaDyJ0K5Mqzee6WsTmFbybk17U/ISZxVw=; b=NogIqXLl5L9YO+VX6BzpIPn4Kn6bFq9JE1JM5ICdFsefsvPw6oA+/cnVbxw4A/D5fA HbP/raJJC2pGvHgRyAh1xCM9A2P9fRQH798U6E/jpD2PojEeVRfE90GgEeWazJhqfngH 0IvUhZyeBrZOb2y3IG4oxWh9ceD/5sKWA6OIIJ3xMi57RJ7yjB4aQxlXBlB9LfRzKxXf bH4iOxsKh/OPfLa2ivILw2Wr8i/DrjDaKYyT9XoUSv+9rTbAYE/8tDmUCDMCtNwhFGNM JFR6mCtdX6xNf9s9QT+Y4bOQsg+L7P/wvAS3uaAhV4YdIPU3t+CaQlHfh+P6/NuXx0Dh 4kQA== X-Gm-Message-State: AAQBX9fUPkaiGmW6jps3MH3UBIK+4sNUcUlABAmAv3ks+ByQ1xaBko1R 7PmGmWmQUCHpOaKE1Ag30bk1Xg== X-Google-Smtp-Source: AKy350ZYWV7EmnR2DX1g4yd/+/TMDgI6NqURNOa1AgDkdJDB3wp0hhgdhcwFQPWfa3b9p0+8RvCmjQ== X-Received: by 2002:a1c:7211:0:b0:3ef:7584:9896 with SMTP id n17-20020a1c7211000000b003ef75849896mr4624502wmc.26.1680700888747; Wed, 05 Apr 2023 06:21:28 -0700 (PDT) Received: from harfang.fritz.box ([2a02:8011:e80c:0:8147:b5f5:f4cc:b39b]) by smtp.gmail.com with ESMTPSA id c22-20020a05600c0ad600b003ed243222adsm2147306wmr.42.2023.04.05.06.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 06:21:28 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Eduard Zingerman , Quentin Monnet Subject: [PATCH bpf-next v3 6/7] bpftool: Support printing opcodes and source file references in CFG Date: Wed, 5 Apr 2023 14:21:19 +0100 Message-Id: <20230405132120.59886-7-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405132120.59886-1-quentin@isovalent.com> References: <20230405132120.59886-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 support for displaying opcodes or/and file references (filepath, line and column numbers) when dumping the control flow graphs of loaded BPF programs with bpftool. The filepaths in the records are absolute. To avoid blocks on the graph to get too wide, we truncate them when they get too long (but we always keep the entire file name). In the unlikely case where the resulting file name is ambiguous, it remains possible to get the full path with a regular dump (no CFG). Signed-off-by: Quentin Monnet --- tools/bpf/bpftool/btf_dumper.c | 51 ++++++++++++++++++++++++++++++- tools/bpf/bpftool/cfg.c | 22 ++++++++----- tools/bpf/bpftool/cfg.h | 3 +- tools/bpf/bpftool/main.h | 2 +- tools/bpf/bpftool/prog.c | 2 +- tools/bpf/bpftool/xlated_dumper.c | 15 +++++++-- tools/bpf/bpftool/xlated_dumper.h | 3 +- 7 files changed, 83 insertions(+), 15 deletions(-) diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c index 583aa843df92..6c5e0e82da22 100644 --- a/tools/bpf/bpftool/btf_dumper.c +++ b/tools/bpf/bpftool/btf_dumper.c @@ -842,8 +842,37 @@ static void dotlabel_puts(const char *s) } } +static const char *shorten_path(const char *path) +{ + const unsigned int MAX_PATH_LEN = 32; + size_t len = strlen(path); + const char *shortpath; + + if (len <= MAX_PATH_LEN) + return path; + + /* Search for last '/' under the MAX_PATH_LEN limit */ + shortpath = strchr(path + len - MAX_PATH_LEN, '/'); + if (shortpath) { + if (shortpath < path + strlen("...")) + /* We removed a very short prefix, e.g. "/w", and we'll + * make the path longer by prefixing with the ellipsis. + * Not worth it, keep initial path. + */ + return path; + return shortpath; + } + + /* File base name length is > MAX_PATH_LEN, search for last '/' */ + shortpath = strrchr(path, '/'); + if (shortpath) + return shortpath; + + return path; +} + void btf_dump_linfo_dotlabel(const struct btf *btf, - const struct bpf_line_info *linfo) + const struct bpf_line_info *linfo, bool linum) { const char *line = btf__name_by_offset(btf, linfo->line_off); @@ -851,6 +880,26 @@ void btf_dump_linfo_dotlabel(const struct btf *btf, return; line = ltrim(line); + if (linum) { + const char *file = btf__name_by_offset(btf, linfo->file_name_off); + const char *shortfile; + + /* More forgiving on file because linum option is + * expected to provide more info than the already + * available src line. + */ + if (!file) + shortfile = ""; + else + shortfile = shorten_path(file); + + printf("; [%s", shortfile > file ? "..." : ""); + dotlabel_puts(shortfile); + printf(" line:%u col:%u]\\l\\\n", + BPF_LINE_INFO_LINE_NUM(linfo->line_col), + BPF_LINE_INFO_LINE_COL(linfo->line_col)); + } + printf("; "); dotlabel_puts(line); printf("\\l\\\n"); diff --git a/tools/bpf/bpftool/cfg.c b/tools/bpf/bpftool/cfg.c index 9fdc1f0cdd6e..eec437cca2ea 100644 --- a/tools/bpf/bpftool/cfg.c +++ b/tools/bpf/bpftool/cfg.c @@ -381,7 +381,8 @@ static void cfg_destroy(struct cfg *cfg) } static void -draw_bb_node(struct func_node *func, struct bb_node *bb, struct dump_data *dd) +draw_bb_node(struct func_node *func, struct bb_node *bb, struct dump_data *dd, + bool opcodes, bool linum) { const char *shape; @@ -401,7 +402,8 @@ draw_bb_node(struct func_node *func, struct bb_node *bb, struct dump_data *dd) unsigned int start_idx; printf("{\\\n"); start_idx = bb->head - func->start; - dump_xlated_for_graph(dd, bb->head, bb->tail, start_idx); + dump_xlated_for_graph(dd, bb->head, bb->tail, start_idx, + opcodes, linum); printf("}"); } @@ -427,12 +429,14 @@ static void draw_bb_succ_edges(struct func_node *func, struct bb_node *bb) } } -static void func_output_bb_def(struct func_node *func, struct dump_data *dd) +static void +func_output_bb_def(struct func_node *func, struct dump_data *dd, + bool opcodes, bool linum) { struct bb_node *bb; list_for_each_entry(bb, &func->bbs, l) { - draw_bb_node(func, bb, dd); + draw_bb_node(func, bb, dd, opcodes, linum); } } @@ -452,7 +456,8 @@ static void func_output_edges(struct func_node *func) func_idx, ENTRY_BLOCK_INDEX, func_idx, EXIT_BLOCK_INDEX); } -static void cfg_dump(struct cfg *cfg, struct dump_data *dd) +static void +cfg_dump(struct cfg *cfg, struct dump_data *dd, bool opcodes, bool linum) { struct func_node *func; @@ -460,14 +465,15 @@ static void cfg_dump(struct cfg *cfg, struct dump_data *dd) list_for_each_entry(func, &cfg->funcs, l) { printf("subgraph \"cluster_%d\" {\n\tstyle=\"dashed\";\n\tcolor=\"black\";\n\tlabel=\"func_%d ()\";\n", func->idx, func->idx); - func_output_bb_def(func, dd); + func_output_bb_def(func, dd, opcodes, linum); func_output_edges(func); printf("}\n"); } printf("}\n"); } -void dump_xlated_cfg(struct dump_data *dd, void *buf, unsigned int len) +void dump_xlated_cfg(struct dump_data *dd, void *buf, unsigned int len, + bool opcodes, bool linum) { struct bpf_insn *insn = buf; struct cfg cfg; @@ -476,7 +482,7 @@ void dump_xlated_cfg(struct dump_data *dd, void *buf, unsigned int len) if (cfg_build(&cfg, insn, len)) return; - cfg_dump(&cfg, dd); + cfg_dump(&cfg, dd, opcodes, linum); cfg_destroy(&cfg); } diff --git a/tools/bpf/bpftool/cfg.h b/tools/bpf/bpftool/cfg.h index 909d17e6d4c2..b3793f4e1783 100644 --- a/tools/bpf/bpftool/cfg.h +++ b/tools/bpf/bpftool/cfg.h @@ -6,6 +6,7 @@ #include "xlated_dumper.h" -void dump_xlated_cfg(struct dump_data *dd, void *buf, unsigned int len); +void dump_xlated_cfg(struct dump_data *dd, void *buf, unsigned int len, + bool opcodes, bool linum); #endif /* __BPF_TOOL_CFG_H */ diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h index e9ee514b22d4..00d11ca6d3f2 100644 --- a/tools/bpf/bpftool/main.h +++ b/tools/bpf/bpftool/main.h @@ -230,7 +230,7 @@ void btf_dump_linfo_plain(const struct btf *btf, void btf_dump_linfo_json(const struct btf *btf, const struct bpf_line_info *linfo, bool linum); void btf_dump_linfo_dotlabel(const struct btf *btf, - const struct bpf_line_info *linfo); + const struct bpf_line_info *linfo, bool linum); struct nlattr; struct ifinfomsg; diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 092525a6933a..430f72306409 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -852,7 +852,7 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode, if (json_output) dump_xlated_json(&dd, buf, member_len, opcodes, linum); else if (visual) - dump_xlated_cfg(&dd, buf, member_len); + dump_xlated_cfg(&dd, buf, member_len, opcodes, linum); else dump_xlated_plain(&dd, buf, member_len, opcodes, linum); kernel_syms_destroy(&dd); diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c index 2ee83561b945..da608e10c843 100644 --- a/tools/bpf/bpftool/xlated_dumper.c +++ b/tools/bpf/bpftool/xlated_dumper.c @@ -361,7 +361,8 @@ void dump_xlated_plain(struct dump_data *dd, void *buf, unsigned int len, } void dump_xlated_for_graph(struct dump_data *dd, void *buf_start, void *buf_end, - unsigned int start_idx) + unsigned int start_idx, + bool opcodes, bool linum) { const struct bpf_insn_cbs cbs = { .cb_print = print_insn_for_graph, @@ -405,7 +406,7 @@ void dump_xlated_for_graph(struct dump_data *dd, void *buf_start, void *buf_end, linfo = bpf_prog_linfo__lfind(prog_linfo, insn_off, 0); if (linfo && linfo != last_linfo) { - btf_dump_linfo_dotlabel(btf, linfo); + btf_dump_linfo_dotlabel(btf, linfo, linum); last_linfo = linfo; } } @@ -413,6 +414,16 @@ void dump_xlated_for_graph(struct dump_data *dd, void *buf_start, void *buf_end, printf("%d: ", insn_off); print_bpf_insn(&cbs, cur, true); + if (opcodes) { + printf("\\ \\ \\ \\ "); + fprint_hex(stdout, cur, 8, " "); + if (double_insn && cur <= insn_end - 1) { + printf(" "); + fprint_hex(stdout, cur + 1, 8, " "); + } + printf("\\l\\\n"); + } + if (cur != insn_end) printf("| "); } diff --git a/tools/bpf/bpftool/xlated_dumper.h b/tools/bpf/bpftool/xlated_dumper.h index 54847e174273..9a946377b0e6 100644 --- a/tools/bpf/bpftool/xlated_dumper.h +++ b/tools/bpf/bpftool/xlated_dumper.h @@ -34,6 +34,7 @@ void dump_xlated_json(struct dump_data *dd, void *buf, unsigned int len, void dump_xlated_plain(struct dump_data *dd, void *buf, unsigned int len, bool opcodes, bool linum); void dump_xlated_for_graph(struct dump_data *dd, void *buf, void *buf_end, - unsigned int start_index); + unsigned int start_index, + bool opcodes, bool linum); #endif From patchwork Wed Apr 5 13:21:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Monnet X-Patchwork-Id: 13201751 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30FB8C7619A for ; Wed, 5 Apr 2023 13:21:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238265AbjDENVt (ORCPT ); Wed, 5 Apr 2023 09:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238110AbjDENVr (ORCPT ); Wed, 5 Apr 2023 09:21:47 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 258745FCA for ; Wed, 5 Apr 2023 06:21:31 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id m8so9965913wmq.5 for ; Wed, 05 Apr 2023 06:21:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1680700889; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hO/P1RTN+ZeQ7JsZ/y5Y2Qjz2b77je0xWLXgsB+vN94=; b=ACdZZ0cJdzzuhM/iOt9xbnd7e5qyiYmTFJqZm8OthUuWhp9Ow8oP7gogaxlCURRX/A ZL0lwGRNoCCOsBF+tWdVzc0BusEnIuf1s/WfaK3Odp/2ApuYwDL11uQaBEuu5/tErMB9 gxh0LYUEp82LiBZE+UNMUQ8388dT+hWi6j5FDz4nO2qcAx0YTWnCwRMxSDxD/EvEIJ2A kTLpWM90zRvkacNi89tA5qdrKAOsFYhCg9sifnCnFixQafaTnI1HN8RX5LK0W4dmBcQH 1k5Dx8vVJ30j3uKHkvfVd0krNOgOacT5Wuo/PVVwanGggPbiwJKbJA5teIHLGFKXlN0E X9Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680700889; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hO/P1RTN+ZeQ7JsZ/y5Y2Qjz2b77je0xWLXgsB+vN94=; b=2nbqXllQ7QnGxWbRqmAeGGDz5jhxEDjsYceRV530UBe7MqnzmEeTf/98dtTIXT7S3Q AfVTEcdxvFI4i+A2vOQ53v4ZzmwE3RWokGWjw+UAU2t/TcylMS5SBqdezT7OYOyXP4wF Y+ryIy5Owlqa+VxWVshiIT99lYjYa1NrAnQOsUYEbxuPSNN60VaE17FrbJUoGtfbGFlO quzZQAYT52HVyTgJEqqNRq8XuANVFtlNAhjSY2Kj+XnEpNAYuiDsg1dYRZiOTYbjNL9w 12pXaeOry9UNSEtOMXGtrRzltEhq42Eu/fFJ+caKBuFE5HSWKoyQhJFG/Bv19PCFbsTh AKWA== X-Gm-Message-State: AAQBX9eLEfSeXqlp5q308AJABw7pj0j6sYlrSB5egPOs6pKHqeshsIIP sIieRei3OH9X5mvcBhi3L8KtMg== X-Google-Smtp-Source: AKy350bKKuiAUg3asQ955dsNmvVFXp0B3olUCpLDIGhoHtVhabu/k2mvn+9cZn9BH3MSyKmT5Kwcyg== X-Received: by 2002:a05:600c:2312:b0:3f0:310c:e3ce with SMTP id 18-20020a05600c231200b003f0310ce3cemr4496658wmo.17.1680700889641; Wed, 05 Apr 2023 06:21:29 -0700 (PDT) Received: from harfang.fritz.box ([2a02:8011:e80c:0:8147:b5f5:f4cc:b39b]) by smtp.gmail.com with ESMTPSA id c22-20020a05600c0ad600b003ed243222adsm2147306wmr.42.2023.04.05.06.21.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 06:21:29 -0700 (PDT) From: Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Eduard Zingerman , Quentin Monnet Subject: [PATCH bpf-next v3 7/7] bpftool: Clean up _bpftool_once_attr() calls in bash completion Date: Wed, 5 Apr 2023 14:21:20 +0100 Message-Id: <20230405132120.59886-8-quentin@isovalent.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230405132120.59886-1-quentin@isovalent.com> References: <20230405132120.59886-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 In bpftool's bash completion file, function _bpftool_once_attr() is able to process multiple arguments. There are a few locations where this function is called multiple times in a row, each time for a single argument; let's pass all arguments instead to minimize the number of function calls required for the completion. Signed-off-by: Quentin Monnet --- tools/bpf/bpftool/bash-completion/bpftool | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool index 69c64dc18b1d..e7234d1a5306 100644 --- a/tools/bpf/bpftool/bash-completion/bpftool +++ b/tools/bpf/bpftool/bash-completion/bpftool @@ -508,10 +508,7 @@ _bpftool() ;; *) COMPREPLY=( $( compgen -W "map" -- "$cur" ) ) - _bpftool_once_attr 'type' - _bpftool_once_attr 'dev' - _bpftool_once_attr 'pinmaps' - _bpftool_once_attr 'autoattach' + _bpftool_once_attr 'type dev pinmaps autoattach' return 0 ;; esac @@ -736,16 +733,10 @@ _bpftool() esac ;; *) - _bpftool_once_attr 'type' - _bpftool_once_attr 'key' - _bpftool_once_attr 'value' - _bpftool_once_attr 'entries' - _bpftool_once_attr 'name' - _bpftool_once_attr 'flags' + _bpftool_once_attr 'type key value entries name flags dev' if _bpftool_search_list 'array_of_maps' 'hash_of_maps'; then _bpftool_once_attr 'inner_map' fi - _bpftool_once_attr 'dev' return 0 ;; esac @@ -886,8 +877,7 @@ _bpftool() return 0 ;; *) - _bpftool_once_attr 'cpu' - _bpftool_once_attr 'index' + _bpftool_once_attr 'cpu index' return 0 ;; esac