History

bpf: Avoid setting bpf insns pages read-only when prog is jited

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.

Daniel Borkmann committed 6 years ago

Commit e1608f31 parent df786c91 file · +6 −2Browse files

Showing the changes to include/linux (1 of 1 file). Show all

Unified · Split

include/linux/filter.h+6−2
@@ -776,8 +776,12 @@ bpf_ctx_narrow_access_offset(u32 off, u32 size, u32 size_default) · 775 unmodified lines
776776
777777 static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
778778 {
779− set_vm_flush_reset_perms(fp);
780− set_memory_ro((unsigned long)fp, fp->pages);
779+#ifndef CONFIG_BPF_JIT_ALWAYS_ON
780+ if (!fp->jited) {
781+ set_vm_flush_reset_perms(fp);
782+ set_memory_ro((unsigned long)fp, fp->pages);
783+ }
784+#endif
781785 }
782786
783787 static inline void bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t