Subject: Re: [PATCH 2/3] powerpc/bpf: Use helper for mapping bpf to ppc registers on PPC64

From: "Naveen N. Rao" <[email-masked]>
Date: Fri, 07 Jan 2022 22:55:37 +0530

Jordan Niethe wrote:
> Prepare for doing commit 40272035e1d0 ("powerpc/bpf: Reallocate BPF
> registers to volatile registers when possible on PPC32") on PPC64 in a
> later patch. Instead of directly accessing the const b2p[] array for
> mapping bpf to ppc registers use bpf_to_ppc() which allows per struct
> codegen_context mappings.
> 
> Signed-off-by: Jordan Niethe <[email-masked]>
> ---
>  arch/powerpc/net/bpf_jit.h        |  5 ++
>  arch/powerpc/net/bpf_jit64.h      | 30 +++++-----
>  arch/powerpc/net/bpf_jit_comp32.c |  5 --
>  arch/powerpc/net/bpf_jit_comp64.c | 96 ++++++++++++++++---------------
>  4 files changed, 71 insertions(+), 65 deletions(-)
> 
> diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h
> index 99fad093f43e..db86fa37f1dd 100644
> --- a/arch/powerpc/net/bpf_jit.h
> +++ b/arch/powerpc/net/bpf_jit.h
> @@ -172,6 +172,11 @@ void bpf_jit_build_prologue(u32 *image, struct codegen_context *ctx);
>  void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx);
>  void bpf_jit_realloc_regs(struct codegen_context *ctx);
> 
> +static inline int bpf_to_ppc(struct codegen_context *ctx, int reg)
> +{
> +	return ctx->b2p[reg];
> +}
> +
>  #endif

You are following what has been done on ppc32 here, but since ctx is 
almost always available where b2p[] is used, I'm thinking it might be 
simpler to convert it into a macro:

#define b2p(i)	ctx->cb2p[i]

We will just need to rename the global b2p array, as well as the one in 
codegen_context. Everywhere else, it will be a simple b2p[] -> b2p() 
change.

- Naveen