* [PATCH] nvme-pci: dma read memory barrier for completions
@ 2020-05-08 20:04 Keith Busch
2020-05-08 20:12 ` Sagi Grimberg
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Keith Busch @ 2020-05-08 20:04 UTC (permalink / raw)
To: linux-nvme, hch, sagi; +Cc: Keith Busch, John Garry, Will Deacon
Control dependencies do not guarantee load order across the condition,
allowing a CPU to predict and speculate memory reads.
Commit 324b494c2862 inlined verifying a new completion with its
handling. At least one architecture was observed to access the contents
out of order, resulting in the driver using stale data for the
completion.
Add a dma read barrier before reading the completion queue entry and
after the condition its contents depend on to ensure the read order is
determinsitic.
Reported-by: John Garry <john.garry@huawei.com>
Suggested-by: Will Deacon <will@kernel.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
drivers/nvme/host/pci.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index e13c370de830..3726dc780d15 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -989,6 +989,11 @@ static inline int nvme_process_cq(struct nvme_queue *nvmeq)
while (nvme_cqe_pending(nvmeq)) {
found++;
+ /*
+ * load-load control dependency between phase and the rest of
+ * the cqe requires a full read memory barrier
+ */
+ dma_rmb();
nvme_handle_cqe(nvmeq, nvmeq->cq_head);
nvme_update_cq_head(nvmeq);
}
--
2.24.1
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH] nvme-pci: dma read memory barrier for completions
2020-05-08 20:04 [PATCH] nvme-pci: dma read memory barrier for completions Keith Busch
@ 2020-05-08 20:12 ` Sagi Grimberg
2020-05-08 21:00 ` Keith Busch
2020-05-11 10:14 ` John Garry
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Sagi Grimberg @ 2020-05-08 20:12 UTC (permalink / raw)
To: Keith Busch, linux-nvme, hch; +Cc: John Garry, Will Deacon
> Control dependencies do not guarantee load order across the condition,
> allowing a CPU to predict and speculate memory reads.
>
> Commit 324b494c2862 inlined verifying a new completion with its
I think we need a "Fixes" tag to get it into stable 5.6.y right?
Otherwise,
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] nvme-pci: dma read memory barrier for completions
2020-05-08 20:12 ` Sagi Grimberg
@ 2020-05-08 21:00 ` Keith Busch
2020-05-08 21:03 ` Sagi Grimberg
0 siblings, 1 reply; 7+ messages in thread
From: Keith Busch @ 2020-05-08 21:00 UTC (permalink / raw)
To: Sagi Grimberg; +Cc: John Garry, Will Deacon, hch, linux-nvme
On Fri, May 08, 2020 at 01:12:50PM -0700, Sagi Grimberg wrote:
>
> > Control dependencies do not guarantee load order across the condition,
> > allowing a CPU to predict and speculate memory reads.
> >
> > Commit 324b494c2862 inlined verifying a new completion with its
>
> I think we need a "Fixes" tag to get it into stable 5.6.y right?
5.6 doesn't include the commit that reintroduced inline completion
handling, so there's no stable this would apply to.
But really, the driver handled completions inline with the phase for
most of its existence (3.3 - 4.17). It was only recently we had the
split handling, so I'm not sure why its only an issue now unless
more recent compilers and/or CPU made it more likely.
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-pci: dma read memory barrier for completions
2020-05-08 21:00 ` Keith Busch
@ 2020-05-08 21:03 ` Sagi Grimberg
0 siblings, 0 replies; 7+ messages in thread
From: Sagi Grimberg @ 2020-05-08 21:03 UTC (permalink / raw)
To: Keith Busch; +Cc: John Garry, Will Deacon, hch, linux-nvme
> On Fri, May 08, 2020 at 01:12:50PM -0700, Sagi Grimberg wrote:
>>
>>> Control dependencies do not guarantee load order across the condition,
>>> allowing a CPU to predict and speculate memory reads.
>>>
>>> Commit 324b494c2862 inlined verifying a new completion with its
>>
>> I think we need a "Fixes" tag to get it into stable 5.6.y right?
>
> 5.6 doesn't include the commit that reintroduced inline completion
> handling, so there's no stable this would apply to.
From some reason I thought I saw it in 5.6, but you're right it isn't,
so you can ignore...
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-pci: dma read memory barrier for completions
2020-05-08 20:04 [PATCH] nvme-pci: dma read memory barrier for completions Keith Busch
2020-05-08 20:12 ` Sagi Grimberg
@ 2020-05-11 10:14 ` John Garry
2020-05-11 11:49 ` Will Deacon
2020-05-12 15:57 ` Christoph Hellwig
3 siblings, 0 replies; 7+ messages in thread
From: John Garry @ 2020-05-11 10:14 UTC (permalink / raw)
To: Keith Busch, linux-nvme, hch, sagi
Cc: Robin Murphy, luojiaxing@huawei.com, Will Deacon
On 08/05/2020 21:04, Keith Busch wrote:
> Control dependencies do not guarantee load order across the condition,
> allowing a CPU to predict and speculate memory reads.
>
> Commit 324b494c2862 inlined verifying a new completion with its
> handling. At least one architecture was observed to access the contents
> out of order, resulting in the driver using stale data for the
> completion.
>
> Add a dma read barrier before reading the completion queue entry and
> after the condition its contents depend on to ensure the read order is
> determinsitic.
deterministic
>
> Reported-by: John Garry <john.garry@huawei.com>
> Suggested-by: Will Deacon <will@kernel.org>
Tested-by: John Garry <john.garry@huawei.com>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
> drivers/nvme/host/pci.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index e13c370de830..3726dc780d15 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -989,6 +989,11 @@ static inline int nvme_process_cq(struct nvme_queue *nvmeq)
>
> while (nvme_cqe_pending(nvmeq)) {
> found++;
> + /*
> + * load-load control dependency between phase and the rest of
> + * the cqe requires a full read memory barrier
> + */
> + dma_rmb();
> nvme_handle_cqe(nvmeq, nvmeq->cq_head);
> nvme_update_cq_head(nvmeq);
> }
>
JFYI, I have confirmed that the ES3000 NVMe controllers which I am using
will write all 4 dwords of the CQE at the same time.
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] nvme-pci: dma read memory barrier for completions
2020-05-08 20:04 [PATCH] nvme-pci: dma read memory barrier for completions Keith Busch
2020-05-08 20:12 ` Sagi Grimberg
2020-05-11 10:14 ` John Garry
@ 2020-05-11 11:49 ` Will Deacon
2020-05-12 15:57 ` Christoph Hellwig
3 siblings, 0 replies; 7+ messages in thread
From: Will Deacon @ 2020-05-11 11:49 UTC (permalink / raw)
To: Keith Busch; +Cc: John Garry, hch, linux-nvme, sagi
On Fri, May 08, 2020 at 01:04:06PM -0700, Keith Busch wrote:
> Control dependencies do not guarantee load order across the condition,
> allowing a CPU to predict and speculate memory reads.
>
> Commit 324b494c2862 inlined verifying a new completion with its
> handling. At least one architecture was observed to access the contents
> out of order, resulting in the driver using stale data for the
> completion.
>
> Add a dma read barrier before reading the completion queue entry and
> after the condition its contents depend on to ensure the read order is
> determinsitic.
>
> Reported-by: John Garry <john.garry@huawei.com>
> Suggested-by: Will Deacon <will@kernel.org>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
> drivers/nvme/host/pci.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index e13c370de830..3726dc780d15 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -989,6 +989,11 @@ static inline int nvme_process_cq(struct nvme_queue *nvmeq)
>
> while (nvme_cqe_pending(nvmeq)) {
> found++;
> + /*
> + * load-load control dependency between phase and the rest of
> + * the cqe requires a full read memory barrier
> + */
> + dma_rmb();
> nvme_handle_cqe(nvmeq, nvmeq->cq_head);
> nvme_update_cq_head(nvmeq);
> }
Thanks for doing this:
Acked-by: Will Deacon <will@kernel.org>
Will
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] nvme-pci: dma read memory barrier for completions
2020-05-08 20:04 [PATCH] nvme-pci: dma read memory barrier for completions Keith Busch
` (2 preceding siblings ...)
2020-05-11 11:49 ` Will Deacon
@ 2020-05-12 15:57 ` Christoph Hellwig
3 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2020-05-12 15:57 UTC (permalink / raw)
To: Keith Busch; +Cc: John Garry, Will Deacon, hch, linux-nvme, sagi
Thanks,
applied to nvme-5.7.
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-05-12 15:57 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-08 20:04 [PATCH] nvme-pci: dma read memory barrier for completions Keith Busch
2020-05-08 20:12 ` Sagi Grimberg
2020-05-08 21:00 ` Keith Busch
2020-05-08 21:03 ` Sagi Grimberg
2020-05-11 10:14 ` John Garry
2020-05-11 11:49 ` Will Deacon
2020-05-12 15:57 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox