From nobody Tue Sep 27 20:01:15 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 4McVqv2tLFz4cnjW; Tue, 27 Sep 2022 20:01:15 +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 4McVqv2P41z49rB; Tue, 27 Sep 2022 20:01:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664308875; 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=C/Js5vh1jpkZyIEPZGOVrfIRV5ktSy3aXyyVCHOO6t8=; b=Ob4RNjCzg7uWYLZDNYbCjMlyLJeZb5+KL0HH+3d9R0RhS5/TGoPNfeND8GgX58qcLsbWPO UmDnCmhykcvuefNWjUEfG3yA/lPGQxYYFiISOTNc2ys4aCezT/yDOX3MMzLxHnLz/xBBPv Vd1SuPe1oi3l243bZUyk5FcDD6udOUU6ECCm6qJxROaIi6YcgQKVR13PsQ6TzbfT2ONQw2 BtOIMtsUekjOefrZUGBzoYCBEdTzJdwRZIzwAWV2tzYiN0oZ42Ans1uEPaLlvt2j/yXUjJ KP6DvAFDBkEaNVP0VQLZLZ8VK9fy+dKu7vzvZnwK4lPLaP4Y1ZfmKT4AkV8tLg== 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 4McVqv1RbhzFGy; Tue, 27 Sep 2022 20:01:15 +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 28RK1Fug073943; Tue, 27 Sep 2022 20:01:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28RK1Fwi073942; Tue, 27 Sep 2022 20:01:15 GMT (envelope-from git) Date: Tue, 27 Sep 2022 20:01:15 GMT Message-Id: <202209272001.28RK1Fwi073942@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: ab17854f974b - main - nfsclient: access v_mount only after the 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: ab17854f974b5671b09139079d98e2068802064b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664308875; 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=C/Js5vh1jpkZyIEPZGOVrfIRV5ktSy3aXyyVCHOO6t8=; b=lGi6gZ/u0sjezVgiP3bfDbGu8NbvbVBFaEy+qhmmgjUZncg6kxmxxrX6DvPlzEkQbADbWp tfRafHXn0Lh4MZ/YpDoiOmNUqz/+W5Dy7Yo6CEIi/ORtPOvh+fDdyBSuKP3lR5z31JDeeR TvWYMQBABuIobVhnTiKDL9z8sES+lgjSTntHLrv5adW0VUuAFJ8GYh7rbGOShqJBxMg8S7 SVayRjL4ss/qWD+sbrCZU9AtPIxI93Xa/BSBU9vOtCl2l1tBFR728TfSr9sz5yAADpRx/P Z93P8KAbVgOOpgs3uxsSNQmhhIZUvyh/D4vWzu3AEKKsypd+UV9kjFnEUCc8rQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664308875; a=rsa-sha256; cv=none; b=TGh0+b+Dl2Ulc8aAg6uc7Mzai8+k/Tb6QKALOPlcUk7WDTXZtDLAij2T5OlVVdaSZ1pF9v xSZJXLc2SgRvOTiYW89XqUaWv6LnCylm1Oer698QFCSQOlfg3mrY4HFtoxIV+9vGWeWvR0 9xkxRZ9YaGWhBc7JFh171Fmq8zSEQGMh6AN+yuUbMoMdbrfzpTA0dfaIKkL73R3G/VrEkN sYJzq4EvWuKb4j+b61H3e092ifnrBBgP96OMNEqQGHyQg3/vcVUzumnh3Fc6kHs4njvloW djzvsLOzSZFlKrYINYGTro0Vq0PYBWePiHyBKABhxANjpDS4K/W+p6XyBiC14A== 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=ab17854f974b5671b09139079d98e2068802064b commit ab17854f974b5671b09139079d98e2068802064b Author: Konstantin Belousov AuthorDate: 2022-09-26 18:10:47 +0000 Commit: Konstantin Belousov CommitDate: 2022-09-27 20:00:51 +0000 nfsclient: access v_mount only after the vnode is locked and we checked that it is not reclaimed. Reviewed by: markj, rmacklem Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D36722 --- sys/fs/nfsclient/nfs_clvnops.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c index 4c6a3b527049..f013b13b0cbe 100644 --- a/sys/fs/nfsclient/nfs_clvnops.c +++ b/sys/fs/nfsclient/nfs_clvnops.c @@ -3894,19 +3894,13 @@ nfs_copy_file_range(struct vop_copy_file_range_args *ap) off_t inoff, outoff; bool consecutive, must_commit, tryoutcred; - ret = ret2 = 0; - nmp = VFSTONFS(invp->v_mount); - mtx_lock(&nmp->nm_mtx); /* NFSv4.2 Copy is not permitted for infile == outfile. */ - if (!NFSHASNFSV4(nmp) || nmp->nm_minorvers < NFSV42_MINORVERSION || - (nmp->nm_privflag & NFSMNTP_NOCOPY) != 0 || invp == outvp) { - mtx_unlock(&nmp->nm_mtx); - error = vn_generic_copy_file_range(ap->a_invp, ap->a_inoffp, - ap->a_outvp, ap->a_outoffp, ap->a_lenp, ap->a_flags, - ap->a_incred, ap->a_outcred, ap->a_fsizetd); - return (error); + if (invp == outvp) { +generic_copy: + return (vn_generic_copy_file_range(invp, ap->a_inoffp, + outvp, ap->a_outoffp, ap->a_lenp, ap->a_flags, + ap->a_incred, ap->a_outcred, ap->a_fsizetd)); } - mtx_unlock(&nmp->nm_mtx); /* Lock both vnodes, avoiding risk of deadlock. */ do { @@ -3933,6 +3927,23 @@ nfs_copy_file_range(struct vop_copy_file_range_args *ap) if (error != 0) return (error); + /* + * More reasons to avoid nfs copy: not NFSv4.2, or explicitly + * disabled. + */ + nmp = VFSTONFS(invp->v_mount); + mtx_lock(&nmp->nm_mtx); + if (!NFSHASNFSV4(nmp) || nmp->nm_minorvers < NFSV42_MINORVERSION || + (nmp->nm_privflag & NFSMNTP_NOCOPY) != 0) { + mtx_unlock(&nmp->nm_mtx); + VOP_UNLOCK(invp); + VOP_UNLOCK(outvp); + if (mp != NULL) + vn_finished_write(mp); + goto generic_copy; + } + mtx_unlock(&nmp->nm_mtx); + /* * Do the vn_rlimit_fsize() check. Should this be above the VOP layer? */ @@ -3959,6 +3970,7 @@ nfs_copy_file_range(struct vop_copy_file_range_args *ap) error = ncl_flush(outvp, MNT_WAIT, curthread, 1, 0); /* Do the actual NFSv4.2 RPC. */ + ret = ret2 = 0; len = *ap->a_lenp; mtx_lock(&nmp->nm_mtx); if ((nmp->nm_privflag & NFSMNTP_NOCONSECUTIVE) == 0)