bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: avoid setting bpf insns pages read-only when prog is jited
@ 2019-11-29 22:29 Daniel Borkmann
  2019-11-30  1:37 ` Eric Dumazet
  0 siblings, 1 reply; 10+ messages in thread
From: Daniel Borkmann @ 2019-11-29 22:29 UTC (permalink / raw)
  To: alexei.starovoitov; +Cc: peterz, netdev, bpf, Daniel Borkmann

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>
---
 include/linux/filter.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/linux/filter.h b/include/linux/filter.h
index 1b1e8b8f88da..a141cb07e76a 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -776,8 +776,12 @@ bpf_ctx_narrow_access_offset(u32 off, u32 size, u32 size_default)
 
 static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
 {
-	set_vm_flush_reset_perms(fp);
-	set_memory_ro((unsigned long)fp, fp->pages);
+#ifndef CONFIG_BPF_JIT_ALWAYS_ON
+	if (!fp->jited) {
+		set_vm_flush_reset_perms(fp);
+		set_memory_ro((unsigned long)fp, fp->pages);
+	}
+#endif
 }
 
 static inline void bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-12-02 20:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-29 22:29 [PATCH bpf] bpf: avoid setting bpf insns pages read-only when prog is jited Daniel Borkmann
2019-11-30  1:37 ` Eric Dumazet
2019-11-30  9:52   ` Daniel Borkmann
2019-12-01 17:54     ` Alexei Starovoitov
2019-12-02  2:49     ` Eric Dumazet
2019-12-02  3:44       ` hpa
2019-12-02  8:30       ` Peter Zijlstra
2019-12-02  9:17         ` Daniel Borkmann
2019-12-02 16:19           ` Alexei Starovoitov
2019-12-02 20:09             ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).