From nobody Sun Dec 11 03:48:53 2022 X-Original-To: dev-commits-src-all@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 4NV9jL1pjgz4kLwt; Sun, 11 Dec 2022 03:48:54 +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 4NV9jL10JXz3LVn; Sun, 11 Dec 2022 03:48:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670730534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kZeoCGJyRR18yGciJhPqviH9yO1uQXyTrM2L3dxCH5k=; b=ncCI8HffUruFHLzFts0D84+h6VvHmvCn6r/h/T0G8aWITNXnaoQ64Hdv0LfyKt4rzTeQd5 qm4zaYAFM83ZCem/wMwutDdNAf287/aVKTsmz/XKVIvAhh2TIW9x+Y4JroahjJcbl63M5c SOUusomKpliLZg6aC/sqicpKUsGti6IKLA3/RZEmzM7M5P6LGlWNrhlafwax4C/UXvKrE9 aDhMx7P2+EWU0IJ970TTcy/Imscc87TW9cSoX6TG+pTu9L5cRWEn6U4CdLipPExkLg5wDD tW1I3nm7dOHpM+KP8vgC5MbxT9uwCbWjzJ9/X8VsvUw6bpJH0w8zCRKz+zzH8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670730534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=kZeoCGJyRR18yGciJhPqviH9yO1uQXyTrM2L3dxCH5k=; b=JqvAvipZOhXG6+4T3537NvGqt/KCzpjW5aeHIGwXFb6fTueytAvFHzder09Ypy4mS0snpA ZzzJRWduk7OuWbLBApzLIoImYvFAamIfSnKDGH+7eHYliK1c1OHX85YBW0KM/IRPGrEmzp oyJjyrCqS6wSMDFR5CLCqQedxs7sWTRHgKFAs5DBXtbA37zL95HoCOC+VgAHE5x0INh00H 7m99ZY91YEYUagsP9Uok0T3FwK1g8cVHH7A6G0hpE3A5vEzbPT+bXC8hKGmFBbCHC2kyQV I7l3QZ3mdSu4KmJqMKt3Mpd+zSGSH/xX2xuQjDWl10wTvOaGdUrNwOQ3oDocfw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670730534; a=rsa-sha256; cv=none; b=o4TxwV8yOZZG0TIAc3bEx9/PUo1IG3nqn0W5mLfOHNl4lGtgETOvlF03uhK6nU27Xukvjp lE1TSWjBNPxSe2Y8zEe+kdjVyyLUPHWBoLEyXhSUNINxghcSUedJgj0K8Jy2CGFvMIs2g9 GmsYERu5wTC1lyLFqYOmtRHj+5jm3lm6KooAL0SJ2yUUUKHfBkftwJ+HZ9tSstyhDAhgJa J5/1o7mD9HJv/o5PeK7aHwGoCoSQ9nM6cFB3+k0YjD/5FzwVYgmliG+mKI7pAu6tRiF/bd o/wOMuenSlSsz9g18cQ25kcFeVpfsmaT+o09l9S2PF/Gzzb1V8TTE4hCaLpWMg== 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 4NV9jL01H1zgyl; Sun, 11 Dec 2022 03:48:54 +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 2BB3mrrE076775; Sun, 11 Dec 2022 03:48:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BB3mrhj076774; Sun, 11 Dec 2022 03:48:53 GMT (envelope-from git) Date: Sun, 11 Dec 2022 03:48:53 GMT Message-Id: <202212110348.2BB3mrhj076774@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: 42442d7a6eeb - main - Generalize the VV_CROSSLOCK logic in vfs_lookup() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: 42442d7a6eeb860e00f76aae5858884b44f6cce5 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jah: URL: https://cgit.FreeBSD.org/src/commit/?id=42442d7a6eeb860e00f76aae5858884b44f6cce5 commit 42442d7a6eeb860e00f76aae5858884b44f6cce5 Author: Jason A. Harmening AuthorDate: 2022-10-26 22:25:20 +0000 Commit: Jason A. Harmening CommitDate: 2022-12-11 04:02:38 +0000 Generalize the VV_CROSSLOCK logic in vfs_lookup() When VV_CROSSLOCK is present, the lock for the vnode at the current stage of lookup must be held across the VFS_ROOT() call for the filesystem mounted at the vnode. Since VV_CROSSLOCK implies that the root vnode reuses the already-held lock, the possibility for recursion should be made clear in the flags passed to VFS_ROOT(). For cases in which the lock is held exclusive, this means passing LK_CANRECURSE. For cases in which the lock is held shared, it means clearing LK_NODDLKTREAT to allow VFS_ROOT() to potentially recurse on the shared lock even in the presence of an exclusive waiter. That the existing code works for unionfs is due to a coincidence of the current unionfs implementation. Reviewed by: kib Tested by: pho Differential Revision: https://reviews.freebsd.org/D37458 --- sys/kern/vfs_lookup.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index cc41849de532..404c41a1bf2c 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -1265,14 +1265,28 @@ good: crosslock = (dp->v_vflag & VV_CROSSLOCK) != 0; crosslkflags = compute_cn_lkflags(mp, cnp->cn_lkflags, cnp->cn_flags); - if (__predict_false(crosslock) && - (crosslkflags & LK_EXCLUSIVE) != 0 && - VOP_ISLOCKED(dp) != LK_EXCLUSIVE) { - vn_lock(dp, LK_UPGRADE | LK_RETRY); - if (VN_IS_DOOMED(dp)) { - error = ENOENT; - goto bad2; - } + if (__predict_false(crosslock)) { + /* + * We are going to be holding the vnode lock, which + * in this case is shared by the root vnode of the + * filesystem mounted at mp, across the call to + * VFS_ROOT(). Make the situation clear to the + * filesystem by passing LK_CANRECURSE if the + * lock is held exclusive, or by clearinng + * LK_NODDLKTREAT to allow recursion on the shared + * lock in the presence of an exclusive waiter. + */ + if (VOP_ISLOCKED(dp) == LK_EXCLUSIVE) { + crosslkflags &= ~LK_SHARED; + crosslkflags |= LK_EXCLUSIVE | LK_CANRECURSE; + } else if ((crosslkflags & LK_EXCLUSIVE) != 0) { + vn_lock(dp, LK_UPGRADE | LK_RETRY); + if (VN_IS_DOOMED(dp)) { + error = ENOENT; + goto bad2; + } + } else + crosslkflags &= ~LK_NODDLKTREAT; } if (vfs_busy(mp, 0) != 0) continue;