Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/sys Revert the changes made in February to make cwdinfo ...
details: https://anonhg.NetBSD.org/src/rev/c82e8cd6d613
branches: trunk
changeset: 971333:c82e8cd6d613
user: ad <ad%NetBSD.org@localhost>
date: Tue Apr 21 21:42:47 2020 +0000
description:
Revert the changes made in February to make cwdinfo use mostly lockless,
which relied on taking extra vnode refs.
Having benchmarked various experimental changes over the past few months it
seems that it's better to avoid vnode refs as much as possible. cwdi_lock
as a RW lock already did that to some extent for getcwd() and will permit
the same for namei() too.
diffstat:
sys/compat/netbsd32/netbsd32_fs.c | 14 ++-
sys/kern/kern_exec.c | 21 ++---
sys/kern/kern_proc.c | 16 ++--
sys/kern/uipc_usrreq.c | 21 ++---
sys/kern/vfs_cwd.c | 131 ++-----------------------------------
sys/kern/vfs_getcwd.c | 13 ++-
sys/kern/vfs_lookup.c | 11 +-
sys/kern/vfs_mount.c | 32 +++-----
sys/kern/vfs_subr.c | 15 ++--
sys/kern/vfs_syscalls.c | 63 ++++++++++--------
sys/miscfs/procfs/procfs_vnops.c | 46 ++++++------
sys/sys/filedesc.h | 12 +--
12 files changed, 133 insertions(+), 262 deletions(-)
diffs (truncated from 958 to 300 lines):
diff -r 2d8dbcebf9e5 -r c82e8cd6d613 sys/compat/netbsd32/netbsd32_fs.c
--- a/sys/compat/netbsd32/netbsd32_fs.c Tue Apr 21 21:39:07 2020 +0000
+++ b/sys/compat/netbsd32/netbsd32_fs.c Tue Apr 21 21:42:47 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_fs.c,v 1.87 2020/02/23 22:14:03 ad Exp $ */
+/* $NetBSD: netbsd32_fs.c,v 1.88 2020/04/21 21:42:47 ad Exp $ */
/*
* Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.87 2020/02/23 22:14:03 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.88 2020/04/21 21:42:47 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -740,12 +740,13 @@
syscallarg(char *) bufp;
syscallarg(size_t) length;
} */
+ struct proc *p = l->l_proc;
int error;
char *path;
char *bp, *bend;
int len = (int)SCARG(uap, length);
int lenused;
- struct vnode *dvp;
+ struct cwdinfo *cwdi;
if (len > MAXPATHLEN*4)
len = MAXPATHLEN*4;
@@ -763,10 +764,11 @@
* limit it to N/2 vnodes for an N byte buffer.
*/
#define GETCWD_CHECK_ACCESS 0x0001
- dvp = cwdcdir();
- error = getcwd_common (dvp, NULL, &bp, path, len/2,
+ cwdi = p->p_cwdi;
+ rw_enter(&cwdi->cwdi_lock, RW_READER);
+ error = getcwd_common (cwdi->cwdi_cdir, NULL, &bp, path, len/2,
GETCWD_CHECK_ACCESS, l);
- vrele(dvp);
+ rw_exit(&cwdi->cwdi_lock);
if (error)
goto out;
diff -r 2d8dbcebf9e5 -r c82e8cd6d613 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c Tue Apr 21 21:39:07 2020 +0000
+++ b/sys/kern/kern_exec.c Tue Apr 21 21:42:47 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exec.c,v 1.497 2020/04/19 20:31:59 thorpej Exp $ */
+/* $NetBSD: kern_exec.c,v 1.498 2020/04/21 21:42:47 ad Exp $ */
/*-
* Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.497 2020/04/19 20:31:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.498 2020/04/21 21:42:47 ad Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@@ -672,7 +672,7 @@
char *path, *bp;
size_t len, tlen;
int error;
- struct vnode *dvp;
+ struct cwdinfo *cwdi;
path = PNBUF_GET();
if (seg == UIO_SYSSPACE) {
@@ -698,10 +698,11 @@
memmove(bp, path, len);
*(--bp) = '/';
- dvp = cwdcdir();
- error = getcwd_common(dvp, NULL, &bp, path, MAXPATHLEN / 2,
+ cwdi = l->l_proc->p_cwdi;
+ rw_enter(&cwdi->cwdi_lock, RW_READER);
+ error = getcwd_common(cwdi->cwdi_cdir, NULL, &bp, path, MAXPATHLEN / 2,
GETCWD_CHECK_ACCESS, l);
- vrele(dvp);
+ rw_exit(&cwdi->cwdi_lock);
if (error)
goto err;
@@ -1118,7 +1119,6 @@
emulexec(struct lwp *l, struct exec_package *epp)
{
struct proc *p = l->l_proc;
- struct cwdinfo *cwdi;
/* The emulation root will usually have been found when we looked
* for the elf interpreter (or similar), if not look now. */
@@ -1127,10 +1127,9 @@
emul_find_root(l, epp);
/* Any old emulation root got removed by fdcloseexec */
- KASSERT(p == curproc);
- cwdi = cwdenter(RW_WRITER);
- cwdi->cwdi_edir = epp->ep_emul_root;
- cwdexit(cwdi);
+ rw_enter(&p->p_cwdi->cwdi_lock, RW_WRITER);
+ p->p_cwdi->cwdi_edir = epp->ep_emul_root;
+ rw_exit(&p->p_cwdi->cwdi_lock);
epp->ep_emul_root = NULL;
if (epp->ep_interp != NULL)
vrele(epp->ep_interp);
diff -r 2d8dbcebf9e5 -r c82e8cd6d613 sys/kern/kern_proc.c
--- a/sys/kern/kern_proc.c Tue Apr 21 21:39:07 2020 +0000
+++ b/sys/kern/kern_proc.c Tue Apr 21 21:42:47 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_proc.c,v 1.245 2020/04/20 16:32:03 maxv Exp $ */
+/* $NetBSD: kern_proc.c,v 1.246 2020/04/21 21:42:47 ad Exp $ */
/*-
* Copyright (c) 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.245 2020/04/20 16:32:03 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.246 2020/04/21 21:42:47 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_kstack.h"
@@ -106,7 +106,6 @@
#include <sys/exec.h>
#include <sys/cpu.h>
#include <sys/compat_stub.h>
-#include <sys/vnode.h>
#include <uvm/uvm_extern.h>
#include <uvm/uvm.h>
@@ -477,7 +476,7 @@
p->p_cred = cred0;
/* Create the CWD info. */
- mutex_init(&cwdi0.cwdi_lock, MUTEX_DEFAULT, IPL_NONE);
+ rw_init(&cwdi0.cwdi_lock);
/* Create the limits structures. */
mutex_init(&limit0.pl_lock, MUTEX_DEFAULT, IPL_NONE);
@@ -2601,7 +2600,7 @@
struct proc *p;
char *path;
char *bp, *bend;
- const struct cwdinfo *cwdi;
+ struct cwdinfo *cwdi;
struct vnode *vp;
size_t len, lenused;
@@ -2616,12 +2615,11 @@
bend = bp;
*(--bp) = '\0';
- cwdi = cwdlock(p);
+ cwdi = p->p_cwdi;
+ rw_enter(&cwdi->cwdi_lock, RW_READER);
vp = cwdi->cwdi_cdir;
- vref(vp);
- cwdunlock(p);
error = getcwd_common(vp, NULL, &bp, path, len/2, 0, l);
- vrele(vp);
+ rw_exit(&cwdi->cwdi_lock);
if (error)
goto out;
diff -r 2d8dbcebf9e5 -r c82e8cd6d613 sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c Tue Apr 21 21:39:07 2020 +0000
+++ b/sys/kern/uipc_usrreq.c Tue Apr 21 21:42:47 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_usrreq.c,v 1.197 2020/02/23 22:14:03 ad Exp $ */
+/* $NetBSD: uipc_usrreq.c,v 1.198 2020/04/21 21:42:47 ad Exp $ */
/*-
* Copyright (c) 1998, 2000, 2004, 2008, 2009, 2020 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.197 2020/02/23 22:14:03 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.198 2020/04/21 21:42:47 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -1395,7 +1395,6 @@
{
struct cmsghdr * const cm = mtod(rights, struct cmsghdr *);
struct proc * const p = l->l_proc;
- struct vnode *rvp = NULL;
file_t **rp;
int error = 0;
@@ -1405,11 +1404,9 @@
goto noop;
int * const fdp = kmem_alloc(nfds * sizeof(int), KM_SLEEP);
-
- KASSERT(l == curlwp);
+ rw_enter(&p->p_cwdi->cwdi_lock, RW_READER);
/* Make sure the recipient should be able to see the files.. */
- rvp = cwdrdir();
rp = (file_t **)CMSG_DATA(cm);
for (size_t i = 0; i < nfds; i++) {
file_t * const fp = *rp++;
@@ -1423,15 +1420,16 @@
* sure it's inside the subtree we're allowed
* to access.
*/
- if (rvp != NULL && fp->f_type == DTYPE_VNODE) {
+ if (p->p_cwdi->cwdi_rdir != NULL && fp->f_type == DTYPE_VNODE) {
vnode_t *vp = fp->f_vnode;
- if ((vp->v_type == VDIR) && !vn_isunder(vp, rvp, l)) {
+ if ((vp->v_type == VDIR) &&
+ !vn_isunder(vp, p->p_cwdi->cwdi_rdir, l)) {
error = EPERM;
goto out;
}
}
}
-
+
restart:
/*
* First loop -- allocate file descriptor table slots for the
@@ -1508,6 +1506,7 @@
cm->cmsg_len = CMSG_LEN(0);
rights->m_len = CMSG_SPACE(0);
}
+ rw_exit(&p->p_cwdi->cwdi_lock);
kmem_free(fdp, nfds * sizeof(int));
noop:
@@ -1517,10 +1516,6 @@
KASSERT(cm->cmsg_len <= rights->m_len);
memset(&mtod(rights, char *)[cm->cmsg_len], 0, rights->m_len -
cm->cmsg_len);
-
- /* Async release since in the networking code. */
- if (rvp != NULL)
- vrele_async(rvp);
return error;
}
diff -r 2d8dbcebf9e5 -r c82e8cd6d613 sys/kern/vfs_cwd.c
--- a/sys/kern/vfs_cwd.c Tue Apr 21 21:39:07 2020 +0000
+++ b/sys/kern/vfs_cwd.c Tue Apr 21 21:42:47 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_cwd.c,v 1.5 2020/02/23 22:14:03 ad Exp $ */
+/* $NetBSD: vfs_cwd.c,v 1.6 2020/04/21 21:42:47 ad Exp $ */
/*-
* Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -31,14 +31,13 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cwd.c,v 1.5 2020/02/23 22:14:03 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cwd.c,v 1.6 2020/04/21 21:42:47 ad Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
#include <sys/filedesc.h>
#include <sys/proc.h>
#include <sys/vnode.h>
-#include <sys/xcall.h>
static int cwdi_ctor(void *, void *, int);
static void cwdi_dtor(void *, void *);
@@ -65,8 +64,9 @@
struct cwdinfo *copy;
cwdi = pool_cache_get(cwdi_cache, PR_WAITOK);
+ copy = curproc->p_cwdi;
- copy = cwdenter(RW_READER);
+ rw_enter(©->cwdi_lock, RW_READER);
cwdi->cwdi_cdir = copy->cwdi_cdir;
if (cwdi->cwdi_cdir)
vref(cwdi->cwdi_cdir);
@@ -78,7 +78,7 @@
vref(cwdi->cwdi_edir);
cwdi->cwdi_cmask = copy->cwdi_cmask;
cwdi->cwdi_refcnt = 1;
- cwdexit(copy);
+ rw_exit(©->cwdi_lock);
return (cwdi);
}
@@ -88,7 +88,7 @@
{
struct cwdinfo *cwdi = obj;
- mutex_init(&cwdi->cwdi_lock, MUTEX_DEFAULT, IPL_NONE);
Home |
Main Index |
Thread Index |
Old Index