[RFC PATCH 1/9] tracepoint: call vmalloc_sync_mappings() on registration

From: Mathieu Desnoyers
Date: Thu Apr 09 2020 - 15:36:03 EST


Similarly to register_die_notifier(), tracepoints register callbacks
which can be invoked from execution contexts such as the page fault
handler and NMIs which should not generate a page fault. Those callbacks
can access virtual mappings and can be implemented in modules.

Calling vmalloc_sync_mappings() before registering a tracepoint callback
ensures that the virtual mappings are synchronized within each process
page tables, thus ensuring that no page fault will be triggered by the
callback.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: Steven Rostedt <rostedt@xxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
---
kernel/tracepoint.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
index 73956eaff8a9..82191a89c72e 100644
--- a/kernel/tracepoint.c
+++ b/kernel/tracepoint.c
@@ -14,6 +14,7 @@
#include <linux/sched/signal.h>
#include <linux/sched/task.h>
#include <linux/static_key.h>
+#include <linux/vmalloc.h>

extern tracepoint_ptr_t __start___tracepoints_ptrs[];
extern tracepoint_ptr_t __stop___tracepoints_ptrs[];
@@ -308,6 +309,7 @@ int tracepoint_probe_register_prio(struct tracepoint *tp, void *probe,
struct tracepoint_func tp_func;
int ret;

+ vmalloc_sync_mappings();
mutex_lock(&tracepoints_mutex);
tp_func.func = probe;
tp_func.data = data;
--
2.17.1