vdpa/mlx5: Use write memory barrier after updating CQ index
Subsystems (2)
PATCH 1/1 vdpa/mlx5: Use write memory barrier after updating CQ index
Make sure to put write memory barrier after updating CQ consumer index so the hardware knows that there are available CQE slots in the queue.
Failure to do this can cause the update of the RX doorbell record to get updated before the CQ consumer index resulting in CQ overrun.
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/vdpa/mlx5/net/mlx5_vnet.c +5 -0
@@ -478,6 +478,11 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)static void mlx5_vdpa_handle_completions (struct mlx5_vdpa_virtqueue *mvq,int num) {mlx5_cq_set_ci (&mvq->cq.mcq); + +/* make sure CQ cosumer update is visible to the hardware before updating +* RX doorbell record. +*/ +wmb ();rx_post (&mvq->vqqp, num);if (mvq->event_cb.callback) mvq->event_cb.callback (mvq->event_cb.private);
Signature · 1 line
2.27.0
Quoted 19 lines · Eli Cohen
Make sure to put write memory barrier after updating CQ consumer index so the hardware knows that there are available CQE slots in the queue.
Failure to do this can cause the update of the RX doorbell record to get updated before the CQ consumer index resulting in CQ overrun.
Change-Id Ib0ae4c118cce524c9f492b32569179f3c1f04cc1Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0@@ -478,6 +478,11 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)static void mlx5_vdpa_handle_completions (struct mlx5_vdpa_virtqueue *mvq,int num)
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq) · line 488
Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-0{mlx5_cq_set_ci (&mvq->cq.mcq); + +/* make sure CQ cosumer update is visible to the hardware before updating +* RX doorbell record. +*/ +wmb ();rx_post (&mvq->vqqp, num);if (mvq->event_cb.callback) mvq->event_cb.callback (mvq->event_cb.private);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 9 lines · Jason Wang
Quoted 7 lines · Eli Cohen
Make sure to put write memory barrier after updating CQ consumer index so the hardware knows that there are available CQE slots in the queue.
Failure to do this can cause the update of the RX doorbell record to get updated before the CQ consumer index resulting in CQ overrun.
Change-Id: Ib0ae4c118cce524c9f492b32569179f3c1f04cc1
Michael, I left this gerrit ID by mistake. Can you remove it before merging?
Quoted 27 lines
Quoted 12 lines
Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0@@ -478,6 +478,11 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)static void mlx5_vdpa_handle_completions (struct mlx5_vdpa_virtqueue *mvq,int num)drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq) · line 488
Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-0{mlx5_cq_set_ci (&mvq->cq.mcq); + +/* make sure CQ cosumer update is visible to the hardware before updating +* RX doorbell record. +*/ +wmb ();rx_post (&mvq->vqqp, num);if (mvq->event_cb.callback) mvq->event_cb.callback (mvq->event_cb.private);Acked-by Jason Wang <[email protected]>
Michael S. Tsirkin
maintainerQuoted 6 lines · Eli Cohen
Quoted 5 lines · Jason Wang
Quoted 3 lines · Eli Cohen
Make sure to put write memory barrier after updating CQ consumer index so the hardware knows that there are available CQE slots in the queue.
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Failure to do this can cause the update of the RX doorbell record to get updated before the CQ consumer index resulting in CQ overrun.
Change-Id: Ib0ae4c118cce524c9f492b32569179f3c1f04cc1
Michael, I left this gerrit ID by mistake. Can you remove it before merging?
No problem.
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-0@@ -478,6 +478,11 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)static void mlx5_vdpa_handle_completions (struct mlx5_vdpa_virtqueue *mvq,int num) {mlx5_cq_set_ci (&mvq->cq.mcq); + +/* make sure CQ cosumer update is visible to the hardware before updating +* RX doorbell record. +*/ +wmb ();
Quoted 8 lines
Quoted 8 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq) · line 488
Quoted 3 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0rx_post (&mvq->vqqp, num);if (mvq->event_cb.callback) mvq->event_cb.callback (mvq->event_cb.private);Acked-by Jason Wang <[email protected]>
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerQuoted 9 lines · Eli Cohen
Make sure to put write memory barrier after updating CQ consumer index so the hardware knows that there are available CQE slots in the queue.
Failure to do this can cause the update of the RX doorbell record to get updated before the CQ consumer index resulting in CQ overrun.
Change-Id Ib0ae4c118cce524c9f492b32569179f3c1f04cc1Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>
Aren't both memory writes? And given that, isn't dma_wmb() sufficient here?
Quoted 22 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-0@@ -478,6 +478,11 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)static void mlx5_vdpa_handle_completions (struct mlx5_vdpa_virtqueue *mvq,int num) {mlx5_cq_set_ci (&mvq->cq.mcq); + +/* make sure CQ cosumer update is visible to the hardware before updating +* RX doorbell record. +*/ +wmb ();rx_post (&mvq->vqqp, num);if (mvq->event_cb.callback) mvq->event_cb.callback (mvq->event_cb.private);Signature · 1 line
2.27.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines · Eli Cohen
Make sure to put write memory barrier after updating CQ consumer index so the hardware knows that there are available CQE slots in the queue.
Quoted 8 lines
Quoted 6 lines
Failure to do this can cause the update of the RX doorbell record to get updated before the CQ consumer index resulting in CQ overrun.
Change-Id Ib0ae4c118cce524c9f492b32569179f3c1f04cc1Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>Aren't both memory writes?
Not sure what exactly you mean here.
Quoted 1 line
And given that, isn't
dma_wmb()sufficient here?
I agree that dma_wmb() is more appropriate here.
Quoted 25 lines
Quoted 24 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-0@@ -478,6 +478,11 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)static void mlx5_vdpa_handle_completions (struct mlx5_vdpa_virtqueue *mvq,int num) {mlx5_cq_set_ci (&mvq->cq.mcq); + +/* make sure CQ cosumer update is visible to the hardware before updating +* RX doorbell record. +*/ +wmb ();rx_post (&mvq->vqqp, num);if (mvq->event_cb.callback) mvq->event_cb.callback (mvq->event_cb.private);Signature · 1 line
2.27.0
Michael S. Tsirkin
maintainerQuoted 8 lines · Eli Cohen
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Eli Cohen
Make sure to put write memory barrier after updating CQ consumer index so the hardware knows that there are available CQE slots in the queue.
Failure to do this can cause the update of the RX doorbell record to get updated before the CQ consumer index resulting in CQ overrun.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Change-Id Ib0ae4c118cce524c9f492b32569179f3c1f04cc1Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>Aren't both memory writes?
Not sure what exactly you mean here.
Both updates are CPU writes into RAM that hardware then reads using DMA.
Quoted 29 lines
Quoted 1 line
And given that, isn't
dma_wmb()sufficient here?I agree that
dma_wmb()is more appropriate here.Quoted 25 lines
Quoted 24 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-0@@ -478,6 +478,11 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)static void mlx5_vdpa_handle_completions (struct mlx5_vdpa_virtqueue *mvq,int num) {mlx5_cq_set_ci (&mvq->cq.mcq); + +/* make sure CQ cosumer update is visible to the hardware before updating +* RX doorbell record. +*/ +wmb ();rx_post (&mvq->vqqp, num);if (mvq->event_cb.callback) mvq->event_cb.callback (mvq->event_cb.private);Signature · 1 line
2.27.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 13 lines · Michael S. Tsirkin
Quoted 12 lines · Eli Cohen
Quoted 11 lines · Michael S. Tsirkin
Quoted 9 lines · Eli Cohen
Make sure to put write memory barrier after updating CQ consumer index so the hardware knows that there are available CQE slots in the queue.
Failure to do this can cause the update of the RX doorbell record to get updated before the CQ consumer index resulting in CQ overrun.
Change-Id Ib0ae4c118cce524c9f492b32569179f3c1f04cc1Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Aren't both memory writes?
Not sure what exactly you mean here.
Both updates are CPU writes into RAM that hardware then reads using DMA.
You mean why I did not put a memory barrier right after updating the recieve doorbell record?
I thought about this and I think it is not required. Suppose it takes a very long time till the hardware can actually see this update. The worst effect would be that the hardware will drop received packets if it does sees none available due to the delayed update. Eventually it will see the update and will continue working.
If I put a memory barrier, I put some delay waiting for the CPU to flush the write before continuing. I tried both options while checking packet rate on couldn't see noticable difference in either case.
Quoted 30 lines
Quoted 29 lines
Quoted 1 line
And given that, isn't
dma_wmb()sufficient here?I agree that
dma_wmb()is more appropriate here.Quoted 25 lines
Quoted 24 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-0@@ -478,6 +478,11 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)static void mlx5_vdpa_handle_completions (struct mlx5_vdpa_virtqueue *mvq,int num) {mlx5_cq_set_ci (&mvq->cq.mcq); + +/* make sure CQ cosumer update is visible to the hardware before updating +* RX doorbell record. +*/ +wmb ();rx_post (&mvq->vqqp, num);if (mvq->event_cb.callback) mvq->event_cb.callback (mvq->event_cb.private);Signature · 1 line
2.27.0
Michael S. Tsirkin
maintainerQuoted 16 lines · Eli Cohen
Quoted 15 lines · Michael S. Tsirkin
Quoted 14 lines · Eli Cohen
Quoted 12 lines · Michael S. Tsirkin
Quoted 9 lines · Eli Cohen
Make sure to put write memory barrier after updating CQ consumer index so the hardware knows that there are available CQE slots in the queue.
Failure to do this can cause the update of the RX doorbell record to get updated before the CQ consumer index resulting in CQ overrun.
Change-Id Ib0ae4c118cce524c9f492b32569179f3c1f04cc1Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>Aren't both memory writes?
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Not sure what exactly you mean here.
Both updates are CPU writes into RAM that hardware then reads using DMA.
You mean why I did not put a memory barrier right after updating the recieve doorbell record?
Sorry about being unclear. I just tried to give justification for why dma_wmb seems more appropriate than wmb here. If you need to order memory writes wrt writes to card, that is different, but generally writeX and friends will handle the ordering for you, except when using relaxed memory mappings - then wmb is generally necessary.
Quoted 9 lines
I thought about this and I think it is not required. Suppose it takes a very long time till the hardware can actually see this update. The worst effect would be that the hardware will drop received packets if it does sees none available due to the delayed update. Eventually it will see the update and will continue working.
If I put a memory barrier, I put some delay waiting for the CPU to flush the write before continuing. I tried both options while checking packet rate on couldn't see noticable difference in either case.
makes sense.
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 1 line
And given that, isn't
dma_wmb()sufficient here?I agree that
dma_wmb()is more appropriate here.Quoted 18 lines
Quoted 18 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +4
-0@@ -478,6 +478,11 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)static void mlx5_vdpa_handle_completions (struct mlx5_vdpa_virtqueue *mvq,int num) {mlx5_cq_set_ci (&mvq->cq.mcq); + +/* make sure CQ cosumer update is visible to the hardware before updating +* RX doorbell record. +*/
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1
-0+wmb ();rx_post (&mvq->vqqp, num);if (mvq->event_cb.callback) mvq->event_cb.callback (mvq->event_cb.private);Signature · 1 line
2.27.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 23 lines · Michael S. Tsirkin
Quoted 22 lines · Eli Cohen
Quoted 20 lines · Michael S. Tsirkin
Quoted 8 lines · Eli Cohen
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Eli Cohen
Make sure to put write memory barrier after updating CQ consumer index so the hardware knows that there are available CQE slots in the queue.
Failure to do this can cause the update of the RX doorbell record to get updated before the CQ consumer index resulting in CQ overrun.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Change-Id Ib0ae4c118cce524c9f492b32569179f3c1f04cc1Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>Aren't both memory writes?
Not sure what exactly you mean here.
Both updates are CPU writes into RAM that hardware then reads using DMA.
Quoted 9 lines
Quoted 2 lines
You mean why I did not put a memory barrier right after updating the recieve doorbell record?
Sorry about being unclear. I just tried to give justification for why
dma_wmbseems more appropriate than wmb here. If you need to order memory writes wrt writes to card, that is different, but generally writeX and friends will handle the ordering for you, except when using relaxed memory mappings - then wmb is generally necessary.
Bear in mind, we're writing to memory (not io memory). In this case, we want this write to be visible my the DMA device.
https://www.kernel.org/doc/Documentation/memory-barriers.txt gives a similar example using dma_wmb() to flush updates to make them visible by the hardware before notifying the hardware to come and inspect this memory.
Quoted 44 lines
Quoted 9 lines
I thought about this and I think it is not required. Suppose it takes a very long time till the hardware can actually see this update. The worst effect would be that the hardware will drop received packets if it does sees none available due to the delayed update. Eventually it will see the update and will continue working.
If I put a memory barrier, I put some delay waiting for the CPU to flush the write before continuing. I tried both options while checking packet rate on couldn't see noticable difference in either case.
makes sense.
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 1 line
And given that, isn't
dma_wmb()sufficient here?I agree that
dma_wmb()is more appropriate here.Quoted 25 lines
Quoted 24 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-0@@ -478,6 +478,11 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)static void mlx5_vdpa_handle_completions (struct mlx5_vdpa_virtqueue *mvq,int num) {mlx5_cq_set_ci (&mvq->cq.mcq); + +/* make sure CQ cosumer update is visible to the hardware before updating +* RX doorbell record. +*/ +wmb ();rx_post (&mvq->vqqp, num);if (mvq->event_cb.callback) mvq->event_cb.callback (mvq->event_cb.private);Signature · 1 line
2.27.0
Michael S. Tsirkin
maintainerQuoted 34 lines · Eli Cohen
Quoted 23 lines · Michael S. Tsirkin
Quoted 22 lines · Eli Cohen
Quoted 20 lines · Michael S. Tsirkin
Quoted 8 lines · Eli Cohen
Quoted 7 lines · Michael S. Tsirkin
Quoted 6 lines · Eli Cohen
Make sure to put write memory barrier after updating CQ consumer index so the hardware knows that there are available CQE slots in the queue.
Failure to do this can cause the update of the RX doorbell record to get updated before the CQ consumer index resulting in CQ overrun.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Change-Id Ib0ae4c118cce524c9f492b32569179f3c1f04cc1Fixes 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")Signed-off-by Eli Cohen <[email protected]>Aren't both memory writes?
Not sure what exactly you mean here.
Both updates are CPU writes into RAM that hardware then reads using DMA.
Quoted 9 lines
Quoted 2 lines
You mean why I did not put a memory barrier right after updating the recieve doorbell record?
Sorry about being unclear. I just tried to give justification for why
dma_wmbseems more appropriate than wmb here. If you need to order memory writes wrt writes to card, that is different, but generally writeX and friends will handle the ordering for you, except when using relaxed memory mappings - then wmb is generally necessary.
Quoted 7 lines
Bear in mind, we're writing to memory (not io memory). In this case, we want this write to be visible my the DMA device.
https://www.kernel.org/doc/Documentation/memory-barriers.txt gives a similar example using
dma_wmb()to flush updates to make them visible by the hardware before notifying the hardware to come and inspect this memory.
Exactly.
Quoted 37 lines
Quoted 37 lines
Quoted 10 lines
I thought about this and I think it is not required. Suppose it takes a very long time till the hardware can actually see this update. The worst effect would be that the hardware will drop received packets if it does sees none available due to the delayed update. Eventually it will see the update and will continue working.
If I put a memory barrier, I put some delay waiting for the CPU to flush the write before continuing. I tried both options while checking packet rate on couldn't see noticable difference in either case.
makes sense.
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 1 line
And given that, isn't
dma_wmb()sufficient here?I agree that
dma_wmb()is more appropriate here.Quoted 19 lines
Quoted 19 lines
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-0@@ -478,6 +478,11 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)static void mlx5_vdpa_handle_completions (struct mlx5_vdpa_virtqueue *mvq,int num) {mlx5_cq_set_ci (&mvq->cq.mcq); + +/* make sure CQ cosumer update is visible to the hardware before updating +* RX doorbell record. +*/ +wmb ();
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0rx_post (&mvq->vqqp, num);if (mvq->event_cb.callback) mvq->event_cb.callback (mvq->event_cb.private);Signature · 1 line
2.27.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization