Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jit BPF_CALL to direct call when possible #3623

Closed
wants to merge 3 commits into from

Conversation

kernel-patches-bot
Copy link

Pull request for series with
subject: Jit BPF_CALL to direct call when possible
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=673664

@kernel-patches-bot
Copy link
Author

Master branch: af515a5
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=673664
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 0b20a13
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=673664
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 274052a
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=673664
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 2786bcf
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=673664
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 1e660f7
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=673664
version: 1

Xu Kuohai added 2 commits September 6, 2022 20:05
Currently BPF_CALL is always jited to indirect call, but when target is
in the range of direct call, a BPF_CALL can be jited to direct call.

For example, the following BPF_CALL

    call __htab_map_lookup_elem

is always jited to an indirect call:

    mov     x10, #0xffffffffffff18f4
    movk    x10, #0x821, lsl #16
    movk    x10, #0x8000, lsl #32
    blr     x10

When the target is in the range of a direct call, it can be jited to:

    bl      0xfffffffffd33bc98

This patch does such jit when possible.

1. Before allocating jit image memory, jit all BPF_CALL to indirect call,
   so we could get the maximum image size at the end.

2. Allocate jit image memory with the maximum image size.

3. Since we have now allocated jit image memory, every jited instruction
   address is determined, so the distance to call target is determined,
   so whether a BPF_CALL can be jited to direct call is determined.

4. Since step 3 may adjust the position of jited instructions, update the
   offset of jump instructions whose target is within the jit image.

Tested with test_bpf.ko and some arm64 working selftests, nothing failed.

Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
With jiting BPF_CALL to indirect call or direct call based on the jump
distance, the bpf trampoline size calculated with NULL image address
may be larger than the actual size needed, resulting in a fake -EFBIG
error.

So remove the estimate of the bpf trampoline size based on NULL image
address, and check if there is enough space when emitting instructions.

Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
@kernel-patches-bot
Copy link
Author

Master branch: 028a964
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=673664
version: 1

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/netdevbpf/list/?series=673664
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am -3
  stdout: 'Applying: bpf, arm64: Jit BPF_CALL to direct call when possible
Applying: bpf, arm64: Eliminate false -EFBIG error in bpf trampoline
Using index info to reconstruct a base tree...
M	arch/arm64/net/bpf_jit_comp.c
Falling back to patching base and 3-way merge...
Auto-merging arch/arm64/net/bpf_jit_comp.c
CONFLICT (content): Merge conflict in arch/arm64/net/bpf_jit_comp.c
Patch failed at 0002 bpf, arm64: Eliminate false -EFBIG error in bpf trampoline
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".'
  stderr: 'error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch'

conflict:

diff --cc arch/arm64/net/bpf_jit_comp.c
index 092248c04c65,34d78ca16beb..000000000000
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@@ -2027,13 -2029,10 +2029,18 @@@ int arch_prepare_bpf_trampoline(struct 
  	if (nargs > 8)
  		return -ENOTSUPP;
  
++<<<<<<< HEAD
 +	/* don't support struct argument */
 +	for (i = 0; i < MAX_BPF_FUNC_ARGS; i++) {
 +		if (m->arg_flags[i] & BTF_FMODEL_STRUCT_ARG)
 +			return -ENOTSUPP;
 +	}
++=======
+ 	jit_fill_hole(image, (unsigned int)(image_end - image));
++>>>>>>> bpf, arm64: Eliminate false -EFBIG error in bpf trampoline
  
  	ret = prepare_trampoline(&ctx, im, tlinks, orig_call, nargs, flags);
+ 
  	if (ret < 0)
  		return ret;
  

@kernel-patches-bot
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=673664 irrelevant now for [{'archived': False, 'project': 399, 'delegate': 121173}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant