* [PATCH bpf-next v3 0/6] core_reloc fixes for s390 @ 2021-10-26 1:08 Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 1/6] libbpf: Fix endianness detection in BPF_CORE_READ_BITFIELD_PROBED() Ilya Leoshkevich ` (6 more replies) 0 siblings, 7 replies; 9+ messages in thread From: Ilya Leoshkevich @ 2021-10-26 1:08 UTC (permalink / raw) To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich v2: https://lore.kernel.org/bpf/20211025131214.731972-1-iii@linux.ibm.com/ v2 -> v3: Split the fix from the cleanup (Daniel). v1: https://lore.kernel.org/bpf/20211021234653.643302-1-iii@linux.ibm.com/ v1 -> v2: Drop bpf_core_calc_field_relo() restructuring, split the __BYTE_ORDER__ change (Andrii). Hi, this series fixes test failures in core_reloc on s390. Patch 1 fixes an endianness bug with __BYTE_ORDER vs __BYTE_ORDER__. Patches 2-5 make the rest of the code consistent in that respect. Patch 6 fixes an endianness issue in test_core_reloc_mods. Best regards, Ilya Ilya Leoshkevich (6): libbpf: Fix endianness detection in BPF_CORE_READ_BITFIELD_PROBED() libbpf: Use __BYTE_ORDER__ selftests/bpf: Use __BYTE_ORDER__ samples: seccomp: use __BYTE_ORDER__ selftests/seccomp: Use __BYTE_ORDER__ selftests/bpf: Fix test_core_reloc_mods on big-endian machines samples/seccomp/bpf-helper.h | 8 ++++---- tools/lib/bpf/bpf_core_read.h | 2 +- tools/lib/bpf/btf.c | 4 ++-- tools/lib/bpf/btf_dump.c | 8 ++++---- tools/lib/bpf/libbpf.c | 4 ++-- tools/lib/bpf/linker.c | 12 ++++++------ tools/lib/bpf/relo_core.c | 2 +- .../testing/selftests/bpf/prog_tests/btf_endian.c | 6 +++--- .../selftests/bpf/progs/test_core_reloc_mods.c | 9 +++++++++ tools/testing/selftests/bpf/test_sysctl.c | 4 ++-- tools/testing/selftests/bpf/verifier/ctx_skb.c | 14 +++++++------- tools/testing/selftests/bpf/verifier/lwt.c | 2 +- .../bpf/verifier/perf_event_sample_period.c | 6 +++--- tools/testing/selftests/seccomp/seccomp_bpf.c | 6 +++--- 14 files changed, 48 insertions(+), 39 deletions(-) -- 2.31.1 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH bpf-next v3 1/6] libbpf: Fix endianness detection in BPF_CORE_READ_BITFIELD_PROBED() 2021-10-26 1:08 [PATCH bpf-next v3 0/6] core_reloc fixes for s390 Ilya Leoshkevich @ 2021-10-26 1:08 ` Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 2/6] libbpf: Use __BYTE_ORDER__ Ilya Leoshkevich ` (5 subsequent siblings) 6 siblings, 0 replies; 9+ messages in thread From: Ilya Leoshkevich @ 2021-10-26 1:08 UTC (permalink / raw) To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich __BYTE_ORDER is supposed to be defined by a libc, and __BYTE_ORDER__ - by a compiler. bpf_core_read.h checks __BYTE_ORDER == __LITTLE_ENDIAN, which is true if neither are defined, leading to incorrect behavior on big-endian hosts if libc headers are not included, which is often the case. Fixes: ee26dade0e3b ("libbpf: Add support for relocatable bitfields") Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> --- tools/lib/bpf/bpf_core_read.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/bpf/bpf_core_read.h b/tools/lib/bpf/bpf_core_read.h index 09ebe3db5f2f..e4aa9996a550 100644 --- a/tools/lib/bpf/bpf_core_read.h +++ b/tools/lib/bpf/bpf_core_read.h @@ -40,7 +40,7 @@ enum bpf_enum_value_kind { #define __CORE_RELO(src, field, info) \ __builtin_preserve_field_info((src)->field, BPF_FIELD_##info) -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define __CORE_BITFIELD_PROBE_READ(dst, src, fld) \ bpf_probe_read_kernel( \ (void *)dst, \ -- 2.31.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH bpf-next v3 2/6] libbpf: Use __BYTE_ORDER__ 2021-10-26 1:08 [PATCH bpf-next v3 0/6] core_reloc fixes for s390 Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 1/6] libbpf: Fix endianness detection in BPF_CORE_READ_BITFIELD_PROBED() Ilya Leoshkevich @ 2021-10-26 1:08 ` Ilya Leoshkevich 2021-10-27 19:05 ` Arnaldo Carvalho de Melo 2021-10-26 1:08 ` [PATCH bpf-next v3 3/6] selftests/bpf: " Ilya Leoshkevich ` (4 subsequent siblings) 6 siblings, 1 reply; 9+ messages in thread From: Ilya Leoshkevich @ 2021-10-26 1:08 UTC (permalink / raw) To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich Use the compiler-defined __BYTE_ORDER__ instead of the libc-defined __BYTE_ORDER for consistency. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> --- tools/lib/bpf/btf.c | 4 ++-- tools/lib/bpf/btf_dump.c | 8 ++++---- tools/lib/bpf/libbpf.c | 4 ++-- tools/lib/bpf/linker.c | 12 ++++++------ tools/lib/bpf/relo_core.c | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index ef924fc2c911..0c628c33e23b 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -538,9 +538,9 @@ int btf__set_pointer_size(struct btf *btf, size_t ptr_sz) static bool is_host_big_endian(void) { -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ return false; -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ return true; #else # error "Unrecognized __BYTE_ORDER__" diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c index 8e05ab44c22a..17db62b5002e 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -1576,11 +1576,11 @@ static int btf_dump_get_bitfield_value(struct btf_dump *d, /* Bitfield value retrieval is done in two steps; first relevant bytes are * stored in num, then we left/right shift num to eliminate irrelevant bits. */ -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ for (i = t->size - 1; i >= 0; i--) num = num * 256 + bytes[i]; nr_copy_bits = bit_sz + bits_offset; -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ for (i = 0; i < t->size; i++) num = num * 256 + bytes[i]; nr_copy_bits = t->size * 8 - bits_offset; @@ -1700,10 +1700,10 @@ static int btf_dump_int_data(struct btf_dump *d, /* avoid use of __int128 as some 32-bit platforms do not * support it. */ -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ lsi = ints[0]; msi = ints[1]; -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ lsi = ints[1]; msi = ints[0]; #else diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 604abe00785f..cd6132c5a416 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -1299,10 +1299,10 @@ static int bpf_object__elf_init(struct bpf_object *obj) static int bpf_object__check_endianness(struct bpf_object *obj) { -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2LSB) return 0; -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2MSB) return 0; #else diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c index 7bf658fbda80..ce0800e61dc7 100644 --- a/tools/lib/bpf/linker.c +++ b/tools/lib/bpf/linker.c @@ -323,12 +323,12 @@ static int init_output_elf(struct bpf_linker *linker, const char *file) linker->elf_hdr->e_machine = EM_BPF; linker->elf_hdr->e_type = ET_REL; -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2LSB; -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2MSB; #else -#error "Unknown __BYTE_ORDER" +#error "Unknown __BYTE_ORDER__" #endif /* STRTAB */ @@ -538,12 +538,12 @@ static int linker_load_obj_file(struct bpf_linker *linker, const char *filename, const struct bpf_linker_file_opts *opts, struct src_obj *obj) { -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ const int host_endianness = ELFDATA2LSB; -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ const int host_endianness = ELFDATA2MSB; #else -#error "Unknown __BYTE_ORDER" +#error "Unknown __BYTE_ORDER__" #endif int err = 0; Elf_Scn *scn; diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c index 4016ed492d0c..b5b8956a1be8 100644 --- a/tools/lib/bpf/relo_core.c +++ b/tools/lib/bpf/relo_core.c @@ -662,7 +662,7 @@ static int bpf_core_calc_field_relo(const char *prog_name, *validate = true; /* signedness is never ambiguous */ break; case BPF_FIELD_LSHIFT_U64: -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ *val = 64 - (bit_off + bit_sz - byte_off * 8); #else *val = (8 - byte_sz) * 8 + (bit_off - byte_off * 8); -- 2.31.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH bpf-next v3 2/6] libbpf: Use __BYTE_ORDER__ 2021-10-26 1:08 ` [PATCH bpf-next v3 2/6] libbpf: Use __BYTE_ORDER__ Ilya Leoshkevich @ 2021-10-27 19:05 ` Arnaldo Carvalho de Melo 0 siblings, 0 replies; 9+ messages in thread From: Arnaldo Carvalho de Melo @ 2021-10-27 19:05 UTC (permalink / raw) To: Ilya Leoshkevich Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, bpf, Heiko Carstens, Vasily Gorbik Em Tue, Oct 26, 2021 at 03:08:27AM +0200, Ilya Leoshkevich escreveu: > Use the compiler-defined __BYTE_ORDER__ instead of the libc-defined > __BYTE_ORDER for consistency. There are some in tools/perf/: ⬢[acme@toolbox perf]$ find tools/perf -name "*.[ch]" | xargs grep -w __BYTE_ORDER tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c:#if __BYTE_ORDER == __BIG_ENDIAN tools/perf/util/intel-pt-decoder/intel-pt-pkt-decoder.c:#if __BYTE_ORDER == __BIG_ENDIAN tools/perf/util/arm-spe-decoder/arm-spe-pkt-decoder.c:#if __BYTE_ORDER == __BIG_ENDIAN tools/perf/util/genelf.h:#if __BYTE_ORDER == __BIG_ENDIAN tools/perf/util/intel-bts.c:#if __BYTE_ORDER == __BIG_ENDIAN tools/perf/util/s390-cpumsf.c:#if __BYTE_ORDER == __LITTLE_ENDIAN tools/perf/util/s390-cpumsf.c:#if __BYTE_ORDER == __LITTLE_ENDIAN tools/perf/util/s390-cpumsf.c:#if __BYTE_ORDER == __LITTLE_ENDIAN tools/perf/util/s390-cpumsf.c:#if __BYTE_ORDER == __LITTLE_ENDIAN tools/perf/util/data-convert-bt.c:#if __BYTE_ORDER == __BIG_ENDIAN ⬢[acme@toolbox perf]$ Please consider submitting a patch for those as well, please :-) - Arnaldo > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> > --- > tools/lib/bpf/btf.c | 4 ++-- > tools/lib/bpf/btf_dump.c | 8 ++++---- > tools/lib/bpf/libbpf.c | 4 ++-- > tools/lib/bpf/linker.c | 12 ++++++------ > tools/lib/bpf/relo_core.c | 2 +- > 5 files changed, 15 insertions(+), 15 deletions(-) > > diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c > index ef924fc2c911..0c628c33e23b 100644 > --- a/tools/lib/bpf/btf.c > +++ b/tools/lib/bpf/btf.c > @@ -538,9 +538,9 @@ int btf__set_pointer_size(struct btf *btf, size_t ptr_sz) > > static bool is_host_big_endian(void) > { > -#if __BYTE_ORDER == __LITTLE_ENDIAN > +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > return false; > -#elif __BYTE_ORDER == __BIG_ENDIAN > +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ > return true; > #else > # error "Unrecognized __BYTE_ORDER__" > diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c > index 8e05ab44c22a..17db62b5002e 100644 > --- a/tools/lib/bpf/btf_dump.c > +++ b/tools/lib/bpf/btf_dump.c > @@ -1576,11 +1576,11 @@ static int btf_dump_get_bitfield_value(struct btf_dump *d, > /* Bitfield value retrieval is done in two steps; first relevant bytes are > * stored in num, then we left/right shift num to eliminate irrelevant bits. > */ > -#if __BYTE_ORDER == __LITTLE_ENDIAN > +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > for (i = t->size - 1; i >= 0; i--) > num = num * 256 + bytes[i]; > nr_copy_bits = bit_sz + bits_offset; > -#elif __BYTE_ORDER == __BIG_ENDIAN > +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ > for (i = 0; i < t->size; i++) > num = num * 256 + bytes[i]; > nr_copy_bits = t->size * 8 - bits_offset; > @@ -1700,10 +1700,10 @@ static int btf_dump_int_data(struct btf_dump *d, > /* avoid use of __int128 as some 32-bit platforms do not > * support it. > */ > -#if __BYTE_ORDER == __LITTLE_ENDIAN > +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > lsi = ints[0]; > msi = ints[1]; > -#elif __BYTE_ORDER == __BIG_ENDIAN > +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ > lsi = ints[1]; > msi = ints[0]; > #else > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 604abe00785f..cd6132c5a416 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -1299,10 +1299,10 @@ static int bpf_object__elf_init(struct bpf_object *obj) > > static int bpf_object__check_endianness(struct bpf_object *obj) > { > -#if __BYTE_ORDER == __LITTLE_ENDIAN > +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2LSB) > return 0; > -#elif __BYTE_ORDER == __BIG_ENDIAN > +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ > if (obj->efile.ehdr->e_ident[EI_DATA] == ELFDATA2MSB) > return 0; > #else > diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c > index 7bf658fbda80..ce0800e61dc7 100644 > --- a/tools/lib/bpf/linker.c > +++ b/tools/lib/bpf/linker.c > @@ -323,12 +323,12 @@ static int init_output_elf(struct bpf_linker *linker, const char *file) > > linker->elf_hdr->e_machine = EM_BPF; > linker->elf_hdr->e_type = ET_REL; > -#if __BYTE_ORDER == __LITTLE_ENDIAN > +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2LSB; > -#elif __BYTE_ORDER == __BIG_ENDIAN > +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ > linker->elf_hdr->e_ident[EI_DATA] = ELFDATA2MSB; > #else > -#error "Unknown __BYTE_ORDER" > +#error "Unknown __BYTE_ORDER__" > #endif > > /* STRTAB */ > @@ -538,12 +538,12 @@ static int linker_load_obj_file(struct bpf_linker *linker, const char *filename, > const struct bpf_linker_file_opts *opts, > struct src_obj *obj) > { > -#if __BYTE_ORDER == __LITTLE_ENDIAN > +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > const int host_endianness = ELFDATA2LSB; > -#elif __BYTE_ORDER == __BIG_ENDIAN > +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ > const int host_endianness = ELFDATA2MSB; > #else > -#error "Unknown __BYTE_ORDER" > +#error "Unknown __BYTE_ORDER__" > #endif > int err = 0; > Elf_Scn *scn; > diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c > index 4016ed492d0c..b5b8956a1be8 100644 > --- a/tools/lib/bpf/relo_core.c > +++ b/tools/lib/bpf/relo_core.c > @@ -662,7 +662,7 @@ static int bpf_core_calc_field_relo(const char *prog_name, > *validate = true; /* signedness is never ambiguous */ > break; > case BPF_FIELD_LSHIFT_U64: > -#if __BYTE_ORDER == __LITTLE_ENDIAN > +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > *val = 64 - (bit_off + bit_sz - byte_off * 8); > #else > *val = (8 - byte_sz) * 8 + (bit_off - byte_off * 8); > -- > 2.31.1 -- - Arnaldo ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH bpf-next v3 3/6] selftests/bpf: Use __BYTE_ORDER__ 2021-10-26 1:08 [PATCH bpf-next v3 0/6] core_reloc fixes for s390 Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 1/6] libbpf: Fix endianness detection in BPF_CORE_READ_BITFIELD_PROBED() Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 2/6] libbpf: Use __BYTE_ORDER__ Ilya Leoshkevich @ 2021-10-26 1:08 ` Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 4/6] samples: seccomp: use __BYTE_ORDER__ Ilya Leoshkevich ` (3 subsequent siblings) 6 siblings, 0 replies; 9+ messages in thread From: Ilya Leoshkevich @ 2021-10-26 1:08 UTC (permalink / raw) To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich Use the compiler-defined __BYTE_ORDER__ instead of the libc-defined __BYTE_ORDER for consistency. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> --- .../testing/selftests/bpf/prog_tests/btf_endian.c | 6 +++--- tools/testing/selftests/bpf/test_sysctl.c | 4 ++-- tools/testing/selftests/bpf/verifier/ctx_skb.c | 14 +++++++------- tools/testing/selftests/bpf/verifier/lwt.c | 2 +- .../bpf/verifier/perf_event_sample_period.c | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/btf_endian.c b/tools/testing/selftests/bpf/prog_tests/btf_endian.c index 2653cc482df4..8afbf3d0b89a 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf_endian.c +++ b/tools/testing/selftests/bpf/prog_tests/btf_endian.c @@ -7,12 +7,12 @@ #include <bpf/btf.h> void test_btf_endian() { -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ enum btf_endianness endian = BTF_LITTLE_ENDIAN; -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ enum btf_endianness endian = BTF_BIG_ENDIAN; #else -#error "Unrecognized __BYTE_ORDER" +#error "Unrecognized __BYTE_ORDER__" #endif enum btf_endianness swap_endian = 1 - endian; struct btf *btf = NULL, *swap_btf = NULL; diff --git a/tools/testing/selftests/bpf/test_sysctl.c b/tools/testing/selftests/bpf/test_sysctl.c index a20a919244c0..a3bb6d399daa 100644 --- a/tools/testing/selftests/bpf/test_sysctl.c +++ b/tools/testing/selftests/bpf/test_sysctl.c @@ -124,7 +124,7 @@ static struct sysctl_test tests[] = { .descr = "ctx:write sysctl:write read ok narrow", .insns = { /* u64 w = (u16)write & 1; */ -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_H, BPF_REG_7, BPF_REG_1, offsetof(struct bpf_sysctl, write)), #else @@ -184,7 +184,7 @@ static struct sysctl_test tests[] = { .descr = "ctx:file_pos sysctl:read read ok narrow", .insns = { /* If (file_pos == X) */ -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_B, BPF_REG_7, BPF_REG_1, offsetof(struct bpf_sysctl, file_pos)), #else diff --git a/tools/testing/selftests/bpf/verifier/ctx_skb.c b/tools/testing/selftests/bpf/verifier/ctx_skb.c index 9e1a30b94197..83cecfbd6739 100644 --- a/tools/testing/selftests/bpf/verifier/ctx_skb.c +++ b/tools/testing/selftests/bpf/verifier/ctx_skb.c @@ -502,7 +502,7 @@ "check skb->hash byte load permitted", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, offsetof(struct __sk_buff, hash)), #else @@ -537,7 +537,7 @@ "check skb->hash byte load permitted 3", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, offsetof(struct __sk_buff, hash) + 3), #else @@ -646,7 +646,7 @@ "check skb->hash half load permitted", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, offsetof(struct __sk_buff, hash)), #else @@ -661,7 +661,7 @@ "check skb->hash half load permitted 2", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, offsetof(struct __sk_buff, hash) + 2), #else @@ -676,7 +676,7 @@ "check skb->hash half load not permitted, unaligned 1", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, offsetof(struct __sk_buff, hash) + 1), #else @@ -693,7 +693,7 @@ "check skb->hash half load not permitted, unaligned 3", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, offsetof(struct __sk_buff, hash) + 3), #else @@ -951,7 +951,7 @@ "check skb->data half load not permitted", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, offsetof(struct __sk_buff, data)), #else diff --git a/tools/testing/selftests/bpf/verifier/lwt.c b/tools/testing/selftests/bpf/verifier/lwt.c index 2cab6a3966bb..5c8944d0b091 100644 --- a/tools/testing/selftests/bpf/verifier/lwt.c +++ b/tools/testing/selftests/bpf/verifier/lwt.c @@ -174,7 +174,7 @@ "check skb->tc_classid half load not permitted for lwt prog", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, offsetof(struct __sk_buff, tc_classid)), #else diff --git a/tools/testing/selftests/bpf/verifier/perf_event_sample_period.c b/tools/testing/selftests/bpf/verifier/perf_event_sample_period.c index 471c1a5950d8..d8a9b1a1f9a2 100644 --- a/tools/testing/selftests/bpf/verifier/perf_event_sample_period.c +++ b/tools/testing/selftests/bpf/verifier/perf_event_sample_period.c @@ -2,7 +2,7 @@ "check bpf_perf_event_data->sample_period byte load permitted", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_1, offsetof(struct bpf_perf_event_data, sample_period)), #else @@ -18,7 +18,7 @@ "check bpf_perf_event_data->sample_period half load permitted", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_H, BPF_REG_0, BPF_REG_1, offsetof(struct bpf_perf_event_data, sample_period)), #else @@ -34,7 +34,7 @@ "check bpf_perf_event_data->sample_period word load permitted", .insns = { BPF_MOV64_IMM(BPF_REG_0, 0), -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, offsetof(struct bpf_perf_event_data, sample_period)), #else -- 2.31.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH bpf-next v3 4/6] samples: seccomp: use __BYTE_ORDER__ 2021-10-26 1:08 [PATCH bpf-next v3 0/6] core_reloc fixes for s390 Ilya Leoshkevich ` (2 preceding siblings ...) 2021-10-26 1:08 ` [PATCH bpf-next v3 3/6] selftests/bpf: " Ilya Leoshkevich @ 2021-10-26 1:08 ` Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 5/6] selftests/seccomp: Use __BYTE_ORDER__ Ilya Leoshkevich ` (2 subsequent siblings) 6 siblings, 0 replies; 9+ messages in thread From: Ilya Leoshkevich @ 2021-10-26 1:08 UTC (permalink / raw) To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich Use the compiler-defined __BYTE_ORDER__ instead of the libc-defined __BYTE_ORDER for consistency. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> --- samples/seccomp/bpf-helper.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/seccomp/bpf-helper.h b/samples/seccomp/bpf-helper.h index 0cc9816fe8e8..417e48a4c4df 100644 --- a/samples/seccomp/bpf-helper.h +++ b/samples/seccomp/bpf-helper.h @@ -62,9 +62,9 @@ void seccomp_bpf_print(struct sock_filter *filter, size_t count); #define EXPAND(...) __VA_ARGS__ /* Ensure that we load the logically correct offset. */ -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define LO_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32) #else #error "Unknown endianness" @@ -85,10 +85,10 @@ void seccomp_bpf_print(struct sock_filter *filter, size_t count); #elif __BITS_PER_LONG == 64 /* Ensure that we load the logically correct offset. */ -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define ENDIAN(_lo, _hi) _lo, _hi #define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) + sizeof(__u32) -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define ENDIAN(_lo, _hi) _hi, _lo #define HI_ARG(idx) offsetof(struct seccomp_data, args[(idx)]) #endif -- 2.31.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH bpf-next v3 5/6] selftests/seccomp: Use __BYTE_ORDER__ 2021-10-26 1:08 [PATCH bpf-next v3 0/6] core_reloc fixes for s390 Ilya Leoshkevich ` (3 preceding siblings ...) 2021-10-26 1:08 ` [PATCH bpf-next v3 4/6] samples: seccomp: use __BYTE_ORDER__ Ilya Leoshkevich @ 2021-10-26 1:08 ` Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 6/6] selftests/bpf: Fix test_core_reloc_mods on big-endian machines Ilya Leoshkevich 2021-10-26 3:40 ` [PATCH bpf-next v3 0/6] core_reloc fixes for s390 Andrii Nakryiko 6 siblings, 0 replies; 9+ messages in thread From: Ilya Leoshkevich @ 2021-10-26 1:08 UTC (permalink / raw) To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich Use the compiler-defined __BYTE_ORDER__ instead of the libc-defined __BYTE_ORDER for consistency. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> --- tools/testing/selftests/seccomp/seccomp_bpf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c index 1d64891e6492..d425688cf59c 100644 --- a/tools/testing/selftests/seccomp/seccomp_bpf.c +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c @@ -276,12 +276,12 @@ int seccomp(unsigned int op, unsigned int flags, void *args) } #endif -#if __BYTE_ORDER == __LITTLE_ENDIAN +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n])) -#elif __BYTE_ORDER == __BIG_ENDIAN +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define syscall_arg(_n) (offsetof(struct seccomp_data, args[_n]) + sizeof(__u32)) #else -#error "wut? Unknown __BYTE_ORDER?!" +#error "wut? Unknown __BYTE_ORDER__?!" #endif #define SIBLING_EXIT_UNKILLED 0xbadbeef -- 2.31.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH bpf-next v3 6/6] selftests/bpf: Fix test_core_reloc_mods on big-endian machines 2021-10-26 1:08 [PATCH bpf-next v3 0/6] core_reloc fixes for s390 Ilya Leoshkevich ` (4 preceding siblings ...) 2021-10-26 1:08 ` [PATCH bpf-next v3 5/6] selftests/seccomp: Use __BYTE_ORDER__ Ilya Leoshkevich @ 2021-10-26 1:08 ` Ilya Leoshkevich 2021-10-26 3:40 ` [PATCH bpf-next v3 0/6] core_reloc fixes for s390 Andrii Nakryiko 6 siblings, 0 replies; 9+ messages in thread From: Ilya Leoshkevich @ 2021-10-26 1:08 UTC (permalink / raw) To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko Cc: bpf, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich This is the same as commit d164dd9a5c08 ("selftests/bpf: Fix test_core_autosize on big-endian machines"), but for test_core_reloc_mods. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> --- tools/testing/selftests/bpf/progs/test_core_reloc_mods.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/testing/selftests/bpf/progs/test_core_reloc_mods.c b/tools/testing/selftests/bpf/progs/test_core_reloc_mods.c index 8b533db4a7a5..b2ded497572a 100644 --- a/tools/testing/selftests/bpf/progs/test_core_reloc_mods.c +++ b/tools/testing/selftests/bpf/progs/test_core_reloc_mods.c @@ -42,7 +42,16 @@ struct core_reloc_mods { core_reloc_mods_substruct_t h; }; +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define CORE_READ(dst, src) bpf_core_read(dst, sizeof(*(dst)), src) +#else +#define CORE_READ(dst, src) ({ \ + int __sz = sizeof(*(dst)) < sizeof(*(src)) ? sizeof(*(dst)) : \ + sizeof(*(src)); \ + bpf_core_read((char *)(dst) + sizeof(*(dst)) - __sz, __sz, \ + (const char *)(src) + sizeof(*(src)) - __sz); \ +}) +#endif SEC("raw_tracepoint/sys_enter") int test_core_mods(void *ctx) -- 2.31.1 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH bpf-next v3 0/6] core_reloc fixes for s390 2021-10-26 1:08 [PATCH bpf-next v3 0/6] core_reloc fixes for s390 Ilya Leoshkevich ` (5 preceding siblings ...) 2021-10-26 1:08 ` [PATCH bpf-next v3 6/6] selftests/bpf: Fix test_core_reloc_mods on big-endian machines Ilya Leoshkevich @ 2021-10-26 3:40 ` Andrii Nakryiko 6 siblings, 0 replies; 9+ messages in thread From: Andrii Nakryiko @ 2021-10-26 3:40 UTC (permalink / raw) To: Ilya Leoshkevich Cc: Alexei Starovoitov, Daniel Borkmann, bpf, Heiko Carstens, Vasily Gorbik On Mon, Oct 25, 2021 at 6:08 PM Ilya Leoshkevich <iii@linux.ibm.com> wrote: > > v2: https://lore.kernel.org/bpf/20211025131214.731972-1-iii@linux.ibm.com/ > v2 -> v3: Split the fix from the cleanup (Daniel). > > v1: https://lore.kernel.org/bpf/20211021234653.643302-1-iii@linux.ibm.com/ > v1 -> v2: Drop bpf_core_calc_field_relo() restructuring, split the > __BYTE_ORDER__ change (Andrii). > > Hi, > > this series fixes test failures in core_reloc on s390. > > Patch 1 fixes an endianness bug with __BYTE_ORDER vs __BYTE_ORDER__. > Patches 2-5 make the rest of the code consistent in that respect. > Patch 6 fixes an endianness issue in test_core_reloc_mods. > Applied to bpf-next, thanks. > Best regards, > Ilya > > Ilya Leoshkevich (6): > libbpf: Fix endianness detection in BPF_CORE_READ_BITFIELD_PROBED() > libbpf: Use __BYTE_ORDER__ > selftests/bpf: Use __BYTE_ORDER__ > samples: seccomp: use __BYTE_ORDER__ > selftests/seccomp: Use __BYTE_ORDER__ > selftests/bpf: Fix test_core_reloc_mods on big-endian machines > > samples/seccomp/bpf-helper.h | 8 ++++---- > tools/lib/bpf/bpf_core_read.h | 2 +- > tools/lib/bpf/btf.c | 4 ++-- > tools/lib/bpf/btf_dump.c | 8 ++++---- > tools/lib/bpf/libbpf.c | 4 ++-- > tools/lib/bpf/linker.c | 12 ++++++------ > tools/lib/bpf/relo_core.c | 2 +- > .../testing/selftests/bpf/prog_tests/btf_endian.c | 6 +++--- > .../selftests/bpf/progs/test_core_reloc_mods.c | 9 +++++++++ > tools/testing/selftests/bpf/test_sysctl.c | 4 ++-- > tools/testing/selftests/bpf/verifier/ctx_skb.c | 14 +++++++------- > tools/testing/selftests/bpf/verifier/lwt.c | 2 +- > .../bpf/verifier/perf_event_sample_period.c | 6 +++--- > tools/testing/selftests/seccomp/seccomp_bpf.c | 6 +++--- > 14 files changed, 48 insertions(+), 39 deletions(-) > > -- > 2.31.1 > ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-10-27 19:05 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-10-26 1:08 [PATCH bpf-next v3 0/6] core_reloc fixes for s390 Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 1/6] libbpf: Fix endianness detection in BPF_CORE_READ_BITFIELD_PROBED() Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 2/6] libbpf: Use __BYTE_ORDER__ Ilya Leoshkevich 2021-10-27 19:05 ` Arnaldo Carvalho de Melo 2021-10-26 1:08 ` [PATCH bpf-next v3 3/6] selftests/bpf: " Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 4/6] samples: seccomp: use __BYTE_ORDER__ Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 5/6] selftests/seccomp: Use __BYTE_ORDER__ Ilya Leoshkevich 2021-10-26 1:08 ` [PATCH bpf-next v3 6/6] selftests/bpf: Fix test_core_reloc_mods on big-endian machines Ilya Leoshkevich 2021-10-26 3:40 ` [PATCH bpf-next v3 0/6] core_reloc fixes for s390 Andrii Nakryiko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).