@@ -23,15 +23,15 @@ static void bpf_jit_fill_ill_insns(void *area, unsigned int size)
23
23
memset32 (area , BREAKPOINT_INSTRUCTION , size / 4 );
24
24
}
25
25
26
- /* Fix the branch target addresses for subprog calls */
27
- static int bpf_jit_fixup_subprog_calls (struct bpf_prog * fp , u32 * image ,
28
- struct codegen_context * ctx , u32 * addrs )
26
+ /* Fix updated addresses ( for subprog calls, ldimm64, et al) during extra pass */
27
+ static int bpf_jit_fixup_addresses (struct bpf_prog * fp , u32 * image ,
28
+ struct codegen_context * ctx , u32 * addrs )
29
29
{
30
30
const struct bpf_insn * insn = fp -> insnsi ;
31
31
bool func_addr_fixed ;
32
32
u64 func_addr ;
33
33
u32 tmp_idx ;
34
- int i , ret ;
34
+ int i , j , ret ;
35
35
36
36
for (i = 0 ; i < fp -> len ; i ++ ) {
37
37
/*
@@ -66,6 +66,23 @@ static int bpf_jit_fixup_subprog_calls(struct bpf_prog *fp, u32 *image,
66
66
* of the JITed sequence remains unchanged.
67
67
*/
68
68
ctx -> idx = tmp_idx ;
69
+ } else if (insn [i ].code == (BPF_LD | BPF_IMM | BPF_DW )) {
70
+ tmp_idx = ctx -> idx ;
71
+ ctx -> idx = addrs [i ] / 4 ;
72
+ #ifdef CONFIG_PPC32
73
+ PPC_LI32 (ctx -> b2p [insn [i ].dst_reg ] - 1 , (u32 )insn [i + 1 ].imm );
74
+ PPC_LI32 (ctx -> b2p [insn [i ].dst_reg ], (u32 )insn [i ].imm );
75
+ for (j = ctx -> idx - addrs [i ] / 4 ; j < 4 ; j ++ )
76
+ EMIT (PPC_RAW_NOP ());
77
+ #else
78
+ func_addr = ((u64 )(u32 )insn [i ].imm ) | (((u64 )(u32 )insn [i + 1 ].imm ) << 32 );
79
+ PPC_LI64 (b2p [insn [i ].dst_reg ], func_addr );
80
+ /* overwrite rest with nops */
81
+ for (j = ctx -> idx - addrs [i ] / 4 ; j < 5 ; j ++ )
82
+ EMIT (PPC_RAW_NOP ());
83
+ #endif
84
+ ctx -> idx = tmp_idx ;
85
+ i ++ ;
69
86
}
70
87
}
71
88
@@ -200,13 +217,13 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
200
217
/*
201
218
* Do not touch the prologue and epilogue as they will remain
202
219
* unchanged. Only fix the branch target address for subprog
203
- * calls in the body.
220
+ * calls in the body, and ldimm64 instructions .
204
221
*
205
222
* This does not change the offsets and lengths of the subprog
206
223
* call instruction sequences and hence, the size of the JITed
207
224
* image as well.
208
225
*/
209
- bpf_jit_fixup_subprog_calls (fp , code_base , & cgctx , addrs );
226
+ bpf_jit_fixup_addresses (fp , code_base , & cgctx , addrs );
210
227
211
228
/* There is no need to perform the usual passes. */
212
229
goto skip_codegen_passes ;
0 commit comments