From owner-svn-src-stable-8@FreeBSD.ORG Fri Aug 14 21:50:48 2009 Return-Path: Delivered-To: svn-src-stable-8@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3D918106568D; Fri, 14 Aug 2009 21:50:48 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 29CAD8FC6B; Fri, 14 Aug 2009 21:50:48 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n7ELombX048919; Fri, 14 Aug 2009 21:50:48 GMT (envelope-from bz@svn.freebsd.org) Received: (from bz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n7ELomPp048914; Fri, 14 Aug 2009 21:50:48 GMT (envelope-from bz@svn.freebsd.org) Message-Id: <200908142150.n7ELomPp048914@svn.freebsd.org> From: "Bjoern A. Zeeb" Date: Fri, 14 Aug 2009 21:50:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r196227 - in stable/8/sys: . amd64/include/xen cddl/contrib/opensolaris contrib/dev/acpica contrib/pf dev/ata dev/cxgb dev/xen/netfront dev/xen/xenpci kern modules/dtrace/dtnfsclient mo... X-BeenThere: svn-src-stable-8@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 8-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Aug 2009 21:50:48 -0000 Author: bz Date: Fri Aug 14 21:50:47 2009 New Revision: 196227 URL: http://svn.freebsd.org/changeset/base/196227 Log: MFC r196226: Add a new macro to test that a variable could be loaded atomically. Check that the given variable is at most uintptr_t in size and that it is aligned. Note: ASSERT_ATOMIC_LOAD() uses ALIGN() to check for adequate alignment -- however, the function of ALIGN() is to guarantee alignment, and therefore may lead to stronger alignment enforcement than necessary for types that are smaller than sizeof(uintptr_t). Add checks to mtx, rw and sx locks init functions to detect possible breakage. This was used during debugging of the problem fixed with r196118 where a pointer was on an un-aligned address in the dpcpu area. In collaboration with: rwatson Reviewed by: rwatson Approved by: re (kib) Modified: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/ata/ (props changed) stable/8/sys/dev/cxgb/ (props changed) stable/8/sys/dev/xen/netfront/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) stable/8/sys/kern/kern_mutex.c stable/8/sys/kern/kern_rwlock.c stable/8/sys/kern/kern_sx.c stable/8/sys/modules/dtrace/dtnfsclient/ (props changed) stable/8/sys/modules/ip6_mroute_mod/ (props changed) stable/8/sys/modules/ipmi/ipmi_linux/ (props changed) stable/8/sys/netinet/ipfw/ip_dummynet.c (props changed) stable/8/sys/netinet/ipfw/ip_fw2.c (props changed) stable/8/sys/netinet/ipfw/ip_fw_nat.c (props changed) stable/8/sys/netinet/ipfw/ip_fw_pfil.c (props changed) stable/8/sys/netipx/spx_reass.c (props changed) stable/8/sys/sys/systm.h stable/8/sys/xen/evtchn.h (props changed) stable/8/sys/xen/hypervisor.h (props changed) stable/8/sys/xen/xen_intr.h (props changed) Modified: stable/8/sys/kern/kern_mutex.c ============================================================================== --- stable/8/sys/kern/kern_mutex.c Fri Aug 14 21:46:54 2009 (r196226) +++ stable/8/sys/kern/kern_mutex.c Fri Aug 14 21:50:47 2009 (r196227) @@ -783,6 +783,8 @@ mtx_init(struct mtx *m, const char *name MPASS((opts & ~(MTX_SPIN | MTX_QUIET | MTX_RECURSE | MTX_NOWITNESS | MTX_DUPOK | MTX_NOPROFILE)) == 0); + ASSERT_ATOMIC_LOAD(m->mtx_lock, ("%s: mtx_lock not aligned for %s: %p", + __func__, name, &m->mtx_lock)); #ifdef MUTEX_DEBUG /* Diagnostic and error correction */ Modified: stable/8/sys/kern/kern_rwlock.c ============================================================================== --- stable/8/sys/kern/kern_rwlock.c Fri Aug 14 21:46:54 2009 (r196226) +++ stable/8/sys/kern/kern_rwlock.c Fri Aug 14 21:50:47 2009 (r196227) @@ -174,6 +174,8 @@ rw_init_flags(struct rwlock *rw, const c MPASS((opts & ~(RW_DUPOK | RW_NOPROFILE | RW_NOWITNESS | RW_QUIET | RW_RECURSE)) == 0); + ASSERT_ATOMIC_LOAD(rw->rw_lock, ("%s: rw_lock not aligned for %s: %p", + __func__, name, &rw->rw_lock)); flags = LO_UPGRADABLE; if (opts & RW_DUPOK) Modified: stable/8/sys/kern/kern_sx.c ============================================================================== --- stable/8/sys/kern/kern_sx.c Fri Aug 14 21:46:54 2009 (r196226) +++ stable/8/sys/kern/kern_sx.c Fri Aug 14 21:50:47 2009 (r196227) @@ -205,6 +205,8 @@ sx_init_flags(struct sx *sx, const char MPASS((opts & ~(SX_QUIET | SX_RECURSE | SX_NOWITNESS | SX_DUPOK | SX_NOPROFILE | SX_NOADAPTIVE)) == 0); + ASSERT_ATOMIC_LOAD(sx->sx_lock, ("%s: sx_lock not aligned for %s: %p", + __func__, description, &sx->sx_lock)); flags = LO_SLEEPABLE | LO_UPGRADABLE; if (opts & SX_DUPOK) Modified: stable/8/sys/sys/systm.h ============================================================================== --- stable/8/sys/sys/systm.h Fri Aug 14 21:46:54 2009 (r196226) +++ stable/8/sys/sys/systm.h Fri Aug 14 21:50:47 2009 (r196227) @@ -89,6 +89,10 @@ extern int maxusers; /* system tune hin #define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1] #endif +#define ASSERT_ATOMIC_LOAD(var,msg) \ + KASSERT(sizeof(var) <= sizeof(uintptr_t) && \ + ALIGN(&(var)) == (uintptr_t)&(var), msg) + /* * XXX the hints declarations are even more misplaced than most declarations * in this file, since they are needed in one file (per arch) and only used