Skip to content

Commit ee71c59

Browse files
borkmanngregkh
authored andcommitted
bpf: Avoid setting bpf insns pages read-only when prog is jited
[ Upstream commit e1608f3 ] For the case where the interpreter is compiled out or when the prog is jited it is completely unnecessary to set the BPF insn pages as read-only. In fact, on frequent churn of BPF programs, it could lead to performance degradation of the system over time since it would break the direct map down to 4k pages when calling set_memory_ro() for the insn buffer on x86-64 / arm64 and there is no reverse operation. Thus, avoid breaking up large pages for data maps, and only limit this to the module range used by the JIT where it is necessary to set the image read-only and executable. Suggested-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20191129222911.3710-1-daniel@iogearbox.net Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4c732e8 commit ee71c59

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎include/linux/filter.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,12 @@ bpf_ctx_narrow_access_offset(u32 off, u32 size, u32 size_default)
770770

771771
static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
772772
{
773-
set_vm_flush_reset_perms(fp);
774-
set_memory_ro((unsigned long)fp, fp->pages);
773+
#ifndef CONFIG_BPF_JIT_ALWAYS_ON
774+
if (!fp->jited) {
775+
set_vm_flush_reset_perms(fp);
776+
set_memory_ro((unsigned long)fp, fp->pages);
777+
}
778+
#endif
775779
}
776780

777781
static inline void bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr)

0 commit comments

Comments
 (0)