Move vfs_stall_barrier() from the fd layer into vn_lock() and the vfs layer.
In some cases it can result in a deadlock while suspending.
Discussed with mpi@ and deraadt@
-/* $OpenBSD: kern_descrip.c,v 1.203 2021/10/21 09:59:13 claudio Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.204 2021/10/25 10:24:54 claudio Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
{
struct file *fp;
+ vfs_stall_barrier();
+
if ((u_int)fd >= fdp->fd_nfiles)
return (NULL);
-/* $OpenBSD: vfs_subr.c,v 1.312 2021/10/24 00:02:25 jsg Exp $ */
+/* $OpenBSD: vfs_subr.c,v 1.313 2021/10/25 10:24:54 claudio Exp $ */
/* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */
/*
vfs_stall_barrier(void)
{
if (__predict_false(vfs_stalling)) {
- if (curproc != RWLOCK_OWNER(&vfs_stall_lock)) {
- rw_enter_read(&vfs_stall_lock);
- rw_exit_read(&vfs_stall_lock);
- }
+ rw_enter_read(&vfs_stall_lock);
+ rw_exit_read(&vfs_stall_lock);
}
}
-/* $OpenBSD: vfs_vnops.c,v 1.117 2021/10/21 09:59:14 claudio Exp $ */
+/* $OpenBSD: vfs_vnops.c,v 1.118 2021/10/25 10:24:54 claudio Exp $ */
/* $NetBSD: vfs_vnops.c,v 1.20 1996/02/04 02:18:41 christos Exp $ */
/*
{
int error, xlocked, do_wakeup;
- vfs_stall_barrier();
-
do {
mtx_enter(&vnode_mtx);
if (vp->v_lflag & VXLOCK) {
-/* $OpenBSD: file.h,v 1.63 2021/10/21 09:59:14 claudio Exp $ */
+/* $OpenBSD: file.h,v 1.64 2021/10/25 10:24:54 claudio Exp $ */
/* $NetBSD: file.h,v 1.11 1995/03/26 20:24:13 jtc Exp $ */
/*
#define FIF_INSERTED 0x80 /* present in `filehead' */
#define FREF(fp) \
- atomic_inc_int(&(fp)->f_count)
+ do { \
+ extern void vfs_stall_barrier(void); \
+ vfs_stall_barrier(); \
+ atomic_inc_int(&(fp)->f_count); \
+ } while (0)
#define FRELE(fp,p) \
(atomic_dec_int_nv(&fp->f_count) == 0 ? fdrop(fp, p) : 0)