[PATCH bpf-next v2 0/2] bpf: Introduce user log

Leon Hwang posted 2 patches 2 years, 7 months ago
include/linux/bpf.h            |  3 ++
include/uapi/linux/bpf.h       |  8 ++++++
kernel/bpf/log.c               | 52 ++++++++++++++++++++++++++++++++++
net/core/dev.c                 |  4 ++-
tools/include/uapi/linux/bpf.h |  8 ++++++
5 files changed, 74 insertions(+), 1 deletion(-)
[PATCH bpf-next v2 0/2] bpf: Introduce user log
Posted by Leon Hwang 2 years, 7 months ago
This series introduces bpf user log to transfer error message from
kernel space to user space when users provide buffer to receive the
error message.

Especially, when to attach XDP to device, it can transfer the error
message along with errno from dev_xdp_attach() to user space, if error
happens in dev_xdp_attach().

Leon Hwang (2):
  bpf: Introduce bpf generic log
  bpf: Introduce bpf user log

 include/linux/bpf.h            |  3 ++
 include/uapi/linux/bpf.h       |  8 ++++++
 kernel/bpf/log.c               | 52 ++++++++++++++++++++++++++++++++++
 net/core/dev.c                 |  4 ++-
 tools/include/uapi/linux/bpf.h |  8 ++++++
 5 files changed, 74 insertions(+), 1 deletion(-)


base-commit: 622f876ab3ced325fe3c2363c6e9c128b7e6c73a
-- 
2.41.0
Re: [PATCH bpf-next v2 0/2] bpf: Introduce user log
Posted by Daniel Xu 2 years, 7 months ago
Hi Leon,

On Sat, Jul 08, 2023 at 12:07:48PM +0800, Leon Hwang wrote:
> This series introduces bpf user log to transfer error message from
> kernel space to user space when users provide buffer to receive the
> error message.
> 
> Especially, when to attach XDP to device, it can transfer the error
> message along with errno from dev_xdp_attach() to user space, if error
> happens in dev_xdp_attach().

Have you considered adding a tracepoint instead? With some TP_printk()
stuff I think you can achieve a similar result without having to do
go through changing uapi.

> 
> Leon Hwang (2):
>   bpf: Introduce bpf generic log
>   bpf: Introduce bpf user log
> 
>  include/linux/bpf.h            |  3 ++
>  include/uapi/linux/bpf.h       |  8 ++++++
>  kernel/bpf/log.c               | 52 ++++++++++++++++++++++++++++++++++
>  net/core/dev.c                 |  4 ++-
>  tools/include/uapi/linux/bpf.h |  8 ++++++
>  5 files changed, 74 insertions(+), 1 deletion(-)
> 
> 
> base-commit: 622f876ab3ced325fe3c2363c6e9c128b7e6c73a
> -- 
> 2.41.0
> 
> 

Thanks,
Daniel
Re: [PATCH bpf-next v2 0/2] bpf: Introduce user log
Posted by Leon Hwang 2 years, 7 months ago

On 2023/7/9 06:02, Daniel Xu wrote:
> Hi Leon,
> 
> On Sat, Jul 08, 2023 at 12:07:48PM +0800, Leon Hwang wrote:
>> This series introduces bpf user log to transfer error message from
>> kernel space to user space when users provide buffer to receive the
>> error message.
>>
>> Especially, when to attach XDP to device, it can transfer the error
>> message along with errno from dev_xdp_attach() to user space, if error
>> happens in dev_xdp_attach().
> 
> Have you considered adding a tracepoint instead? With some TP_printk()
> stuff I think you can achieve a similar result without having to do
> go through changing uapi.

If just for dev_xdp_attach(), I think netlink approach is better than
tracepoint approach.

As for BPF syscall, error message along with errno through uapi is a
good UX, like "create link: invalid argument (Invalid XDP flags for BPF
link attachment)" when failed to attach XDP to a device. Hence, users
are able to know the error details instead of -EINVAL or "invalid
argument" only.

Furthermore, as for other BPF syscall subcommands, we are able to
provide error message along with errno by bpf_ulog_once(&attr->xxx.ulog,
"An error").