Commit 8423f5d4 authored by Warner Losh's avatar Warner Losh
Browse files

nvme: use config_intrhook_drain to avoid removable card races

nvme drives are configured early in boot. However, a number of the configuration
steps takes which take a while, so we defer those to a config intrhook that runs
before the root filesystem is mounted. At the same time, the PCI hot plug wakes
up and tests the status of the card. It may decide that the card has gone away
and deletes the child. As part of that process nvme_detach is called. If this
call happens after the config_intrhook starts to run, but before it is finished,
there's a race where we can tear down the device's soft state while the
config_intrhook is still using it. Use the new config_intrhook_drain to
disestablish the hook. Either it will be removed w/o running, or the routine
will wait for it to finish. This closes the race and allows safe hotplug at any
time, even very early in boot.

Sponsored by:		Netflix, Inc
Reviewed by:		jhb, mav
Differential Revision:
parent e5236836
......@@ -143,10 +143,7 @@ nvme_detach(device_t dev)
struct nvme_controller *ctrlr = DEVICE2SOFTC(dev);
if (ctrlr->config_hook.ich_arg != NULL) {
ctrlr->config_hook.ich_arg = NULL;
nvme_ctrlr_destruct(ctrlr, dev);
return (0);
......@@ -1135,7 +1135,6 @@ nvme_ctrlr_start_config_hook(void *arg)
ctrlr->config_hook.ich_arg = NULL;
......@@ -1154,7 +1153,6 @@ nvme_ctrlr_start_config_hook(void *arg)
ctrlr->config_hook.ich_arg = NULL;
ctrlr->is_initialized = 1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment