суббота, 4 декабря 2021 г.

overhead of eBPF JIT

Lets try to estimate overhead of JIT compiler

I wrote simple perl script - it just counts redundant bytes for several cases:

  • pair mov reg, rbp/add reg, imm (total length 7 bytes) can be replaced with lea reg, [rbp-imm] which is only 4 bytes
  • pair mov reg, imm/add reg,imm can be replaced with just loading of right address so second instruction can be removed
  • add reg, 1/sub reg, 1 (length 4 bytes) can be replaced to inc/dec reg (which has length 3 bytes)
etc etc
Results

среда, 1 декабря 2021 г.

jitted eBPF code

I add yesterday disasm for jitted eBPF code. To put it mildly this code is very poor

Every function has 7 bytes of nops in prolog. Comment says that this is for BPF trampoline - well, ok

Lots of code like

 mov eax, 0x1
 cmp r14, 0x2
 jnz 0xc0561497
 xor eax, eax
0xc0561497:
 ...
Somebody - tell them about cmovXX instructions

Lots of code like
mov rdi, 0xffff8fd687f3e000
add rdi, 0x110

and related to get addresses of stack var:
mov rdi, rbp
add rdi, 0xffffffffffffffe0 
Perhaps it would be preferable to use lea rdi, [rbp-XX]

Slow inc/dec:
add r8, 0x1
sub rdi, 0x1

Lots of repeated instructions:
and rdi, 0xfff
and rdi, 0xfff
it's obvious bug

And finally