# Re: \[PATCH 10/14\] bpf/tests: Add branch conversion JIT test

- From: Yonghong Song \<hidden\>
- Date: 2021-07-29 15:50:23 
- List: netdev
- Page: https://ratatoskr.run/netdev/2021/07/7775030
- Thread: https://ratatoskr.run/netdev/2021/07/7774981/t.md

```text


On 7/29/21 6:24 AM, Johan Almbladh wrote:
> On Thu, Jul 29, 2021 at 2:55 AM Yonghong Song [ref] wrote:
>>> +static int bpf_fill_long_jmp(struct bpf_test *self)
>>> +{
>>> +     unsigned int len = BPF_MAXINSNS;
>>
>> BPF_MAXINSNS is 4096 as defined in uapi/linux/bpf_common.h.
>> Will it be able to trigger a PC relative branch + long
>> conditional jump?
>
> It does, on the MIPS32 JIT. The ALU64 MUL instruction with a large
> immediate was chosen since it expands to a lot of MIPS32 instructions:
> 2 to load the immediate, 1 to zero/sign extend it, and then 9 for the
> 64x64 multiply.

Maybe added a comment in the code to mention that with BPF_MAXINSNS
PC relative branch + long conditional jump can be triggered on MIPS32
JIT. Other architecture may need a different/larger number?

>
> Other JITs will be different of course. On the other hand, other
> architectures have other limitations that this test may not trigger
> anyway. I added the test because I was implementing a non-trivial
> iterative branch conversion logic in the MIPS32 JIT. One can argue
> that when such complex JIT mechanisms are added, the test suite should
> also be updated to cover that, especially if the mechanism handles
> something that almost never occur in practice.
>
> Since I was able to trigger the branch conversion with BPF_MAXINSNS
> instructions, and no other test was using more, I left it at that.
> However, should I or someone else work on the MIPS64 JIT, I think
> updating the test suite so that similar special cases there are
> triggered would be a valuable contribution.
>
```
