bpf: Optimize emit_mov_imm64().
authorAlexei Starovoitov <ast@kernel.org>
Mon, 1 Apr 2024 23:38:00 +0000 (16:38 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 4 Apr 2024 14:13:26 +0000 (16:13 +0200)
commitaf682b767a41772499f8e54ca7d7e1deb3395f44
tree6d1b833f7a32bae58032ff46b09ffea035ef5147
parent1e9e0b85255e6eca6036b59d8a5fbca6501905ac
bpf: Optimize emit_mov_imm64().

Turned out that bpf prog callback addresses, bpf prog addresses
used in bpf_trampoline, and in other cases the 64-bit address
can be represented as sign extended 32-bit value.

According to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82339
"Skylake has 0.64c throughput for mov r64, imm64, vs. 0.25 for mov r32, imm32."
So use shorter encoding and faster instruction when possible.

Special care is needed in jit_subprogs(), since bpf_pseudo_func()
instruction cannot change its size during the last step of JIT.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/CAADnVQKFfpY-QZBrOU2CG8v2du8Lgyb7MNVmOZVK_yTyOdNbBA@mail.gmail.com
Link: https://lore.kernel.org/bpf/20240401233800.42737-1-alexei.starovoitov@gmail.com
arch/x86/net/bpf_jit_comp.c
kernel/bpf/verifier.c