net/virtio: missing/wrong read barriers.
A message that is not in the archive (sent off-list or not yet received): CGME20190124165910eucas1p212dd655a34f42e11048e85eb17c7d0d0@eucas1p2.samsung.com
cover net/virtio: missing/wrong read barriers.
Ilya Maximets (3):
net/virtio: fix improper read barriers on packed Tx cleanup net/virtio: add barriers for extra descriptors on Rx split net/virtio: add missing read barrier for packed dequeue
drivers/net/virtio/virtio_rxtx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 net/virtio: fix improper read barriers on packed Tx cleanup
Read barrier must be implied between reading descriptor flags and descriptor id. Otherwise, in case of reordering, we could read wrong descriptor id.
For the reference, similar barrier for split rings is the read barrier between VIRTQUEUE_NUSED (reading the used->idx) and the call to the virtio_xmit_cleanup().
Additionally removed double update of 'used_idx'. It's enough to set it in the end of the loop.
--- drivers/net/virtio/virtio_rxtx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/virtio/virtio_rxtx.c +1 -2
@@ -234,7 +234,7 @@ virtio_xmit_cleanup_packed(struct virtqueue *vq, int num) used_idx = vq->vq_used_cons_idx;while (num-- &&desc_is_used (&desc[used_idx], vq)) { - used_idx = vq->vq_used_cons_idx; +virtio_rmb (vq->hw->weak_barriers); id = desc[used_idx].id; dxp = &vq->vq_descx[id]; vq->vq_used_cons_idx += dxp->ndescs;
@@ -1940,7 +1940,6 @@ virtio_xmit_pkts_packed(void *tx_queue, struct rte_mbuf **tx_pkts,/* Positive value indicates it need free vring descriptors */ if (unlikely (need >0 )) { -virtio_rmb (hw->weak_barriers); need =RTE_MIN (need, (int )nb_pkts);virtio_xmit_cleanup_packed (vq, need); need = slots - vq->vq_free_cnt;
Signature · 1 line
2.17.1
Re: [PATCH 1/3] net/virtio: fix improper read barriers on packed Tx cleanup
Quoted 11 lines · Ilya Maximets
Read barrier must be implied between reading descriptor flags and descriptor id. Otherwise, in case of reordering, we could read wrong descriptor id.
For the reference, similar barrier for split rings is the read barrier between
VIRTQUEUE_NUSED(reading theused->idx) and the call to thevirtio_xmit_cleanup().Additionally removed double update of '
used_idx'. It's enough to set it in the end of the loop.
Quoted 8 lines
Fixes 892dc798fa9c ("net/virtio: implement Tx path for packed queues")Signed-off-by Ilya Maximets <[email protected]>---
drivers/net/virtio/virtio_rxtx.c| 3 +--1 file changed, 1 insertion(+), 2 deletions(-)
Re: [PATCH 1/3] net/virtio: fix improper read barriers on packed Tx cleanup
In reply to Ilya MaximetsQuoted 8 lines · Ilya Maximets
Read barrier must be implied between reading descriptor flags and descriptor id. Otherwise, in case of reordering, we could read wrong descriptor id.
For the reference, similar barrier for split rings is the read barrier between
VIRTQUEUE_NUSED(reading theused->idx) and the call to thevirtio_xmit_cleanup().
Quoted 5 lines
Additionally removed double update of '
used_idx'. It's enough to set it in the end of the loop.Fixes 892dc798fa9c ("net/virtio: implement Tx path for packed queues")
I don't think cc stable is required as 892dc798fa9c is only in v19.02-rc1 and newer.
regards,
Jens
PATCH 2/3 net/virtio: add barriers for extra descriptors on Rx split
In reply to Ilya MaximetsThere should be read barrier between checking VIRTQUEUE_NUSED (reading the used->idx) and reading these descriptors. It's done for the first checks at the beginning of these functions but missed while checking for extra required descriptors.
--- drivers/net/virtio/virtio_rxtx.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/virtio/virtio_rxtx.c +2 -0
@@ -1456,6 +1456,7 @@ virtio_recv_pkts_inorder(void *rx_queue, prev = rcv_pkts[nb_rx];if (likely (VIRTQUEUE_NUSED (vq) >= rcv_cnt)) { +virtio_rmb (hw->weak_barriers); num =virtqueue_dequeue_rx_inorder (vq, rcv_pkts, len, rcv_cnt);uint16_t extra_idx =0 ;
@@ -1642,6 +1643,7 @@ virtio_recv_mergeable_pkts(void *rx_queue, prev = rcv_pkts[nb_rx];if (likely (VIRTQUEUE_NUSED (vq) >= rcv_cnt)) { +virtio_rmb (hw->weak_barriers); num =virtqueue_dequeue_burst_rx (vq, rcv_pkts, len, rcv_cnt);uint16_t extra_idx =0 ;
Signature · 1 line
2.17.1
PATCH 3/3 net/virtio: add missing read barrier for packed dequeue
In reply to Ilya MaximetsRead barrier is required between reading the flags (desc_is_used) and the content of descriptor to ensure the ordering. Otherwise, speculative read of desc.id could be reordered with reading of the desc.flags.
--- drivers/net/virtio/virtio_rxtx.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/virtio/virtio_rxtx.c +1 -0
@@ -124,6 +124,7 @@ virtqueue_dequeue_burst_rx_packed(struct virtqueue *vq, used_idx = vq->vq_used_cons_idx;if (!desc_is_used (&desc[used_idx], vq))return i; +virtio_rmb (vq->hw->weak_barriers); len[i] = desc[used_idx].len; id = desc[used_idx].id; cookie = (struct rte_mbuf *)vq->vq_descx[id].cookie;
Signature · 1 line
2.17.1
Re: [PATCH 3/3] net/virtio: add missing read barrier for packed dequeue
Quoted 5 lines · Ilya Maximets
Read barrier is required between reading the flags (
desc_is_used) and the content of descriptor to ensure the ordering. Otherwise, speculative read of desc.id could be reordered with reading of the desc.flags.
Quoted 8 lines
Fixes a76290c8f1cf ("net/virtio: implement Rx path for packed queues")Signed-off-by Ilya Maximets <[email protected]>---
drivers/net/virtio/virtio_rxtx.c| 1 +1 file changed, 1 insertion(+)
Re: [PATCH 3/3] net/virtio: add missing read barrier for packed dequeue
In reply to Ilya MaximetsQuoted 7 lines · Ilya Maximets
Read barrier is required between reading the flags (
desc_is_used) and the content of descriptor to ensure the ordering. Otherwise, speculative read of desc.id could be reordered with reading of the desc.flags.Fixes a76290c8f1cf ("net/virtio: implement Rx path for packed queues")
I don't thing cc stable is required as a76290c8f1cf is only in v19.02-rc1 and newer.
regards,
Jens
Quoted 7 lines · Ilya Maximets
Ilya Maximets (3):
net/virtio: fix improper read barriers on packed Tx cleanup net/virtio: add barriers for extra descriptors on Rx split net/virtio: add missing read barrier for packed dequeuedrivers/net/virtio/virtio_rxtx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Hi Ilya,
Quoted 8 lines · Ilya Maximets
Ilya Maximets (3):
net/virtio: fix improper read barriers on packed Tx cleanup net/virtio: add barriers for extra descriptors on Rx split net/virtio: add missing read barrier for packed dequeuedrivers/net/virtio/virtio_rxtx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Thanks for the series, it is sadly too late for v19.02. I'll pick it as soon as v19.05 merge windo opens.
Maxime
Maxime Coquelin
AppliedQuoted 8 lines · Ilya Maximets
Ilya Maximets (3):
net/virtio: fix improper read barriers on packed Tx cleanup net/virtio: add barriers for extra descriptors on Rx split net/virtio: add missing read barrier for packed dequeuedrivers/net/virtio/virtio_rxtx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Applied to dpdk-next-virtio/master.
Thanks,
Maxime