From nobody Sat Nov 06 14:02:19 2021 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 2B1691843E85; Sat, 6 Nov 2021 14:02:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HmfFl5h3lz3KcK; Sat, 6 Nov 2021 14:02:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 979D2493E; Sat, 6 Nov 2021 14:02:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1A6E2J9S023234; Sat, 6 Nov 2021 14:02:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A6E2JUj023233; Sat, 6 Nov 2021 14:02:19 GMT (envelope-from git) Date: Sat, 6 Nov 2021 14:02:19 GMT Message-Id: <202111061402.1A6E2JUj023233@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Jason A. Harmening" Subject: git: 66191a76ace5 - main - unionfs: Improve locking assertions List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jah X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 66191a76ace56af6603b343ad2e9a003e0589d70 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jah: URL: https://cgit.FreeBSD.org/src/commit/?id=66191a76ace56af6603b343ad2e9a003e0589d70 commit 66191a76ace56af6603b343ad2e9a003e0589d70 Author: Jason A. Harmening AuthorDate: 2021-10-28 05:31:16 +0000 Commit: Jason A. Harmening CommitDate: 2021-11-06 14:08:33 +0000 unionfs: Improve locking assertions Add an assertion to unionfs_node_update() that the upper vnode is exclusively locked; we already make the same assertion for the lower vnode. Also, assert in unionfs_noderem() that the vnode lock is not recursed and acquire v_lock with LK_NOWAIT. Since v_lock is not the active lock for the vnode at this point, it should not be contended. Finally, remove VDIR assertions from unionfs_get_cached_vnode(). lvp/uvp will be referenced but not locked at this point, so v_type may concurrently change due to vgonel(). The cached unionfs node, if one exists, would only have made it into the cache if lvp/uvp were of type VDIR at the time of insertion; the corresponding VDIR assert in unionfs_ins_cached_vnode() should be safe because lvp/uvp will be locked by that time and will not be used if either is doomed. Noted by: kib Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D32629 --- sys/fs/unionfs/union_subr.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sys/fs/unionfs/union_subr.c b/sys/fs/unionfs/union_subr.c index 449e171d52cf..0ca209c47502 100644 --- a/sys/fs/unionfs/union_subr.c +++ b/sys/fs/unionfs/union_subr.c @@ -183,11 +183,6 @@ unionfs_get_cached_vnode(struct vnode *uvp, struct vnode *lvp, { struct vnode *vp; - KASSERT(uvp == NULLVP || uvp->v_type == VDIR, - ("%s: v_type != VDIR", __func__)); - KASSERT(lvp == NULLVP || lvp->v_type == VDIR, - ("%s: v_type != VDIR", __func__)); - vp = NULLVP; VI_LOCK(dvp); if (uvp != NULLVP) @@ -209,6 +204,8 @@ unionfs_ins_cached_vnode(struct unionfs_node *uncp, struct unionfs_node_hashhead *hd; struct vnode *vp; + ASSERT_VOP_ELOCKED(uncp->un_uppervp, __func__); + ASSERT_VOP_ELOCKED(uncp->un_lowervp, __func__); KASSERT(uncp->un_uppervp == NULLVP || uncp->un_uppervp->v_type == VDIR, ("%s: v_type != VDIR", __func__)); KASSERT(uncp->un_lowervp == NULLVP || uncp->un_lowervp->v_type == VDIR, @@ -439,7 +436,9 @@ unionfs_noderem(struct vnode *vp, struct thread *td) struct vnode *dvp; int count; - if (lockmgr(&(vp->v_lock), LK_EXCLUSIVE, NULL) != 0) + KASSERT(vp->v_vnlock->lk_recurse == 0, + ("%s: vnode %p locked recursively", __func__, vp)); + if (lockmgr(&vp->v_lock, LK_EXCLUSIVE | LK_NOWAIT, NULL) != 0) panic("%s: failed to acquire lock for vnode lock", __func__); /* @@ -803,6 +802,7 @@ unionfs_node_update(struct unionfs_node *unp, struct vnode *uvp, vp = UNIONFSTOV(unp); lvp = unp->un_lowervp; ASSERT_VOP_ELOCKED(lvp, __func__); + ASSERT_VOP_ELOCKED(uvp, __func__); dvp = unp->un_dvp; /*