diff options
| author | riastradh <riastradh@NetBSD.org> | 2022-08-22 00:19:12 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2022-08-22 00:19:12 +0000 |
| commit | 639e3bb52914d4db63014cd38eb63018cdddb9db (patch) | |
| tree | 411749a6651b03d77832bc72f30fe0cb22fb7638 /sys/dev | |
| parent | 6778c43f7397884475ce0fc52f2a19f4ab3b5265 (diff) | |
dk(4): Serialize closing parent's dk_rawvp with opening it.
Otherwise, the following events might happen:
- process 123 had /dev/rdkN open, starts close, enters dk_close_parent
- process 456 opens /dev/rdkM (same parent, different wedge), calls
dk_open_parent
At this point, the block device hasn't yet closed, so dk_open_parent
will fail with EBUSY. This is incorrect -- the chardev is never
supposed to fail with EBUSY, and dkopen/dkclose carefully manage
state to avoid opening the block device while it's still open. The
problem is that dkopen in process 456 didn't wait for vn_close
in process 123 to finish before calling VOP_OPEN.
(Note: If it were the _same_ chardev /dev/rdkN in both processes,
then spec_open/close would prevent this. But since it's a
_different_ chardev, spec_open/close assume that concurrency is OK,
and it's the driver's responsibility to serialize access to the
parent disk which, unbeknownst to spec_open/close, is shared between
dkN and dkM.)
It appears that the vn_close call was previously moved outside
dk_rawlock in 2010 to work around an unrelated bug in raidframe that
had already been fixed in HEAD:
Crash pointing to dk_rawlock and raidclose:
https://mail-index.netbsd.org/tech-kern/2010/07/27/msg008612.html
Change working around that crash:
https://mail-index.netbsd.org/source-changes/2010/08/04/msg012270.html
Change removing raidclose -> mutex_destroy(&dk_rawlock) path:
https://mail-index.netbsd.org/source-changes/2009/07/23/msg223381.html
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/dkwedge/dk.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/sys/dev/dkwedge/dk.c b/sys/dev/dkwedge/dk.c index 97430e76da1..9379ebadf9e 100644 --- a/sys/dev/dkwedge/dk.c +++ b/sys/dev/dkwedge/dk.c @@ -1,4 +1,4 @@ -/* $NetBSD: dk.c,v 1.112 2022/06/11 18:17:00 martin Exp $ */ +/* $NetBSD: dk.c,v 1.113 2022/08/22 00:19:12 riastradh Exp $ */ /*- * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.112 2022/06/11 18:17:00 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.113 2022/08/22 00:19:12 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_dkwedge.h" @@ -1220,13 +1220,13 @@ dklastclose(struct dkwedge_softc *sc) } } - mutex_exit(&sc->sc_parent->dk_rawlock); - mutex_exit(&sc->sc_dk.dk_openlock); - if (vp) { dk_close_parent(vp, mode); } + mutex_exit(&sc->sc_parent->dk_rawlock); + mutex_exit(&sc->sc_dk.dk_openlock); + return error; } |
