BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Alan Maguire <alan.maguire@oracle.com>,
	Donglin Peng <dolinux.peng@gmail.com>,
	ast@kernel.org
Cc: daniel@iogearbox.net, song@kernel.org, andrii@kernel.org,
	haoluo@google.com,  yonghong.song@linux.dev, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] libbpf: checking the btf_type kind when fixing variable offsets
Date: Mon, 17 Jun 2024 13:00:48 -0700	[thread overview]
Message-ID: <2404b12b71fb361df262c2838d94f1ee6f35e5c4.camel@gmail.com> (raw)
In-Reply-To: <0c0ef20c-c05e-4db9-bad7-2cbc0d6dfae7@oracle.com>

On Mon, 2024-06-17 at 12:29 +0100, Alan Maguire wrote:

[...]

> The only thing I could come up with is we were usually lucky; when we
> misinterpreted the func as a var and looked its type up, we got
> 
> 		int var_linkage = btf_var(vt)->linkage;
> 
> ...and were lucky it never equalled 1 (BTF_VAR_GLOBAL_ALLOCATED):
> 	
> 		/* no need to patch up static or extern vars */
>                 if (var_linkage != BTF_VAR_GLOBAL_ALLOCATED)
> 			continue;
> 
> In the case of a function, the above btf_var(vt) would really be
> pointing at the struct btf_type immediately after the relevant
> function's struct btf_type (since unlike variables, functions don't have
> metadata following them). So the only way we'd trip this bug would be if
> the struct btf_type following the func was had a name_off value that
> happened to equal 1 (BTF_VAR_GLOBAL_ALLOCATED).
> 
> So maybe the sorting changes to BTF order resulted in us tripping on
> this bug, but regardless the fix seems right to me.

I've added the following debug logging:
 
                        sym = find_sym_by_name(obj, sec->sec_idx, STT_OBJECT, var_name);
                        if (!sym) {
+                               const struct btf_type *nt;
                                pr_warn("failed to find symbol for variable '%s' in section '%s'\n", var_name, sec_name);
+                               nt = btf__type_by_id(obj->btf, vi->type + 1);
+                               pr_warn("  vi->type == %d\n", vi->type);
+                               pr_warn("  next id %d kind '%s', name '%s' off %d\n",
+                                       vi->type + 1,
+                                       btf_kind_str(nt),
+                                       btf__str_by_offset(obj->btf, nt->name_off), nt->name_off);
                                return -ENOENT;
                        }

The output is as follows:

  libbpf: failed to find symbol for variable 'bpf_dynptr_slice' in section '.ksyms'
  libbpf:   vi->type == 17
  libbpf:   next id 18 kind 'struct', name 'bpf_nf_ctx' off 1

This matches your analysis and hits the unlikely situation when
name_off of the next type is 1.

  reply	other threads:[~2024-06-17 20:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-16  0:29 [PATCH] libbpf: checking the btf_type kind when fixing variable offsets Donglin Peng
2024-06-17 11:29 ` Alan Maguire
2024-06-17 20:00   ` Eduard Zingerman [this message]
2024-06-17 20:51   ` Andrii Nakryiko
2024-06-19  5:02   ` Donglin Peng
2024-06-17 18:12 ` Eduard Zingerman
2024-06-19  5:03   ` Donglin Peng

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=2404b12b71fb361df262c2838d94f1ee6f35e5c4.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dolinux.peng@gmail.com \
    --cc=haoluo@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --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