All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Protopopov <a.s.protopopov@gmail.com>
To: Eduard Zingerman <eddyz87@gmail.com>
Cc: Yonghong Song <yonghong.song@linux.dev>,
	bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Anton Protopopov <aspsk@isovalent.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Quentin Monnet <qmo@kernel.org>
Subject: Re: [PATCH v10 bpf-next 08/11] libbpf: support llvm-generated indirect jumps
Date: Wed, 5 Nov 2025 08:12:52 +0000	[thread overview]
Message-ID: <aQsHBJbvOro9QKLh@mail.gmail.com> (raw)
In-Reply-To: <4c4ecade1a8297dada4c398a10aaa965ddf08399.camel@gmail.com>

On 25/11/04 10:31AM, Eduard Zingerman wrote:
> On Mon, 2025-11-03 at 21:26 -0800, Yonghong Song wrote:
> 
> [...]
> 
> > > > +		if (subprog_idx >= 0) {
> > > > +			insn_off -= prog->subprogs[subprog_idx].sec_insn_off;
> > > > +			insn_off += prog->subprogs[subprog_idx].sub_insn_off;
> > > I'd like to reiterate my point about relocation related warnings [1]:
> > > 
> > >    > I'm seeing the following messages when rebuilding bpf_gotox using
> > >    > llvm main, where Yonghong added __BPF_FEATURE_GOTOX.
> > >    >
> > >    >     CLNG-BPF [test_progs-cpuv4] bpf_gotox.bpf.o
> > >    >     GEN-SKEL [test_progs-cpuv4] bpf_gotox.skel.h
> > >    >   libbpf: elf: skipping relo section(13) .rel.jumptables for section(6) .jumptables
> > >    >   libbpf: elf: skipping relo section(13) .rel.jumptables for section(6) .jumptables
> > > 
> > > In the context of Yonghong's reply [2].
> > > 
> > > I inserted some debug prints and confirm that these relocations are
> > > generated for basic block labels, e.g.:
> > > 
> > >    .S file corresponding to shortened bpf_gotox.c:
> > >        ...
> > >               gotox r1
> > >       .Ltmp25:
> > >       .Ltmp26:
> > >       .Ltmp27:                                # Block address taken
> > >       LBB0_5:                                 # %l1
> > >               #DEBUG_LABEL: one_jump_two_maps:l1
> > >               .loc    0 36 10 is_stmt 1               # progs/bpf_gotox.c:36:10
> > >       .Ltmp28:
> > >               w1 = *(u32 *)(r10 - 4)
> > >        ...
> > >               .section        .jumptables,"",@progbits
> > >      BPF.JT.0.0:
> > >              .quad   LBB0_5
> > > 
> > >    objdump --symbols, corresponding to same shortened bpf_gotox.c:
> > > 
> > >      Symbol table '.symtab' contains 18 entries:
> > >         Num:    Value          Size Type    Bind   Vis       Ndx Name
> > >           ...
> > >           2: 0000000000000000     0 SECTION LOCAL  DEFAULT     3 syscall
> > > 
> > >    objdump --relocations, corresponding to same shortened bpf_gotox.c:
> > > 
> > >      Relocation section '.rel.jumptables' at offset 0xde8 contains 4 entries:
> > >           Offset             Info             Type               Symbol's Value  Symbol's Name
> > >       0000000000000000  0000000200000002 R_BPF_64_ABS64         0000000000000000 syscall
> > >       ...
> > > 
> > > Here the first entry corresponds to LBB0_5 symbol, specifically:
> > > 
> > >                           Relocation type (R_BPF_64_ABS64).
> > >                               vvvvvvvv
> > >     0000000000000000  0000000200000002 R_BPF_64_ABS64         0000000000000000 syscall
> > >     ^^^^^^^^^^^^^^^^  ^^^^^^^^                                ^^^^^^^^^^^^^^^^
> > >     Offset at which   Section                                 Given that relocation type is
> > >     to apply the      index                                   R_BPF_64_ABS64, this is the value
> > >     relocation,       for 'syscall'.                          which has to be written at offset.
> > >     first jumptables                                          (See [3]).
> > >     record.
> > > 
> > > Given above, I conclude that:
> > > 
> > > - [to Anton] libbpf has to apply the relocations from .rel.jumptables
> > >    in order to assign correct the sec_insn_off for records in the jump
> > >    table.  Right now we imply that each record in the table corresponds
> > >    to a section where jump table is referenced from, but that is not
> > >    true.
> > > 
> > > - [to Yonghong] LLVM should generate a different relocation kind,
> > >    or a different "Symbol's Value", otherwise applying relocations as
> > >    instructed in [3] will lead to zeroes in the jump table:
> > >    
> > >    > In another case, R_BPF_64_ABS64 relocation type is used for normal
> > >    > 64-bit data. The actual to-be-relocated data is stored at
> > >    > r_offset and the read/write data bitsize is 64 (8 bytes). The
> > >    > relocation can be resolved with the symbol value plus implicit
> > >    > addend.
> > 
> > I think the following llvm patch
> >     https://github.com/llvm/llvm-project/pull/166301
> > should avoid jumptable relocation. The idea is originated from one of
> > Eduard's idea which put the label difference in the jump table entry.
> > Please give a try. I think it should work.
> 
> I tried Yonghong's llvm change, and it solves the issue.
> Relocations are no longer generated for .jumptables section.
> So, nothing to change on the libbpf side.

Thanks Eduard and Yonghong! It does work, I've removed the check from libbpf.

One additional change I had to do is to fix verifier_gotox not
to generate .jumptables.rel:

        SEC("socket")                                                   \
        OUTCOME                                                         \
        __naked void jump_table_ ## NAME(void)                          \
        {                                                               \
                asm volatile ("                                         \
                .pushsection .jumptables,\"\",@progbits;                \
        jt0_%=:                                                         \
-               .quad ret0_%=;                                          \
-               .quad ret1_%=;                                          \
+               .quad ret0_%= - socket;                                 \
+               .quad ret1_%= - socket;                                 \
                .size jt0_%=, 16;                                       \
                .global jt0_%=;                                         \
                .popsection;                                            \

(And alike in other subtests, of course.)

> [...]

  reply	other threads:[~2025-11-05  8:06 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-02 20:57 [PATCH v10 bpf-next 00/11] BPF indirect jumps Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 01/11] bpf, x86: add new map type: instructions array Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 02/11] selftests/bpf: add selftests for new insn_array map Anton Protopopov
2025-11-04  2:10   ` Alexei Starovoitov
2025-11-04 13:52     ` Anton Protopopov
2025-11-04 16:49       ` Alexei Starovoitov
2025-11-05  6:35         ` Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 03/11] bpf: support instructions arrays with constants blinding Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 04/11] selftests/bpf: test instructions arrays with blinding Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 05/11] bpf, x86: allow indirect jumps to r8...r15 Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 06/11] bpf, x86: add support for indirect jumps Anton Protopopov
2025-11-02 21:20   ` bot+bpf-ci
2025-11-02 22:00     ` Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 07/11] bpf: disasm: add support for BPF_JMP|BPF_JA|BPF_X Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 08/11] libbpf: support llvm-generated indirect jumps Anton Protopopov
2025-11-02 21:13   ` bot+bpf-ci
2025-11-02 21:36     ` Anton Protopopov
2025-11-02 21:38     ` Anton Protopopov
2025-11-03  0:32       ` Ihor Solodrai
2025-11-03  0:58         ` Chris Mason
2025-11-03  8:29           ` Anton Protopopov
2025-11-03  8:21         ` Anton Protopopov
2025-11-04  1:15   ` Eduard Zingerman
2025-11-04  1:30     ` Eduard Zingerman
2025-11-04  5:26     ` Yonghong Song
2025-11-04 18:31       ` Eduard Zingerman
2025-11-05  8:12         ` Anton Protopopov [this message]
2025-11-02 20:57 ` [PATCH v10 bpf-next 09/11] bpftool: Recognize insn_array map type Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 10/11] selftests/bpf: add new verifier_gotox test Anton Protopopov
2025-11-02 20:57 ` [PATCH v10 bpf-next 11/11] selftests/bpf: add C-level selftests for indirect jumps Anton Protopopov
2025-11-03 20:45   ` Eduard Zingerman
2025-11-05  7:26     ` Anton Protopopov

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=aQsHBJbvOro9QKLh@mail.gmail.com \
    --to=a.s.protopopov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=aspsk@isovalent.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=qmo@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 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.