bpf, arm64/riscv: Remove redundant icache flush after pack allocator finalize
Subsystems (6)
Puranjay Mohan
maintainercover bpf, arm64/riscv: Remove redundant icache flush after pack allocator finalize
When the BPF prog pack allocator was added for arm64 and riscv, the existing bpf_flush_icache() calls were retained after bpf_jit_binary_pack_finalize(). However, the finalize path copies the JITed code via architecture text patching routines (__text_poke on arm64, patch_text_nosync on riscv) that already perform a full flush_icache_range() internally. The subsequent bpf_flush_icache() repeats the same cache maintenance on the same range.
Remove the redundant flush and the now-unused bpf_flush_icache() definitions on both architectures.
Puranjay Mohan (2):
bpf, arm64: Remove redundant bpf_flush_icache() after pack allocator
finalize
bpf, riscv: Remove redundant bpf_flush_icache() after pack allocator
finalize
arch/arm64/net/bpf_jit_comp.c | 11 ----------- arch/riscv/net/bpf_jit.h | 5 ----- arch/riscv/net/bpf_jit_core.c | 7 ------- 3 files changed, 23 deletions(-)
base-commit: 71b500afd2f7336f5b6c6026f2af546fc079be26
Signature · 1 line
2.52.0
Puranjay Mohan
maintainerPATCH 1/2 bpf, arm64: Remove redundant bpf_flush_icache() after pack allocator finalize
bpf_flush_icache() calls flush_icache_range() to clean the data cache and invalidate the instruction cache for the JITed code region. However, since commit 1dad391daef1 ("bpf, arm64: use bpf_prog_pack for memory management"), this flush is redundant.
bpf_jit_binary_pack_finalize() copies the JITed instructions to the ROX region via bpf_arch_text_copy() -> aarch64_insn_copy() -> __text_poke(), and __text_poke() already calls flush_icache_range() on the written range. The subsequent bpf_flush_icache() repeats the same cache maintenance on an overlapping range, including an unnecessary second synchronous IPI to all CPUs via kick_all_cpus_sync().
Remove the redundant bpf_flush_icache() call and its now-unused definition.
--- arch/arm64/net/bpf_jit_comp.c | 11 ----------- 1 file changed, 11 deletions(-)
arch/arm64/net/bpf_jit_comp.c +0 -11
@@ -1961,11 +1961,6 @@ static int validate_ctx(struct jit_ctx *ctx)return 0 ; } -static inline void bpf_flush_icache (void *start,void *end) -{ -flush_icache_range ((unsigned long )start, (unsigned long )end); -} -static void priv_stack_init_guard (void __percpu *priv_stack_ptr,int alloc_size) {int cpu, underflow_idx = (alloc_size -PRIV_STACK_GUARD_SZ ) >>3 ;
@@ -2204,12 +2199,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) prog = orig_prog; goto out_off; } -/* -* The instructions have now been copied to the ROX region from -* where they will execute. Now the data cache has to be cleaned to -* the PoU and the I-cache has to be invalidated for the VAs. -*/ -bpf_flush_icache (ro_header, ctx.ro_image + ctx.idx); }else { jit_data->ctx = ctx; jit_data->ro_image = ro_image_ptr;
Signature · 1 line
2.52.0
Puranjay Mohan
maintainerPATCH 2/2 bpf, riscv: Remove redundant bpf_flush_icache() after pack allocator finalize
In reply to Puranjay Mohanbpf_flush_icache() calls flush_icache_range() to clean the data cache and invalidate the instruction cache for the JITed code region. However, since commit 48a8f78c50bd ("bpf, riscv: use prog pack allocator in the BPF JIT"), this flush is redundant.
bpf_jit_binary_pack_finalize() copies the JITed instructions to the ROX region via bpf_arch_text_copy() -> patch_text_nosync(), and patch_text_nosync() already calls flush_icache_range() on the written range. The subsequent bpf_flush_icache() repeats the same cache maintenance on an overlapping range.
Remove the redundant bpf_flush_icache() call and its now-unused definition.
--- arch/riscv/net/bpf_jit.h | 5 ----- arch/riscv/net/bpf_jit_core.c | 7 ------- 2 files changed, 12 deletions(-)
arch/riscv/net/bpf_jit.h +0 -5
@@ -105,11 +105,6 @@ static inline void bpf_fill_ill_insns(void *area, unsigned int size)memset (area,0 , size); } -static inline void bpf_flush_icache (void *start,void *end) -{ -flush_icache_range ((unsigned long )start, (unsigned long )end); -} -/* Emit a 4-byte riscv instruction. */ static inline void emit (const u32 insn,struct rv_jit_context *ctx) {
arch/riscv/net/bpf_jit_core.c +0 -7
@@ -183,13 +183,6 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) prog = orig_prog; goto out_offset; } -/* -* The instructions have now been copied to the ROX region from -* where they will execute. -* Write any modified data cache blocks out to memory and -* invalidate the corresponding blocks in the instruction cache. -*/ -bpf_flush_icache (jit_data->ro_header, ctx->ro_insns + ctx->ninsns);for (i =0 ; i < prog->len; i++) ctx->offset[i] =ninsns_rvoff (ctx->offset[i]);bpf_prog_fill_jited_linfo (prog, ctx->offset);
Signature · 1 line
2.52.0
Re: [PATCH bpf-next 1/2] bpf, arm64: Remove redundant bpf_flush_icache() after pack allocator finalize
In reply to Puranjay MohanQuoted 13 lines · Puranjay Mohan
bpf_flush_icache()callsflush_icache_range()to clean the data cache and invalidate the instruction cache for the JITed code region. However, since commit1dad391daef1("bpf, arm64: usebpf_prog_packfor memory management"), this flush is redundant.
bpf_jit_binary_pack_finalize()copies the JITed instructions to the ROX region viabpf_arch_text_copy()->aarch64_insn_copy()->__text_poke(), and__text_poke()already callsflush_icache_range()on the written range. The subsequentbpf_flush_icache()repeats the same cache maintenance on an overlapping range, including an unnecessary second synchronous IPI to all CPUs viakick_all_cpus_sync().
Quoted 5 lines
Remove the redundant
bpf_flush_icache()call and its now-unused definition.Fixes 1dad391daef1 ("bpf, arm64: use bpf_prog_pack for memory management")Signed-off-by Puranjay Mohan <[email protected]>
We can now remove "#include <asm/cacheflush.h>".
Other than that,
Re: [PATCH bpf-next 2/2] bpf, riscv: Remove redundant bpf_flush_icache() after pack allocator finalize
In reply to Puranjay MohanQuoted 12 lines · Puranjay Mohan
bpf_flush_icache()callsflush_icache_range()to clean the data cache and invalidate the instruction cache for the JITed code region. However, since commit48a8f78c50bd("bpf, riscv: use prog pack allocator in the BPF JIT"), this flush is redundant.
bpf_jit_binary_pack_finalize()copies the JITed instructions to the ROX region viabpf_arch_text_copy()->patch_text_nosync(), andpatch_text_nosync()already callsflush_icache_range()on the written range. The subsequentbpf_flush_icache()repeats the same cache maintenance on an overlapping range.
Quoted 5 lines
Remove the redundant
bpf_flush_icache()call and its now-unused definition.Fixes 48a8f78c50bd ("bpf, riscv: use prog pack allocator in the BPF JIT")Signed-off-by Puranjay Mohan <[email protected]>
ditto on #include <asm/cacheflush.h>.