Skip to content

Commit 012b78e

Browse files
TropicaoKernel Patches Daemon
authored andcommitted
bpf/powerpc64: use define for max regs count used for arguments
powerpc allows using up to 8 registers to pass arguments between function calls. This value is hardcoded in multiple places, use a define for this value. Signed-off-by: Alexis Lothoré (eBPF Foundation) <[email protected]>
1 parent fb745d3 commit 012b78e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

arch/powerpc/net/bpf_jit_comp.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "bpf_jit.h"
2424

25+
#define MAX_REGS_FOR_ARGS 8
26+
2527
/* These offsets are from bpf prog end and stay the same across progs */
2628
static int bpf_jit_ool_stub, bpf_jit_long_branch_stub;
2729

@@ -613,7 +615,7 @@ static void bpf_trampoline_save_args(u32 *image, struct codegen_context *ctx, in
613615
param_save_area_offset += STACK_FRAME_MIN_SIZE; /* param save area is past frame header */
614616

615617
for (int i = 0; i < nr_regs; i++) {
616-
if (i < 8) {
618+
if (i < MAX_REGS_FOR_ARGS) {
617619
EMIT(PPC_RAW_STL(_R3 + i, _R1, regs_off + i * SZL));
618620
} else {
619621
EMIT(PPC_RAW_LL(_R3, _R1, param_save_area_offset + i * SZL));
@@ -626,7 +628,7 @@ static void bpf_trampoline_save_args(u32 *image, struct codegen_context *ctx, in
626628
static void bpf_trampoline_restore_args_regs(u32 *image, struct codegen_context *ctx,
627629
int nr_regs, int regs_off)
628630
{
629-
for (int i = 0; i < nr_regs && i < 8; i++)
631+
for (int i = 0; i < nr_regs && i < MAX_REGS_FOR_ARGS; i++)
630632
EMIT(PPC_RAW_LL(_R3 + i, _R1, regs_off + i * SZL));
631633
}
632634

@@ -725,7 +727,9 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im
725727
*
726728
* Reserve space for at least 8 registers for now. This can be optimized later.
727729
*/
728-
bpf_frame_size += (nr_regs > 8 ? nr_regs : 8) * SZL;
730+
bpf_frame_size +=
731+
(nr_regs > MAX_REGS_FOR_ARGS ? nr_regs : MAX_REGS_FOR_ARGS) *
732+
SZL;
729733

730734
/* Room for struct bpf_tramp_run_ctx */
731735
run_ctx_off = bpf_frame_size;

0 commit comments

Comments
 (0)