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

powerpc64/bpf: fix JIT code size calculation of bpf trampoline #8714

Open
wants to merge 1 commit into
base: bpf-next_base
Choose a base branch
from

Conversation

kernel-patches-daemon-bpf[bot]
Copy link

Pull request for series with
subject: powerpc64/bpf: fix JIT code size calculation of bpf trampoline
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=947435

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 9aa8fe2
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=947435
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 9aa8fe2
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=947470
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 9aa8fe2
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=947470
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 9aa8fe2
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=947470
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: aa918db
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=947470
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 4e82c87
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=947470
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 4e82c87
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=947470
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 1e7857b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=947470
version: 1

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 1e7857b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=947470
version: 1

The JIT compile of ldimm instructions can be anywhere between 1-5
instructions long depending on the value being loaded.

arch_bpf_trampoline_size() provides JIT size of the BPF trampoline
before the buffer for JIT'ing it is allocated. BPF trampoline JIT
code has ldimm instructions that need to load the value of pointer
to struct bpf_tramp_image. But this pointer value is not same while
calling arch_bpf_trampoline_size() & arch_prepare_bpf_trampoline().
So, the size arrived at using arch_bpf_trampoline_size() can vary
from the size needed in arch_prepare_bpf_trampoline(). When the
number of ldimm instructions emitted in arch_bpf_trampoline_size()
is less than the number of ldimm instructions emitted during the
actual JIT compile of trampoline, the below warning is produced:

  WARNING: CPU: 8 PID: 204190 at arch/powerpc/net/bpf_jit_comp.c:981 __arch_prepare_bpf_trampoline.isra.0+0xd2c/0xdcc

which is:

  /* Make sure the trampoline generation logic doesn't overflow */
  if (image && WARN_ON_ONCE(&image[ctx->idx] >
			(u32 *)rw_image_end - BPF_INSN_SAFETY)) {

Pass NULL as the first argument to __arch_prepare_bpf_trampoline()
call from arch_bpf_trampoline_size() function, to differentiate it
from how arch_prepare_bpf_trampoline() calls it and ensure maximum
possible instructions are emitted in arch_bpf_trampoline_size() for
ldimm instructions that load a different value during the actual JIT
compile of BPF trampoline.

Fixes: d243b62 ("powerpc64/bpf: Add support for bpf trampolines")
Reported-by: Venkat Rao Bagalkote <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Cc: [email protected] # v6.13+
Signed-off-by: Hari Bathini <[email protected]>
Tested-by: Venkat Rao Bagalkote <[email protected]>
@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 25601e8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=947470
version: 1

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

Successfully merging this pull request may close these issues.

1 participant