From owner-svn-src-stable-9@FreeBSD.ORG Sat Aug 10 00:00:22 2013 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 18B52698; Sat, 10 Aug 2013 00:00:22 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id EB8EB2B0E; Sat, 10 Aug 2013 00:00:21 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r7A00LAE094357; Sat, 10 Aug 2013 00:00:21 GMT (envelope-from marius@svn.freebsd.org) Received: (from marius@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r7A00JoM094339; Sat, 10 Aug 2013 00:00:19 GMT (envelope-from marius@svn.freebsd.org) Message-Id: <201308100000.r7A00JoM094339@svn.freebsd.org> From: Marius Strobl Date: Sat, 10 Aug 2013 00:00:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r254169 - in stable/9/sys: amd64/include gnu/fs/xfs/FreeBSD i386/include kern mips/include pc98/include sparc64/include sys x86/include X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Aug 2013 00:00:22 -0000 Author: marius Date: Sat Aug 10 00:00:19 2013 New Revision: 254169 URL: http://svnweb.freebsd.org/changeset/base/254169 Log: MFC: r241374 Add an unified macro to deny ability from the compiler to reorder instruction loads/stores at its will. The macro __compiler_membar() is currently supported for both gcc and clang, but kernel compilation will fail otherwise. Reviewed by: bde, kib Discussed with: dim, theraven Modified: stable/9/sys/amd64/include/atomic.h stable/9/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h stable/9/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd.h stable/9/sys/i386/include/atomic.h stable/9/sys/kern/kern_rmlock.c stable/9/sys/mips/include/cpufunc.h stable/9/sys/pc98/include/bus.h stable/9/sys/sparc64/include/atomic.h stable/9/sys/sys/cdefs.h stable/9/sys/x86/include/bus.h Modified: stable/9/sys/amd64/include/atomic.h ============================================================================== --- stable/9/sys/amd64/include/atomic.h Fri Aug 9 23:47:43 2013 (r254168) +++ stable/9/sys/amd64/include/atomic.h Sat Aug 10 00:00:19 2013 (r254169) @@ -226,7 +226,7 @@ atomic_fetchadd_long(volatile u_long *p, static __inline void \ atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ { \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ *p = v; \ } \ struct __hack @@ -240,7 +240,7 @@ atomic_load_acq_##TYPE(volatile u_##TYPE u_##TYPE tmp; \ \ tmp = *p; \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ return (tmp); \ } \ struct __hack Modified: stable/9/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h ============================================================================== --- stable/9/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h Fri Aug 9 23:47:43 2013 (r254168) +++ stable/9/sys/gnu/fs/xfs/FreeBSD/xfs_compat.h Sat Aug 10 00:00:19 2013 (r254169) @@ -129,10 +129,6 @@ typedef dev_t os_dev_t; #define copy_from_user(dst, src, len) copyin((src), (dst), (len)) #endif -#ifndef barrier -#define barrier() __asm__ __volatile__("": : :"memory") -#endif - /* * Map simple global vairables to FreeBSD kernel equivalents */ Modified: stable/9/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd.h ============================================================================== --- stable/9/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd.h Fri Aug 9 23:47:43 2013 (r254168) +++ stable/9/sys/gnu/fs/xfs/FreeBSD/xfs_freebsd.h Sat Aug 10 00:00:19 2013 (r254169) @@ -162,7 +162,7 @@ */ #define EFSCORRUPTED 990 /* Filesystem is corrupted */ -#define SYNCHRONIZE() barrier() +#define SYNCHRONIZE() __compiler_membar() #define __return_address __builtin_return_address(0) /* Modified: stable/9/sys/i386/include/atomic.h ============================================================================== --- stable/9/sys/i386/include/atomic.h Fri Aug 9 23:47:43 2013 (r254168) +++ stable/9/sys/i386/include/atomic.h Sat Aug 10 00:00:19 2013 (r254169) @@ -296,7 +296,7 @@ atomic_fetchadd_int(volatile u_int *p, u static __inline void \ atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ { \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ *p = v; \ } \ struct __hack @@ -310,7 +310,7 @@ atomic_load_acq_##TYPE(volatile u_##TYPE u_##TYPE tmp; \ \ tmp = *p; \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ return (tmp); \ } \ struct __hack Modified: stable/9/sys/kern/kern_rmlock.c ============================================================================== --- stable/9/sys/kern/kern_rmlock.c Fri Aug 9 23:47:43 2013 (r254168) +++ stable/9/sys/kern/kern_rmlock.c Sat Aug 10 00:00:19 2013 (r254169) @@ -65,10 +65,6 @@ __FBSDID("$FreeBSD$"); * does not seem very useful */ -static __inline void compiler_memory_barrier(void) { - __asm __volatile("":::"memory"); -} - static void assert_rm(struct lock_object *lock, int what); static void lock_rm(struct lock_object *lock, int how); #ifdef KDTRACE_HOOKS @@ -353,7 +349,7 @@ _rm_rlock(struct rmlock *rm, struct rm_p td->td_critnest++; /* critical_enter(); */ - compiler_memory_barrier(); + __compiler_membar(); pc = cpuid_to_pcpu[td->td_oncpu]; /* pcpu_find(td->td_oncpu); */ @@ -361,7 +357,7 @@ _rm_rlock(struct rmlock *rm, struct rm_p sched_pin(); - compiler_memory_barrier(); + __compiler_membar(); td->td_critnest--; Modified: stable/9/sys/mips/include/cpufunc.h ============================================================================== --- stable/9/sys/mips/include/cpufunc.h Fri Aug 9 23:47:43 2013 (r254168) +++ stable/9/sys/mips/include/cpufunc.h Sat Aug 10 00:00:19 2013 (r254169) @@ -70,7 +70,7 @@ static __inline void mips_barrier(void) { #ifdef CPU_CNMIPS - __asm __volatile("" : : : "memory"); + __compiler_membar(); #else __asm __volatile (".set noreorder\n\t" "nop\n\t" Modified: stable/9/sys/pc98/include/bus.h ============================================================================== --- stable/9/sys/pc98/include/bus.h Fri Aug 9 23:47:43 2013 (r254168) +++ stable/9/sys/pc98/include/bus.h Sat Aug 10 00:00:19 2013 (r254169) @@ -559,7 +559,7 @@ bus_space_barrier(bus_space_tag_t tag, b if (flags & BUS_SPACE_BARRIER_READ) __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory"); else - __asm __volatile("" : : : "memory"); + __compiler_membar(); } #ifdef BUS_SPACE_NO_LEGACY Modified: stable/9/sys/sparc64/include/atomic.h ============================================================================== --- stable/9/sys/sparc64/include/atomic.h Fri Aug 9 23:47:43 2013 (r254168) +++ stable/9/sys/sparc64/include/atomic.h Sat Aug 10 00:00:19 2013 (r254169) @@ -97,7 +97,7 @@ #define atomic_cas_acq(p, e, s, sz) ({ \ itype(sz) v; \ v = atomic_cas((p), (e), (s), sz); \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ v; \ }) @@ -122,7 +122,7 @@ #define atomic_op_acq(p, op, v, sz) ({ \ itype(sz) t; \ t = atomic_op((p), op, (v), sz); \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ t; \ }) @@ -139,7 +139,7 @@ #define atomic_load_acq(p, sz) ({ \ itype(sz) v; \ v = atomic_load((p), sz); \ - __asm __volatile("" : : : "memory"); \ + __compiler_membar(); \ v; \ }) Modified: stable/9/sys/sys/cdefs.h ============================================================================== --- stable/9/sys/sys/cdefs.h Fri Aug 9 23:47:43 2013 (r254168) +++ stable/9/sys/sys/cdefs.h Sat Aug 10 00:00:19 2013 (r254169) @@ -82,6 +82,13 @@ # define __GNUC_VA_LIST_COMPATIBILITY 1 #endif +/* + * Compiler memory barriers, specific to gcc and clang. + */ +#if defined(__GNUC__) +#define __compiler_membar() __asm __volatile(" " : : : "memory") +#endif + #ifndef __INTEL_COMPILER # define __GNUCLIKE_BUILTIN_NEXT_ARG 1 # define __GNUCLIKE_MATH_BUILTIN_RELOPS Modified: stable/9/sys/x86/include/bus.h ============================================================================== --- stable/9/sys/x86/include/bus.h Fri Aug 9 23:47:43 2013 (r254168) +++ stable/9/sys/x86/include/bus.h Sat Aug 10 00:00:19 2013 (r254169) @@ -1014,7 +1014,7 @@ bus_space_barrier(bus_space_tag_t tag __ __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory"); #endif else - __asm __volatile("" : : : "memory"); + __compiler_membar(); #endif }