]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commit
tracing: Add barrier to trace_printk() buffer nesting modification
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Tue, 5 Sep 2017 15:32:01 +0000 (11:32 -0400)
committerSeth Forshee <seth.forshee@canonical.com>
Thu, 28 Sep 2017 14:34:57 +0000 (10:34 -0400)
commit6f722e82e07cc5bce5ed1eb5e49e5ed5cf55250e
tree4dc871cea5cdc327f1161426c4a2b04f2e079483
parente6b5d4905e3f0c757f6e9fe690919451ad65d5e8
tracing: Add barrier to trace_printk() buffer nesting modification

BugLink: http://bugs.launchpad.net/bugs/1720154
commit 3d9622c12c8873911f4cc0ccdabd0362c2fca06b upstream.

trace_printk() uses 4 buffers, one for each context (normal, softirq, irq
and NMI), such that it does not need to worry about one context preempting
the other. There's a nesting counter that gets incremented to figure out
which buffer to use. If the context gets preempted by another context which
calls trace_printk() it will increment the counter and use the next buffer,
and restore the counter when it is finished.

The problem is that gcc may optimize the modification of the buffer nesting
counter and it may not be incremented in memory before the buffer is used.
If this happens, and the context gets interrupted by another context, it
could pick the same buffer and corrupt the one that is being used.

Compiler barriers need to be added after the nesting variable is incremented
and before it is decremented to prevent usage of the context buffers by more
than one context at the same time.

Cc: Andy Lutomirski <luto@kernel.org>
Fixes: e2ace00117 ("tracing: Choose static tp_printk buffer by explicit nesting count")
Hat-tip-to: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
kernel/trace/trace.c