Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ic nvme(4): Read cqe flags and cid in that order.



details:   https://anonhg.NetBSD.org/src/rev/b2edabe6c4f6
branches:  trunk
changeset: 369488:b2edabe6c4f6
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Aug 20 11:31:38 2022 +0000

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

diffstat:

 sys/dev/ic/nvme.c |  12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diffs (33 lines):

diff -r 745dac2f411b -r b2edabe6c4f6 sys/dev/ic/nvme.c
--- a/sys/dev/ic/nvme.c Sat Aug 20 11:27:09 2022 +0000
+++ b/sys/dev/ic/nvme.c Sat Aug 20 11:31:38 2022 +0000
@@ -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 @@
                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) {



Home | Main Index | Thread Index | Old Index