On Thu, Aug 29, 2024 at 06:40:59PM -0700, Eduard Zingerman wrote: > On Thu, 2024-08-29 at 18:27 -0700, Tony Ambardar wrote: > > > > Thanks for looking at this. I ran into the CI failure while using s390x > > to test a series adding libbpf bi-endian support. Since I'm deep into > > endianness issues right now, I thought to try the fix you suggested just > > to make some progress but noticed the CI failure has disappeared.[0] > > Hi Tony, > > There is no fix yet, sorry :) > I think that something like below should do the trick: > > --- a/tools/lib/bpf/btf.c > +++ b/tools/lib/bpf/btf.c > @@ -5394,6 +5394,7 @@ int btf__distill_base(const struct btf *src_btf, struct btf **new_base_btf, > new_base = btf__new_empty(); > if (!new_base) > return libbpf_err(-ENOMEM); > + btf__set_endianness(new_base, btf__endianness(src_btf)); > dist.id_map = calloc(n, sizeof(*dist.id_map)); > if (!dist.id_map) { > err = -ENOMEM; > > as far as I understand btf__raw_data() should do all conversions after this. > But I have not tested it yet and would be AFK for a few hours. > Hi Eduard, Yes, btf__raw_data() will work as expected. I updated my local pahole and managed to reproduce the problem after cross-compiling to s390x. Looking at lib/bpf/btf.c, I see one more spot that needs to preserve source endianness compared to patch above, and local testing under QEMU now works for me: root@(none):/usr/libexec/kselftests-bpf# insmod bpf_testmod.ko bpf_testmod: loading out-of-tree module taints kernel. bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel root@(none):/usr/libexec/kselftests-bpf# ./test_progs -a map_ptr #166 map_ptr:OK Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED and: $ llvm-readelf -x .BTF bpf_testmod.ko | head -5 Hex dump of section '.BTF': 0x00000000 eb9f0100 00000018 00000000 00001a30 ...............0 0x00000010 00001a30 00001180 00000000 0a000000 ...0............ 0x00000020 00000022 00000000 03000000 00000000 ..."............ 0x00000030 00000028 00000006 0000002b 00000000 ...(.......+.... $ llvm-readelf -x .BTF.base bpf_testmod.ko | head -5 Hex dump of section '.BTF.base': 0x00000000 eb9f0100 00000018 00000000 000001fc ................ 0x00000010 000001fc 000001ea 00000001 01000000 ................ 0x00000020 00000008 00000040 00000013 01000000 .......@........ 0x00000030 00000001 00000008 00000018 01000000 ................ Please try with the patch below, or I can just send a proper one to the list with some added "Co-developed-by:" if easier? --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -996,6 +996,7 @@ static struct btf *btf_new_empty(struct btf *base_btf) btf->base_btf = base_btf; btf->start_id = btf__type_cnt(base_btf); btf->start_str_off = base_btf->hdr->str_len; + btf->swapped_endian = base_btf->swapped_endian; } /* +1 for empty string at offset 0 */ @@ -5554,6 +5555,7 @@ int btf__distill_base(const struct btf *src_btf, struct btf **new_base_btf, new_base = btf__new_empty(); if (!new_base) return libbpf_err(-ENOMEM); + btf__set_endianness(new_base, btf__endianness(src_btf)); dist.id_map = calloc(n, sizeof(*dist.id_map)); if (!dist.id_map) { err = -ENOMEM; > > Did something get fixed already? I can't seem to find the change. > > pahole version w/o support for distilled base was pinned on CI: > https://github.com/kernel-patches/vmtest/pull/285/commits/d3eff26fc978ca8fb3bce3f93421f7425aef0f55 > Ah, got it! That makes more sense now. Thanks for the extra details. Take care, Tony > > Thanks, > Eduard