From nobody Thu Nov 25 19:35:08 2021 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 BB04818A4E18; Thu, 25 Nov 2021 19:35:09 +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 4J0Sl12rKJz3Bp3; Thu, 25 Nov 2021 19:35:09 +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 17C5723481; Thu, 25 Nov 2021 19:35:09 +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 1APJZ8VS094702; Thu, 25 Nov 2021 19:35:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1APJZ84i094701; Thu, 25 Nov 2021 19:35:08 GMT (envelope-from git) Date: Thu, 25 Nov 2021 19:35:08 GMT Message-Id: <202111251935.1APJZ84i094701@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 6ddf41faa6f5 - main - swapon: extend the region where the swap vnode is locked 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6ddf41faa6f54738db9b3f313086974b6403d680 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1637868909; 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=t9Y3kr5G2zrG/2yjfHGp/wBKxBR9zTw0O/0Mje5U5TI=; b=GF0ArNVakDIch3MZ0azvOO7W4CqjOEr5gWqeYmW5m01SG2DjYWigXC149Q5GaDyOth4Zx6 AJzbR8wP1QMDOdL+zy/TweoV0Dxxrb4vHS+h3g85bjQ2ExpzgIYpZsM5ButFjgRpgOjKmp rGyp6wOdidjM27pdLO/tKOBb3u3LXy7ajRcDYzkWBX8EgVR/kXmLxVU1uoEOetYAvfFFVc cToEyPAVBv4x18DLT0WOxgCvbWNa7ybhk104s4pp7/qg+BOnp89JgMcYrEyHAzge58WHi8 ytli+uPyuPajm7MzvSGM4UFEr6OTBXQusSCa62h+qfeD6118HwFlfwLCIYtDaA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1637868909; a=rsa-sha256; cv=none; b=jG3uRv6klaYmz2LkHI5Fse82nQhKD+kXmKHFuqH7vyqaA5GRYwghhB/G1V6ZBqtoWrdnM9 v6Blt5YPObqrx71itZOku5wikkrk9l4jzeOWqz6ux+RRegjTxsci5qHs3CmqvBsUI7uGQo E+p1mR302I+InqyAUWXdye6aaCzW15ea2Dv8ev7xxRuN/AaYxQyWg6IblnMsRP0IqwIJHF SH21vk143aQgfMIHf8s6x/rxuXrtjMCX23hKt6Wz1stRur/MpDddfERz9GtpR+mM3SiWTM Vpo3HQK07rolsqtWriVAZQkbvDEW0Lhge9QawDUWRWkZdtM7fM1gZyVidAU8jQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=6ddf41faa6f54738db9b3f313086974b6403d680 commit 6ddf41faa6f54738db9b3f313086974b6403d680 Author: Konstantin Belousov AuthorDate: 2021-11-24 03:06:02 +0000 Commit: Konstantin Belousov CommitDate: 2021-11-25 19:34:44 +0000 swapon: extend the region where the swap vnode is locked to cover VOP_GETATTR() call in sys_swapon(). Move locking from inside swapongeom() and swaponvp() into sys_swapon(). Reported by and tested by: peterj Reviewed by: markj MFC after: 1 week Differential revision: https://reviews.freebsd.org/D33119 --- sys/vm/swap_pager.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index 1a44d699bc05..880e2a1894df 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -2366,8 +2366,8 @@ sys_swapon(struct thread *td, struct swapon_args *uap) goto done; } - NDINIT(&nd, LOOKUP, ISOPEN | FOLLOW | AUDITVNODE1, UIO_USERSPACE, - uap->name, td); + NDINIT(&nd, LOOKUP, ISOPEN | FOLLOW | LOCKLEAF | AUDITVNODE1, + UIO_USERSPACE, uap->name, td); error = namei(&nd); if (error) goto done; @@ -2387,8 +2387,10 @@ sys_swapon(struct thread *td, struct swapon_args *uap) error = swaponvp(td, vp, attr.va_size / DEV_BSIZE); } - if (error) - vrele(vp); + if (error != 0) + vput(vp); + else + VOP_UNLOCK(vp); done: sx_xunlock(&swdev_syscall_lock); return (error); @@ -3012,7 +3014,7 @@ swapongeom(struct vnode *vp) { int error; - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + ASSERT_VOP_ELOCKED(vp, "swapongeom"); if (vp->v_type != VCHR || VN_IS_DOOMED(vp)) { error = ENOENT; } else { @@ -3020,7 +3022,6 @@ swapongeom(struct vnode *vp) error = swapongeom_locked(vp->v_rdev, vp); g_topology_unlock(); } - VOP_UNLOCK(vp); return (error); } @@ -3071,6 +3072,7 @@ swaponvp(struct thread *td, struct vnode *vp, u_long nblks) struct swdevt *sp; int error; + ASSERT_VOP_ELOCKED(vp, "swaponvp"); if (nblks == 0) return (ENXIO); mtx_lock(&sw_dev_mtx); @@ -3082,14 +3084,12 @@ swaponvp(struct thread *td, struct vnode *vp, u_long nblks) } mtx_unlock(&sw_dev_mtx); - (void) vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); #ifdef MAC error = mac_system_check_swapon(td->td_ucred, vp); if (error == 0) #endif error = VOP_OPEN(vp, FREAD | FWRITE, td->td_ucred, td, NULL); - (void) VOP_UNLOCK(vp); - if (error) + if (error != 0) return (error); swaponsomething(vp, vp, nblks, swapdev_strategy, swapdev_close,