DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v2] igc: fix invalid length and corrupted multi-segment mbufs
@ 2024-11-01 13:57 Martin Weiser
  2024-11-01 14:30 ` Bruce Richardson
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Weiser @ 2024-11-01 13:57 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev


The issue only appeared with hardware-timestamping enabled
(RTE_ETH_RX_OFFLOAD_TIMESTAMP).

The length of the prepended hardware timestamp was not subtracted from
the data length so that received packets were 16 bytes longer than
expected.

In scatter-gather mode only the first mbuf has a timestamp but the
data offset of the follow-up mbufs was not adjusted accordingly.
This caused 16 bytes of packet data to be missing between
the segments.

Signed-off-by: Martin Weiser <martin.weiser@allegro-packets.com>
---
v2:
* Added comments for clarification.


 drivers/net/igc/igc_txrx.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/net/igc/igc_txrx.c b/drivers/net/igc/igc_txrx.c
index d0cee1b016..fabab5b1a3 100644
--- a/drivers/net/igc/igc_txrx.c
+++ b/drivers/net/igc/igc_txrx.c
@@ -347,6 +347,13 @@ igc_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 
 		rxm->data_off = RTE_PKTMBUF_HEADROOM;
 		data_len = rte_le_to_cpu_16(rxd.wb.upper.length) - rxq->crc_len;
+		/*
+		 * When the RTE_ETH_RX_OFFLOAD_TIMESTAMP offload is enabled the
+		 * length in the descriptor still accounts for the timestamp so
+		 * it must be subtracted.
+		 */
+		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
+			data_len -= IGC_TS_HDR_LEN;
 		rxm->data_len = data_len;
 		rxm->pkt_len = data_len;
 		rxm->nb_segs = 1;
@@ -509,6 +516,24 @@ igc_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 		 */
 		rxm->data_off = RTE_PKTMBUF_HEADROOM;
 		data_len = rte_le_to_cpu_16(rxd.wb.upper.length);
+		if (rxq->offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
+			/*
+			 * When the RTE_ETH_RX_OFFLOAD_TIMESTAMP offload is enabled
+			 * the pkt_addr of all software ring entries is moved forward
+			 * by IGC_TS_HDR_LEN (see igc_alloc_rx_queue_mbufs()) so that
+			 * when the hardware writes the packet with a prepended
+			 * timestamp the actual packet data still starts at the
+			 * normal data offset. The length in the descriptor still
+			 * accounts for the timestamp so it needs to be subtracted.
+			 * Follow-up mbufs do not have the timestamp so the data
+			 * offset must be adjusted to point to the start of the packet
+			 * data.
+			 */
+			if (first_seg == NULL)
+				data_len -= IGC_TS_HDR_LEN;
+			else
+				rxm->data_off -= IGC_TS_HDR_LEN;
+		}
 		rxm->data_len = data_len;
 
 		/*
@@ -557,6 +582,7 @@ igc_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 				last_seg->data_len = last_seg->data_len -
 					 (RTE_ETHER_CRC_LEN - data_len);
 				last_seg->next = NULL;
+				rxm = last_seg;
 			} else {
 				rxm->data_len = (uint16_t)
 					(data_len - RTE_ETHER_CRC_LEN);
-- 
2.47.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-01 14:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-01 13:57 [PATCH v2] igc: fix invalid length and corrupted multi-segment mbufs Martin Weiser
2024-11-01 14:30 ` Bruce Richardson
2024-11-01 14:43   ` Bruce Richardson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).