From a6a4e9ecd6b6ca6397be82b02b287bf7a0d9e188 Mon Sep 17 00:00:00 2001 From: riastradh Date: Mon, 28 Mar 2022 12:37:18 +0000 Subject: [PATCH] specfs: Wait for last close in spec_node_revoke. Otherwise, revoke -- and vdevgone, in the detach path of removable devices -- may complete while I/O operations are still running concurrently. --- sys/miscfs/specfs/spec_vnops.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sys/miscfs/specfs/spec_vnops.c b/sys/miscfs/specfs/spec_vnops.c index 34f8e70ca405..6674cbdf3cf9 100644 --- a/sys/miscfs/specfs/spec_vnops.c +++ b/sys/miscfs/specfs/spec_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: spec_vnops.c,v 1.204 2022/03/28 12:37:09 riastradh Exp $ */ +/* $NetBSD: spec_vnops.c,v 1.205 2022/03/28 12:37:18 riastradh Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.204 2022/03/28 12:37:09 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.205 2022/03/28 12:37:18 riastradh Exp $"); #include #include @@ -597,6 +597,16 @@ spec_node_revoke(vnode_t *vp) mutex_enter(&device_lock); KASSERT(sn->sn_opencnt == 0); } + + /* + * We may have revoked the vnode in this thread while another + * thread was in the middle of spec_close, in the window when + * spec_close releases the vnode lock to call .d_close for the + * last close. In that case, wait for the concurrent + * spec_close to complete. + */ + while (sd->sd_closing) + cv_wait(&specfs_iocv, &device_lock); mutex_exit(&device_lock); }