From f3a86755d7de2bdf589cf6125b2960ab6b66bb48 Mon Sep 17 00:00:00 2001 From: attilio Date: Mon, 29 Oct 2012 01:35:17 +0000 Subject: Compiler have a precise knowledge of the content of sched_pin() and sched_unpin() as they are functions static and inline. This way it can do two dangerous things: - Reorder instructions around both of them, taking out from the safe path operations that are supposed to be (ie. per-cpu accesses) - Cache the value of td_pinned in CPU registers not making visible in kernel context to the scheduler once it is scanning the runqueue, as td_pinned is not marked volatile. In order to avoid both possible bugs explicitly, protect the safe path with compiler memory barriers. This will prevent reordering and caching by the compiler about td_pinned operations. Generally this could lead to suboptimal code traversing the pinnings but this is not the case as can be easilly verified: http://lists.freebsd.org/pipermail/svn-src-projects/2012-October/005797.html Discussed with: jeff, jhb MFC after: 2 weeks --- sys/sys/sched.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sys/sys') diff --git a/sys/sys/sched.h b/sys/sys/sched.h index b15104e..bfd8522 100644 --- a/sys/sys/sched.h +++ b/sys/sys/sched.h @@ -151,11 +151,13 @@ static __inline void sched_pin(void) { curthread->td_pinned++; + __compiler_membar(); } static __inline void sched_unpin(void) { + __compiler_membar(); curthread->td_pinned--; } -- cgit v1.1