Update for kernel 5.7: use vmalloc_sync_mappings on kernels >= 5.7
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 5 May 2020 17:38:31 +0000 (13:38 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 8 May 2020 17:56:40 +0000 (13:56 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
31 files changed:
lib/ringbuffer/ring_buffer_backend.c
lttng-abi.c
lttng-context-callstack.c
lttng-context-cpu-id.c
lttng-context-hostname.c
lttng-context-interruptible.c
lttng-context-migratable.c
lttng-context-need-reschedule.c
lttng-context-nice.c
lttng-context-perf-counters.c
lttng-context-pid.c
lttng-context-ppid.c
lttng-context-preemptible.c
lttng-context-prio.c
lttng-context-procname.c
lttng-context-tid.c
lttng-context-vpid.c
lttng-context-vppid.c
lttng-context-vtid.c
lttng-context.c
lttng-events.c
lttng-ring-buffer-client.h
lttng-ring-buffer-metadata-client.h
lttng-syscalls.c
probes/lttng-kprobes.c
probes/lttng-kretprobes.c
probes/lttng-tracepoint-event-impl.h
probes/lttng-uprobes.c
probes/lttng.c
tests/probes/lttng-test.c
wrapper/vmalloc.h

index d4bec25ff956bfc21bc9c184b8230ca2963cbabc..d232b7f23e0915f3467b1450f205eb2a479a11a2 100644 (file)
@@ -17,7 +17,7 @@
 #include <linux/vmalloc.h>
 
 #include <wrapper/mm.h>
-#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_all() */
+#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_mappings() */
 #include <wrapper/ringbuffer/config.h>
 #include <wrapper/ringbuffer/backend.h>
 #include <wrapper/ringbuffer/frontend.h>
@@ -156,7 +156,7 @@ int lib_ring_buffer_backend_allocate(const struct lib_ring_buffer_config *config
         * If kmalloc ever uses vmalloc underneath, make sure the buffer pages
         * will not fault.
         */
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        wrapper_clear_current_oom_origin();
        vfree(pages);
        return 0;
index 2c6d6623a5bd7d5018a166a885a82922d4cc5420..816e6fddf57848d4e68e323b3f902fe3e2bff515 100644 (file)
@@ -30,7 +30,7 @@
 #include <linux/uaccess.h>
 #include <linux/slab.h>
 #include <linux/err.h>
-#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_all() */
+#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_mappings() */
 #include <wrapper/ringbuffer/vfs.h>
 #include <wrapper/ringbuffer/backend.h>
 #include <wrapper/ringbuffer/frontend.h>
@@ -1832,7 +1832,7 @@ int __init lttng_abi_init(void)
 {
        int ret = 0;
 
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        lttng_clock_ref();
 
        ret = lttng_tp_mempool_init();
index 195990a6e3e1292bebce8277a7b3bdefbd0d5acb..ba35a3940845399cfa73a605ea3d59c75002fc3c 100644 (file)
@@ -141,7 +141,7 @@ int __lttng_add_callstack_generic(struct lttng_ctx **ctx,
        field->record = lttng_callstack_record;
        field->priv = fdata;
        field->destroy = lttng_callstack_destroy;
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 
 error_create:
index 3778225163ee4e3f6a9223313b6f286ee9625c75..6e2f3f45d60b75c70b7c61dd28bc693679d8fd42 100644 (file)
@@ -68,7 +68,7 @@ int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx)
        field->record = cpu_id_record;
        field->get_value = cpu_id_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_cpu_id_to_ctx);
index e485aa9742c567a2befb343ffa9e17e925af2f4f..17dbd5776100d0d7c145edfbfe8d5fdf6016460e 100644 (file)
@@ -101,7 +101,7 @@ int lttng_add_hostname_to_ctx(struct lttng_ctx **ctx)
        field->record = hostname_record;
        field->get_value = hostname_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_hostname_to_ctx);
index f3da19903e31d83fa32d57f6ad82f5a87e741c57..8bd279a39f83e27d9dadc0747c4db8458f5cb44a 100644 (file)
@@ -75,7 +75,7 @@ int lttng_add_interruptible_to_ctx(struct lttng_ctx **ctx)
        field->record = interruptible_record;
        field->get_value = interruptible_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_interruptible_to_ctx);
index e3d8ede5decb9fdeb53c9153e23f1be821559436..65154b8b0d0b73f00ac1fcc1934c87855ce7141d 100644 (file)
@@ -68,7 +68,7 @@ int lttng_add_migratable_to_ctx(struct lttng_ctx **ctx)
        field->record = migratable_record;
        field->get_value = migratable_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_migratable_to_ctx);
index f29fb28da7abf635ba3349c7b7dd29e27e348edd..94efaa5c8b1c03c7bd63902133132c1b4c3aa53b 100644 (file)
@@ -68,7 +68,7 @@ int lttng_add_need_reschedule_to_ctx(struct lttng_ctx **ctx)
        field->record = need_reschedule_record;
        field->get_value = need_reschedule_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_need_reschedule_to_ctx);
index 563e8058677aa9d96e83f35c5a673cb65e22a5dc..acaba855fcc06a4446cc75fe666e35918ee9ba8c 100644 (file)
@@ -68,7 +68,7 @@ int lttng_add_nice_to_ctx(struct lttng_ctx **ctx)
        field->record = nice_record;
        field->get_value = nice_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_nice_to_ctx);
index 43c4077bb7a766f46543d6e8090261497d47b1a0..6b04d12342f061c0a0b9187ec536524d98095a14 100644 (file)
@@ -321,7 +321,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type,
        field->u.perf_counter = perf_field;
        lttng_context_update(*ctx);
 
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
index b3caabb4fa6c057c01c875ad5503cd19d49fdead..326eabe8408b91b33ee580d0e6d5ea17335fbda6 100644 (file)
@@ -68,7 +68,7 @@ int lttng_add_pid_to_ctx(struct lttng_ctx **ctx)
        field->record = pid_record;
        field->get_value = pid_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_pid_to_ctx);
index ef84ad1109e52967c94d7e272db510765c92492c..ff25288fa0b522b6cf58bf46ffc294839ecfaddf 100644 (file)
@@ -90,7 +90,7 @@ int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx)
        field->record = ppid_record;
        field->get_value = ppid_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_ppid_to_ctx);
index 328f2a43764ea383343270f28eeb862e6e91d943..867805b7c739d68f81614b6a7f39c803203c3091 100644 (file)
@@ -86,7 +86,7 @@ int lttng_add_preemptible_to_ctx(struct lttng_ctx **ctx)
        field->record = preemptible_record;
        field->get_value = preemptible_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_preemptible_to_ctx);
index b5d21e7e9438bafee3779d483532745f1ec1e65b..367f7bd67ca04f7dbe89788417b8f807f5a60406 100644 (file)
@@ -89,7 +89,7 @@ int lttng_add_prio_to_ctx(struct lttng_ctx **ctx)
        field->record = prio_record;
        field->get_value = prio_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_prio_to_ctx);
index 54007d15f5180a544d317d65171fb35bfca07aa4..8f18ca2c55320d5f1bca84a5e5ab806f6cbac8bc 100644 (file)
@@ -72,7 +72,7 @@ int lttng_add_procname_to_ctx(struct lttng_ctx **ctx)
        field->record = procname_record;
        field->get_value = procname_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_procname_to_ctx);
index d2a20e60e87db2be9cbee94df047b5e7f231e341..f6defc462036036805a0220446551b662d76bdcb 100644 (file)
@@ -71,7 +71,7 @@ int lttng_add_tid_to_ctx(struct lttng_ctx **ctx)
        field->record = tid_record;
        field->get_value = tid_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_tid_to_ctx);
index 982ce5584d5e626234d9bef3595f8242f008d706..b5b6ce0a59a1eedea2f8ec1de0c3c98e7da1fdb2 100644 (file)
@@ -83,7 +83,7 @@ int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx)
        field->record = vpid_record;
        field->get_value = vpid_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_vpid_to_ctx);
index 66d638244c4cba12d4b8b411cb84b3632bda8cea..347ac634c81e35b2af02ab21ced95b2205d7d0b6 100644 (file)
@@ -112,7 +112,7 @@ int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx)
        field->record = vppid_record;
        field->get_value = vppid_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_vppid_to_ctx);
index 8fd68a8c27041f73d1ac0bed6c4bff2e5a433a08..e81ba0e27532d0e1434362f0b8f0f9c5e10b4fc8 100644 (file)
@@ -83,7 +83,7 @@ int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx)
        field->record = vtid_record;
        field->get_value = vtid_get_value;
        lttng_context_update(*ctx);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return 0;
 }
 EXPORT_SYMBOL_GPL(lttng_add_vtid_to_ctx);
index 869496d8ce0f222925afd2b4535ba15b2168ec87..ce11f56594843ed325ce46b0b690eb4c15da7104 100644 (file)
@@ -11,7 +11,7 @@
 #include <linux/list.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
-#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_all() */
+#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_mappings() */
 #include <lttng-events.h>
 #include <lttng-tracer.h>
 
index 6233c75ce15b954a72c96ba49647e55549525fd1..d78e8efabe50fdf87f55dfbb6ede91176bbc4b9f 100644 (file)
@@ -30,7 +30,7 @@
 #include <linux/uuid.h>
 
 #include <wrapper/uuid.h>
-#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_all() */
+#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_mappings() */
 #include <wrapper/random.h>
 #include <wrapper/tracepoint.h>
 #include <wrapper/list.h>
@@ -2707,9 +2707,9 @@ end:
  * Registers a transport which can be used as output to extract the data out of
  * LTTng. The module calling this registration function must ensure that no
  * trap-inducing code will be executed by the transport functions. E.g.
- * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
+ * vmalloc_sync_mappings() must be called between a vmalloc and the moment the memory
  * is made visible to the transport function. This registration acts as a
- * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
+ * vmalloc_sync_mappings. Therefore, only if the module allocates virtual memory
  * after its registration must it synchronize the TLBs.
  */
 void lttng_transport_register(struct lttng_transport *transport)
@@ -2717,9 +2717,9 @@ void lttng_transport_register(struct lttng_transport *transport)
        /*
         * Make sure no page fault can be triggered by the module about to be
         * registered. We deal with this here so we don't have to call
-        * vmalloc_sync_all() in each module's init.
+        * vmalloc_sync_mappings() in each module's init.
         */
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
 
        mutex_lock(&sessions_mutex);
        list_add_tail(&transport->node, &lttng_transport_list);
index d5c512c5ccb8c372845541296fa8bafd48fb46b2..ff6283087d6176bb87763a85c0a9e3fc5853c9f4 100644 (file)
@@ -10,7 +10,7 @@
 #include <linux/module.h>
 #include <linux/types.h>
 #include <lib/bitfield.h>
-#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_all() */
+#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_mappings() */
 #include <wrapper/trace-clock.h>
 #include <lttng-events.h>
 #include <lttng-tracer.h>
@@ -766,7 +766,7 @@ static int __init lttng_ring_buffer_client_init(void)
         * This vmalloc sync all also takes care of the lib ring buffer
         * vmalloc'd module pages when it is built as a module into LTTng.
         */
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        lttng_transport_register(&lttng_relay_transport);
        return 0;
 }
index 17ffd7593812a45af8f80e75a7b25e1301e4cfe9..a098b8d8474f1d0f409172a6fd784a3131cdaad7 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <linux/module.h>
 #include <linux/types.h>
-#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_all() */
+#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_mappings() */
 #include <lttng-events.h>
 #include <lttng-tracer.h>
 
@@ -428,7 +428,7 @@ static int __init lttng_ring_buffer_client_init(void)
         * This vmalloc sync all also takes care of the lib ring buffer
         * vmalloc'd module pages when it is built as a module into LTTng.
         */
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        lttng_transport_register(&lttng_relay_transport);
        return 0;
 }
index fb14f6b043a877a77176e94a5ff3926a4b180b07..97f1ba9444d758a0140652e09b98c239524048a2 100644 (file)
@@ -760,7 +760,7 @@ int lttng_syscalls_register(struct lttng_channel *chan, void *filter)
        struct lttng_kernel_event ev;
        int ret;
 
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
 
        if (!chan->sc_table) {
                /* create syscall table mapping syscall to events */
index c0a15e47a0c0b4db1cef98c27cf960dead54790f..a44eaa11d7a1d0a4ffcdabd5880d69622c126994 100644 (file)
@@ -132,7 +132,7 @@ int lttng_kprobes_register(const char *name,
         * Well.. kprobes itself puts the page fault handler on the blacklist,
         * but we can never be too careful.
         */
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
 
        ret = register_kprobe(&event->u.kprobe.kp);
        if (ret)
index 4b18d46077df8749c7c01dfea52c67384b3f0406..ab98ff221d85b0f1bd5c7c3242927d747c33f5fb 100644 (file)
@@ -221,7 +221,7 @@ int lttng_kretprobes_register(const char *name,
         * Well.. kprobes itself puts the page fault handler on the blacklist,
         * but we can never be too careful.
         */
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
 
        ret = register_kretprobe(&lttng_krp->krp);
        if (ret)
index 3fe9d995cf310bbc9d15b794b92892dd475c9afd..0ab3bd011893e098bd1c23213aac1d20b0207d98 100644 (file)
@@ -15,7 +15,7 @@
 #include <probes/lttng.h>
 #include <probes/lttng-types.h>
 #include <probes/lttng-probe-user.h>
-#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_all() */
+#include <wrapper/vmalloc.h>   /* for wrapper_vmalloc_sync_mappings() */
 #include <wrapper/ringbuffer/frontend_types.h>
 #include <wrapper/ringbuffer/backend.h>
 #include <wrapper/rcu.h>
@@ -1352,7 +1352,7 @@ static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = {
 #ifndef TP_MODULE_NOINIT
 static int TP_ID(__lttng_events_init__, TRACE_SYSTEM)(void)
 {
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        return lttng_probe_register(&TP_ID(__probe_desc___, TRACE_SYSTEM));
 }
 
index 64d8237ca6eac2cbbc1c07df5f976dc7dd45367c..bc1012895f958b48a1542443432ed7162b5bbbc7 100644 (file)
@@ -161,7 +161,7 @@ int lttng_uprobes_add_callsite(struct lttng_event *event,
        }
 
        /* Ensure the memory we just allocated don't trigger page faults. */
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
 
        uprobe_handler->event = event;
        uprobe_handler->up_consumer.handler = lttng_uprobes_handler_pre;
index 383202c68efd8f4f46c6dd30302de5e935f6c54f..05bc1388df2926eebf0f15b080af5b55788f62d2 100644 (file)
@@ -116,7 +116,7 @@ int __init lttng_logger_init(void)
 {
        int ret = 0;
 
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
 
        /* /dev/lttng-logger */
        ret = misc_register(&logger_dev);
index f2d607a1107e861c7199e29e9e3dc5cc89e6c6b2..c728bed51f5d696931e200b6221e7592528c411d 100644 (file)
@@ -98,7 +98,7 @@ int __init lttng_test_init(void)
        int ret = 0;
 
        (void) wrapper_lttng_fixup_sig(THIS_MODULE);
-       wrapper_vmalloc_sync_all();
+       wrapper_vmalloc_sync_mappings();
        lttng_test_filter_event_dentry =
                        proc_create_data(LTTNG_TEST_FILTER_EVENT_FILE,
                                S_IRUGO | S_IWUGO, NULL,
index 0c3eb86bc209d8b5ccf070bd4009a83d3d0f4ec7..54715b5741d6d775d11319bcb101b0f7e5d8cc0d 100644 (file)
 #include <linux/kallsyms.h>
 #include <wrapper/kallsyms.h>
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0))
+
+static inline
+void wrapper_vmalloc_sync_mappings(void)
+{
+       void (*vmalloc_sync_mappings_sym)(void);
+
+       vmalloc_sync_mappings_sym = (void *) kallsyms_lookup_funcptr("vmalloc_sync_mappings");
+       if (vmalloc_sync_mappings_sym) {
+               vmalloc_sync_mappings_sym();
+       } else {
+#ifdef CONFIG_X86
+               /*
+                * Only x86 needs vmalloc_sync_mappings to make sure LTTng does not
+                * trigger recursive page faults.
+                */
+               printk_once(KERN_WARNING "LTTng: vmalloc_sync_mappings symbol lookup failed.\n");
+               printk_once(KERN_WARNING "Page fault handler and NMI tracing might trigger faults.\n");
+#endif
+       }
+}
+
+#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)) */
+
+/*
+ * Map vmalloc_sync_mappings to vmalloc_sync_all() on kernels before 5.7.
+ */
 static inline
-void wrapper_vmalloc_sync_all(void)
+void wrapper_vmalloc_sync_mappings(void)
 {
        void (*vmalloc_sync_all_sym)(void);
 
@@ -40,13 +67,29 @@ void wrapper_vmalloc_sync_all(void)
 #endif
        }
 }
+
+#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)) */
+
 #else
 
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0))
+
+static inline
+void wrapper_vmalloc_sync_mappings(void)
+{
+       return vmalloc_sync_mappings();
+}
+
+#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)) */
+
 static inline
-void wrapper_vmalloc_sync_all(void)
+void wrapper_vmalloc_sync_mappings(void)
 {
        return vmalloc_sync_all();
 }
+
+#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,7,0)) */
+
 #endif
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0))
@@ -61,7 +104,7 @@ void *lttng_kvmalloc_node(unsigned long size, gfp_t flags, int node)
                 * Make sure we don't trigger recursive page faults in the
                 * tracing fast path.
                 */
-               wrapper_vmalloc_sync_all();
+               wrapper_vmalloc_sync_mappings();
        }
        return ret;
 }
This page took 0.041449 seconds and 4 git commands to generate.