diff options
| author | 2020-03-13 10:07:01 +0000 | |
|---|---|---|
| committer | 2020-03-13 10:07:01 +0000 | |
| commit | 9af56a697ae2af4a65b068bf9b7fc1685644e504 (patch) | |
| tree | 6513ab14c4cbab14877e621b1bd21a1e70bce8c4 | |
| parent | Anthony Steinhauser reports that 32-bit arm cpus have the same speculation (diff) | |
| download | wireguard-openbsd-9af56a697ae2af4a65b068bf9b7fc1685644e504.tar.xz wireguard-openbsd-9af56a697ae2af4a65b068bf9b7fc1685644e504.zip | |
In order to unlock flock(2), make writes to the f_iflags field of struct
file atomic. This also gets rid of the last kernel lock protected field
in the scope of struct file.
ok mpi@ visa@
| -rw-r--r-- | sys/kern/kern_descrip.c | 8 | ||||
| -rw-r--r-- | sys/kern/vfs_syscalls.c | 6 | ||||
| -rw-r--r-- | sys/sys/file.h | 5 | ||||
| -rw-r--r-- | sys/sys/sysctl.h | 4 |
4 files changed, 11 insertions, 12 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 059a62120a0..1b79eefaf7d 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_descrip.c,v 1.200 2020/02/26 13:54:52 visa Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.201 2020/03/13 10:07:01 anton Exp $ */ /* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */ /* @@ -707,7 +707,7 @@ fdinsert(struct filedesc *fdp, int fd, int flags, struct file *fp) mtx_enter(&fhdlk); if ((fp->f_iflags & FIF_INSERTED) == 0) { - fp->f_iflags |= FIF_INSERTED; + atomic_setbits_int(&fp->f_iflags, FIF_INSERTED); if ((fq = fdp->fd_ofiles[0]) != NULL) { LIST_INSERT_AFTER(fq, fp, f_list); } else { @@ -1317,7 +1317,7 @@ sys_flock(struct proc *p, void *v, register_t *retval) lf.l_len = 0; if (how & LOCK_UN) { lf.l_type = F_UNLCK; - fp->f_iflags &= ~FIF_HASLOCK; + atomic_clearbits_int(&fp->f_iflags, FIF_HASLOCK); error = VOP_ADVLOCK(vp, (caddr_t)fp, F_UNLCK, &lf, F_FLOCK); goto out; } @@ -1329,7 +1329,7 @@ sys_flock(struct proc *p, void *v, register_t *retval) error = EINVAL; goto out; } - fp->f_iflags |= FIF_HASLOCK; + atomic_setbits_int(&fp->f_iflags, FIF_HASLOCK); if (how & LOCK_NB) error = VOP_ADVLOCK(vp, (caddr_t)fp, F_SETLK, &lf, F_FLOCK); else diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 34dc786d60f..3a8c9208f9e 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_syscalls.c,v 1.342 2020/01/30 15:36:11 visa Exp $ */ +/* $OpenBSD: vfs_syscalls.c,v 1.343 2020/03/13 10:07:01 anton Exp $ */ /* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */ /* @@ -1188,7 +1188,7 @@ doopenat(struct proc *p, int fd, const char *path, int oflags, mode_t mode, goto out; } vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); - fp->f_iflags |= FIF_HASLOCK; + atomic_setbits_int(&fp->f_iflags, FIF_HASLOCK); } if (localtrunc) { if ((fp->f_flag & FWRITE) == 0) @@ -1457,7 +1457,7 @@ sys_fhopen(struct proc *p, void *v, register_t *retval) goto bad; } vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); - fp->f_iflags |= FIF_HASLOCK; + atomic_setbits_int(&fp->f_iflags, FIF_HASLOCK); } VOP_UNLOCK(vp); *retval = indx; diff --git a/sys/sys/file.h b/sys/sys/file.h index c52d9c8e089..f638c1507b6 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -1,4 +1,4 @@ -/* $OpenBSD: file.h,v 1.60 2020/02/01 08:57:27 anton Exp $ */ +/* $OpenBSD: file.h,v 1.61 2020/03/13 10:07:01 anton Exp $ */ /* $NetBSD: file.h,v 1.11 1995/03/26 20:24:13 jtc Exp $ */ /* @@ -75,7 +75,6 @@ struct fileops { * a atomic operations * f per file `f_mtx' * v vnode lock - * k kernel lock */ struct file { LIST_ENTRY(file) f_list;/* [F] list of active files */ @@ -86,7 +85,7 @@ struct file { #define DTYPE_PIPE 3 /* pipe */ #define DTYPE_KQUEUE 4 /* event queue */ #define DTYPE_DMABUF 5 /* DMA buffer (for DRM) */ - int f_iflags; /* [k] internal flags */ + u_int f_iflags; /* [a] internal flags */ int f_type; /* [I] descriptor type */ u_int f_count; /* [a] reference count */ struct ucred *f_cred; /* [I] credentials associated with descriptor */ diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 7848b7059be..9e2fc55ce52 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.204 2020/02/16 07:55:30 anton Exp $ */ +/* $OpenBSD: sysctl.h,v 1.205 2020/03/13 10:07:01 anton Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -735,7 +735,7 @@ do { \ struct kinfo_file { uint64_t f_fileaddr; /* PTR: address of struct file */ uint32_t f_flag; /* UINT: flags (see fcntl.h) */ - uint32_t f_iflags; /* INT: internal flags */ + uint32_t f_iflags; /* UINT: internal flags */ uint32_t f_type; /* INT: descriptor type */ uint32_t f_count; /* UINT: reference count */ uint32_t f_msgcount; /* UINT: references from msg queue */ |
