@@ -48,8 +48,6 @@ struct bpf_jit {
4848 int lit64 ; /* Current position in 64-bit literal pool */
4949 int base_ip ; /* Base address for literal pool */
5050 int exit_ip ; /* Address of exit */
51- int r1_thunk_ip ; /* Address of expoline thunk for 'br %r1' */
52- int r14_thunk_ip ; /* Address of expoline thunk for 'br %r14' */
5351 int tail_call_start ; /* Tail call start offset */
5452 int excnt ; /* Number of exception table entries */
5553 int prologue_plt_ret ; /* Return address for prologue hotpatch PLT */
@@ -642,28 +640,17 @@ static void bpf_jit_prologue(struct bpf_jit *jit, struct bpf_prog *fp,
642640}
643641
644642/*
645- * Emit an expoline for a jump that follows
643+ * Jump using a register either directly or via an expoline thunk
646644 */
647- static void emit_expoline (struct bpf_jit * jit )
648- {
649- /* exrl %r0,.+10 */
650- EMIT6_PCREL_RIL (0xc6000000 , jit -> prg + 10 );
651- /* j . */
652- EMIT4_PCREL (0xa7f40000 , 0 );
653- }
654-
655- /*
656- * Emit __s390_indirect_jump_r1 thunk if necessary
657- */
658- static void emit_r1_thunk (struct bpf_jit * jit )
659- {
660- if (nospec_uses_trampoline ()) {
661- jit -> r1_thunk_ip = jit -> prg ;
662- emit_expoline (jit );
663- /* br %r1 */
664- _EMIT2 (0x07f1 );
665- }
666- }
645+ #define EMIT_JUMP_REG (reg ) do { \
646+ if (nospec_uses_trampoline()) \
647+ /* brcl 0xf,__s390_indirect_jump_rN */ \
648+ EMIT6_PCREL_RILC_PTR (0xc0040000 , 0x0f , \
649+ __s390_indirect_jump_r ## reg ); \
650+ else \
651+ /* br %rN */ \
652+ _EMIT2 (0x07f0 | reg ); \
653+ } while (0 )
667654
668655/*
669656 * Call r1 either directly or via __s390_indirect_jump_r1 thunk
@@ -672,7 +659,8 @@ static void call_r1(struct bpf_jit *jit)
672659{
673660 if (nospec_uses_trampoline ())
674661 /* brasl %r14,__s390_indirect_jump_r1 */
675- EMIT6_PCREL_RILB (0xc0050000 , REG_14 , jit -> r1_thunk_ip );
662+ EMIT6_PCREL_RILB_PTR (0xc0050000 , REG_14 ,
663+ __s390_indirect_jump_r1 );
676664 else
677665 /* basr %r14,%r1 */
678666 EMIT2 (0x0d00 , REG_14 , REG_1 );
@@ -688,16 +676,7 @@ static void bpf_jit_epilogue(struct bpf_jit *jit, u32 stack_depth)
688676 EMIT4 (0xb9040000 , REG_2 , BPF_REG_0 );
689677 /* Restore registers */
690678 save_restore_regs (jit , REGS_RESTORE , stack_depth , 0 );
691- if (nospec_uses_trampoline ()) {
692- jit -> r14_thunk_ip = jit -> prg ;
693- /* Generate __s390_indirect_jump_r14 thunk */
694- emit_expoline (jit );
695- }
696- /* br %r14 */
697- _EMIT2 (0x07fe );
698-
699- if (is_first_pass (jit ) || (jit -> seen & SEEN_FUNC ))
700- emit_r1_thunk (jit );
679+ EMIT_JUMP_REG (14 );
701680
702681 jit -> prg = ALIGN (jit -> prg , 8 );
703682 jit -> prologue_plt = jit -> prg ;
@@ -1899,7 +1878,8 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
18991878 /* aghi %r1,tail_call_start */
19001879 EMIT4_IMM (0xa70b0000 , REG_1 , jit -> tail_call_start );
19011880 /* brcl 0xf,__s390_indirect_jump_r1 */
1902- EMIT6_PCREL_RILC (0xc0040000 , 0xf , jit -> r1_thunk_ip );
1881+ EMIT6_PCREL_RILC_PTR (0xc0040000 , 0xf ,
1882+ __s390_indirect_jump_r1 );
19031883 } else {
19041884 /* bc 0xf,tail_call_start(%r1) */
19051885 _EMIT4 (0x47f01000 + jit -> tail_call_start );
@@ -2868,17 +2848,10 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
28682848 0xf000 | tjit -> tccnt_off );
28692849 /* aghi %r15,stack_size */
28702850 EMIT4_IMM (0xa70b0000 , REG_15 , tjit -> stack_size );
2871- /* Emit an expoline for the following indirect jump. */
2872- if (nospec_uses_trampoline ())
2873- emit_expoline (jit );
28742851 if (flags & BPF_TRAMP_F_SKIP_FRAME )
2875- /* br %r14 */
2876- _EMIT2 (0x07fe );
2852+ EMIT_JUMP_REG (14 );
28772853 else
2878- /* br %r1 */
2879- _EMIT2 (0x07f1 );
2880-
2881- emit_r1_thunk (jit );
2854+ EMIT_JUMP_REG (1 );
28822855
28832856 return 0 ;
28842857}
0 commit comments