Skip to content

Commit 24dea04

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf, x32: remove ld_abs/ld_ind
Since LD_ABS/LD_IND instructions are now removed from the core and reimplemented through a combination of inlined BPF instructions and a slow-path helper, we can get rid of the complexity from x32 JIT. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent e1cf4be commit 24dea04

File tree

1 file changed

+1
-135
lines changed

1 file changed

+1
-135
lines changed

arch/x86/net/bpf_jit_comp32.c

Lines changed: 1 addition & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,13 @@ static const u8 bpf2ia32[][2] = {
175175
#define SCRATCH_SIZE 96
176176

177177
/* Total stack size used in JITed code */
178-
#define _STACK_SIZE \
179-
(stack_depth + \
180-
+ SCRATCH_SIZE + \
181-
+ 4 /* Extra space for skb_copy_bits buffer */)
178+
#define _STACK_SIZE (stack_depth + SCRATCH_SIZE)
182179

183180
#define STACK_SIZE ALIGN(_STACK_SIZE, STACK_ALIGNMENT)
184181

185182
/* Get the offset of eBPF REGISTERs stored on scratch space. */
186183
#define STACK_VAR(off) (off)
187184

188-
/* Offset of skb_copy_bits buffer */
189-
#define SKB_BUFFER STACK_VAR(SCRATCH_SIZE)
190-
191185
/* Encode 'dst_reg' register into IA32 opcode 'byte' */
192186
static u8 add_1reg(u8 byte, u32 dst_reg)
193187
{
@@ -2276,134 +2270,6 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
22762270
return -EFAULT;
22772271
}
22782272
break;
2279-
2280-
case BPF_LD | BPF_ABS | BPF_W:
2281-
case BPF_LD | BPF_ABS | BPF_H:
2282-
case BPF_LD | BPF_ABS | BPF_B:
2283-
case BPF_LD | BPF_IND | BPF_W:
2284-
case BPF_LD | BPF_IND | BPF_H:
2285-
case BPF_LD | BPF_IND | BPF_B:
2286-
{
2287-
int size;
2288-
const u8 *r6 = bpf2ia32[BPF_REG_6];
2289-
2290-
/* Setting up first argument */
2291-
/* mov eax,dword ptr [ebp+off] */
2292-
EMIT3(0x8B, add_2reg(0x40, IA32_EBP, IA32_EAX),
2293-
STACK_VAR(r6[0]));
2294-
2295-
/* Setting up second argument */
2296-
if (BPF_MODE(code) == BPF_ABS) {
2297-
/* mov %edx, imm32 */
2298-
EMIT1_off32(0xBA, imm32);
2299-
} else {
2300-
if (sstk)
2301-
/* mov edx,dword ptr [ebp+off] */
2302-
EMIT3(0x8B, add_2reg(0x40, IA32_EBP,
2303-
IA32_EDX),
2304-
STACK_VAR(src_lo));
2305-
else
2306-
/* mov edx,src_lo */
2307-
EMIT2(0x8B, add_2reg(0xC0, src_lo,
2308-
IA32_EDX));
2309-
if (imm32) {
2310-
if (is_imm8(imm32))
2311-
/* add %edx,imm8 */
2312-
EMIT3(0x83, 0xC2, imm32);
2313-
else
2314-
/* add %edx,imm32 */
2315-
EMIT2_off32(0x81, 0xC2, imm32);
2316-
}
2317-
}
2318-
2319-
/* Setting up third argument */
2320-
switch (BPF_SIZE(code)) {
2321-
case BPF_W:
2322-
size = 4;
2323-
break;
2324-
case BPF_H:
2325-
size = 2;
2326-
break;
2327-
case BPF_B:
2328-
size = 1;
2329-
break;
2330-
default:
2331-
return -EINVAL;
2332-
}
2333-
/* mov ecx,val */
2334-
EMIT2(0xB1, size);
2335-
/* movzx ecx,ecx */
2336-
EMIT3(0x0F, 0xB6, add_2reg(0xC0, IA32_ECX, IA32_ECX));
2337-
2338-
/* mov ebx,ebp */
2339-
EMIT2(0x8B, add_2reg(0xC0, IA32_EBP, IA32_EBX));
2340-
/* add %ebx,imm8 */
2341-
EMIT3(0x83, add_1reg(0xC0, IA32_EBX), SKB_BUFFER);
2342-
/* push ebx */
2343-
EMIT1(0x53);
2344-
2345-
/* Setting up function pointer to call */
2346-
/* mov ebx,imm32*/
2347-
EMIT2_off32(0xC7, add_1reg(0xC0, IA32_EBX),
2348-
(unsigned int)bpf_load_pointer);
2349-
2350-
EMIT2(0xFF, add_1reg(0xD0, IA32_EBX));
2351-
/* add %esp,4 */
2352-
EMIT3(0x83, add_1reg(0xC0, IA32_ESP), 4);
2353-
/* xor edx,edx */
2354-
EMIT2(0x33, add_2reg(0xC0, IA32_EDX, IA32_EDX));
2355-
2356-
/* mov dword ptr [ebp+off],eax */
2357-
EMIT3(0x89, add_2reg(0x40, IA32_EBP, IA32_EDX),
2358-
STACK_VAR(r0[0]));
2359-
/* mov dword ptr [ebp+off],edx */
2360-
EMIT3(0x89, add_2reg(0x40, IA32_EBP, IA32_EDX),
2361-
STACK_VAR(r0[1]));
2362-
2363-
/*
2364-
* Check if return address is NULL or not.
2365-
* If NULL then jump to epilogue else continue
2366-
* to load the value from retn address
2367-
*/
2368-
EMIT3(0x83, add_1reg(0xF8, IA32_EAX), 0);
2369-
jmp_offset = ctx->cleanup_addr - addrs[i];
2370-
2371-
switch (BPF_SIZE(code)) {
2372-
case BPF_W:
2373-
jmp_offset += 7;
2374-
break;
2375-
case BPF_H:
2376-
jmp_offset += 10;
2377-
break;
2378-
case BPF_B:
2379-
jmp_offset += 6;
2380-
break;
2381-
}
2382-
2383-
EMIT2_off32(0x0F, IA32_JE + 0x10, jmp_offset);
2384-
/* Load value from the address */
2385-
switch (BPF_SIZE(code)) {
2386-
case BPF_W:
2387-
/* mov eax,[eax] */
2388-
EMIT2(0x8B, 0x0);
2389-
/* Emit 'bswap eax' */
2390-
EMIT2(0x0F, add_1reg(0xC8, IA32_EAX));
2391-
break;
2392-
case BPF_H:
2393-
EMIT3(0x0F, 0xB7, 0x0);
2394-
EMIT1(0x66);
2395-
EMIT3(0xC1, add_1reg(0xC8, IA32_EAX), 8);
2396-
break;
2397-
case BPF_B:
2398-
EMIT3(0x0F, 0xB6, 0x0);
2399-
break;
2400-
}
2401-
2402-
/* mov dword ptr [ebp+off],eax */
2403-
EMIT3(0x89, add_2reg(0x40, IA32_EBP, IA32_EAX),
2404-
STACK_VAR(r0[0]));
2405-
break;
2406-
}
24072273
/* STX XADD: lock *(u32 *)(dst + off) += src */
24082274
case BPF_STX | BPF_XADD | BPF_W:
24092275
/* STX XADD: lock *(u64 *)(dst + off) += src */

0 commit comments

Comments
 (0)