Module Name:    src
Committed By:   riastradh
Date:           Sat Aug 20 11:31:39 UTC 2022

Modified Files:
        src/sys/dev/ic: nvme.c

Log Message:
nvme(4): Read cqe flags and cid in that order.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/dev/ic/nvme.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.63 src/sys/dev/ic/nvme.c:1.64
--- src/sys/dev/ic/nvme.c:1.63	Mon Aug 15 10:15:59 2022
+++ src/sys/dev/ic/nvme.c	Sat Aug 20 11:31:38 2022
@@ -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, s
 		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) {

Reply via email to