mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: wusamuel@google.com,corbet@lwn.net,skhan@linuxfoundation.org,rdunlap@infradead.org,ast@kernel.org,daniel@iogearbox.net,john.fastabend@gmail.com,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,mcgrof@kernel.org,petr.pavlu@suse.com,da.gomez@kernel.org,samitolvanen@google.com,atomlin@atomlin.com,viro@zeniv.linux.org.uk,brauner@kernel.org,jack@suse.cz,nathan@kernel.org,ndesaulniers@google.com,morbo@google.com,justinstitt@google.com
Cc: david.laight.linux@gmail.com,akpm@linux-foundation.org,pmladek@suse.com,wusamuel@google.com,kernel-team@android.com,linux-kernel@vger.kernel.org,linux-fsdevel@vger.kernel.org,linux-doc@vger.kernel.org,bpf@vger.kernel.org,linux-modules@vger.kernel.org,linux-kselftest@vger.kernel.org,llvm@lists.linux.dev,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v4 09/10] libbpf: Resolve typeless ksyms via KALLSYMS_QUERY_BY_NAME ioctl
Date: Wed,  2 Dec 2026 00:59:13 +0000 (UTC)	[thread overview]
Message-ID: <bf9eae04e0794041d3636b815e35f95a712aa39360d46a30baa1543e7aa13850@mail.kernel.org> (raw)
In-Reply-To: <20261202001344.2721429-21-wusamuel@google.com>

[-- Attachment #1: Type: text/plain, Size: 4206 bytes --]

> libbpf: Resolve typeless ksyms via KALLSYMS_QUERY_BY_NAME ioctl

TL;DR: Dropping the old 'd'-only restriction on ".llvm." matches may make some
typeless ksym externs fail with -ENOTUNIQ or bind new addresses on ThinLTO
kernels. Standalone libbpf builds may also lack the linux/fs.h definitions.

> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -31,6 +31,7 @@
>  #include <linux/bpf.h>
>  #include <linux/btf.h>
>  #include <linux/filter.h>
> +#include <linux/fs.h>
>  #include <linux/limits.h>

This isn't a bug, but libbpf.c now depends on KALLSYMS_QUERY_BY_NAME,
KALLSYMS_QUERY_NAME_PREFIX, struct kallsyms_query_by_name and struct
kallsyms_query_sym coming from <linux/fs.h>.

The in-tree build is fine since tools/include/uapi is used.  The
stand-alone build from the mirror would pick up the system <linux/fs.h>,
and with a header older than this series libbpf.c would fail to compile.

libbpf.c usually guards constants from headers it does not carry with
fallbacks, for example #ifndef BPF_FS_MAGIC and #ifndef MFD_CLOEXEC.
Should local definitions be added here, or should the commit message
state that the mirror must start shipping linux/fs.h (and the
linux/mount.h and linux/fscrypt.h it includes)?

[ ... ]

> +static int query_ksym_by_name(int fd, struct extern_desc *ext, bool lto_prefix)
> +{
[ ... ]
> +	if (lto_prefix) {
> +		n = snprintf(prefix_buf, sizeof(prefix_buf), "%s.llvm.", ext->name);
> +		if (n < 0 || n >= sizeof(prefix_buf))
> +			return 0;
> +		q.query_name = ptr_to_u64(prefix_buf);
> +	}
> +
> +	while (!ioctl(fd, KALLSYMS_QUERY_BY_NAME, &q)) {
> +		if (!ext->is_set) {
> +			ext->is_set = true;
> +			ext->ksym.addr = sym.sym_addr;
> +			pr_debug("extern (ksym) '%s': set to 0x%llx\n", ext->name, ext->ksym.addr);
> +		} else if (sym.sym_addr != ext->ksym.addr) {
> +			pr_warn("extern (ksym) '%s': resolution is ambiguous: 0x%llx or 0x%llx\n",
> +				ext->name, ext->ksym.addr, (unsigned long long)sym.sym_addr);
> +			return -ENOTUNIQ;
> +		}
> +		q.pos++;
> +	}

Was dropping the 'd' restriction on the "<name>.llvm." match intended?

The text parser this replaces only did that for 'd' (static data)
symbols:

	res = strstr(sym_name, ".llvm.");
	if (sym_type == 'd' && res)
		ext = find_extern_by_name_with_len(obj, sym_name, res - sym_name);
	else
		ext = find_extern_by_name(obj, sym_name);

That restriction came from c56e59776f46 ("libbpf: Handle
<orig_name>.llvm.<hash> symbol properly").  KALLSYMS_QUERY_BY_NAME does
not filter by type and struct kallsyms_query_sym does not return the
type, so the old rule cannot be kept.  The commit message ("exact names,
plus "<name>.llvm." prefix matches") does not mention this.

On Clang ThinLTO kernels, promoted static functions, bss and rodata
appear as 't'/'b'/'r' foo.llvm.<hash>, which gives two visible changes.

First, suppose there is an exact global symbol foo (type 'T') and an
unrelated static foo.llvm.<hash> of type 't', 'b' or 'r' at another
address.  The old code resolved extern foo uniquely.  Now the exact
lookup sets ext->ksym.addr, the prefix lookup finds a different address
and returns -ENOTUNIQ, and bpf_object__resolve_typeless_ksyms() skips
the text fallback for -ENOTUNIQ.  Can this make
bpf_object__resolve_externs() return -EINVAL for an object that loaded
before?

Second, a weak typeless extern that used to stay 0, because only a
non-'d' foo.llvm.<hash> existed, now binds to that symbol's address.
Does this change `if (&foo)` style feature checks?

Also, the ambiguity message prints ext->name rather than the symbol that
matched, so the user sees "'foo': resolution is ambiguous" without
knowing which foo.llvm.<hash> caused it.  The old message printed
sym_name.  Should the matched name be reported?

If the 'd' restriction was dropped intentionally, should the changelog
say so and explain why ambiguity against non-data .llvm. symbols should
fail the load?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/46779970959

  reply	other threads:[~2026-12-02  0:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  0:13 [PATCH bpf-next v4 00/10] kallsyms: Add KALLSYMS_QUERY_BY_NAME and KALLSYMS_QUERY_BY_ADDR ioctls Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 01/10] Documentation: ioctl-number: Add PROCFS_IOCTL_MAGIC range 0x10-0x11 Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 02/10] module: Add module_kallsyms_query_name() Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 03/10] bpf: Add bpf_kallsyms_query_name() Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 04/10] kallsyms: Add KALLSYMS_QUERY_BY_NAME ioctl to /proc/kallsyms Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 05/10] kallsyms: Add KALLSYMS_QUERY_BY_ADDR " Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 06/10] docs/procfs: Document KALLSYMS_QUERY_* ioctls on /proc/kallsyms Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 07/10] tools: Copy KALLSYMS_QUERY_* definitions to linux/fs.h Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 08/10] selftests/proc: Add KALLSYMS_QUERY_* ioctl tests Samuel Wu
2026-12-02  0:13 ` [PATCH bpf-next v4 09/10] libbpf: Resolve typeless ksyms via KALLSYMS_QUERY_BY_NAME ioctl Samuel Wu
2026-12-02  0:59   ` bot+bpf-ci [this message]
2026-12-02  0:13 ` [PATCH bpf-next v4 10/10] selftests/bpf: Test typeless module ksym resolution Samuel Wu

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=bf9eae04e0794041d3636b815e35f95a712aa39360d46a30baa1543e7aa13850@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=atomlin@atomlin.com \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=corbet@lwn.net \
    --cc=da.gomez@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=david.laight.linux@gmail.com \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jack@suse.cz \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=memxor@gmail.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=petr.pavlu@suse.com \
    --cc=pmladek@suse.com \
    --cc=rdunlap@infradead.org \
    --cc=samitolvanen@google.com \
    --cc=skhan@linuxfoundation.org \
    --cc=song@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wusamuel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®