mbox series

[v3,bpf-next,0/2] Make bpf_endian.h compatible with vmlinux.h

Message ID 20200630152125.3631920-1-andriin@fb.com
Headers show
Series Make bpf_endian.h compatible with vmlinux.h | expand

Message

Andrii Nakryiko June 30, 2020, 3:21 p.m. UTC
Change libbpf's bpf_endian.h header to be compatible when used with system
headers and when using just vmlinux.h. This is a frequent request for users
writing BPF CO-RE applications. Do this by re-implementing byte swap
compile-time macros. Also add simple tests validating correct results both for
byte-swapping built-ins and macros.

v2->v3:
- explicit zero-initialization of global variables (Daniel);

v1->v2:
- reimplement byte swapping macros (Alexei).

Andrii Nakryiko (2):
  libbpf: make bpf_endian co-exist with vmlinux.h
  selftests/bpf: add byte swapping selftest

 tools/lib/bpf/bpf_endian.h                    | 43 ++++++++++++---
 .../testing/selftests/bpf/prog_tests/endian.c | 53 +++++++++++++++++++
 .../testing/selftests/bpf/progs/test_endian.c | 37 +++++++++++++
 3 files changed, 125 insertions(+), 8 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/endian.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_endian.c

Comments

Yonghong Song June 30, 2020, 6:09 p.m. UTC | #1
On 6/30/20 8:21 AM, Andrii Nakryiko wrote:
> Change libbpf's bpf_endian.h header to be compatible when used with system
> headers and when using just vmlinux.h. This is a frequent request for users
> writing BPF CO-RE applications. Do this by re-implementing byte swap
> compile-time macros. Also add simple tests validating correct results both for
> byte-swapping built-ins and macros.
> 
> v2->v3:
> - explicit zero-initialization of global variables (Daniel);
> 
> v1->v2:
> - reimplement byte swapping macros (Alexei).
> 
> Andrii Nakryiko (2):
>    libbpf: make bpf_endian co-exist with vmlinux.h
>    selftests/bpf: add byte swapping selftest
> 
>   tools/lib/bpf/bpf_endian.h                    | 43 ++++++++++++---
>   .../testing/selftests/bpf/prog_tests/endian.c | 53 +++++++++++++++++++
>   .../testing/selftests/bpf/progs/test_endian.c | 37 +++++++++++++
>   3 files changed, 125 insertions(+), 8 deletions(-)
>   create mode 100644 tools/testing/selftests/bpf/prog_tests/endian.c
>   create mode 100644 tools/testing/selftests/bpf/progs/test_endian.c
Ack for the series:
Acked-by: Yonghong Song <yhs@fb.com>
Daniel Borkmann July 1, 2020, 2:53 p.m. UTC | #2
On 6/30/20 5:21 PM, Andrii Nakryiko wrote:
> Change libbpf's bpf_endian.h header to be compatible when used with system
> headers and when using just vmlinux.h. This is a frequent request for users
> writing BPF CO-RE applications. Do this by re-implementing byte swap
> compile-time macros. Also add simple tests validating correct results both for
> byte-swapping built-ins and macros.
> 
> v2->v3:
> - explicit zero-initialization of global variables (Daniel);
> 
> v1->v2:
> - reimplement byte swapping macros (Alexei).
> 
> Andrii Nakryiko (2):
>    libbpf: make bpf_endian co-exist with vmlinux.h
>    selftests/bpf: add byte swapping selftest
> 
>   tools/lib/bpf/bpf_endian.h                    | 43 ++++++++++++---
>   .../testing/selftests/bpf/prog_tests/endian.c | 53 +++++++++++++++++++
>   .../testing/selftests/bpf/progs/test_endian.c | 37 +++++++++++++
>   3 files changed, 125 insertions(+), 8 deletions(-)
>   create mode 100644 tools/testing/selftests/bpf/prog_tests/endian.c
>   create mode 100644 tools/testing/selftests/bpf/progs/test_endian.c
> 

All good now & applied, thanks!