perf: Fix races in computing the header sizes
authorPeter Zijlstra <peterz@infradead.org>
Wed, 9 Sep 2015 18:48:22 +0000 (20:48 +0200)
committerIngo Molnar <mingo@kernel.org>
Fri, 18 Sep 2015 07:20:26 +0000 (09:20 +0200)
commitf73e22ab450140830005581c2c7ec389791a1b8d
tree78ff75731998d7b9cf2857b91ad4a944ce996f2c
parenta723968c0ed36db676478c3d26078f13484fe01c
perf: Fix races in computing the header sizes

There are two races with the current code:

 - Another event can join the group and compute a larger header_size
   concurrently, if the smaller store wins we'll have an incorrect
   header_size set.

 - We compute the header_size after the event becomes active,
   therefore its possible to use the size before its computed.

Remedy the first by moving the computation inside the ctx::mutex lock,
and the second by placing it _before_ perf_install_in_context().

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/events/core.c