All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: add BTF ids in procfs for file descriptors to BTF objects
@ 2019-08-20  9:52 Quentin Monnet
  2019-08-20 13:36 ` Daniel Borkmann
  0 siblings, 1 reply; 3+ messages in thread
From: Quentin Monnet @ 2019-08-20  9:52 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: bpf, netdev, oss-drivers, Quentin Monnet

Implement the show_fdinfo hook for BTF FDs file operations, and make it
print the id and the size of the BTF object. This allows for a quick
retrieval of the BTF id from its FD; or it can help understanding what
type of object (BTF) the file descriptor points to.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 kernel/bpf/btf.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 5fcc7a17eb5a..39e184f1b27c 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -3376,6 +3376,19 @@ void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj,
 	btf_type_ops(t)->seq_show(btf, t, type_id, obj, 0, m);
 }
 
+#ifdef CONFIG_PROC_FS
+static void bpf_btf_show_fdinfo(struct seq_file *m, struct file *filp)
+{
+	const struct btf *btf = filp->private_data;
+
+	seq_printf(m,
+		   "btf_id:\t%u\n"
+		   "data_size:\t%u\n",
+		   btf->id,
+		   btf->data_size);
+}
+#endif
+
 static int btf_release(struct inode *inode, struct file *filp)
 {
 	btf_put(filp->private_data);
@@ -3383,6 +3396,9 @@ static int btf_release(struct inode *inode, struct file *filp)
 }
 
 const struct file_operations btf_fops = {
+#ifdef CONFIG_PROC_FS
+	.show_fdinfo	= bpf_btf_show_fdinfo,
+#endif
 	.release	= btf_release,
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] bpf: add BTF ids in procfs for file descriptors to BTF objects
  2019-08-20  9:52 [PATCH bpf-next] bpf: add BTF ids in procfs for file descriptors to BTF objects Quentin Monnet
@ 2019-08-20 13:36 ` Daniel Borkmann
  2019-08-20 13:48   ` [oss-drivers] " Quentin Monnet
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Borkmann @ 2019-08-20 13:36 UTC (permalink / raw)
  To: Quentin Monnet, Alexei Starovoitov; +Cc: bpf, netdev, oss-drivers

On 8/20/19 11:52 AM, Quentin Monnet wrote:
> Implement the show_fdinfo hook for BTF FDs file operations, and make it
> print the id and the size of the BTF object. This allows for a quick
> retrieval of the BTF id from its FD; or it can help understanding what
> type of object (BTF) the file descriptor points to.
> 
> Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
> ---
>   kernel/bpf/btf.c | 16 ++++++++++++++++
>   1 file changed, 16 insertions(+)
> 
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 5fcc7a17eb5a..39e184f1b27c 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -3376,6 +3376,19 @@ void btf_type_seq_show(const struct btf *btf, u32 type_id, void *obj,
>   	btf_type_ops(t)->seq_show(btf, t, type_id, obj, 0, m);
>   }
>   
> +#ifdef CONFIG_PROC_FS
> +static void bpf_btf_show_fdinfo(struct seq_file *m, struct file *filp)
> +{
> +	const struct btf *btf = filp->private_data;
> +
> +	seq_printf(m,
> +		   "btf_id:\t%u\n"
> +		   "data_size:\t%u\n",
> +		   btf->id,
> +		   btf->data_size);

Looks good, exposing btf_id makes sense to me in order to correlate with applications.
Do you have a concrete use case for data_size to expose it this way as opposed to fetch
it via btf_get_info_by_fd()? If not, I'd say lets only add btf_id in there.

> +}
> +#endif
> +
>   static int btf_release(struct inode *inode, struct file *filp)
>   {
>   	btf_put(filp->private_data);
> @@ -3383,6 +3396,9 @@ static int btf_release(struct inode *inode, struct file *filp)
>   }
>   
>   const struct file_operations btf_fops = {
> +#ifdef CONFIG_PROC_FS
> +	.show_fdinfo	= bpf_btf_show_fdinfo,
> +#endif
>   	.release	= btf_release,
>   };
>   
> 

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [oss-drivers] Re: [PATCH bpf-next] bpf: add BTF ids in procfs for file descriptors to BTF objects
  2019-08-20 13:36 ` Daniel Borkmann
@ 2019-08-20 13:48   ` Quentin Monnet
  0 siblings, 0 replies; 3+ messages in thread
From: Quentin Monnet @ 2019-08-20 13:48 UTC (permalink / raw)
  To: Daniel Borkmann, Alexei Starovoitov; +Cc: bpf, netdev, oss-drivers

2019-08-20 15:36 UTC+0200 ~ Daniel Borkmann <daniel@iogearbox.net>
> On 8/20/19 11:52 AM, Quentin Monnet wrote:
>> Implement the show_fdinfo hook for BTF FDs file operations, and make it
>> print the id and the size of the BTF object. This allows for a quick
>> retrieval of the BTF id from its FD; or it can help understanding what
>> type of object (BTF) the file descriptor points to.
>>
>> Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
>> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
>> ---
>>   kernel/bpf/btf.c | 16 ++++++++++++++++
>>   1 file changed, 16 insertions(+)
>>
>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>> index 5fcc7a17eb5a..39e184f1b27c 100644
>> --- a/kernel/bpf/btf.c
>> +++ b/kernel/bpf/btf.c
>> @@ -3376,6 +3376,19 @@ void btf_type_seq_show(const struct btf *btf,
>> u32 type_id, void *obj,
>>       btf_type_ops(t)->seq_show(btf, t, type_id, obj, 0, m);
>>   }
>>   +#ifdef CONFIG_PROC_FS
>> +static void bpf_btf_show_fdinfo(struct seq_file *m, struct file *filp)
>> +{
>> +    const struct btf *btf = filp->private_data;
>> +
>> +    seq_printf(m,
>> +           "btf_id:\t%u\n"
>> +           "data_size:\t%u\n",
>> +           btf->id,
>> +           btf->data_size);
> 
> Looks good, exposing btf_id makes sense to me in order to correlate with
> applications.
> Do you have a concrete use case for data_size to expose it this way as
> opposed to fetch
> it via btf_get_info_by_fd()? If not, I'd say lets only add btf_id in there.

No, I don't have one for data_size to be honest. I'll respin with btf_id
only then.

Thanks,
Quentin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-20 13:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-20  9:52 [PATCH bpf-next] bpf: add BTF ids in procfs for file descriptors to BTF objects Quentin Monnet
2019-08-20 13:36 ` Daniel Borkmann
2019-08-20 13:48   ` [oss-drivers] " Quentin Monnet

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.