Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/ad-namecache]: src/sys Make cwdinfo use mostly lockless, and largely hid...
details: https://anonhg.NetBSD.org/src/rev/0b3a08b1152e
branches: ad-namecache
changeset: 744141:0b3a08b1152e
user: ad <ad%NetBSD.org@localhost>
date: Sat Jan 25 15:54:03 2020 +0000
description:
Make cwdinfo use mostly lockless, and largely hide the details in vfs_cwd.c.
diffstat:
sys/compat/netbsd32/netbsd32_fs.c | 14 +--
sys/kern/kern_exec.c | 23 +++---
sys/kern/kern_proc.c | 18 ++--
sys/kern/uipc_usrreq.c | 22 ++++--
sys/kern/vfs_cwd.c | 133 +++++++++++++++++++++++++++++++++++--
sys/kern/vfs_getcwd.c | 13 +--
sys/kern/vfs_lookup.c | 11 +-
sys/kern/vfs_mount.c | 34 +++++----
sys/kern/vfs_subr.c | 17 ++--
sys/kern/vfs_syscalls.c | 108 ++++++++++++++----------------
sys/kern/vfs_vnode.c | 6 +-
sys/miscfs/procfs/procfs_vnops.c | 48 +++++++------
sys/sys/filedesc.h | 14 ++-
sys/sys/vfs_syscalls.h | 4 +-
14 files changed, 297 insertions(+), 168 deletions(-)
diffs (truncated from 1114 to 300 lines):
diff -r c11c04aa1297 -r 0b3a08b1152e sys/compat/netbsd32/netbsd32_fs.c
--- a/sys/compat/netbsd32/netbsd32_fs.c Fri Jan 24 16:49:12 2020 +0000
+++ b/sys/compat/netbsd32/netbsd32_fs.c Sat Jan 25 15:54:03 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_fs.c,v 1.85 2019/09/26 01:32:09 christos Exp $ */
+/* $NetBSD: netbsd32_fs.c,v 1.85.2.1 2020/01/25 15:54:03 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.85 2019/09/26 01:32:09 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.85.2.1 2020/01/25 15:54:03 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -740,13 +740,12 @@
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 cwdinfo *cwdi;
+ struct vnode *dvp;
if (len > MAXPATHLEN*4)
len = MAXPATHLEN*4;
@@ -764,11 +763,10 @@
* limit it to N/2 vnodes for an N byte buffer.
*/
#define GETCWD_CHECK_ACCESS 0x0001
- cwdi = p->p_cwdi;
- rw_enter(&cwdi->cwdi_lock, RW_READER);
- error = getcwd_common (cwdi->cwdi_cdir, NULL, &bp, path, len/2,
+ dvp = cwdcdir();
+ error = getcwd_common (dvp, NULL, &bp, path, len/2,
GETCWD_CHECK_ACCESS, l);
- rw_exit(&cwdi->cwdi_lock);
+ vrele(dvp);
if (error)
goto out;
diff -r c11c04aa1297 -r 0b3a08b1152e sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c Fri Jan 24 16:49:12 2020 +0000
+++ b/sys/kern/kern_exec.c Sat Jan 25 15:54:03 2020 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: kern_exec.c,v 1.485.2.1 2020/01/17 21:47:35 ad Exp $ */
+/* $NetBSD: kern_exec.c,v 1.485.2.2 2020/01/25 15:54:03 ad Exp $ */
/*-
- * Copyright (c) 2008, 2019 The NetBSD Foundation, Inc.
+ * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.485.2.1 2020/01/17 21:47:35 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.485.2.2 2020/01/25 15:54:03 ad Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@@ -664,7 +664,7 @@
char *path, *bp;
size_t len, tlen;
int error;
- struct cwdinfo *cwdi;
+ struct vnode *dvp;
path = PNBUF_GET();
if (seg == UIO_SYSSPACE) {
@@ -690,11 +690,10 @@
memmove(bp, path, len);
*(--bp) = '/';
- cwdi = l->l_proc->p_cwdi;
- rw_enter(&cwdi->cwdi_lock, RW_READER);
- error = getcwd_common(cwdi->cwdi_cdir, NULL, &bp, path, MAXPATHLEN / 2,
+ dvp = cwdcdir();
+ error = getcwd_common(dvp, NULL, &bp, path, MAXPATHLEN / 2,
GETCWD_CHECK_ACCESS, l);
- rw_exit(&cwdi->cwdi_lock);
+ vrele(dvp);
if (error)
goto err;
@@ -1111,6 +1110,7 @@
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. */
@@ -1119,9 +1119,10 @@
emul_find_root(l, epp);
/* Any old emulation root got removed by fdcloseexec */
- 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);
+ KASSERT(p == curproc);
+ cwdi = cwdenter(RW_WRITER);
+ cwdi->cwdi_edir = epp->ep_emul_root;
+ cwdexit(cwdi);
epp->ep_emul_root = NULL;
if (epp->ep_interp != NULL)
vrele(epp->ep_interp);
diff -r c11c04aa1297 -r 0b3a08b1152e sys/kern/kern_proc.c
--- a/sys/kern/kern_proc.c Fri Jan 24 16:49:12 2020 +0000
+++ b/sys/kern/kern_proc.c Sat Jan 25 15:54:03 2020 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: kern_proc.c,v 1.239 2019/12/31 13:07:13 ad Exp $ */
+/* $NetBSD: kern_proc.c,v 1.239.2.1 2020/01/25 15:54:03 ad Exp $ */
/*-
- * Copyright (c) 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.239 2019/12/31 13:07:13 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.239.2.1 2020/01/25 15:54:03 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_kstack.h"
@@ -106,6 +106,7 @@
#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>
@@ -470,7 +471,7 @@
p->p_cred = cred0;
/* Create the CWD info. */
- rw_init(&cwdi0.cwdi_lock);
+ mutex_init(&cwdi0.cwdi_lock, MUTEX_DEFAULT, IPL_NONE);
/* Create the limits structures. */
mutex_init(&limit0.pl_lock, MUTEX_DEFAULT, IPL_NONE);
@@ -2588,7 +2589,7 @@
struct proc *p;
char *path;
char *bp, *bend;
- struct cwdinfo *cwdi;
+ const struct cwdinfo *cwdi;
struct vnode *vp;
size_t len, lenused;
@@ -2603,11 +2604,12 @@
bend = bp;
*(--bp) = '\0';
- cwdi = p->p_cwdi;
- rw_enter(&cwdi->cwdi_lock, RW_READER);
+ cwdi = cwdlock(p);
vp = cwdi->cwdi_cdir;
+ vref(vp);
+ cwdunlock(p);
error = getcwd_common(vp, NULL, &bp, path, len/2, 0, l);
- rw_exit(&cwdi->cwdi_lock);
+ vrele(vp);
if (error)
goto out;
diff -r c11c04aa1297 -r 0b3a08b1152e sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c Fri Jan 24 16:49:12 2020 +0000
+++ b/sys/kern/uipc_usrreq.c Sat Jan 25 15:54:03 2020 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: uipc_usrreq.c,v 1.194 2019/07/29 09:42:17 maxv Exp $ */
+/* $NetBSD: uipc_usrreq.c,v 1.194.4.1 2020/01/25 15:54:03 ad Exp $ */
/*-
- * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2000, 2004, 2008, 2009, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.194 2019/07/29 09:42:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.194.4.1 2020/01/25 15:54:03 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -1395,6 +1395,7 @@
{
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;
@@ -1404,9 +1405,11 @@
goto noop;
int * const fdp = kmem_alloc(nfds * sizeof(int), KM_SLEEP);
- rw_enter(&p->p_cwdi->cwdi_lock, RW_READER);
+
+ KASSERT(l == curlwp);
/* 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++;
@@ -1420,15 +1423,15 @@
* sure it's inside the subtree we're allowed
* to access.
*/
- if (p->p_cwdi->cwdi_rdir != NULL && fp->f_type == DTYPE_VNODE) {
+ if (rvp != NULL && fp->f_type == DTYPE_VNODE) {
vnode_t *vp = fp->f_vnode;
- if ((vp->v_type == VDIR) &&
- !vn_isunder(vp, p->p_cwdi->cwdi_rdir, l)) {
+ if ((vp->v_type == VDIR) && !vn_isunder(vp, rvp, l)) {
error = EPERM;
goto out;
}
}
}
+
restart:
/*
@@ -1506,7 +1509,6 @@
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:
@@ -1516,6 +1518,10 @@
KASSERT(cm->cmsg_len <= rights->m_len);
memset(&mtod(rights, char *)[cm->cmsg_len], 0, rights->m_len -
cm->cmsg_len);
+
+ /* Async release please since in the networking code. */
+ if (rvp != NULL)
+ vrele_async(rvp);
return error;
}
diff -r c11c04aa1297 -r 0b3a08b1152e sys/kern/vfs_cwd.c
--- a/sys/kern/vfs_cwd.c Fri Jan 24 16:49:12 2020 +0000
+++ b/sys/kern/vfs_cwd.c Sat Jan 25 15:54:03 2020 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: vfs_cwd.c,v 1.4 2011/02/15 15:54:28 pooka Exp $ */
+/* $NetBSD: vfs_cwd.c,v 1.4.62.1 2020/01/25 15:54:03 ad Exp $ */
/*-
- * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,13 +31,14 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cwd.c,v 1.4 2011/02/15 15:54:28 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cwd.c,v 1.4.62.1 2020/01/25 15:54:03 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 *);
@@ -64,9 +65,8 @@
struct cwdinfo *copy;
cwdi = pool_cache_get(cwdi_cache, PR_WAITOK);
- copy = curproc->p_cwdi;
- rw_enter(©->cwdi_lock, RW_READER);
+ copy = cwdenter(RW_READER);
cwdi->cwdi_cdir = copy->cwdi_cdir;
if (cwdi->cwdi_cdir)
Home |
Main Index |
Thread Index |
Old Index