@@ -48,8 +48,6 @@ struct bpf_jit {
48
48
int lit64 ; /* Current position in 64-bit literal pool */
49
49
int base_ip ; /* Base address for literal pool */
50
50
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' */
53
51
int tail_call_start ; /* Tail call start offset */
54
52
int excnt ; /* Number of exception table entries */
55
53
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,
642
640
}
643
641
644
642
/*
645
- * Emit an expoline for a jump that follows
643
+ * Jump using a register either directly or via an expoline thunk
646
644
*/
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 )
667
654
668
655
/*
669
656
* Call r1 either directly or via __s390_indirect_jump_r1 thunk
@@ -672,7 +659,8 @@ static void call_r1(struct bpf_jit *jit)
672
659
{
673
660
if (nospec_uses_trampoline ())
674
661
/* 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 );
676
664
else
677
665
/* basr %r14,%r1 */
678
666
EMIT2 (0x0d00 , REG_14 , REG_1 );
@@ -688,16 +676,7 @@ static void bpf_jit_epilogue(struct bpf_jit *jit, u32 stack_depth)
688
676
EMIT4 (0xb9040000 , REG_2 , BPF_REG_0 );
689
677
/* Restore registers */
690
678
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 );
701
680
702
681
jit -> prg = ALIGN (jit -> prg , 8 );
703
682
jit -> prologue_plt = jit -> prg ;
@@ -1899,7 +1878,8 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
1899
1878
/* aghi %r1,tail_call_start */
1900
1879
EMIT4_IMM (0xa70b0000 , REG_1 , jit -> tail_call_start );
1901
1880
/* 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 );
1903
1883
} else {
1904
1884
/* bc 0xf,tail_call_start(%r1) */
1905
1885
_EMIT4 (0x47f01000 + jit -> tail_call_start );
@@ -2868,17 +2848,10 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
2868
2848
0xf000 | tjit -> tccnt_off );
2869
2849
/* aghi %r15,stack_size */
2870
2850
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 );
2874
2851
if (flags & BPF_TRAMP_F_SKIP_FRAME )
2875
- /* br %r14 */
2876
- _EMIT2 (0x07fe );
2852
+ EMIT_JUMP_REG (14 );
2877
2853
else
2878
- /* br %r1 */
2879
- _EMIT2 (0x07f1 );
2880
-
2881
- emit_r1_thunk (jit );
2854
+ EMIT_JUMP_REG (1 );
2882
2855
2883
2856
return 0 ;
2884
2857
}
0 commit comments