BPF List
 help / color / mirror / Atom feed
From: Tony Ambardar <tony.ambardar@gmail.com>
To: bpf@vger.kernel.org
Cc: Tony Ambardar <tony.ambardar@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>
Subject: [PATCH bpf-next v1] libbpf: ensure new BTF objects inherit input endianness
Date: Fri, 30 Aug 2024 02:51:50 -0700	[thread overview]
Message-ID: <20240830095150.278881-1-tony.ambardar@gmail.com> (raw)
In-Reply-To: <5be4f797c3d5092b34d243361ebd0609f3301452.camel@gmail.com>

The pahole master branch recently added support for "distilled BTF" based
on libbpf v1.5, but may add .BTF and .BTF.base sections with the wrong byte
order (e.g. on s390x BPF CI), which then lead to kernel Oops when loaded.

Fix by updating libbpf's btf__distill_base() and btf_new_empty() to retain
the byte order of any source BTF objects when creating new ones.

Reported-by: Song Liu <song@kernel.org>
Reported-by: Eduard Zingerman <eddyz87@gmail.com>
Suggested-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/6358db36c5f68b07873a0a5be2d062b1af5ea5f8.camel@gmail.com/
Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
---
 tools/lib/bpf/btf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 064cfe126c09..7726b7c6d40a 100644
--- 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,10 @@ 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);
+	err = btf__set_endianness(new_base, btf__endianness(src_btf));
+	if (err < 0)
+		goto done;
+
 	dist.id_map = calloc(n, sizeof(*dist.id_map));
 	if (!dist.id_map) {
 		err = -ENOMEM;
-- 
2.34.1


  reply	other threads:[~2024-08-30  9:52 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-30  0:05 FYI: CI regression on big-endian arch (s390) after recent pahole changes Eduard Zingerman
2024-08-30  1:27 ` Tony Ambardar
2024-08-30  1:40   ` Eduard Zingerman
2024-08-30  6:57     ` Tony Ambardar
2024-08-30  9:13       ` Eduard Zingerman
2024-08-30  9:51         ` Tony Ambardar [this message]
2024-08-30 11:15           ` [PATCH bpf-next v1] libbpf: ensure new BTF objects inherit input endianness Eduard Zingerman
2024-08-30 11:25             ` Alan Maguire
2024-08-30 15:58               ` Andrii Nakryiko
2024-08-30 16:00           ` Andrii Nakryiko
2024-08-30 17:51             ` Andrii Nakryiko
2024-08-30  2:49 ` FYI: CI regression on big-endian arch (s390) after recent pahole changes Song Liu
2024-08-30  9:21   ` Eduard Zingerman
2024-08-30 10:05     ` Alan Maguire
2024-08-30 10:07       ` Eduard Zingerman
2024-08-30 13:19       ` Arnaldo Carvalho de Melo
2024-08-30 15:56         ` Andrii Nakryiko
2024-08-30 20:49           ` Arnaldo Carvalho de Melo
2024-08-30 22:20             ` Andrii Nakryiko
2024-08-30 22:34               ` Alan Maguire
2024-08-30 23:30                 ` Andrii Nakryiko
2024-09-02 13:06                   ` Alan Maguire
2024-09-02 14:08                 ` Arnaldo Carvalho de Melo
2024-09-02 14:59                   ` Alan Maguire
2024-09-02 18:44                     ` Arnaldo Carvalho de Melo
2024-08-30 22:22             ` Alan Maguire

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240830095150.278881-1-tony.ambardar@gmail.com \
    --to=tony.ambardar@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox