From mboxrd@z Thu Jan 1 00:00:00 1970 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 07E64C43334 for ; Wed, 13 Jul 2022 13:40:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233943AbiGMNky (ORCPT ); Wed, 13 Jul 2022 09:40:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236219AbiGMNkc (ORCPT ); Wed, 13 Jul 2022 09:40:32 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 68936DFEE; Wed, 13 Jul 2022 06:40:27 -0700 (PDT) Received: from pwmachine.localnet (240.119.92.79.rev.sfr.net [79.92.119.240]) by linux.microsoft.com (Postfix) with ESMTPSA id 966D2204DE95; Wed, 13 Jul 2022 06:40:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 966D2204DE95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1657719627; bh=zhcQR1NFu1moQf6ZTM3VRhL0045EbCU1SDAmi7ztlFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UmSuTozVzulQTaajsVaj3Gnjob2uKqT9SkBU96fnLL+ZaEfbLYDXoDdrrd+QONl+e r1Gz9Prf087V+neK0QXmunHw8x2hH+/hSsVgjHmbJX8xJSteMjj928GEr7DSn92of3 pKKelj4W70WA4nfLT7ymZKjjUOt4Po4XTaPLMOe8= From: Francis Laniel To: sdf@google.com Cc: bpf@vger.kernel.org, Quentin Monnet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Jiri Olsa , open list Subject: Re: [RFC PATCH v1 1/1] bpftool: Add generating command to C dumped file. Date: Wed, 13 Jul 2022 15:40:22 +0200 Message-ID: <12015028.O9o76ZdvQC@pwmachine> Organization: Microsoft In-Reply-To: References: <20220712184225.52429-1-flaniel@linux.microsoft.com> <20220712184225.52429-2-flaniel@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi. Le mardi 12 juillet 2022, 22:47:40 CEST sdf@google.com a =E9crit : > On 07/12, Francis Laniel wrote: > > This commit adds the following lines to file generated by dump: > > /* > >=20 > > * File generated by bpftool using: > > * bpftool btf dump file /sys/kernel/btf/vmlinux format c > > * DO NOT EDIT. > > */ > >=20 > > This warns users to not edit the file and documents the command used to > > generate the file. > >=20 > > Signed-off-by: Francis Laniel > > --- > >=20 > > tools/bpf/bpftool/btf.c | 16 ++++++++++++++-- > > 1 file changed, 14 insertions(+), 2 deletions(-) > >=20 > > diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c > > index 7e6accb9d9f7..eecfc27370c3 100644 > > --- a/tools/bpf/bpftool/btf.c > > +++ b/tools/bpf/bpftool/btf.c > > @@ -415,7 +415,8 @@ static void __printf(2, 0) btf_dump_printf(void *ct= x, > >=20 > > } > > =20 > > static int dump_btf_c(const struct btf *btf, > >=20 > > - __u32 *root_type_ids, int root_type_cnt) > > + __u32 *root_type_ids, int root_type_cnt, > > + int argc, char **argv) > >=20 > > { > > =20 > > struct btf_dump *d; > > int err =3D 0, i; > >=20 > > @@ -425,6 +426,14 @@ static int dump_btf_c(const struct btf *btf, > >=20 > > if (err) > > =09 > > return err; > >=20 > > + printf("/*\n"); > > + printf(" * File generated by bpftool using:\n"); > > + printf(" * bpftool btf dump"); >=20 > [..] >=20 > > + for (i =3D 0; i < argc; i++) > > + printf(" %s", argv[i]); >=20 > Do we really need that complexity to preserve the arguments? I was also a bit sceptickal when I first wrote as I found this code a bit=20 complex for not so much added value. But in my case, I do not use bpftool often, so having the command documente= d=20 in the generated file would have been useful. I will just find another way to document (or I think now I will not forget = it=20 anymore since this series). > For skeletons we're simply doing: >=20 > /* THIS FILE IS AUTOGENERATED BY BPFTOOL! */ >=20 > So probably the same should be fine here? >=20 > Also, while at it, might be worth adding SPDX license comment? So let's > align with whatever we have in gen.c ? I will send a v2 aligned on skeletons in no more than 15 minutes. > > + printf("\n"); > > + printf(" * DO NOT EDIT.\n"); > > + printf(" */\n"); > >=20 > > printf("#ifndef __VMLINUX_H__\n"); > > printf("#define __VMLINUX_H__\n"); > > printf("\n"); > >=20 > > @@ -507,8 +516,10 @@ static bool btf_is_kernel_module(__u32 btf_id) > >=20 > > static int do_dump(int argc, char **argv) > > { > > =20 > > struct btf *btf =3D NULL, *base =3D NULL; > >=20 > > + char **orig_argv =3D argv; > >=20 > > __u32 root_type_ids[2]; > > int root_type_cnt =3D 0; > >=20 > > + int orig_argc =3D argc; > >=20 > > bool dump_c =3D false; > > __u32 btf_id =3D -1; > > const char *src; > >=20 > > @@ -649,7 +660,8 @@ static int do_dump(int argc, char **argv) > >=20 > > err =3D -ENOTSUP; > > goto done; > > =09 > > } > >=20 > > - err =3D dump_btf_c(btf, root_type_ids, root_type_cnt); > > + err =3D dump_btf_c(btf, root_type_ids, root_type_cnt, > > + orig_argc, orig_argv); > >=20 > > } else { > > =09 > > err =3D dump_btf_raw(btf, root_type_ids, root_type_cnt); > > =09 > > } > >=20 > > -- > > 2.25.1 Best regards.