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

- From: Naveen N. Rao \<hidden\>
- Date: 2022-01-07 17:26:38 
- List: linuxppc-dev
- Page: https://ratatoskr.run/linuxppc-dev/2022/01/9525718
- Thread: https://ratatoskr.run/linuxppc-dev/2021/07/9523786/t.md

```text
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 <redacted>
> ---
>  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

```
