Skip to content

Commit

Permalink
powerpc/bpf: Move common helpers into bpf_jit.h
Browse files Browse the repository at this point in the history
[ Upstream commit f1b1583 ]

Move functions bpf_flush_icache(), bpf_is_seen_register() and
bpf_set_seen_register() in order to reuse them in future
bpf_jit_comp32.c

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/28e8d5a75e64807d7e9d39a4b52658755e259f8c.1616430991.git.christophe.leroy@csgroup.eu
Stable-dep-of: 71f656a ("bpf: Fix to preserve reg parent/live fields when copying range info")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
chleroy authored and Sasha Levin committed Feb 11, 2023
1 parent 230865a commit 8db4374
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
35 changes: 35 additions & 0 deletions arch/powerpc/net/bpf_jit.h
Expand Up @@ -117,6 +117,41 @@
#define COND_LT (CR0_LT | COND_CMP_TRUE)
#define COND_LE (CR0_GT | COND_CMP_FALSE)

#define SEEN_FUNC 0x1000 /* might call external helpers */
#define SEEN_STACK 0x2000 /* uses BPF stack */
#define SEEN_TAILCALL 0x4000 /* uses tail calls */

struct codegen_context {
/*
* This is used to track register usage as well
* as calls to external helpers.
* - register usage is tracked with corresponding
* bits (r3-r10 and r27-r31)
* - rest of the bits can be used to track other
* things -- for now, we use bits 16 to 23
* encoded in SEEN_* macros above
*/
unsigned int seen;
unsigned int idx;
unsigned int stack_size;
};

static inline void bpf_flush_icache(void *start, void *end)
{
smp_wmb(); /* smp write barrier */
flush_icache_range((unsigned long)start, (unsigned long)end);
}

static inline bool bpf_is_seen_register(struct codegen_context *ctx, int i)
{
return ctx->seen & (1 << (31 - i));
}

static inline void bpf_set_seen_register(struct codegen_context *ctx, int i)
{
ctx->seen |= 1 << (31 - i);
}

#endif

#endif
19 changes: 0 additions & 19 deletions arch/powerpc/net/bpf_jit64.h
Expand Up @@ -86,25 +86,6 @@ static const int b2p[] = {
} while(0)
#define PPC_BPF_STLU(r, base, i) do { EMIT(PPC_RAW_STDU(r, base, i)); } while(0)

#define SEEN_FUNC 0x1000 /* might call external helpers */
#define SEEN_STACK 0x2000 /* uses BPF stack */
#define SEEN_TAILCALL 0x4000 /* uses tail calls */

struct codegen_context {
/*
* This is used to track register usage as well
* as calls to external helpers.
* - register usage is tracked with corresponding
* bits (r3-r10 and r27-r31)
* - rest of the bits can be used to track other
* things -- for now, we use bits 16 to 23
* encoded in SEEN_* macros above
*/
unsigned int seen;
unsigned int idx;
unsigned int stack_size;
};

#endif /* !__ASSEMBLY__ */

#endif
16 changes: 0 additions & 16 deletions arch/powerpc/net/bpf_jit_comp64.c
Expand Up @@ -24,22 +24,6 @@ static void bpf_jit_fill_ill_insns(void *area, unsigned int size)
memset32(area, BREAKPOINT_INSTRUCTION, size/4);
}

static inline void bpf_flush_icache(void *start, void *end)
{
smp_wmb();
flush_icache_range((unsigned long)start, (unsigned long)end);
}

static inline bool bpf_is_seen_register(struct codegen_context *ctx, int i)
{
return ctx->seen & (1 << (31 - i));
}

static inline void bpf_set_seen_register(struct codegen_context *ctx, int i)
{
ctx->seen |= 1 << (31 - i);
}

static inline bool bpf_has_stack_frame(struct codegen_context *ctx)
{
/*
Expand Down

0 comments on commit 8db4374

Please sign in to comment.