tracepoint: Fix out of sync data passing by static caller
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Fri, 2 Oct 2020 01:27:57 +0000 (21:27 -0400)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 2 Oct 2020 19:18:25 +0000 (21:18 +0200)
commit547305a64632813286700cb6d768bfe773df7d19
tree5794b5f95a015645070022512939a324b8a84100
parentde394e7568ce2cdb4643ed230169f484f25f9442
tracepoint: Fix out of sync data passing by static caller

Naresh reported a bug that appears to be a side effect of the static
calls. It happens when going from more than one tracepoint callback to
a single one, and removing the first callback on the list. The list of
tracepoint callbacks holds data and a function to call with the
parameters of that tracepoint and a handler to the associated data.

 old_list:
0: func = foo; data = NULL;
1: func = bar; data = &bar_struct;

 new_list:
0: func = bar; data = &bar_struct;

CPU 0 CPU 1
----- -----
   tp_funcs = old_list;
   tp_static_caller = tp_interator

   __DO_TRACE()

    data = tp_funcs[0].data = NULL;

   tp_funcs = new_list;
   tracepoint_update_call()
      tp_static_caller = tp_funcs[0] = bar;
    tp_static_caller(data)
       bar(data)
         x = data->item = NULL->item

       BOOM!

To solve this, add a tracepoint_synchronize_unregister() between
changing tp_funcs and updating the static tracepoint, that does both a
synchronize_rcu() and synchronize_srcu(). This will ensure that when
the static call is updated to the single callback that it will be
receiving the data that it registered with.

Fixes: d25e37d89dd2f ("tracepoint: Optimize using static_call()")
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/linux-next/CA+G9fYvPXVRO0NV7yL=FxCmFEMYkCwdz7R=9W+_votpT824YJA@mail.gmail.com
kernel/tracepoint.c