Skip to contentSkip to conversation

igb: only pull the Rx timestamp header from the first buffer of a frame

PATCH In review Cyriel Ladriere 2 participants 2 messages Nov 27

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 igb: only pull the Rx timestamp header from the first buffer of a frame

When Rx hardware timestamping is enabled on 82580 and later parts, the NIC timestamps every received packet in-band: it writes a 16 byte timestamp header in front of the frame and sets E1000_RXDADV_STAT_TSIP in the Rx descriptor.

Since commit 5379260852b0 ("igb: Fix XDP with PTP enabled"), igb_clean_rx_irq() checks TSIP and calls igb_ptp_rx_pktstamp() for every Rx buffer, including the continuation buffers of a frame that spans several descriptors (jumbo frames, e.g. MTU 9000 with 3072 byte buffers). igb_ptp_rx_pktstamp() is meant for the first buffer only; its only validity check is that the first 8 bytes are zero. When a continuation buffer happens to start with 8 zero bytes, 16 bytes of packet data are treated as a timestamp header and removed from the frame. ip_rcv_core() then drops the packet because skb->len is smaller than the IP total length (IpExtInTruncatedPkts).

The drop depends on the payload, so retransmissions of the same data are dropped as well. We hit this with GigE Vision cameras streaming 9000 byte UDP packets to an I210 with ptp4l running: about one 4K frame in 700 lost one packet; every original and every resend counted in IpExtInTruncatedPkts, and a capture on the interface showed those packets exactly 16 bytes short (8994 instead of 9010 bytes). With Rx hardware timestamping disabled, or with packets small enough to fit one Rx buffer, no packet was lost.

Only pull the timestamp header while no skb has been started for the frame, i.e. from its first buffer, as before the commit above.

Fixes 5379260852b0 ("igb: Fix XDP with PTP enabled")
---
 drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +6 -2
index 131df3e09ba1..24be1f37cc6a 100644
@@ -9068,8 +9068,12 @@ static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)
 		rx_buffer = igb_get_rx_buffer(rx_ring, size, &rx_buf_pgcnt);
 		pktbuf = page_address(rx_buffer->page) + rx_buffer->page_offset;
 
-		/* pull rx packet timestamp if available and valid */
-		if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
+		/* pull rx packet timestamp if available and valid; the
+		 * timestamp header is only present in the first buffer of a
+		 * frame, a continuation buffer (skb already started) holds
+		 * packet data that must not be stripped
+		 */
+		if (!skb && igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
 			int ts_hdr_len;
 
 			ts_hdr_len = igb_ptp_rx_pktstamp(rx_ring->q_vector,
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 56 lines · Cyriel Ladriere

When Rx hardware timestamping is enabled on 82580 and later parts, the NIC timestamps every received packet in-band: it writes a 16 byte timestamp header in front of the frame and sets E1000_RXDADV_STAT_TSIP in the Rx descriptor.

Since commit 5379260852b0 ("igb: Fix XDP with PTP enabled"), igb_clean_rx_irq() checks TSIP and calls igb_ptp_rx_pktstamp() for every Rx buffer, including the continuation buffers of a frame that spans several descriptors (jumbo frames, e.g. MTU 9000 with 3072 byte buffers). igb_ptp_rx_pktstamp() is meant for the first buffer only; its only validity check is that the first 8 bytes are zero. When a continuation buffer happens to start with 8 zero bytes, 16 bytes of packet data are treated as a timestamp header and removed from the frame. ip_rcv_core() then drops the packet because skb->len is smaller than the IP total length (IpExtInTruncatedPkts).

The drop depends on the payload, so retransmissions of the same data are dropped as well. We hit this with GigE Vision cameras streaming 9000 byte UDP packets to an I210 with ptp4l running: about one 4K frame in 700 lost one packet; every original and every resend counted in IpExtInTruncatedPkts, and a capture on the interface showed those packets exactly 16 bytes short (8994 instead of 9010 bytes). With Rx hardware timestamping disabled, or with packets small enough to fit one Rx buffer, no packet was lost.

Only pull the timestamp header while no skb has been started for the frame, i.e. from its first buffer, as before the commit above.

Fixes 5379260852b0 ("igb: Fix XDP with PTP enabled")

---
drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++++--

1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +6 -2
index 131df3e09ba1..24be1f37cc6a 100644
@@ -9068,8 +9068,12 @@ static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)
 		rx_buffer = igb_get_rx_buffer(rx_ring, size, &rx_buf_pgcnt);
 		pktbuf = page_address(rx_buffer->page) + rx_buffer->page_offset;
 
-		/* pull rx packet timestamp if available and valid */
-		if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
+		/* pull rx packet timestamp if available and valid; the
+		 * timestamp header is only present in the first buffer of a
+		 * frame, a continuation buffer (skb already started) holds
+		 * packet data that must not be stripped
+		 */
+		if (!skb && igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
 			int ts_hdr_len;
 
 			ts_hdr_len = igb_ptp_rx_pktstamp(rx_ring->q_vector,
Signature · 1 line
2.53.0