summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorriastradh <riastradh@NetBSD.org>2022-08-20 11:31:38 +0000
committerriastradh <riastradh@NetBSD.org>2022-08-20 11:31:38 +0000
commit343eb2dd1e1e6221cc6b4c6dfe33cd89489a300c (patch)
tree11c783ca5b15bdaeec6fedbc02ed563ab4be6b7c /sys/dev
parent684004d7f479e7aa76459e43acd0706dc9c28c3f (diff)
nvme(4): Read cqe flags and cid in that order.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ic/nvme.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/sys/dev/ic/nvme.c b/sys/dev/ic/nvme.c
index 4697300c5cd..a4b395e30e7 100644
--- a/sys/dev/ic/nvme.c
+++ b/sys/dev/ic/nvme.c
@@ -1,4 +1,4 @@
-/* $NetBSD: nvme.c,v 1.63 2022/08/15 10:15:59 riastradh Exp $ */
+/* $NetBSD: nvme.c,v 1.64 2022/08/20 11:31:38 riastradh Exp $ */
/* $OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
/*
@@ -18,7 +18,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.63 2022/08/15 10:15:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.64 2022/08/20 11:31:38 riastradh Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1508,6 +1508,14 @@ nvme_q_complete(struct nvme_softc *sc, struct nvme_queue *q)
if ((flags & NVME_CQE_PHASE) != q->q_cq_phase)
break;
+ /*
+ * Make sure we have read the flags _before_ we read
+ * the cid. Otherwise the CPU might speculatively read
+ * the cid before the entry has been assigned to our
+ * phase.
+ */
+ nvme_dmamem_sync(sc, q->q_cq_dmamem, BUS_DMASYNC_POSTREAD);
+
ccb = &q->q_ccbs[lemtoh16(&cqe->cid)];
if (++q->q_cq_head >= q->q_entries) {