All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hengqi Chen <hengqi.chen@gmail.com>
To: Namhyung Kim <namhyung@kernel.org>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Yonghong Song <yhs@fb.com>,
	bpf@vger.kernel.org, Song Liu <song@kernel.org>,
	Jiri Olsa <jolsa@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Hao Luo <haoluo@google.com>, Ian Rogers <irogers@google.com>
Subject: Re: [HELP] failed to resolve CO-RE relocation
Date: Thu, 27 Apr 2023 12:19:58 +0800	[thread overview]
Message-ID: <c2a5cb6d-8779-4197-d491-d2249bb49635@gmail.com> (raw)
In-Reply-To: <CAM9d7ci3xAcnqdkpb-J4rv7yfiB2Trb-e2h7gfj6Wu5N_V7a-Q@mail.gmail.com>

Hi, Namhyung

On 2023/4/27 10:21, Namhyung Kim wrote:
> Hello Andrii,
> 
> On Wed, Apr 26, 2023 at 6:19 PM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
>>
>> On Wed, Apr 26, 2023 at 5:14 PM Namhyung Kim <namhyung@kernel.org> wrote:
>>>
>>> Hello,
>>>
>>> I'm having a problem of loading perf lock contention BPF program [1]
>>> on old kernels.  It has collect_lock_syms() to get the address of each
>>> CPU's run-queue lock.  The kernel 5.14 changed the name of the field
>>> so there's bpf_core_field_exists to check the name like below.
>>>
>>>         if (bpf_core_field_exists(rq_new->__lock))
>>>                 lock_addr = (__u64)&rq_new->__lock;
>>>         else
>>>                 lock_addr = (__u64)&rq_old->lock;
>>
>> I suspect compiler rewrites it to something like
>>
>>    lock_addr = (__u64)&rq_old->lock;
>>    if (bpf_core_field_exists(rq_new->__lock))
>>         lock_addr = (__u64)&rq_new->__lock;
>>
>> so rq_old relocation always happens and ends up being not guarded
>> properly. You can try adding barrier_var(rq_new) and
>> barrier_var(rq_old) around if and inside branches, that should
>> pessimize compiler
>>
>> alternatively if you do
>>
>> if (bpf_core_field_exists(rq_new->__lock))
>>     lock_addr = (__u64)&rq_new->__lock;
>> else if (bpf_core_field_exists(rq_old->lock))
>>     lock_addr = (__u64)&rq_old->lock;
>> else
>>     lock_addr = 0; /* or signal error somehow */
>>
>> It might work as well.
> 
> Thanks a lot for your comment!
> 
> I've tried the below code but no luck. :(
> 
>         barrier_var(rq_old);
>         barrier_var(rq_new);
> 
>         if (bpf_core_field_exists(rq_old->lock)) {
>             barrier_var(rq_old);
>             lock_addr = (__u64)&rq_old->lock;

Have you tried `BPF_CORE_READ(rq_old, lock)` ?

>         } else if (bpf_core_field_exists(rq_new->__lock)) {
>             barrier_var(rq_new);
>             lock_addr = (__u64)&rq_new->__lock;
>         } else
>             lock_addr = 0;
> 
> 
> ; int BPF_PROG(collect_lock_syms)
> 0: (b7) r8 = 0                        ; R8_w=0
> 1: (b7) r7 = 1                        ; R7_w=1
> 2: <invalid CO-RE relocation>
> failed to resolve CO-RE relocation <byte_off> [381] struct
> rq___old.lock (0:0 @ offset 0)
> processed 3 insns (limit 1000000) max_states_per_insn 0 total_states 0
> peak_states 0 mark_read
> 
> Thanks,
> Namhyung

Cheers,
Hengqi

  reply	other threads:[~2023-04-27  4:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27  0:14 [HELP] failed to resolve CO-RE relocation Namhyung Kim
2023-04-27  1:19 ` Andrii Nakryiko
2023-04-27  2:21   ` Namhyung Kim
2023-04-27  4:19     ` Hengqi Chen [this message]
2023-04-27  4:27       ` Namhyung Kim
2023-04-27  4:26     ` Andrii Nakryiko
2023-04-27  4:53       ` Namhyung Kim
2023-04-27 22:15         ` Andrii Nakryiko
2023-04-27 23:27           ` Namhyung Kim
2023-04-27 23:38             ` Andrii Nakryiko

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=c2a5cb6d-8779-4197-d491-d2249bb49635@gmail.com \
    --to=hengqi.chen@gmail.com \
    --cc=acme@kernel.org \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=song@kernel.org \
    --cc=yhs@fb.com \
    /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.