diff options
author | Alexei Starovoitov <ast@plumgrid.com> | 2014-09-23 16:50:10 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-09-24 15:04:07 -0400 |
commit | 35607b02dbef304fa5037236a3b43c1d8ab2aa52 (patch) | |
tree | c219ac28ef9d9691122fb445be7a6dfbcf120a3d /arch/sparc/net | |
parent | 543a2dff5edfab3ea53f3e16f4a876a00bf8023b (diff) |
sparc: bpf_jit: fix loads from negative offsets
- fix BPF_LD|ABS|IND from negative offsets:
make sure to sign extend lower 32 bits in 64-bit register
before calling C helpers from JITed code, otherwise 'int k'
argument of bpf_internal_load_pointer_neg_helper() function
will be added as large unsigned integer, causing packet size
check to trigger and abort the program.
It's worth noting that JITed code for 'A = A op K' will affect
upper 32 bits differently depending whether K is simm13 or not.
Since small constants are sign extended, whereas large constants
are stored in temp register and zero extended.
That is ok and we don't have to pay a penalty of sign extension
for every sethi, since all classic BPF instructions have 32-bit
semantics and we only need to set correct upper bits when
transitioning from JITed code into C.
- though instructions 'A &= 0' and 'A *= 0' are odd, JIT compiler
should not optimize them out
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc/net')
-rw-r--r-- | arch/sparc/net/bpf_jit_asm.S | 3 | ||||
-rw-r--r-- | arch/sparc/net/bpf_jit_comp.c | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/arch/sparc/net/bpf_jit_asm.S b/arch/sparc/net/bpf_jit_asm.S index 9d016c7017f7..8c83f4b8eb15 100644 --- a/arch/sparc/net/bpf_jit_asm.S +++ b/arch/sparc/net/bpf_jit_asm.S | |||
@@ -6,10 +6,12 @@ | |||
6 | #define SAVE_SZ 176 | 6 | #define SAVE_SZ 176 |
7 | #define SCRATCH_OFF STACK_BIAS + 128 | 7 | #define SCRATCH_OFF STACK_BIAS + 128 |
8 | #define BE_PTR(label) be,pn %xcc, label | 8 | #define BE_PTR(label) be,pn %xcc, label |
9 | #define SIGN_EXTEND(reg) sra reg, 0, reg | ||
9 | #else | 10 | #else |
10 | #define SAVE_SZ 96 | 11 | #define SAVE_SZ 96 |
11 | #define SCRATCH_OFF 72 | 12 | #define SCRATCH_OFF 72 |
12 | #define BE_PTR(label) be label | 13 | #define BE_PTR(label) be label |
14 | #define SIGN_EXTEND(reg) | ||
13 | #endif | 15 | #endif |
14 | 16 | ||
15 | #define SKF_MAX_NEG_OFF (-0x200000) /* SKF_LL_OFF from filter.h */ | 17 | #define SKF_MAX_NEG_OFF (-0x200000) /* SKF_LL_OFF from filter.h */ |
@@ -135,6 +137,7 @@ bpf_slow_path_byte_msh: | |||
135 | save %sp, -SAVE_SZ, %sp; \ | 137 | save %sp, -SAVE_SZ, %sp; \ |
136 | mov %i0, %o0; \ | 138 | mov %i0, %o0; \ |
137 | mov r_OFF, %o1; \ | 139 | mov r_OFF, %o1; \ |
140 | SIGN_EXTEND(%o1); \ | ||
138 | call bpf_internal_load_pointer_neg_helper; \ | 141 | call bpf_internal_load_pointer_neg_helper; \ |
139 | mov (LEN), %o2; \ | 142 | mov (LEN), %o2; \ |
140 | mov %o0, r_TMP; \ | 143 | mov %o0, r_TMP; \ |
diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c index 51ae87b483e0..ece4af0575e9 100644 --- a/arch/sparc/net/bpf_jit_comp.c +++ b/arch/sparc/net/bpf_jit_comp.c | |||
@@ -184,7 +184,7 @@ do { \ | |||
184 | */ | 184 | */ |
185 | #define emit_alu_K(OPCODE, K) \ | 185 | #define emit_alu_K(OPCODE, K) \ |
186 | do { \ | 186 | do { \ |
187 | if (K) { \ | 187 | if (K || OPCODE == AND || OPCODE == MUL) { \ |
188 | unsigned int _insn = OPCODE; \ | 188 | unsigned int _insn = OPCODE; \ |
189 | _insn |= RS1(r_A) | RD(r_A); \ | 189 | _insn |= RS1(r_A) | RD(r_A); \ |
190 | if (is_simm13(K)) { \ | 190 | if (is_simm13(K)) { \ |