From patchwork Fri Dec 13 19:44:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 13907799 X-Patchwork-Delegate: bpf@iogearbox.net Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 5B6BF1EE03C; Fri, 13 Dec 2024 19:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119068; cv=none; b=J0aCpZzbLVBDTxcajLNNegN4BsFet4WBilwLv3Ganp3J0vIJzGdnxR4GQvQvJXf2N1ggNrGGEgmFEtkaodnO4RglXi2YkQjfN3IqXwbp/R24vi+0q/3I5oauHrr3addPXftjmm16us2QV6lriG/H6YqS/z9BNmsmGqhr+RYXne0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119068; c=relaxed/simple; bh=xxjFD9Hj5YUqHTUhy0eKOIT14MQBXPozrxJ0m5PQGsE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AYvbV6AXQGp0DLqXScBfSFsVi4VoLd+E76HIkk9dBbLdbNRmG+PBRJghZYOqAyuVvKAZGm4MEHk8xB8diKVAE7Dp+tytzKpkzj07X5I+bNy+MQ6fI7ceY1N2kd/VX3duf1JWws0aIwngKukjC/C1nAOUsU/tCA9k8RUq2D7/vLI= 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=JOsaka5h; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=UhFt5R1L; arc=none smtp.client-ip=103.168.172.154 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="JOsaka5h"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="UhFt5R1L" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5F0DE1140189; Fri, 13 Dec 2024 14:44:25 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 13 Dec 2024 14:44:25 -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=1734119065; x= 1734205465; bh=sYAU7uN4FLAT86HvspuDCpL7NoZlksxeDfGgZHhfGGw=; b=J Osaka5hL8/qq5YUR1Dsl8XQ0kpQHXYW0tG600SKzhaUidV5YWdwdl0ciTeF/jmNh 2KcP4kXxdMbkjOHyY2pDy63uUyVjyWbzZdjU7DVjo5nDFEYcsQPVWLKo1Egftvp8 Zl/Hf30DgtUVkVd0JZ2l+B1dpC5JAAUxL2jsCIoExT6WOWQ+3KReDnefu6mXkkJS HI0zEZ0P4VuX9DovbOlINNCpQpPe3HVihYt4v0AYTBy4kwHg9FA9svge5ISxjtSh YFKs/UuDB1xZsQUtP9rc+2Bp58Pvlj61ZPWhZI5LDr7Ix2t5/I3MsG3CJtMZ13Eq uaVhAjt4yvEXpmlTT9MDA== 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=1734119065; x=1734205465; bh=s YAU7uN4FLAT86HvspuDCpL7NoZlksxeDfGgZHhfGGw=; b=UhFt5R1LWaGkG1QUd So6uaQjOZUwJIa9rMwFw4qtSGlhxnjwHKUlkhS3CVd3g6oqsj9xljfocjaGl8/zO W/Gnalt0CqlqsuFenms/JXS4yS4r2VDbTOduBq2+Gc8KJmERNXYqOTIAM0mhptfO 7yudobKH2Q0I2YQoICtYIxlPsnXr7fBiljTljUjaOY1n9iOHB1LLfE+AHbKHsrPh Gs14CRjJG8Fy0RTm9Lq6IwfAmXTNamKlawyB71jYgdqYNcKLl0MfBuxBpCW72QGE +FpVuyiPMIuzQL+kCU6vPziJwwhxepI83AEFVHMZW86Fb8fb+9hQ/wOJM9VyzJEI x8FaQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeejgdduvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlje dtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeff rghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnh epgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesug iguhhuuhdrgiihiidpnhgspghrtghpthhtohepudekpdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopegurghnihgvlhesihhoghgvrghrsghogidrnhgvthdprhgtphhtthhope hqmhhosehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghl rdhorhhgpdhrtghpthhtoheprghstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmh grrhhtihhnrdhlrghusehlihhnuhigrdguvghvpdhrtghpthhtohepvgguugihiiekjees ghhmrghilhdrtghomhdprhgtphhtthhopehsohhngheskhgvrhhnvghlrdhorhhgpdhrtg hpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhugidruggvvhdprhgtphhtthho pehjohhhnhdrfhgrshhtrggsvghnugesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 13 Dec 2024 14:44:22 -0500 (EST) From: Daniel Xu To: daniel@iogearbox.net, qmo@kernel.org, andrii@kernel.org, ast@kernel.org 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 v5 1/4] bpftool: man: Add missing format argument to command description Date: Fri, 13 Dec 2024 12:44:09 -0700 Message-ID: <140402f22fc377fba4c34376b7e1d2eba2c276b1.1734119028.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 The command description was missing the optional argument. Add it there for consistency with the rest of the commands. Reviewed-by: Quentin Monnet 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 19:44:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 13907800 X-Patchwork-Delegate: bpf@iogearbox.net Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 E4DD61EF08E; Fri, 13 Dec 2024 19:44:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119070; cv=none; b=faS5S0bdVZaFUvsa3Rak06YABXL4jH2K2MovbkpI/wOPEXuWHn6tNcWMa7nOF8BzXiRP83PjmmRqAhqGI/DjrR/MFCAlqsAvWuXxZbyaKigST7tzkmkzjkEWU0RZUdm7FofrqGn5tmY70wkTab4uySFEdoyNijmQ6UAXaQk4jPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119070; c=relaxed/simple; bh=aV1LU33mjPimJ3grymbwCJbkQ1UMQZmHjtKrS7aYHTc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=acg+TevtbVhCxdDNUOpGbiv4r89OOqYCijRDI0YeJLzX//K25b5BeELkVgQnwP6UBTiA/paOrlmw82xrV04yMi4ILwqazxR66enLYNWuo65fzXHYlocbQ7T3BTAANGLmu4Tb6Z/ANNKhO6vIqEqE1WOzUkcNCvyiXt9HefWGJhY= 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=fdZYdO4L; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QHm4y3rC; arc=none smtp.client-ip=103.168.172.154 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="fdZYdO4L"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QHm4y3rC" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id EBEDF114018F; Fri, 13 Dec 2024 14:44:27 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Fri, 13 Dec 2024 14:44:27 -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=1734119067; x= 1734205467; bh=YinbvjKzdE2chJYUSe+K0GkdcFRtXOMJspcMdt83bi8=; b=f dZYdO4Lq+5ZCyO3lH4rGo8M9mSTEdPpgDkvDKN1hyOZVlZgMwpBz7gnM5UfQiCW7 gxcZig9bVwsyzCTY71xLXMJ4EMkzGeN+k9iDBZYRqXUWSDHD1P6+b5yNWeP4GU6p WsbZHZXBtgUY9SQFQzJHfA4KWX6KyoMQboyMDir7hkpWLl0iSKH7rN89O2Eng5vK TQ4fYHHoZxhO4aUunA9aDBIp0kbF/nIg/rdTnGieAZ+6PWBlSyBXINhc/pqsCNV1 ULJ/3JP/2FeQ25r3k8JWxrO7mjY7FoMlrngvSADf1voR8S1yY9uPPMgvyqMp/DWt pr/PeCOUbWMsY1gUfr+1Q== 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=1734119067; x=1734205467; bh=Y inbvjKzdE2chJYUSe+K0GkdcFRtXOMJspcMdt83bi8=; b=QHm4y3rC3ECiXk6WP J+46ue/KX0X9KoWdpp1qK7z1cMXRJTMZlPeYSt1aTHzoT1WpLj+iI9v128/iukSq WNQQ4eV55YPVdrZTF+PEDLZ5bgG/ceCWfGJrgOXJ+gJjvsNpUuNJKwEjfpsECCRb NSt3O6/TxfJNdagXG4YKipwX9hWHroD+AxF+Ulf21AELoE8bNGyPEnnXewh4l+Pz gyhJsI3N/uaOzS4CjMf+nJ3PFGL22fBcaeo6ukj5qdJz0rtsy1TIbyNHyCA3/raU Oy6LoqLm7aVe/b+prARGTEK8Q4JW4GOT4zvYWnAv1yoofslQrp4uiXXDelvpu/ky b9xPA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeejgdduvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlje dtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeff rghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnh epgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesug iguhhuuhdrgiihiidpnhgspghrtghpthhtohepudekpdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopegurghnihgvlhesihhoghgvrghrsghogidrnhgvthdprhgtphhtthhope hqmhhosehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghl rdhorhhgpdhrtghpthhtoheprghstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmh grrhhtihhnrdhlrghusehlihhnuhigrdguvghvpdhrtghpthhtohepvgguugihiiekjees ghhmrghilhdrtghomhdprhgtphhtthhopehsohhngheskhgvrhhnvghlrdhorhhgpdhrtg hpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhugidruggvvhdprhgtphhtthho pehjohhhnhdrfhgrshhtrggsvghnugesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 13 Dec 2024 14:44:25 -0500 (EST) From: Daniel Xu To: daniel@iogearbox.net, qmo@kernel.org, andrii@kernel.org, ast@kernel.org 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 v5 2/4] bpftool: btf: Validate root_type_ids early Date: Fri, 13 Dec 2024 12:44:10 -0700 Message-ID: <33e09a08a6072f8381cb976218a009709309b7e1.1734119028.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. Reviewed-by: Quentin Monnet 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 19:44:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 13907801 X-Patchwork-Delegate: bpf@iogearbox.net Received: from flow-a6-smtp.messagingengine.com (flow-a6-smtp.messagingengine.com [103.168.172.141]) (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 D8F461F4280; Fri, 13 Dec 2024 19:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119073; cv=none; b=I3Q9U20FjuHEu1UCY82TcbOQ5l+hZrV8f4WwTq+Nl+ZsYnkgWpQK6TkbuY/b+OmKG/d64itE8xBuvoUNNrWtRKq5w0mnXLqw5/FtQRsUq02CMEnukaQ3waSVLpKq7S5Pj6HPnzvR2ovMeHCvO1PYkhb9tp3pNj81/NfDT+syURQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119073; c=relaxed/simple; bh=G3agrlK21+2NjM3MigaoVGU0YXHc2phKcX4ht1E64Ks=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WPv3nGYzQuhqyDfCxwbaPQnN+GXmjtnf18+ZgABf7yVccqQd9rO1HgycaUYN0GVTsS7FMy4poGO/iA3RbFD99CXpog0VnkOOL44lHCzT83rIhM5a5iD1NH8zySSbyTqosRH27M1BuXTMNKdYe11NhGksWsUSL2oVrlGb5PC9D3A= 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=hh18jNMA; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FDHqDf1x; arc=none smtp.client-ip=103.168.172.141 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="hh18jNMA"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FDHqDf1x" Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailflow.phl.internal (Postfix) with ESMTP id B65742008D6; Fri, 13 Dec 2024 14:44:30 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Fri, 13 Dec 2024 14:44:30 -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=1734119070; x= 1734126270; bh=pFCgMZCyhykBHY5GaSdQAkacUHmaYs+i9UHMe/ejd5I=; b=h h18jNMAQiw6VMhl4J3U7E8T3hwvoN9a0Y2THIirMVDMVA0ZXJMvkKzOgUp3wi7Hr ogIW8u3zEPxDA0FDH6ssRvcoMkamELkrUcFvp6hTqcbDbtssHo18/S/RDxvuw9sE GYB27kT9yM/w4gUAOyAxUqF5ph+BEi5HKfWZDUs9M67y86TiLtrKisKb3sHh0/jx QBf6J0r3hOEkGrPFxQeTGh110VBlsCheuf8eJ1927+Y+l6zW+Jw5gnolFvrMqW0H kQlR5oLIeWQPrn9n1phck3eJmsy/+QOerVjoTWhIvx0Ktq4utTJKZlNSaErfWZgq p2wMNC2DCQq19MyfJmlvA== 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=1734119070; x=1734126270; bh=p FCgMZCyhykBHY5GaSdQAkacUHmaYs+i9UHMe/ejd5I=; b=FDHqDf1x1D6AmDbex UU6L/64a2F7dlnMNWk4P+/UtmQN97Wj7NcbdHYHwDNHDDqVJ4khxqQK/N7VOoDad IGcJKqfJGwhQOh4Bk3FHwxbEJCconGB9pIQY2Fa3UDC1WNjEQxY0jEMNmd5ZM+yg FF9NWIG7ctFAsRokWRhuk40FDL3EVq/rz2adjsvXU8XvFB2eoJ2RUWpIT7MeUOm3 i2zqjjcIS7KvQRrmj0P4Ld3Cql8SuEAcwdVZPyagSeGuOTDrUEW6dM+g6JIqk1Fg Wwyo6abRrMdgh0yBu/BwIJzyA4fRtH8+X4clYWSGtipQlnLk+OAKZO+9EBMhxMuM ICsOA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeejgdduvdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfe ehmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeff rghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnh epvedtkeejffekgfefhfevffeftefgueeuuedtteejudduheehieffvdeghffhvefhnecu ffhomhgrihhnpehgihhthhhusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpegugihusegugihuuhhurdighiiipdhnsggprhgtphht thhopedvvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepuggrvhgvmhesuggrvh gvmhhlohhfthdrnhgvthdprhgtphhtthhopehhrgifkheskhgvrhhnvghlrdhorhhgpdhr tghpthhtohepuggrnhhivghlsehiohhgvggrrhgsohigrdhnvghtpdhrtghpthhtohepkh husggrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghl rdhorhhgpdhrtghpthhtohepjhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrdgtoh hmpdhrtghpthhtohepqhhmoheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprghsthes khgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhnuhigrd guvghv X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 13 Dec 2024 14:44:28 -0500 (EST) From: Daniel Xu To: davem@davemloft.net, hawk@kernel.org, daniel@iogearbox.net, kuba@kernel.org, andrii@kernel.org, john.fastabend@gmail.com, qmo@kernel.org, ast@kernel.org 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 v5 3/4] bpftool: btf: Support dumping a specific types from file Date: Fri, 13 Dec 2024 12:44:11 -0700 Message-ID: <04feb860c0a56a7da66f923551484e1483a72074.1734119028.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 | 9 ++++- tools/bpf/bpftool/btf.c | 39 ++++++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/tools/bpf/bpftool/Documentation/bpftool-btf.rst b/tools/bpf/bpftool/Documentation/bpftool-btf.rst index 245569f43035..d47dddc2b4ee 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,11 @@ 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 + (such as the "key", "value", or "kv" arguments when dumping BTF for a map). + 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 19:44:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Xu X-Patchwork-Id: 13907802 X-Patchwork-Delegate: bpf@iogearbox.net Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 32E941F470F; Fri, 13 Dec 2024 19:44:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119075; cv=none; b=k/Fo3z3Fu0w59rXYjmEiehVz8cP77RB85AnWfZYQiXjUEeuT4bXJ2/QyM7jjEPCfYp81Odcb5mEZ/hirtxr4JXt3vvLo+B6AhiFz9i86+B1CFoodHEC78sPa4KAJ4T+sTFVFk9kEjWeheOXARHWj5NaBX8BTYVOYZjZgOuL3fjw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734119075; c=relaxed/simple; bh=4yPh3o5msytngK0b2M7uPcwE2itl/ZpxnSyMzy56frI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z6NtYaXVQQPHLr61iT69uQBUT1VsnFlVCkNmxb/XV6q2Kpf019+pqzbv3fUIzMITqXkqaDumn7vlmyqPQxJhbmSFi9wLEN28X2ymIXKoFGNo/E2lk1FH60Z1lEMUn+vWoxVt/OtQDk8kDSL0tmxlBFBDCQiGhaUik0bXNdIULTA= 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=Yy6RW/j4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=uE/ld55m; arc=none smtp.client-ip=103.168.172.151 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="Yy6RW/j4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="uE/ld55m" Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 21B221383EA2; Fri, 13 Dec 2024 14:44:33 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Fri, 13 Dec 2024 14:44:33 -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=1734119073; x= 1734205473; bh=Hqyz5RNb3bsM+MDynbvfut+TaE71hr9iEdgs6WRLNZg=; b=Y y6RW/j4DzmIVsOhUtNyY4kwRgU2nowV3hrmkcOcCyskn5owUGwY9k++uthZVAX5k 7K+LTdhMNPDTILtv0+p0TPimK9/kf4Yh4KVXK2RJdynO3Ep0RoAdqyg7LzaRPGsO yp1b2PIuKexsZimhSkPpfykkEN23YuAXfqbjhiDsINUZL1jzfgTGXnAQB31KB0BN l8D2lX73YkYkLZWflZEnit3PqSpEn5UWcHzLQOaPzRKReVjbgDNmqBCQJpeBReCL wITxuHD/czdEwlb2yA1U/iFU2HeLnXNivudQTdF79+V+k7+LfRgWZO7SC5oGiFHE aUL7SVWyYh56U7XpLlwtQ== 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=1734119073; x=1734205473; bh=H qyz5RNb3bsM+MDynbvfut+TaE71hr9iEdgs6WRLNZg=; b=uE/ld55mV5AApECKd GD9Kq4A3t64CFfCyFZfplrEd+OkxqpNjLnQiATYpMFJwn/vPCZGHSunJAp92Nc8V J5PTiYrrV/fSKVwbTu2/rzDh2TbLT81cIascAgiWfjwMforTiebRgTiu2j9Uxzod hlRFqNGtIp6KlyV0zXkHLXNuIRyTFlVhEeohqPfT8eDBjXXbFrz1MJCbgW7CmB2k P57nRwKHlF/+UnoT3aTJtaMKsFJRIJSE7We7b+TtZxz4kVqZe5vnL5c3ifkpBW9S Hgp2Z/AHz2iZKQB70cu9iR3PuMzCkaMV6EZwoxhA2pkNo5vytQhEX5SfgipW66Cb c5qeg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrkeejgdduvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlje dtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeff rghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnh epgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesug iguhhuuhdrgiihiidpnhgspghrtghpthhtohepudekpdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopegurghnihgvlhesihhoghgvrghrsghogidrnhgvthdprhgtphhtthhope hqmhhosehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghl rdhorhhgpdhrtghpthhtoheprghstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmh grrhhtihhnrdhlrghusehlihhnuhigrdguvghvpdhrtghpthhtohepvgguugihiiekjees ghhmrghilhdrtghomhdprhgtphhtthhopehsohhngheskhgvrhhnvghlrdhorhhgpdhrtg hpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhugidruggvvhdprhgtphhtthho pehjohhhnhdrfhgrshhtrggsvghnugesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 13 Dec 2024 14:44:30 -0500 (EST) From: Daniel Xu To: daniel@iogearbox.net, qmo@kernel.org, andrii@kernel.org, ast@kernel.org 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 v5 4/4] bpftool: bash: Add bash completion for root_id argument Date: Fri, 13 Dec 2024 12:44:12 -0700 Message-ID: <37016c786620761e621a88240e36f6cb27a8f628.1734119028.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, 6 insertions(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool index 0c541498c301..1ce409a6cbd9 100644 --- a/tools/bpf/bpftool/bash-completion/bpftool +++ b/tools/bpf/bpftool/bash-completion/bpftool @@ -930,19 +930,24 @@ _bpftool() format) COMPREPLY=( $( compgen -W "c raw" -- "$cur" ) ) ;; + root_id) + return 0; + ;; c) - COMPREPLY=( $( compgen -W "unsorted" -- "$cur" ) ) + COMPREPLY=( $( compgen -W "unsorted root_id" -- "$cur" ) ) ;; *) # emit extra options case ${words[3]} in id|file) + COMPREPLY=( $( compgen -W "root_id" -- "$cur" ) ) _bpftool_once_attr 'format' ;; map|prog) if [[ ${words[3]} == "map" ]] && [[ $cword == 6 ]]; then COMPREPLY+=( $( compgen -W "key value kv all" -- "$cur" ) ) fi + COMPREPLY=( $( compgen -W "root_id" -- "$cur" ) ) _bpftool_once_attr 'format' ;; *)