sparc: Fix JIT fused branch convergance.
authorDavid Miller <davem@davemloft.net>
Mon, 26 Nov 2018 21:03:46 +0000 (13:03 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 13 Dec 2019 07:51:52 +0000 (08:51 +0100)
commitd4926994be7f5669a57ff796cbd3213f4178a40a
tree053a492ee3db41b86da795dc93cea523288e72f6
parentc8aa27cf7e946da7d6c065dab3dbb7c5325f4b2c
sparc: Fix JIT fused branch convergance.

[ Upstream commit c44768a33da81b4a0986e79bbf0588f1a0651dec ]

On T4 and later sparc64 cpus we can use the fused compare and branch
instruction.

However, it can only be used if the branch destination is in the range
of a signed 10-bit immediate offset.  This amounts to 1024
instructions forwards or backwards.

After the commit referenced in the Fixes: tag, the largest possible
size program seen by the JIT explodes by a significant factor.

As a result of this convergance takes many more passes since the
expanded "BPF_LDX | BPF_MSH | BPF_B" code sequence, for example,
contains several embedded branch on condition instructions.

On each pass, as suddenly new fused compare and branch instances
become valid, this makes thousands more in range for the next pass.
And so on and so forth.

This is most greatly exemplified by "BPF_MAXINSNS: exec all MSH" which
takes 35 passes to converge, and shrinks the image by about 64K.

To decrease the cost of this number of convergance passes, do the
convergance pass before we have the program image allocated, just like
other JITs (such as x86) do.

Fixes: e0cea7ce988c ("bpf: implement ld_abs/ld_ind in native bpf")
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/sparc/net/bpf_jit_comp_64.c