All of lore.kernel.org
 help / color / mirror / Atom feed
From: Francis Laniel <flaniel@linux.microsoft.com>
To: sdf@google.com
Cc: bpf@vger.kernel.org, Quentin Monnet <quentin@isovalent.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH v1 1/1] bpftool: Add generating command to C dumped file.
Date: Wed, 13 Jul 2022 15:40:22 +0200	[thread overview]
Message-ID: <12015028.O9o76ZdvQC@pwmachine> (raw)
In-Reply-To: <Ys3d7LCN8yATY9az@google.com>

Hi.


Le mardi 12 juillet 2022, 22:47:40 CEST sdf@google.com a écrit :
> On 07/12, Francis Laniel wrote:
> > This commit adds the following lines to file generated by dump:
> > /*
> > 
> >   * File generated by bpftool using:
> >   * bpftool btf dump file /sys/kernel/btf/vmlinux format c
> >   * DO NOT EDIT.
> >   */
> > 
> > This warns users to not edit the file and documents the command used to
> > generate the file.
> > 
> > Signed-off-by: Francis Laniel <flaniel@linux.microsoft.com>
> > ---
> > 
> >   tools/bpf/bpftool/btf.c | 16 ++++++++++++++--
> >   1 file changed, 14 insertions(+), 2 deletions(-)
> > 
> > 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 *ctx,
> > 
> >   }
> >   
> >   static int dump_btf_c(const struct btf *btf,
> > 
> > -		      __u32 *root_type_ids, int root_type_cnt)
> > +		      __u32 *root_type_ids, int root_type_cnt,
> > +		      int argc, char **argv)
> > 
> >   {
> >   
> >   	struct btf_dump *d;
> >   	int err = 0, i;
> > 
> > @@ -425,6 +426,14 @@ static int dump_btf_c(const struct btf *btf,
> > 
> >   	if (err)
> >   	
> >   		return err;
> > 
> > +	printf("/*\n");
> > +	printf(" * File generated by bpftool using:\n");
> > +	printf(" * bpftool btf dump");
> 
> [..]
> 
> > +	for (i = 0; i < argc; i++)
> > +		printf(" %s", argv[i]);
> 
> 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 
complex for not so much added value.
But in my case, I do not use bpftool often, so having the command documented 
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 
anymore since this series).

> For skeletons we're simply doing:
> 
> 	/* THIS FILE IS AUTOGENERATED BY BPFTOOL! */
> 
> So probably the same should be fine here?
> 
> 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");
> > 
> >   	printf("#ifndef __VMLINUX_H__\n");
> >   	printf("#define __VMLINUX_H__\n");
> >   	printf("\n");
> > 
> > @@ -507,8 +516,10 @@ static bool btf_is_kernel_module(__u32 btf_id)
> > 
> >   static int do_dump(int argc, char **argv)
> >   {
> >   
> >   	struct btf *btf = NULL, *base = NULL;
> > 
> > +	char **orig_argv = argv;
> > 
> >   	__u32 root_type_ids[2];
> >   	int root_type_cnt = 0;
> > 
> > +	int orig_argc = argc;
> > 
> >   	bool dump_c = false;
> >   	__u32 btf_id = -1;
> >   	const char *src;
> > 
> > @@ -649,7 +660,8 @@ static int do_dump(int argc, char **argv)
> > 
> >   			err = -ENOTSUP;
> >   			goto done;
> >   		
> >   		}
> > 
> > -		err = dump_btf_c(btf, root_type_ids, root_type_cnt);
> > +		err = dump_btf_c(btf, root_type_ids, root_type_cnt,
> > +				 orig_argc, orig_argv);
> > 
> >   	} else {
> >   	
> >   		err = dump_btf_raw(btf, root_type_ids, root_type_cnt);
> >   	
> >   	}
> > 
> > --
> > 2.25.1


Best regards.



      reply	other threads:[~2022-07-13 13:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 18:42 [RFC PATCH v1 0/1] bpftool: Add generating command to C dumped file Francis Laniel
2022-07-12 18:42 ` [RFC PATCH v1 1/1] " Francis Laniel
2022-07-12 20:47   ` sdf
2022-07-13 13:40     ` Francis Laniel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12015028.O9o76ZdvQC@pwmachine \
    --to=flaniel@linux.microsoft.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=quentin@isovalent.com \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.