From patchwork Fri Dec 13 01:24:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 13906321 X-Patchwork-Delegate: bpf@iogearbox.net Received: from fhigh-a7-smtp.messagingengine.com (fhigh-a7-smtp.messagingengine.com [103.168.172.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CBBE21345; Fri, 13 Dec 2024 01:24:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734053076; cv=none; b=tUN402Z0MfoFNUFR/NNShmY85isB0mGXut9JmOt6Jev5P6GKBV5Vx+ZmjUVRmgKDzX1RS+O0ohxQ1X9E/hlUEgfJtI49tT71gX72TM6MmebXYhpo1Ajcs4NZaWfYH9bIvWL4dFKrakNl00WDspAXjw4fTujO5V4B5Vqh8MJ+plA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734053076; c=relaxed/simple; bh=xOJhmhJiPT7XucS+JvvOAwbDKJCLQ0uJS5LKiah0erk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XC/V2Pv9ZeJ5XCuKhXLkAcp1lSMd08FklcriL8js9KgSiO/5p2eP+NNCmrFxWZH4+f/1hdtAZl66Dvz9tZhngt9y3eCjpapkziI81DTgtBZCxGP/WCBM8Y2UQeBTAz1lxsKwfTiLXu1QQRwG17hich5WLczdgECQ7oW8fFbExSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=LOs2VIg7; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=wm+ceT+a; arc=none smtp.client-ip=103.168.172.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="LOs2VIg7"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="wm+ceT+a" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id EEB221140233; Thu, 12 Dec 2024 20:24:32 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Thu, 12 Dec 2024 20:24:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1734053072; x= 1734139472; bh=1nIfMacAqxf+3GQ6nJo3PSByZmybpP146S5tZBDJZ8g=; b=L Os2VIg7DAVg7B5EyRxfr7IpsNHTExRLRIxdZNGxQnW2szVjSgwIUKEwBFVISb3Kp TtUczP5hJqDDCF6lf2d0yoOlgAlNkjhMI2uVQlLAcs5orG1e0J7TdiunTTv3yugt G8i0NAXdwHF35Lt6s6MzZg1Iwn6aogErT9uSUmVMpzHl1Elbcrgn02akQpqz0ypK 2xPfuLjYb2YizAdPeqvLw6rQJ0+w7lmPCc+ppn4wtiHmveHxmkiQwl9rkT35DBT3 uAtscjKIW9kil0o906VNnMQ/VsbycGHguAfqmsiouSDisPAdhL+OekN2EHv1+U3s 5Vt6KE/IyNxvMhgcgaFGQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1734053072; x=1734139472; bh=1 nIfMacAqxf+3GQ6nJo3PSByZmybpP146S5tZBDJZ8g=; b=wm+ceT+azr4sYf3uo 3JvmiAcqRaFg59MmUpKQMd9u3PCos6pqjYnV2O1CqHk7awRJ0ncdnAY5375LHMd7 5Hzp3CTpmy6DKMCqpRQsi2vx5Eqlt/Sgq7cqHIIXxW7N6he9nj+pH2ecJ1IEF56p SX/jFRaQghF+5hLNLeVe/OlWn0BPd04SifFNksG6zuEvEqXk7Ptg5U77ZAFkPXG7 ST3fnYAc2+HzbA2Oy0yiqiXqDZc6Wz2vG6Frn/zZpG0IVYRAsLWMLMOKi+ER0r8c IAVpFQ2XTQN+QtRJL2Sy3Ah7n9ZTpbmVlpiG4MU0bRJaO9uTOEWH7wL3NjZpdc/z H6HSw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeeigdeffecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtd dmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgr nhhivghlucgiuhcuoegugihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpe fgfefggeejhfduieekvdeuteffleeifeeuvdfhheejleejjeekgfffgefhtddtteenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugi huuhhurdighiiipdhnsggprhgtphhtthhopedukedpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtoheprghnughrihhisehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrshhtse hkvghrnhgvlhdrohhrghdprhgtphhtthhopehqmhhosehkvghrnhgvlhdrohhrghdprhgt phhtthhopegurghnihgvlhesihhoghgvrghrsghogidrnhgvthdprhgtphhtthhopehmrg hrthhinhdrlhgruheslhhinhhugidruggvvhdprhgtphhtthhopegvugguhiiikeejsehg mhgrihhlrdgtohhmpdhrtghpthhtohepshhonhhgsehkvghrnhgvlhdrohhrghdprhgtph htthhopeihohhnghhhohhnghdrshhonhhgsehlihhnuhigrdguvghvpdhrtghpthhtohep jhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Dec 2024 20:24:30 -0500 (EST) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, qmo@kernel.org, daniel@iogearbox.net Cc: martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, andrii.nakryiko@gmail.com, antony@phenome.org, toke@kernel.org Subject: [PATCH bpf-next v4 1/4] bpftool: man: Add missing format argument to command description Date: Thu, 12 Dec 2024 18:24:13 -0700 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net The command description was missing the optional argument. Add it there for consistency with the rest of the commands. Signed-off-by: Daniel Xu --- tools/bpf/bpftool/Documentation/bpftool-btf.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/Documentation/bpftool-btf.rst b/tools/bpf/bpftool/Documentation/bpftool-btf.rst index 3f6bca03ad2e..245569f43035 100644 --- a/tools/bpf/bpftool/Documentation/bpftool-btf.rst +++ b/tools/bpf/bpftool/Documentation/bpftool-btf.rst @@ -43,7 +43,7 @@ bpftool btf { show | list } [id *BTF_ID*] that hold open file descriptors (FDs) against BTF objects. On such kernels bpftool will automatically emit this information as well. -bpftool btf dump *BTF_SRC* +bpftool btf dump *BTF_SRC* [format *FORMAT*] Dump BTF entries from a given *BTF_SRC*. When **id** is specified, BTF object with that ID will be loaded and all From patchwork Fri Dec 13 01:24:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 13906322 X-Patchwork-Delegate: bpf@iogearbox.net Received: from fout-a4-smtp.messagingengine.com (fout-a4-smtp.messagingengine.com [103.168.172.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40C3D3D0D5; Fri, 13 Dec 2024 01:24:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734053078; cv=none; b=pr0ikbupiywcXJ/P8DGQphiTiCz1afIFffR0HfZdb930rDBw0VQZO8fCniIvY5uYSVR5YTFUZJSIZh6ytZipDad6Uzgow3jgk95UkzIgm2CdN/wbHIursr3XryITk6kqokaRP4Bw3V5WSFTypQboiPoEtte97CM913+cln/jV3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734053078; c=relaxed/simple; bh=tIaQGA6ru209wj2zRo7/LOYxSSw8NE0ffGbyi5wMNY0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A+b/9dnic8vSe0CHZic40r5Jb3g20jA0h3KJX8Iwmd2g5HV8qI1Io10SxYe90JjTo7x2/4UVrsuxpyTcIbBnUBnNFPhVW9qmq9wNRyIv0uiYVeQSXAWWsa4xwWacsjJvfr0FUcBeqpdSF2p8H9+nRu3JOTf9YwxFncJ3OGb1zg0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=ZzKNWCRx; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=S3ZUNfug; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="ZzKNWCRx"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="S3ZUNfug" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 5B87713841A1; Thu, 12 Dec 2024 20:24:35 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Thu, 12 Dec 2024 20:24:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1734053075; x= 1734139475; bh=xpRdN0TuD11EDsUB/g43WYAhnnZK310+Kd5LiZ2xWXA=; b=Z zKNWCRxh0Pj1j5226hK8mLCFETaVhB1I3IHyro5/MqrTN3IxtvRMDWySNrklKd5Z zoHEsDHH9HPVG+h51wXVwoSnhY20TaiI34OphQ/4mahZtzJ9CRBEGEYp05fDNbQf 5F96grkTNEAFayDRsCWcFxz9FfY3mFYokxvgG75uGTQ/PKgFLEt/P7ctASkemc8D +F+xQyF3FLjMeEn5hSdrqLxXYbhFn3CGatvIgO3bK7VRAHU28NTq6w1TRa75mGJ7 Ug+0QLg9VaNJH6gl5l85uQeivFglO1s9kV0z60cIYPL7eYAg2AZVZiM1GwXQzFu/ VVsK9/kingErW0/74ZkpQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1734053075; x=1734139475; bh=x pRdN0TuD11EDsUB/g43WYAhnnZK310+Kd5LiZ2xWXA=; b=S3ZUNfug7iLzSPtku IG4p/oQ6kHtVIxZQilslRWJ2tacDK+9HmtygC1NR0Mu57wOi17KGqei6uryOV3w4 0if+NM0A3HRPfad72AEw/gN9XrtqoGtVrN9K6vC0s+NcfDtxxkJA7D172UIUn3Yc MkWMuBhRdU2GlTTQ4gxuhBlNaDf1lWYQkn+LxCjimw1TXcuGxSZbyNqctjo6IpqQ szJNRvZPQCojwKnFPHYYtAqptdF991DwRn7txPZt5rxW/oCP4Uo2Gx89cjZYwstf e//RJG6e/RVMyzx3dG7zr6DSKHyYuuGevIIxEZ2uCX83UGcG+HlfWPso9K4GRCWu k5LKQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeeigdeffecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtd dmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgr nhhivghlucgiuhcuoegugihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpe fgfefggeejhfduieekvdeuteffleeifeeuvdfhheejleejjeekgfffgefhtddtteenucev lhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugi huuhhurdighiiipdhnsggprhgtphhtthhopedukedpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtoheprghnughrihhisehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrshhtse hkvghrnhgvlhdrohhrghdprhgtphhtthhopehqmhhosehkvghrnhgvlhdrohhrghdprhgt phhtthhopegurghnihgvlhesihhoghgvrghrsghogidrnhgvthdprhgtphhtthhopehmrg hrthhinhdrlhgruheslhhinhhugidruggvvhdprhgtphhtthhopegvugguhiiikeejsehg mhgrihhlrdgtohhmpdhrtghpthhtohepshhonhhgsehkvghrnhgvlhdrohhrghdprhgtph htthhopeihohhnghhhohhnghdrshhonhhgsehlihhnuhigrdguvghvpdhrtghpthhtohep jhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Dec 2024 20:24:33 -0500 (EST) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, qmo@kernel.org, daniel@iogearbox.net Cc: martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, andrii.nakryiko@gmail.com, antony@phenome.org, toke@kernel.org Subject: [PATCH bpf-next v4 2/4] bpftool: btf: Validate root_type_ids early Date: Thu, 12 Dec 2024 18:24:14 -0700 Message-ID: <5b5dbe4219d051f0184b8f40e35f47512ebde07a.1734052995.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Handle invalid root_type_ids early, as an invalid ID will cause dumpers to half-emit valid boilerplate and then bail with an unclean exit. This is ugly and possibly confusing for users, so preemptively handle the common error case before any dumping begins. Signed-off-by: Daniel Xu --- tools/bpf/bpftool/btf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c index d005e4fd6128..3e995faf9efa 100644 --- a/tools/bpf/bpftool/btf.c +++ b/tools/bpf/bpftool/btf.c @@ -886,6 +886,7 @@ static int do_dump(int argc, char **argv) const char *src; int fd = -1; int err = 0; + int i; if (!REQ_ARGS(2)) { usage(); @@ -1017,6 +1018,17 @@ static int do_dump(int argc, char **argv) } } + /* Invalid root IDs causes half emitted boilerplate and then unclean + * exit. It's an ugly user experience, so handle common error here. + */ + for (i = 0; i < root_type_cnt; i++) { + if (root_type_ids[i] >= btf__type_cnt(btf)) { + err = -EINVAL; + p_err("invalid root ID: %u", root_type_ids[i]); + goto done; + } + } + if (dump_c) { if (json_output) { p_err("JSON output for C-syntax dump is not supported"); From patchwork Fri Dec 13 01:24:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 13906323 X-Patchwork-Delegate: bpf@iogearbox.net Received: from flow-a1-smtp.messagingengine.com (flow-a1-smtp.messagingengine.com [103.168.172.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F11517082C; Fri, 13 Dec 2024 01:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.136 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734053081; cv=none; b=JNiDdGTW8v5k+1UXbOBmsc+rQC0QIzxiHHFMnvhIedj10ruh1tL4Y+ab02ez3IOFkBtQu56TPMQ0EsLGfgUWNyNNVT3FqKljHoeRDeuzysT2+Mds0uXrkLyE3KLFWQFiaJqHxfPuqUSzqybGzEwfS9oEt+HbBOgfE1bsid8/hLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734053081; c=relaxed/simple; bh=Xlr00EpboX3eZ9NN8BWfYhvPSIPU75I+cn8Uw0VlVoM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j8d28mVsbqecWulh9LxxxwknoBe+YKhmaY2mG4Gp/WpH5iABMRI4M8biGSMjKlzWswAvrrOMSJMPMNzKWx8LRYMumlbFhhMrV5h9oS+oF7+l8gQPg7yYBtujj+FYgwGKXd9LvsOMMCs88xmG2/pFeTi1cn3zdpTvyOJT5rWQa60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=NsrHQO8W; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=m/bFB3BP; arc=none smtp.client-ip=103.168.172.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="NsrHQO8W"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="m/bFB3BP" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailflow.phl.internal (Postfix) with ESMTP id BF984200804; Thu, 12 Dec 2024 20:24:38 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Thu, 12 Dec 2024 20:24:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1734053078; x= 1734060278; bh=YccxXOXPERZDzs8A9WsRki084bV04s4hgsiDdgoqGtw=; b=N srHQO8W4eHslfAxnE8l2yicRucFK0rfFlNlXS3Dl6A7xRfQb1XPmJ+NkeuEXEwnM ZxpSqSZ6AjMSv22YZZFwgjjMu8gGgzqye6OVBp2VwTDC0/LsDJ8R+43M9pnXQaet 5CnnI0K01YIv0vs4kOEJbMLDaAMsAY2uXg1JrQqDW1NoOWMrp6HqptOwI1Q5F4qp CxLuBDDXuyYSaK0zc+5SRdtFSaFs6VRfCKHT7WXhiRt7jf+Pr0UcV+TR3ZtwKvcr 8/qUCxxO/eeYCTQlrlVSHs8p5iCSuHCJTl/1MwF3mGX29XS27MFYWcDO0yOOq9DD iLCZnk5t8uW4O4M4UZseA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1734053078; x=1734060278; bh=Y ccxXOXPERZDzs8A9WsRki084bV04s4hgsiDdgoqGtw=; b=m/bFB3BPfSX33QXqw oGpNtF5yGVagNMgUAt20QwUf3Dvv5MYS+L3raIGh13Ci94yvp0SFFICOi2b8Mp4q Du9LFL1dL38rRtE2mX66/c5msfLIxuxDHh8z4HlhYx1KlzWwFyeg49WCvqdLwGp8 nmhlcnh2L8go6chyS+avnsrWef+OUNIzc2bdfiTUrTixNjNJYcsJTS0WT2/s/uam 1YqSNWUOZqi8mPR203mLvE6q/ARWhbsLvT1ZoToDZ/bGx11ED48gkxn3Y1QCjwKu t5Oq34umlQEdiXclGqwhZoJQJFkQdmMFvSoznij/094eYDzLLMcM5TXBcGq6ZxDs Hhi5g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeeigdeffecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdefhe dmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgr nhhivghlucgiuhcuoegugihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpe evtdekjeffkefgfefhvefffeetgfeuueeutdetjeduudehheeiffdvgefhhfevhfenucff ohhmrghinhepghhithhhuhgsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihiidpnhgspghrtghpthht ohepvddvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehhrgifkheskhgvrhhnvg hlrdhorhhgpdhrtghpthhtohepkhhusggrsehkvghrnhgvlhdrohhrghdprhgtphhtthho pegrnhgurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhohhhnrdhfrghsth grsggvnhgusehgmhgrihhlrdgtohhmpdhrtghpthhtoheprghstheskhgvrhhnvghlrdho rhhgpdhrtghpthhtohepqhhmoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnh hivghlsehiohhgvggrrhgsohigrdhnvghtpdhrtghpthhtohepuggrvhgvmhesuggrvhgv mhhlohhfthdrnhgvthdprhgtphhtthhopehmrghrthhinhdrlhgruheslhhinhhugidrug gvvh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Dec 2024 20:24:35 -0500 (EST) From: Daniel Xu To: hawk@kernel.org, kuba@kernel.org, andrii@kernel.org, john.fastabend@gmail.com, ast@kernel.org, qmo@kernel.org, daniel@iogearbox.net, davem@davemloft.net Cc: martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, andrii.nakryiko@gmail.com, antony@phenome.org, toke@kernel.org Subject: [PATCH bpf-next v4 3/4] bpftool: btf: Support dumping a specific types from file Date: Thu, 12 Dec 2024 18:24:15 -0700 Message-ID: <5ec7617fd9c28ff721947aceb80937dc10fca770.1734052995.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net Some projects, for example xdp-tools [0], prefer to check in a minimized vmlinux.h rather than the complete file which can get rather large. However, when you try to add a minimized version of a complex struct (eg struct xfrm_state), things can get quite complex if you're trying to manually untangle and deduplicate the dependencies. This commit teaches bpftool to do a minimized dump of a specific types by providing a optional root_id argument(s). Example usage: $ ./bpftool btf dump file ~/dev/linux/vmlinux | rg "STRUCT 'xfrm_state'" [12643] STRUCT 'xfrm_state' size=912 vlen=58 $ ./bpftool btf dump file ~/dev/linux/vmlinux root_id 12643 format c #ifndef __VMLINUX_H__ #define __VMLINUX_H__ [..] struct xfrm_type_offload; struct xfrm_sec_ctx; struct xfrm_state { possible_net_t xs_net; union { struct hlist_node gclist; struct hlist_node bydst; }; union { struct hlist_node dev_gclist; struct hlist_node bysrc; }; struct hlist_node byspi; [..] [0]: https://github.com/xdp-project/xdp-tools/blob/master/headers/bpf/vmlinux.h Signed-off-by: Daniel Xu --- .../bpf/bpftool/Documentation/bpftool-btf.rst | 8 +++- tools/bpf/bpftool/btf.c | 39 ++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/tools/bpf/bpftool/Documentation/bpftool-btf.rst b/tools/bpf/bpftool/Documentation/bpftool-btf.rst index 245569f43035..dbe6d6d94e4c 100644 --- a/tools/bpf/bpftool/Documentation/bpftool-btf.rst +++ b/tools/bpf/bpftool/Documentation/bpftool-btf.rst @@ -24,7 +24,7 @@ BTF COMMANDS ============= | **bpftool** **btf** { **show** | **list** } [**id** *BTF_ID*] -| **bpftool** **btf dump** *BTF_SRC* [**format** *FORMAT*] +| **bpftool** **btf dump** *BTF_SRC* [**format** *FORMAT*] [**root_id** *ROOT_ID*] | **bpftool** **btf help** | | *BTF_SRC* := { **id** *BTF_ID* | **prog** *PROG* | **map** *MAP* [{**key** | **value** | **kv** | **all**}] | **file** *FILE* } @@ -43,7 +43,7 @@ bpftool btf { show | list } [id *BTF_ID*] that hold open file descriptors (FDs) against BTF objects. On such kernels bpftool will automatically emit this information as well. -bpftool btf dump *BTF_SRC* [format *FORMAT*] +bpftool btf dump *BTF_SRC* [format *FORMAT*] [root_id *ROOT_ID*] Dump BTF entries from a given *BTF_SRC*. When **id** is specified, BTF object with that ID will be loaded and all @@ -67,6 +67,10 @@ bpftool btf dump *BTF_SRC* [format *FORMAT*] formatting, the output is sorted by default. Use the **unsorted** option to avoid sorting the output. + **root_id** option can be used to filter a dump to a single type and all + its dependent types. It cannot be used with any other types of filtering. + It can be passed multiple times to dump multiple types. + bpftool btf help Print short help message. diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c index 3e995faf9efa..2636655ac180 100644 --- a/tools/bpf/bpftool/btf.c +++ b/tools/bpf/bpftool/btf.c @@ -27,6 +27,8 @@ #define KFUNC_DECL_TAG "bpf_kfunc" #define FASTCALL_DECL_TAG "bpf_fastcall" +#define MAX_ROOT_IDS 16 + static const char * const btf_kind_str[NR_BTF_KINDS] = { [BTF_KIND_UNKN] = "UNKNOWN", [BTF_KIND_INT] = "INT", @@ -880,7 +882,8 @@ static int do_dump(int argc, char **argv) { bool dump_c = false, sort_dump_c = true; struct btf *btf = NULL, *base = NULL; - __u32 root_type_ids[2]; + __u32 root_type_ids[MAX_ROOT_IDS]; + bool have_id_filtering; int root_type_cnt = 0; __u32 btf_id = -1; const char *src; @@ -974,6 +977,8 @@ static int do_dump(int argc, char **argv) goto done; } + have_id_filtering = !!root_type_cnt; + while (argc) { if (is_prefix(*argv, "format")) { NEXT_ARG(); @@ -993,6 +998,36 @@ static int do_dump(int argc, char **argv) goto done; } NEXT_ARG(); + } else if (is_prefix(*argv, "root_id")) { + __u32 root_id; + char *end; + + if (have_id_filtering) { + p_err("cannot use root_id with other type filtering"); + err = -EINVAL; + goto done; + } else if (root_type_cnt == MAX_ROOT_IDS) { + p_err("only %d root_id are supported", MAX_ROOT_IDS); + err = -E2BIG; + goto done; + } + + NEXT_ARG(); + root_id = strtoul(*argv, &end, 0); + if (*end) { + err = -1; + p_err("can't parse %s as root ID", *argv); + goto done; + } + for (i = 0; i < root_type_cnt; i++) { + if (root_type_ids[i] == root_id) { + err = -EINVAL; + p_err("duplicate root_id %d supplied", root_id); + goto done; + } + } + root_type_ids[root_type_cnt++] = root_id; + NEXT_ARG(); } else if (is_prefix(*argv, "unsorted")) { sort_dump_c = false; NEXT_ARG(); @@ -1403,7 +1438,7 @@ static int do_help(int argc, char **argv) fprintf(stderr, "Usage: %1$s %2$s { show | list } [id BTF_ID]\n" - " %1$s %2$s dump BTF_SRC [format FORMAT]\n" + " %1$s %2$s dump BTF_SRC [format FORMAT] [root_id ROOT_ID]\n" " %1$s %2$s help\n" "\n" " BTF_SRC := { id BTF_ID | prog PROG | map MAP [{key | value | kv | all}] | file FILE }\n" From patchwork Fri Dec 13 01:24:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 13906324 X-Patchwork-Delegate: bpf@iogearbox.net Received: from fout-a4-smtp.messagingengine.com (fout-a4-smtp.messagingengine.com [103.168.172.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52D63140E3C; Fri, 13 Dec 2024 01:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734053084; cv=none; b=e8dXwpV7QZk3GPprd0OnTaZxxBn8Q9AJ+uKTQyd0fskfWi44PUs7C/LJmwEDFxMrITQReqiKl9bTNf8M3Bi67v6UiKC373i3PuNtm9WCV4F+qTqhy8CoJhuA06NrR15ci6NVSUtyYr8cRAeQFtNuLa6Ux81v58BIAuKOZYWPM2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734053084; c=relaxed/simple; bh=QuBBOqOn9skmD/yQ2slK+O2S+eRa5jWm0OTerYyplK0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ka+xrrsJWiXDL7gH1oOyuc6qPG/7tdnKTCYuSnfxI9VTyItWv1xPz/bsqGBWNqriw/mUlh7Y3O8YKlDfhhlM4s9DO1HWt8Cmj18bddlz7Q9KjqT4n6mQOj0b8B1ELK1LsnK/rI3eLEEksFs0PH0EK2ch1LrllmQpZqGURTs9WEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=ZSaplK9h; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PY5oTQXq; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="ZSaplK9h"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PY5oTQXq" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfout.phl.internal (Postfix) with ESMTP id 514EF138419E; Thu, 12 Dec 2024 20:24:41 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Thu, 12 Dec 2024 20:24:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1734053081; x= 1734139481; bh=4P+JI44Oh/HBRFwdfuPqepgrqtXY6Ln0AAuCdeRjQbA=; b=Z SaplK9h8pttqfKmNsiyBlQVqBsw5Jrce4bU3Ur33TF06Jd6KwUIePxVozmoqHkNd PedLL4zdFw7sCXsQx5UtcRFOhV3WdDJyIG/Q3Y2UF0YEXdJ3cxXRTTA2D87Qofvm zG+spd7vRS4gtMTaahiIC7ZocpLRSnQ8uCH/oGgUBrdAZ5amHjxpW31gTI/irMNj CbPJ86ksmjGpLOuSWfZCBguhv7TqznfV73cfJRpg4Xdyc7JuH2H3iNWLVZ3V76wc QTouy6maempRj0Vsyjv/Df6nGpCDzbtA+WXFKzYJYXERwa5AU9Y3BWAMHPzpRAP8 SgweztOAixgx95e6XFd+w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1734053081; x=1734139481; bh=4 P+JI44Oh/HBRFwdfuPqepgrqtXY6Ln0AAuCdeRjQbA=; b=PY5oTQXqv1sTk7P8T nU0bcIunY9QbR38JdEjSDqhE2eDhcNdn0+fUuRwJTlY+BOK5kXz8LGJ5FQ14QEmJ TMl5aB7zE/Fl84HutcHcmto/4M+8hCEsNafgd5/RkrMKamBdMkJbVYDHKjBk6Nqn xeNv7aiIEG1Ofsjgpv7z9bqmCIn9v4U0yf/4wU1xNbis4tJk+sP2bFM6PUK5Pwjo jE6wgXKIYrO1RM29u8xS9dUrTaTbGCWgmCrAwN8FFrmOwDylcy48HzgxnI22K5/1 +V9YbGDgbegUWp6MfDNkKiTk1Yy/ie51lbfhOv1ND8v+YkOaDMTjpPSQGzES6ghj YWg6w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeeigdeffecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtd dmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepffgr nhhivghlucgiuhcuoegugihusegugihuuhhurdighiiiqeenucggtffrrghtthgvrhhnpe fgfefggeejhfduieekvdeuteffleeifeeuvdfhheejleejjeekgfffgefhtddtteenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegugihusegugi huuhhurdighiiipdhnsggprhgtphhtthhopedukedpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtoheprghnughrihhisehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrshhtse hkvghrnhgvlhdrohhrghdprhgtphhtthhopehqmhhosehkvghrnhgvlhdrohhrghdprhgt phhtthhopegurghnihgvlhesihhoghgvrghrsghogidrnhgvthdprhgtphhtthhopehmrg hrthhinhdrlhgruheslhhinhhugidruggvvhdprhgtphhtthhopegvugguhiiikeejsehg mhgrihhlrdgtohhmpdhrtghpthhtohepshhonhhgsehkvghrnhgvlhdrohhrghdprhgtph htthhopeihohhnghhhohhnghdrshhonhhgsehlihhnuhigrdguvghvpdhrtghpthhtohep jhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 12 Dec 2024 20:24:38 -0500 (EST) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, qmo@kernel.org, daniel@iogearbox.net Cc: martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, andrii.nakryiko@gmail.com, antony@phenome.org, toke@kernel.org Subject: [PATCH bpf-next v4 4/4] bpftool: bash: Add bash completion for root_id argument Date: Thu, 12 Dec 2024 18:24:16 -0700 Message-ID: <7aa45a2c19ac50b72be1921e0d94f9bc77c97896.1734052995.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net This commit updates the bash completion script with the new root_id argument. Signed-off-by: Daniel Xu --- tools/bpf/bpftool/bash-completion/bpftool | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool index 0c541498c301..097d406ee21f 100644 --- a/tools/bpf/bpftool/bash-completion/bpftool +++ b/tools/bpf/bpftool/bash-completion/bpftool @@ -930,6 +930,9 @@ _bpftool() format) COMPREPLY=( $( compgen -W "c raw" -- "$cur" ) ) ;; + root_id) + return 0; + ;; c) COMPREPLY=( $( compgen -W "unsorted" -- "$cur" ) ) ;; @@ -937,13 +940,13 @@ _bpftool() # emit extra options case ${words[3]} in id|file) - _bpftool_once_attr 'format' + _bpftool_once_attr 'format root_id' ;; map|prog) if [[ ${words[3]} == "map" ]] && [[ $cword == 6 ]]; then COMPREPLY+=( $( compgen -W "key value kv all" -- "$cur" ) ) fi - _bpftool_once_attr 'format' + _bpftool_once_attr 'format root_id' ;; *) ;;