From owner-svn-src-all@freebsd.org Fri Aug 17 15:41:02 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 632391072D7E; Fri, 17 Aug 2018 15:41:02 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 16FF983FFC; Fri, 17 Aug 2018 15:41:02 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EB0612524; Fri, 17 Aug 2018 15:41:01 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7HFf1LJ098548; Fri, 17 Aug 2018 15:41:01 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7HFf13I098547; Fri, 17 Aug 2018 15:41:01 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201808171541.w7HFf13I098547@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Fri, 17 Aug 2018 15:41:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r337974 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 337974 X-SVN-Commit-Repository: base 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.27 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: Fri, 17 Aug 2018 15:41:02 -0000 Author: markj Date: Fri Aug 17 15:41:01 2018 New Revision: 337974 URL: https://svnweb.freebsd.org/changeset/base/337974 Log: Add INVARIANTS-only fences around lockless vnode refcount updates. Some internal KASSERTs access the v_iflag field without the vnode interlock held after such a refcount update. The fences are needed for the assertions to be correct in the face of store reordering. Reported and tested by: jhibbits Reviewed by: kib, mjg MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D16756 Modified: head/sys/kern/vfs_subr.c Modified: head/sys/kern/vfs_subr.c ============================================================================== --- head/sys/kern/vfs_subr.c Fri Aug 17 15:18:57 2018 (r337973) +++ head/sys/kern/vfs_subr.c Fri Aug 17 15:41:01 2018 (r337974) @@ -118,6 +118,22 @@ static void vnlru_return_batches(struct vfsops *mnt_op static void destroy_vpollinfo(struct vpollinfo *vi); /* + * These fences are intended for cases where some synchronization is + * needed between access of v_iflags and lockless vnode refcount (v_holdcnt + * and v_usecount) updates. Access to v_iflags is generally synchronized + * by the interlock, but we have some internal assertions that check vnode + * flags * without acquiring the lock. Thus, these fences are INVARIANTS-only + * for now. + */ +#ifdef INVARIANTS +#define VNODE_REFCOUNT_FENCE_ACQ() atomic_thread_fence_acq() +#define VNODE_REFCOUNT_FENCE_REL() atomic_thread_fence_rel() +#else +#define VNODE_REFCOUNT_FENCE_ACQ() +#define VNODE_REFCOUNT_FENCE_REL() +#endif + +/* * Number of vnodes in existence. Increased whenever getnewvnode() * allocates a new vnode, decreased in vdropl() for VI_DOOMED vnode. */ @@ -1018,6 +1034,7 @@ vnlru_free_locked(int count, struct vfsops *mnt_op) */ freevnodes--; vp->v_iflag &= ~VI_FREE; + VNODE_REFCOUNT_FENCE_REL(); refcount_acquire(&vp->v_holdcnt); mtx_unlock(&vnode_free_list_mtx); @@ -2495,6 +2512,7 @@ v_incr_usecount(struct vnode *vp) if (vp->v_type != VCHR && refcount_acquire_if_not_zero(&vp->v_usecount)) { + VNODE_REFCOUNT_FENCE_ACQ(); VNASSERT((vp->v_iflag & VI_OWEINACT) == 0, vp, ("vnode with usecount and VI_OWEINACT set")); } else { @@ -2593,6 +2611,7 @@ vget(struct vnode *vp, int flags, struct thread *td) } else { oweinact = 1; vp->v_iflag &= ~VI_OWEINACT; + VNODE_REFCOUNT_FENCE_REL(); } refcount_acquire(&vp->v_usecount); v_incr_devcount(vp); @@ -2807,6 +2826,7 @@ _vhold(struct vnode *vp, bool locked) CTR2(KTR_VFS, "%s: vp %p", __func__, vp); if (!locked) { if (refcount_acquire_if_not_zero(&vp->v_holdcnt)) { + VNODE_REFCOUNT_FENCE_ACQ(); VNASSERT((vp->v_iflag & VI_FREE) == 0, vp, ("_vhold: vnode with holdcnt is free")); return;