]> git.baikalelectronics.ru Git - kernel.git/commit
bpf, arm64: Optimize BPF store/load using arm64 str/ldr(immediate offset)
authorXu Kuohai <xukuohai@huawei.com>
Mon, 21 Mar 2022 15:28:49 +0000 (11:28 -0400)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 31 Mar 2022 22:27:34 +0000 (00:27 +0200)
commita39ad7088bacceb1c876047837712a5c1d2a0f28
tree3af861aaa48c023084343617d8e0649755e44ec9
parentf2c03e5ff39c0167a53622881b636b314d82b745
bpf, arm64: Optimize BPF store/load using arm64 str/ldr(immediate offset)

The current BPF store/load instruction is translated by the JIT into two
instructions. The first instruction moves the immediate offset into a
temporary register. The second instruction uses this temporary register
to do the real store/load.

In fact, arm64 supports addressing with immediate offsets. So This patch
introduces optimization that uses arm64 str/ldr instruction with immediate
offset when the offset fits.

Example of generated instuction for r2 = *(u64 *)(r1 + 0):

without optimization:
mov x10, 0
ldr x1, [x0, x10]

with optimization:
ldr x1, [x0, 0]

If the offset is negative, or is not aligned correctly, or exceeds max
value, rollback to the use of temporary register.

Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220321152852.2334294-3-xukuohai@huawei.com
arch/arm64/net/bpf_jit.h
arch/arm64/net/bpf_jit_comp.c