Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp730919imw; Wed, 13 Jul 2022 07:04:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uKcSZb2X9hDCdd/rka8mtAPRbwsfRPWrVQr123wIDHQgGIZzekPL4JGLclJaSSPR2CgYLQ X-Received: by 2002:aa7:9d8a:0:b0:52a:bb32:528f with SMTP id f10-20020aa79d8a000000b0052abb32528fmr3584537pfq.0.1657721070862; Wed, 13 Jul 2022 07:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657721070; cv=none; d=google.com; s=arc-20160816; b=qICz+ZKdN7Cakvhs26o9AACiDDMXPP8GmCXIwjxelOR7TlSB290/oAk/1LLk+s+Ip3 LgJdvSyei5F1QeKM0V73Kf5ai1CtPh+kDL3pbJ4/U2PDiW8mIkbVZ/fF72/su81QWnyH 6zv3CN4xLcpw2Jqz6/pF1++GE3zsFf4KuELPC4yvPVea9P5XEL0i74ZD5uDiwVlKf+dz upG/lOhXn2W2fuYD4vTalJew/GS5CLBnuXUaE9slTw4hA/w/AqexTu0vvB2FAs3YQ+O+ 3lSEeuYCfHJTtocGV3eM+XybihQyF0Nd9Zx0sMcmaboyHqM9e+HMHg6Mc+0C3bDFT7We q2AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:organization:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter; bh=zhcQR1NFu1moQf6ZTM3VRhL0045EbCU1SDAmi7ztlFw=; b=tQqH7O1gOFQacxjXK/MSxk7Lg7qyl4ZWI+vhTLdCerOjnSnf2zfPxC74wGy5KUh+6d EVxYIfCI4mg0+GR1axysOEXO67GPpALWp9GwlHsUGwCJc+3LG+Ma+NzEfrqcw4FZXk+e d/EVEPSGGCISBStRJIsAK8T+GZXPOIJU2Sc/++cBBNGgOOg8BOLqobYEWeIEqTvcDYpg SZOjMI9lRgdrARuzpOb/WoLgaJZtjfXjjj2EYk31VWxucRA5YA5y8oFnYAXbBHhT/Ow9 N7oHTPhRIwkd2VkGCtGQObK5AzIsLDVrQVdOkf04eU9dtkSzyEubkpP5FHdV21B3qSSk xB3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=UmSuTozV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id be6-20020a170902aa0600b0015e9ff43b64si15448973plb.585.2022.07.13.07.04.18; Wed, 13 Jul 2022 07:04:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=UmSuTozV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233865AbiGMNkw (ORCPT + 99 others); Wed, 13 Jul 2022 09:40:52 -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" X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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.