Re: [PATCH bpf] libbpf: fix CO-RE relocs against .text section

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 6/23/20 5:40 PM, Alexei Starovoitov wrote:
On Sat, Jun 20, 2020 at 12:06 AM Yonghong Song <yhs@xxxxxx> wrote:



On 6/19/20 4:04 PM, Andrii Nakryiko wrote:
bpf_object__find_program_by_title(), used by CO-RE relocation code, doesn't
return .text "BPF program", if it is a function storage for sub-programs.
Because of that, any CO-RE relocation in helper non-inlined functions will
fail. Fix this by searching for .text-corresponding BPF program manually.

Adjust one of bpf_iter selftest to exhibit this pattern.

Reported-by: Yonghong Song <yhs@xxxxxx>
Fixes: ddc7c3042614 ("libbpf: implement BPF CO-RE offset relocation algorithm")
Signed-off-by: Andrii Nakryiko <andriin@xxxxxx>

Acked-by: Yonghong Song <yhs@xxxxxx>

But the fix here only fixed the issue for interpreter mode.
For jit only mode, we still have issues. The following patch can fix
the jit mode issue,

=============

  From 4d66814513ec45b86a30a1231b8a000d4bfc6f1a Mon Sep 17 00:00:00 2001
From: Yonghong Song <yhs@xxxxxx>
Date: Fri, 19 Jun 2020 23:26:13 -0700
Subject: [PATCH bpf] bpf: set the number of exception entries properly for
   subprograms

Currently, if a bpf program has more than one subprograms, each
program will be jitted separately. For tracing problem, the
prog->aux->num_exentries is not setup properly. For example,
with bpf_iter_netlink.c modified to force one function not inlined,
and with proper libbpf fix, with CONFIG_BPF_JIT_ALWAYS_ON,
we will have error like below:
    $ ./test_progs -n 3/3
    ...
    libbpf: failed to load program 'iter/netlink'
    libbpf: failed to load object 'bpf_iter_netlink'
    libbpf: failed to load BPF skeleton 'bpf_iter_netlink': -4007
    test_netlink:FAIL:bpf_iter_netlink__open_and_load skeleton
open_and_load failed
    #3/3 netlink:FAIL
The dmesg shows the following errors:
    ex gen bug
which is triggered by the following code in arch/x86/net/bpf_jit_comp.c:
    if (excnt >= bpf_prog->aux->num_exentries) {
      pr_err("ex gen bug\n");
      return -EFAULT;
    }

If the program has more than one subprograms, num_exentries is actually
0 since it is not setup.

This patch fixed the issue by setuping proper num_exentries for
each subprogram before calling jit function.

Signed-off-by: Yonghong Song <yhs@xxxxxx>

Thanks for fixing. Applied both to bpf tree.
Yonghong, next time please submit the patch properly.
It was very awkward to copy-paste it manually from the thread.
I've edited the commit log a bit.

Thanks. I posted original commit as I am not sure how to proceed as
this and Andrii's patch belongs to the same patch set to fix bpf_iter_netlink problem. I guess next time I will go ahead with
patch submit with proper description in the patch, which
sounds better for review and to get notice from other people.



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux