Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/uvm Tighten up the locking around vp->v_iflag a little m...



details:   https://anonhg.NetBSD.org/src/rev/2512dea4e901
branches:  trunk
changeset: 969693:2512dea4e901
user:      ad <ad%NetBSD.org@localhost>
date:      Thu Feb 27 22:12:53 2020 +0000

description:
Tighten up the locking around vp->v_iflag a little more after the recent
split of vmobjlock & v_interlock.

diffstat:

 sys/fs/msdosfs/msdosfs_vfsops.c |   6 +++---
 sys/fs/puffs/puffs_vfsops.c     |   8 +++++---
 sys/fs/smbfs/smbfs_vfsops.c     |   6 +++---
 sys/fs/udf/udf_subr.c           |   6 +++---
 sys/kern/vfs_subr.c             |  21 ++++++++++++++++-----
 sys/kern/vfs_vnode.c            |  15 +++++++--------
 sys/kern/vfs_vnops.c            |  11 +++++++++--
 sys/miscfs/genfs/genfs_io.c     |   6 +++---
 sys/nfs/nfs_vfsops.c            |   7 ++++---
 sys/sys/vnode.h                 |   3 ++-
 sys/ufs/ext2fs/ext2fs_vfsops.c  |   6 +++---
 sys/ufs/ffs/ffs_vfsops.c        |   6 +++---
 sys/uvm/uvm_page.c              |  18 ++++++++++++++----
 sys/uvm/uvm_vnode.c             |  17 +++++++++++++----
 14 files changed, 88 insertions(+), 48 deletions(-)

diffs (truncated from 511 to 300 lines):

diff -r 7e997e3c47b0 -r 2512dea4e901 sys/fs/msdosfs/msdosfs_vfsops.c
--- a/sys/fs/msdosfs/msdosfs_vfsops.c   Thu Feb 27 20:54:24 2020 +0000
+++ b/sys/fs/msdosfs/msdosfs_vfsops.c   Thu Feb 27 22:12:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msdosfs_vfsops.c,v 1.131 2020/01/17 20:08:07 ad Exp $  */
+/*     $NetBSD: msdosfs_vfsops.c,v 1.132 2020/02/27 22:12:53 ad Exp $  */
 
 /*-
  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.131 2020/01/17 20:08:07 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.132 2020/02/27 22:12:53 ad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -1008,7 +1008,7 @@
            dep == NULL || (((dep->de_flag &
            (DE_ACCESS | DE_CREATE | DE_UPDATE | DE_MODIFIED)) == 0) &&
             (LIST_EMPTY(&vp->v_dirtyblkhd) &&
-             UVM_OBJ_IS_CLEAN(&vp->v_uobj))))
+             (vp->v_iflag & VI_ONWORKLST) == 0)))
                return false;
        return true;
 }
diff -r 7e997e3c47b0 -r 2512dea4e901 sys/fs/puffs/puffs_vfsops.c
--- a/sys/fs/puffs/puffs_vfsops.c       Thu Feb 27 20:54:24 2020 +0000
+++ b/sys/fs/puffs/puffs_vfsops.c       Thu Feb 27 22:12:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_vfsops.c,v 1.124 2020/01/17 20:08:08 ad Exp $    */
+/*     $NetBSD: puffs_vfsops.c,v 1.125 2020/02/27 22:12:53 ad Exp $    */
 
 /*
  * Copyright (c) 2005, 2006  Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.124 2020/01/17 20:08:08 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.125 2020/02/27 22:12:53 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -517,7 +517,9 @@
        KASSERT(mutex_owned(vp->v_interlock));
 
        return vp->v_type == VREG &&
-           !(LIST_EMPTY(&vp->v_dirtyblkhd) && UVM_OBJ_IS_CLEAN(&vp->v_uobj));
+           !(LIST_EMPTY(&vp->v_dirtyblkhd) &&
+           (vp->v_iflag & VI_ONWORKLST) == 0);
+
 }
 
 static int
diff -r 7e997e3c47b0 -r 2512dea4e901 sys/fs/smbfs/smbfs_vfsops.c
--- a/sys/fs/smbfs/smbfs_vfsops.c       Thu Feb 27 20:54:24 2020 +0000
+++ b/sys/fs/smbfs/smbfs_vfsops.c       Thu Feb 27 22:12:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: smbfs_vfsops.c,v 1.107 2020/01/17 20:08:08 ad Exp $    */
+/*     $NetBSD: smbfs_vfsops.c,v 1.108 2020/02/27 22:12:54 ad Exp $    */
 
 /*
  * Copyright (c) 2000-2001, Boris Popov
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: smbfs_vfsops.c,v 1.107 2020/01/17 20:08:08 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smbfs_vfsops.c,v 1.108 2020/02/27 22:12:54 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -406,7 +406,7 @@
 
        if ((vp->v_type == VNON || (np->n_flag & NMODIFIED) == 0) &&
             LIST_EMPTY(&vp->v_dirtyblkhd) &&
-            UVM_OBJ_IS_CLEAN(&vp->v_uobj))
+            (vp->v_iflag & VI_ONWORKLST) == 0)
                return false;
 
        return true;
diff -r 7e997e3c47b0 -r 2512dea4e901 sys/fs/udf/udf_subr.c
--- a/sys/fs/udf/udf_subr.c     Thu Feb 27 20:54:24 2020 +0000
+++ b/sys/fs/udf/udf_subr.c     Thu Feb 27 22:12:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: udf_subr.c,v 1.148 2020/01/17 20:08:08 ad Exp $ */
+/* $NetBSD: udf_subr.c,v 1.149 2020/02/27 22:12:54 ad Exp $ */
 
 /*
  * Copyright (c) 2006, 2008 Reinoud Zandijk
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.148 2020/01/17 20:08:08 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udf_subr.c,v 1.149 2020/02/27 22:12:54 ad Exp $");
 #endif /* not lint */
 
 
@@ -6448,7 +6448,7 @@
                return false;
        if ((udf_node->i_flags & (IN_ACCESSED | IN_UPDATE | IN_MODIFIED)) == 0)
                return false;
-       if (LIST_EMPTY(&vp->v_dirtyblkhd) && UVM_OBJ_IS_CLEAN(&vp->v_uobj))
+       if (LIST_EMPTY(&vp->v_dirtyblkhd) && (vp->v_iflag & VI_ONWORKLST) == 0)
                return false;
 
        return true;
diff -r 7e997e3c47b0 -r 2512dea4e901 sys/kern/vfs_subr.c
--- a/sys/kern/vfs_subr.c       Thu Feb 27 20:54:24 2020 +0000
+++ b/sys/kern/vfs_subr.c       Thu Feb 27 22:12:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_subr.c,v 1.481 2020/02/23 22:14:03 ad Exp $        */
+/*     $NetBSD: vfs_subr.c,v 1.482 2020/02/27 22:12:54 ad Exp $        */
 
 /*-
  * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008, 2019, 2020
@@ -69,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.481 2020/02/23 22:14:03 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.482 2020/02/27 22:12:54 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -421,8 +421,13 @@
        if (LIST_NEXT(bp, b_vnbufs) != NOLIST)
                bufremvn(bp);
 
-       if (vp->v_uobj.uo_npages == 0 && (vp->v_iflag & VI_ONWORKLST) &&
+       if ((vp->v_iflag & (VI_ONWORKLST | VI_PAGES)) == VI_ONWORKLST &&
            LIST_FIRST(&vp->v_dirtyblkhd) == NULL) {
+               /*
+                * Okay to clear VI_WRMAPDIRTY without the uvm_object locked
+                * here, because new pages can't be inserted without first
+                * taking v_interlock (which is held here).
+                */
                vp->v_iflag &= ~VI_WRMAPDIRTY;
                vn_syncer_remove_from_worklist(vp);
        }
@@ -461,9 +466,15 @@
         */
        if ((bp->b_oflags & BO_DELWRI) == 0) {
                listheadp = &vp->v_cleanblkhd;
-               if (vp->v_uobj.uo_npages == 0 &&
-                   (vp->v_iflag & VI_ONWORKLST) &&
+               if ((vp->v_iflag & (VI_ONWORKLST | VI_PAGES)) ==
+                   VI_ONWORKLST &&
                    LIST_FIRST(&vp->v_dirtyblkhd) == NULL) {
+                       /*
+                        * Okay to clear VI_WRMAPDIRTY without the
+                        * uvm_object locked here, because new pages can't
+                        * be inserted without first taking v_interlock
+                        * (which is held here).
+                        */
                        vp->v_iflag &= ~VI_WRMAPDIRTY;
                        vn_syncer_remove_from_worklist(vp);
                }
diff -r 7e997e3c47b0 -r 2512dea4e901 sys/kern/vfs_vnode.c
--- a/sys/kern/vfs_vnode.c      Thu Feb 27 20:54:24 2020 +0000
+++ b/sys/kern/vfs_vnode.c      Thu Feb 27 22:12:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnode.c,v 1.112 2020/02/23 22:14:04 ad Exp $       */
+/*     $NetBSD: vfs_vnode.c,v 1.113 2020/02/27 22:12:54 ad Exp $       */
 
 /*-
  * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc.
@@ -155,7 +155,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.112 2020/02/23 22:14:04 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.113 2020/02/27 22:12:54 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -843,20 +843,18 @@
                VOP_INACTIVE(vp, &recycle);
                if (!recycle)
                        VOP_UNLOCK(vp);
+               rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
                mutex_enter(vp->v_interlock);
                VSTATE_CHANGE(vp, VS_BLOCKED, VS_LOADED);
                if (!recycle) {
                        if (vtryrele(vp)) {
                                mutex_exit(vp->v_interlock);
+                               rw_exit(vp->v_uobj.vmobjlock);
                                return;
                        }
                }
 
-               /*
-                * Take care of space accounting.  We hold the last ref so
-                * it's OK to update VM related fields in v_iflag without
-                * holding vmobjlock: nobody else will be looking at them.
-                */
+               /* Take care of space accounting. */
                if ((vp->v_iflag & VI_EXECMAP) != 0 &&
                    vp->v_uobj.uo_npages != 0) {
                        cpu_count(CPU_COUNT_EXECPAGES, -vp->v_uobj.uo_npages);
@@ -864,6 +862,7 @@
                }
                vp->v_iflag &= ~(VI_TEXT|VI_EXECMAP|VI_WRMAP);
                vp->v_vflag &= ~VV_MAPPED;
+               rw_exit(vp->v_uobj.vmobjlock);
 
                /*
                 * Recycle the vnode if the file is now unused (unlinked),
@@ -1728,7 +1727,7 @@
        }
 
        KASSERT(vp->v_data == NULL);
-       KASSERT(vp->v_uobj.uo_npages == 0);
+       KASSERT((vp->v_iflag & VI_PAGES) == 0);
 
        if (vp->v_type == VREG && vp->v_ractx != NULL) {
                uvm_ra_freectx(vp->v_ractx);
diff -r 7e997e3c47b0 -r 2512dea4e901 sys/kern/vfs_vnops.c
--- a/sys/kern/vfs_vnops.c      Thu Feb 27 20:54:24 2020 +0000
+++ b/sys/kern/vfs_vnops.c      Thu Feb 27 22:12:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnops.c,v 1.206 2020/02/23 15:46:41 ad Exp $       */
+/*     $NetBSD: vfs_vnops.c,v 1.207 2020/02/27 22:12:54 ad Exp $       */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.206 2020/02/23 15:46:41 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.207 2020/02/27 22:12:54 ad Exp $");
 
 #include "veriexec.h"
 
@@ -339,6 +339,7 @@
                return;
        }
 
+       rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
        mutex_enter(vp->v_interlock);
        if ((vp->v_iflag & VI_EXECMAP) == 0) {
                cpu_count(CPU_COUNT_FILEPAGES, -vp->v_uobj.uo_npages);
@@ -346,6 +347,7 @@
                vp->v_iflag |= VI_EXECMAP;
        }
        mutex_exit(vp->v_interlock);
+       rw_exit(vp->v_uobj.vmobjlock);
 }
 
 /*
@@ -361,10 +363,12 @@
                return (0);
        }
 
+       rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
        mutex_enter(vp->v_interlock);
        if (vp->v_writecount != 0) {
                KASSERT((vp->v_iflag & VI_TEXT) == 0);
                mutex_exit(vp->v_interlock);
+               rw_exit(vp->v_uobj.vmobjlock);
                return (ETXTBSY);
        }
        if ((vp->v_iflag & VI_EXECMAP) == 0) {
@@ -373,6 +377,7 @@
        }
        vp->v_iflag |= (VI_TEXT | VI_EXECMAP);
        mutex_exit(vp->v_interlock);
+       rw_exit(vp->v_uobj.vmobjlock);
        return (0);
 }
 
@@ -979,9 +984,11 @@
                vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
                vp->v_vflag |= VV_MAPPED;
                if (needwritemap) {
+                       rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
                        mutex_enter(vp->v_interlock);
                        vp->v_iflag |= VI_WRMAP;
                        mutex_exit(vp->v_interlock);
+                       rw_exit(vp->v_uobj.vmobjlock);
                }
                VOP_UNLOCK(vp);
        }
diff -r 7e997e3c47b0 -r 2512dea4e901 sys/miscfs/genfs/genfs_io.c
--- a/sys/miscfs/genfs/genfs_io.c       Thu Feb 27 20:54:24 2020 +0000
+++ b/sys/miscfs/genfs/genfs_io.c       Thu Feb 27 22:12:53 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: genfs_io.c,v 1.87 2020/02/24 20:49:51 ad Exp $ */
+/*     $NetBSD: genfs_io.c,v 1.88 2020/02/27 22:12:54 ad Exp $ */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>



Home | Main Index | Thread Index | Old Index