From owner-svn-src-all@FreeBSD.ORG Mon Oct 29 01:35:17 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id DC3203FA; Mon, 29 Oct 2012 01:35:17 +0000 (UTC) (envelope-from attilio@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C38608FC12; Mon, 29 Oct 2012 01:35:17 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q9T1ZHUQ047283; Mon, 29 Oct 2012 01:35:17 GMT (envelope-from attilio@svn.freebsd.org) Received: (from attilio@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q9T1ZHUJ047280; Mon, 29 Oct 2012 01:35:17 GMT (envelope-from attilio@svn.freebsd.org) Message-Id: <201210290135.q9T1ZHUJ047280@svn.freebsd.org> From: Attilio Rao Date: Mon, 29 Oct 2012 01:35:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r242274 - head/sys/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Oct 2012 01:35:18 -0000 Author: attilio Date: Mon Oct 29 01:35:17 2012 New Revision: 242274 URL: http://svn.freebsd.org/changeset/base/242274 Log: 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 Modified: head/sys/sys/sched.h Modified: head/sys/sys/sched.h ============================================================================== --- head/sys/sys/sched.h Mon Oct 29 00:51:53 2012 (r242273) +++ head/sys/sys/sched.h Mon Oct 29 01:35:17 2012 (r242274) @@ -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--; }