aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2026-02-17 08:00:34 +0000
committerWarner Losh <imp@FreeBSD.org>2026-02-18 16:39:28 +0000
commitc8d63d63679fc0d8a67b33499a2a2edd444c8e2e (patch)
treeb47231b6108702e31f713fd3e00fabb0191cef26
parent8e593a1f143203cace2e14bd6629a8ebdf9b47dc (diff)
nvme: fix panic if we boot w/o a namespace
If we format a drive, and then crash, we'll come back up. nvme_sim_ns device won't attach because we don't have a namespace. Some drives (all? I couldn't find it in the standard) send an AER with a namespace change, which causes a NULL dereference because s_sim wasn't initialized because we didn't attach. So, if we get into the ns_changed routine, bail early if we didn't attach. We'll attach later, and deal with the ns correctly if it's really there, or not attach one if it's not. Sponsored by: Netflix
-rw-r--r--sys/dev/nvme/nvme_sim.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/sys/dev/nvme/nvme_sim.c b/sys/dev/nvme/nvme_sim.c
index 8b861cf3aa71..a59823847c39 100644
--- a/sys/dev/nvme/nvme_sim.c
+++ b/sys/dev/nvme/nvme_sim.c
@@ -406,6 +406,16 @@ nvme_sim_ns_added(device_t dev, struct nvme_namespace *ns)
union ccb *ccb;
/*
+ * If we have no namespaces, then we both do not attach the nvme_sim_ns
+ * device. And then get a ns changed AER as well to tell us about it
+ * (which is how we get here). If there's no device attached, then
+ * there's nothing to do. sc->s_sim will be NULL as well (since it
+ * only gets set when we attach).
+ */
+ if (!device_is_attached(dev))
+ return (0);
+
+ /*
* We map the NVMe namespace idea onto the CAM unit LUN. For each new
* namespace, scan or rescan the path to enumerate it.
*/