From 84644b0db8903f96224c67a45599357f2019b4a7 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Mon, 15 Aug 2022 10:15:57 +0000 Subject: [PATCH] nvme(4): Read cqe flags and cid in that order. --- sys/dev/ic/nvme.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sys/dev/ic/nvme.c b/sys/dev/ic/nvme.c index a50622da422c..9af7250b194d 100644 --- a/sys/dev/ic/nvme.c +++ b/sys/dev/ic/nvme.c @@ -1505,6 +1505,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) {