net/gve: add IO memory barriers before reading descriptors
PATCH 1/1 net/gve: add IO memory barriers before reading descriptors
Without memory barriers, there is no guarantee that the CPU will actually wait until after the descriptor has been fully written before loading descriptor data. In this case, it is possible that stale data is read and acted on by the driver when processing TX or RX completions.
This change adds read memory barriers just after the generation bit is read in both the RX and the TX path to ensure that the NIC has properly passed ownership to the driver before descriptor data is read in full.
Note that memory barriers should not be needed after writing the RX buffer queue/TX descriptor queue tails because rte_write32 includes an implicit write memory barrier.
--- drivers/net/gve/gve_rx_dqo.c | 2 ++ drivers/net/gve/gve_tx_dqo.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/net/gve/gve_rx_dqo.c +2 -0
@@ -132,6 +132,8 @@ gve_rx_burst_dqo(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)if (rx_desc->generation != rxq->cur_gen_bit)break ; +rte_io_rmb (); +if (unlikely (rx_desc->rx_error)) { rxq->stats.errors++;continue ;
drivers/net/gve/gve_tx_dqo.c +2 -0
@@ -24,6 +24,8 @@ gve_tx_clean_dqo(struct gve_tx_queue *txq)if (compl_desc->generation != txq->cur_gen_bit)return ; +rte_io_rmb (); + compl_tag =rte_le_to_cpu_16 (compl_desc->completion_tag); aim_txq = txq->txqs[compl_desc->id];
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
Ferruh Yigit
AppliedQuoted 13 lines · Joshua Washington
Without memory barriers, there is no guarantee that the CPU will actually wait until after the descriptor has been fully written before loading descriptor data. In this case, it is possible that stale data is read and acted on by the driver when processing TX or RX completions.
This change adds read memory barriers just after the generation bit is read in both the RX and the TX path to ensure that the NIC has properly passed ownership to the driver before descriptor data is read in full.
Note that memory barriers should not be needed after writing the RX buffer queue/TX descriptor queue tails because
rte_write32includes an implicit write memory barrier.
Quoted 9 lines
Fixes 4022f9999f56 ("net/gve: support basic Tx data path for DQO")Fixes 45da16b5b181 ("net/gve: support basic Rx data path for DQO")Signed-off-by Joshua Washington <[email protected]>Reviewed-by Praveen Kaligineedi <[email protected]>Reviewed-by Rushil Gupta <[email protected]>
Applied to dpdk-next-net/main, thanks.