All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Thiébaud Weksteen" <tweek@google.com>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Shuah Khan" <shuah@kernel.org>,
	"Siddharth Nayyar" <sidnayyar@google.com>
Cc: <bpf@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>
Subject: Re: [PATCH bpf-next 1/2] libbpf: Skip reading /proc/kallsyms for typeless ksyms in gen_loader
Date: Wed, 02 Dec 2026 04:58:47 +0000	[thread overview]
Message-ID: <DN9ZC6OZHHL1.1SQ8MF28DZA6V@gmail.com> (raw)
In-Reply-To: <20261202003234.2630157-2-tweek@google.com>

On Tue, Dec 01, 2026 at 04:32 PM Thiébaud Weksteen <tweek@google.com> wrote:
> Also fix emit_relo_ksym_typeless() to only ignore -ENOENT from
> bpf_kallsyms_lookup_name() when relo->is_weak is set. Previously,
> -ENOENT was ignored unconditionally, which silently resolved missing
> strong typeless ksyms to 0 on the target kernel (previously masked on
> single-host builds by the host /proc/kallsyms check). Enforcing -ENOENT
> for non-weak symbols ensures missing strong typeless ksyms fail at load
> time on the target kernel now that host /proc/kallsyms is no longer
> consulted.

Yep. That's a real issue. Thank you for working on it.

> Fixes: c24941cd3766 ("libbpf: Add typeless ksym support to gen_loader")

The tag invites a backport. Pls drop it.

> -static int bpf_object__read_kallsyms_file(struct bpf_object *obj)
> +static int bpf_object__resolve_ksyms_kallsyms(struct bpf_object *obj)
>  {
> -	return libbpf_kallsyms_parse(kallsyms_cb, obj);
> +	struct extern_desc *ext;
> +	int i;
> +
> +	if (!obj->gen_loader)
> +		return libbpf_kallsyms_parse(kallsyms_cb, obj);
> +
> +	for (i = 0; i < obj->nr_extern; i++) {
> +		ext = &obj->externs[i];
> +		if (ext->type != EXT_KSYM || ext->ksym.type_id)
> +			continue;
> +
> +		ext->is_set = true;
> +		ext->ksym.addr = 0;
> +	}
> +	return 0;
>  }

No need for another loop and the rename.
bpf_object__resolve_externs() walks all ksyms already.
bpf_object__collect_externs() zeroes ext, so is_set is enough.
Set it once for typed and typeless ksyms.

In place of patch 1... pls double check my logic.

diff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c
index 749a86c..3376770 100644
--- a/tools/lib/bpf/gen_loader.c
+++ b/tools/lib/bpf/gen_loader.c
@@ -817,8 +817,10 @@ static void emit_relo_ksym_typeless(struct bpf_gen *gen,
 	/* skip typeless ksym_desc in fd closing loop in cleanup_relos */
 	kdesc->typeless = true;
 	emit_bpf_kallsyms_lookup_name(gen, relo);
-	emit(gen, BPF_JMP_IMM(BPF_JNE, BPF_REG_7, -ENOENT, 1));
-	emit(gen, BPF_MOV64_IMM(BPF_REG_7, 0));
+	if (relo->is_weak) {
+		emit(gen, BPF_JMP_IMM(BPF_JNE, BPF_REG_7, -ENOENT, 1));
+		emit(gen, BPF_MOV64_IMM(BPF_REG_7, 0));
+	}
 	emit_check_err(gen);
 	/* store lower half of addr into insn[insn_idx].imm */
 	emit(gen, BPF_STX_MEM(BPF_W, BPF_REG_8, BPF_REG_9, offsetof(struct bpf_insn, imm)));
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e66e848..69f11d7 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9663,12 +9663,6 @@ static int bpf_object__resolve_ksyms_btf_id(struct bpf_object *obj)
 		if (ext->type != EXT_KSYM || !ext->ksym.type_id)
 			continue;
 
-		if (obj->gen_loader) {
-			ext->is_set = true;
-			ext->ksym.kernel_btf_obj_fd = 0;
-			ext->ksym.kernel_btf_id = 0;
-			continue;
-		}
 		t = btf__type_by_id(obj->btf, ext->btf_id);
 		if (btf_is_var(t))
 			err = bpf_object__resolve_ksym_var_btf_id(obj, ext);
@@ -9699,7 +9693,10 @@ static int bpf_object__resolve_externs(struct bpf_object *obj,
 		ext = &obj->externs[i];
 
 		if (ext->type == EXT_KSYM) {
-			if (ext->ksym.type_id)
+			if (obj->gen_loader)
+				/* the loader prog resolves it */
+				ext->is_set = true;
+			else if (ext->ksym.type_id)
 				need_vmlinux_btf = true;
 			else
 				need_kallsyms = true;

pw-bot: cr

  reply	other threads:[~2026-12-02  4:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  0:32 [PATCH bpf-next 0/2] libbpf: Skip host /proc/kallsyms for typeless ksyms in gen_loader Thiébaud Weksteen
2026-12-02  0:32 ` [PATCH bpf-next 1/2] libbpf: Skip reading " Thiébaud Weksteen
2026-12-02  4:58   ` Alexei Starovoitov [this message]
2026-12-02  0:32 ` [PATCH bpf-next 2/2] selftests/bpf: Test missing strong typeless ksym in light skeleton Thiébaud Weksteen

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=DN9ZC6OZHHL1.1SQ8MF28DZA6V@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=shuah@kernel.org \
    --cc=sidnayyar@google.com \
    --cc=song@kernel.org \
    --cc=tweek@google.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.