From owner-svn-src-head@freebsd.org Fri Nov 13 09:42:33 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id F12652D4F6F; Fri, 13 Nov 2020 09:42:33 +0000 (UTC) (envelope-from kib@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CXYRF6Q39z3gyV; Fri, 13 Nov 2020 09:42:33 +0000 (UTC) (envelope-from kib@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 CEFD2160D8; Fri, 13 Nov 2020 09:42:33 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0AD9gXCL090590; Fri, 13 Nov 2020 09:42:33 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0AD9gWim090587; Fri, 13 Nov 2020 09:42:32 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202011130942.0AD9gWim090587@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Fri, 13 Nov 2020 09:42:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367632 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 367632 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Nov 2020 09:42:34 -0000 Author: kib Date: Fri Nov 13 09:42:32 2020 New Revision: 367632 URL: https://svnweb.freebsd.org/changeset/base/367632 Log: Allow some VOPs to return ERELOOKUP to indicate VFS operation restart at top level. Restart syscalls and some sync operations when filesystem indicated ERELOOKUP condition, mostly for VOPs operating on metdata. In particular, lookup results cached in the inode/v_data is no longer valid and needs recalculating. Right now this should be nop. Assert that ERELOOKUP is catched everywhere and not returned to userspace, by asserting that td_errno != ERELOOKUP on syscall return path. In collaboration with: pho Reviewed by: mckusick (previous version), markj Tested by: markj (syzkaller), pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D26136 Modified: head/sys/kern/subr_syscall.c head/sys/kern/uipc_usrreq.c head/sys/kern/vfs_subr.c head/sys/kern/vfs_syscalls.c Modified: head/sys/kern/subr_syscall.c ============================================================================== --- head/sys/kern/subr_syscall.c Fri Nov 13 09:31:57 2020 (r367631) +++ head/sys/kern/subr_syscall.c Fri Nov 13 09:42:32 2020 (r367632) @@ -217,6 +217,8 @@ syscallret(struct thread *td) KASSERT((td->td_pflags & TDP_FORKING) == 0, ("fork() did not clear TDP_FORKING upon completion")); + KASSERT(td->td_errno != ERELOOKUP, + ("ERELOOKUP not consumed syscall %d", td->td_sa.code)); p = td->td_proc; sa = &td->td_sa; Modified: head/sys/kern/uipc_usrreq.c ============================================================================== --- head/sys/kern/uipc_usrreq.c Fri Nov 13 09:31:57 2020 (r367631) +++ head/sys/kern/uipc_usrreq.c Fri Nov 13 09:42:32 2020 (r367632) @@ -671,6 +671,8 @@ restart: vput(nd.ni_dvp); if (error) { vn_finished_write(mp); + if (error == ERELOOKUP) + goto restart; goto error; } vp = nd.ni_vp; Modified: head/sys/kern/vfs_subr.c ============================================================================== --- head/sys/kern/vfs_subr.c Fri Nov 13 09:31:57 2020 (r367631) +++ head/sys/kern/vfs_subr.c Fri Nov 13 09:42:32 2020 (r367632) @@ -1937,7 +1937,10 @@ bufobj_invalbuf(struct bufobj *bo, int flags, int slpf } if (bo->bo_dirty.bv_cnt > 0) { BO_UNLOCK(bo); - if ((error = BO_SYNC(bo, MNT_WAIT)) != 0) + do { + error = BO_SYNC(bo, MNT_WAIT); + } while (error == ERELOOKUP); + if (error != 0) return (error); /* * XXX We could save a lock/unlock if this was only @@ -3678,7 +3681,9 @@ loop: vm_object_page_clean(vp->v_object, 0, 0, 0); VM_OBJECT_WUNLOCK(vp->v_object); } - error = VOP_FSYNC(vp, MNT_WAIT, td); + do { + error = VOP_FSYNC(vp, MNT_WAIT, td); + } while (error == ERELOOKUP); if (error != 0) { VOP_UNLOCK(vp); vdrop(vp); Modified: head/sys/kern/vfs_syscalls.c ============================================================================== --- head/sys/kern/vfs_syscalls.c Fri Nov 13 09:31:57 2020 (r367631) +++ head/sys/kern/vfs_syscalls.c Fri Nov 13 09:42:32 2020 (r367632) @@ -1384,6 +1384,8 @@ restart: NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_dvp); vn_finished_write(mp); + if (error == ERELOOKUP) + goto restart; return (error); } @@ -1470,6 +1472,8 @@ out: vput(nd.ni_dvp); vn_finished_write(mp); NDFREE(&nd, NDF_ONLY_PNBUF); + if (error == ERELOOKUP) + goto restart; return (error); } @@ -1568,7 +1572,7 @@ kern_linkat(struct thread *td, int fd1, int fd2, const return (error); NDFREE(&nd, NDF_ONLY_PNBUF); error = kern_linkat_vp(td, nd.ni_vp, fd2, path2, segflag); - } while (error == EAGAIN); + } while (error == EAGAIN || error == ERELOOKUP); return (error); } @@ -1741,6 +1745,8 @@ out2: NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_dvp); vn_finished_write(mp); + if (error == ERELOOKUP) + goto restart; out: if (segflg != UIO_SYSSPACE) uma_zfree(namei_zone, tmppath); @@ -1791,6 +1797,8 @@ restart: NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_dvp); vn_finished_write(mp); + if (error == ERELOOKUP) + goto restart; return (error); } @@ -1937,6 +1945,8 @@ out: vrele(vp); else vput(vp); + if (error == ERELOOKUP) + goto restart; fdout: if (fp != NULL) fdrop(fp, td); @@ -3395,7 +3405,8 @@ kern_truncate(struct thread *td, const char *path, enu int error; if (length < 0) - return(EINVAL); + return (EINVAL); +retry: NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, pathseg, path, td); if ((error = namei(&nd)) != 0) return (error); @@ -3424,6 +3435,8 @@ kern_truncate(struct thread *td, const char *path, enu vn_finished_write(mp); vn_rangelock_unlock(vp, rl_cookie); vrele(vp); + if (error == ERELOOKUP) + goto retry; return (error); } @@ -3479,6 +3492,7 @@ kern_fsync(struct thread *td, int fd, bool fullsync) if (!fullsync) /* XXXKIB: compete outstanding aio writes */; #endif +retry: error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) goto drop; @@ -3498,6 +3512,8 @@ kern_fsync(struct thread *td, int fd, bool fullsync) error = fullsync ? VOP_FSYNC(vp, MNT_WAIT, td) : VOP_FDATASYNC(vp, td); VOP_UNLOCK(vp); vn_finished_write(mp); + if (error == ERELOOKUP) + goto retry; drop: fdrop(fp, td); return (error); @@ -3679,7 +3695,7 @@ again: * are links to the same vnode), then there is nothing to do. */ if (fvp == tvp) - error = -1; + error = ERESTART; #ifdef MAC else error = mac_vnode_check_rename_to(td->td_ucred, tdvp, @@ -3708,8 +3724,10 @@ out: out1: if (fromnd.ni_startdir) vrele(fromnd.ni_startdir); - if (error == -1) + if (error == ERESTART) return (0); + if (error == ERELOOKUP) + goto again; return (error); } @@ -3803,6 +3821,8 @@ out: if (error == 0) vput(nd.ni_vp); vn_finished_write(mp); + if (error == ERELOOKUP) + goto restart; return (error); } @@ -3903,6 +3923,8 @@ out: vrele(nd.ni_dvp); else vput(nd.ni_dvp); + if (error == ERELOOKUP) + goto restart; fdout: if (fp != NULL) fdrop(fp, td); @@ -4416,7 +4438,8 @@ kern_fhlinkat(struct thread *td, int fd, const char *p if (error != 0) return (error); VOP_UNLOCK(vp); - } while ((error = kern_linkat_vp(td, vp, fd, path, pathseg)) == EAGAIN); + error = kern_linkat_vp(td, vp, fd, path, pathseg); + } while (error == EAGAIN || error == ERELOOKUP); return (error); }