Skip to contentSkip to conversation

net/iavf: fix scalar Rx path zero-length segment

PATCH Applied Ciara Loftus 2 participants 5 messages Jun 12 – Jun 16 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/iavf: fix scalar Rx path zero-length segment

When hardware CRC stripping is active, a frame whose on-wire size is an exact multiple of the Rx buffer size can cause the NIC to fill the final data descriptor and place the four CRC bytes into a separate trailing descriptor. After hardware stripping, that descriptor carries zero bytes of payload.

The existing CRC cleanup code only handles a zero-length trailing segment when software CRC stripping is enabled. When hardware stripping is active, the zero-length mbuf is silently chained to the reassembled packet. Forwarding such a packet causes a zero-length Tx descriptor, triggering a Malicious Driver Detection event on the PF and resetting the VF.

Fix by adding logic to detect a zero-length final segment when hardware CRC stripping is active, and freeing it.

Fixes a2b29a7733ef ("net/avf: enable basic Rx Tx")
Fixes b8b4c54ef9b0 ("net/iavf: support flexible Rx descriptor in normal path")
---
 drivers/net/intel/iavf/iavf_rxtx.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/net/intel/iavf/iavf_rxtx.c +16 -0
index a57af7faed..86ebb2618d 100644
@@ -1716,6 +1716,14 @@ iavf_recv_scattered_pkts_flex_rxd(void *rx_queue, struct rte_mbuf **rx_pkts,
 				rxm->data_len = (uint16_t)(rx_packet_len -
 							RTE_ETHER_CRC_LEN);
 			}
+		} else if (unlikely(rx_packet_len == 0)) {
+			/*
+			 * NIC split CRC bytes into a trailing segment which is
+			 * now empty after hardware CRC stripping. Free it.
+			 */
+			rte_pktmbuf_free_seg(rxm);
+			first_seg->nb_segs--;
+			last_seg->next = NULL;
 		}
 
 		first_seg->port = rxq->port_id;
@@ -1884,6 +1892,14 @@ iavf_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 			} else
 				rxm->data_len = (uint16_t)(rx_packet_len -
 							RTE_ETHER_CRC_LEN);
+		} else if (unlikely(rx_packet_len == 0)) {
+			/*
+			 * NIC split CRC bytes into a trailing segment which is
+			 * now empty after hardware CRC stripping. Free it.
+			 */
+			rte_pktmbuf_free_seg(rxm);
+			first_seg->nb_segs--;
+			last_seg->next = NULL;
 		}
 
 		first_seg->port = rxq->port_id;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 34 lines · Ciara Loftus

When hardware CRC stripping is active, a frame whose on-wire size is an exact multiple of the Rx buffer size can cause the NIC to fill the final data descriptor and place the four CRC bytes into a separate trailing descriptor. After hardware stripping, that descriptor carries zero bytes of payload.

The existing CRC cleanup code only handles a zero-length trailing segment when software CRC stripping is enabled. When hardware stripping is active, the zero-length mbuf is silently chained to the reassembled packet. Forwarding such a packet causes a zero-length Tx descriptor, triggering a Malicious Driver Detection event on the PF and resetting the VF.

Fix by adding logic to detect a zero-length final segment when hardware CRC stripping is active, and freeing it.

Fixes a2b29a7733ef ("net/avf: enable basic Rx Tx")
Fixes b8b4c54ef9b0 ("net/iavf: support flexible Rx descriptor in normal path")
---
 drivers/net/intel/iavf/iavf_rxtx.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/net/intel/iavf/iavf_rxtx.c +0 -0
index a57af7faed..86ebb2618d 100644
@@ -1716,6 +1716,14 @@ iavf_recv_scattered_pkts_flex_rxd(void *rx_queue, struct rte_mbuf **rx_pkts,
 				rxm->data_len = (uint16_t)(rx_packet_len -
 							RTE_ETHER_CRC_LEN);
 			}

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts_flex_rxd(void *rx_queue, struct rte_mbuf **rx_pkts, · line 1728

Quoted 10 lines
drivers/net/intel/iavf/iavf_rxtx.c +8 -0
+		} else if (unlikely(rx_packet_len == 0)) {
+			/*
+			 * NIC split CRC bytes into a trailing segment which is
+			 * now empty after hardware CRC stripping. Free it.
+			 */
+			rte_pktmbuf_free_seg(rxm);
+			first_seg->nb_segs--;
+			last_seg->next = NULL;
 		}
 

The vector paths also handle scattered packets (via reassembly). Do they need a fix for this? What about the other drivers that work on the PF, such as ice/i40e?

/Bruce

Quoted 19 lines
drivers/net/intel/iavf/iavf_rxtx.c +8 -0
 		first_seg->port = rxq->port_id;
@@ -1884,6 +1892,14 @@ iavf_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
 			} else
 				rxm->data_len = (uint16_t)(rx_packet_len -
 							RTE_ETHER_CRC_LEN);
+		} else if (unlikely(rx_packet_len == 0)) {
+			/*
+			 * NIC split CRC bytes into a trailing segment which is
+			 * now empty after hardware CRC stripping. Free it.
+			 */
+			rte_pktmbuf_free_seg(rxm);
+			first_seg->nb_segs--;
+			last_seg->next = NULL;
 		}
 
 		first_seg->port = rxq->port_id;
Signature · 1 line
2.43.0
#2 lore raw
Quoted 40 lines

Subject: Re: [PATCH] net/iavf: fix scalar Rx path zero-length segment

Quoted 13 lines · Ciara Loftus

When hardware CRC stripping is active, a frame whose on-wire size is an exact multiple of the Rx buffer size can cause the NIC to fill the final data descriptor and place the four CRC bytes into a separate trailing descriptor. After hardware stripping, that descriptor carries zero bytes of payload.

The existing CRC cleanup code only handles a zero-length trailing segment when software CRC stripping is enabled. When hardware stripping is active, the zero-length mbuf is silently chained to the reassembled packet. Forwarding such a packet causes a zero-length Tx descriptor, triggering a Malicious Driver Detection event on the PF and resetting the VF.

Quoted 5 lines

Fix by adding logic to detect a zero-length final segment when hardware CRC stripping is active, and freeing it.

Fixes a2b29a7733ef ("net/avf: enable basic Rx Tx")
Fixes b8b4c54ef9b0 ("net/iavf: support flexible Rx descriptor in normal

path")

Review

Quoted 9 lines
---
 drivers/net/intel/iavf/iavf_rxtx.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
(quoted diff) +0 -0

b/drivers/net/intel/iavf/iavf_rxtx.c

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts_flex_rxd(void

Quoted 4 lines

index a57af7faed..86ebb2618d 100644

drivers/net/intel/iavf/iavf_rxtx.c +0 -0
@@ -1716,6 +1716,14 @@ iavf_recv_scattered_pkts_flex_rxd(void

*rx_queue, struct rte_mbuf **rx_pkts,

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts_flex_rxd(void · line 1717

Quoted 2 lines
drivers/net/intel/iavf/iavf_rxtx.c +0 -0
 				rxm->data_len = (uint16_t)(rx_packet_len -
 
	RTE_ETHER_CRC_LEN);
Quoted 15 lines

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts_flex_rxd(void *rx_queue, struct rte_mbuf **rx_pkts, · line 1728

Quoted 11 lines
drivers/net/intel/iavf/iavf_rxtx.c +8 -0
 			}
+		} else if (unlikely(rx_packet_len == 0)) {
+			/*
+			 * NIC split CRC bytes into a trailing segment which is
+			 * now empty after hardware CRC stripping. Free it.
+			 */
+			rte_pktmbuf_free_seg(rxm);
+			first_seg->nb_segs--;
+			last_seg->next = NULL;
 		}
 

The vector paths also handle scattered packets (via reassembly). Do they need a fix for this? What about the other drivers that work on the PF, such as ice/i40e?

The vector paths use the common ci_rx_reassemble_packets which already handles the zero-length trailing segment case correctly. When crc_len == 0 and the last segment has data_len == 0, the empty segment is freed.

The ice scalar path had the same issue but it was patched in 2022:
https://git.dpdk.org/dpdk/commit/?id=90ba4442058a14763e57ca96d03ab1e6044e3e5c
I cannot reproduce the behaviour on i40e hardware (either PF or VF) so I don't think it needs to be patched as the HW seems to behave differently.

Quoted 24 lines

/Bruce

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts(void *rx_queue, struct

Quoted 2 lines
drivers/net/intel/iavf/iavf_rxtx.c +0 -0
 		first_seg->port = rxq->port_id;
@@ -1884,6 +1892,14 @@ iavf_recv_scattered_pkts(void *rx_queue, struct

rte_mbuf **rx_pkts,

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, · line 1904

Quoted 3 lines
drivers/net/intel/iavf/iavf_rxtx.c +0 -0
 			} else
 				rxm->data_len = (uint16_t)(rx_packet_len -
 
	RTE_ETHER_CRC_LEN);
Quoted 14 lines
drivers/net/intel/iavf/iavf_rxtx.c +8 -1
+		} else if (unlikely(rx_packet_len == 0)) {
+			/*
+			 * NIC split CRC bytes into a trailing segment which is
+			 * now empty after hardware CRC stripping. Free it.
+			 */
+			rte_pktmbuf_free_seg(rxm);
+			first_seg->nb_segs--;
+			last_seg->next = NULL;
 		}
 
 		first_seg->port = rxq->port_id;
--

2.43.0

#3 lore raw
Quoted 61 lines · Ciara
Quoted 40 lines

Subject: Re: [PATCH] net/iavf: fix scalar Rx path zero-length segment

Quoted 13 lines · Ciara Loftus

When hardware CRC stripping is active, a frame whose on-wire size is an exact multiple of the Rx buffer size can cause the NIC to fill the final data descriptor and place the four CRC bytes into a separate trailing descriptor. After hardware stripping, that descriptor carries zero bytes of payload.

The existing CRC cleanup code only handles a zero-length trailing segment when software CRC stripping is enabled. When hardware stripping is active, the zero-length mbuf is silently chained to the reassembled packet. Forwarding such a packet causes a zero-length Tx descriptor, triggering a Malicious Driver Detection event on the PF and resetting the VF.

Quoted 5 lines

Fix by adding logic to detect a zero-length final segment when hardware CRC stripping is active, and freeing it.

Fixes a2b29a7733ef ("net/avf: enable basic Rx Tx")
Fixes b8b4c54ef9b0 ("net/iavf: support flexible Rx descriptor in normal

path")

Review

Quoted 9 lines
---
 drivers/net/intel/iavf/iavf_rxtx.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
(quoted diff) +0 -0

b/drivers/net/intel/iavf/iavf_rxtx.c

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts_flex_rxd(void

Quoted 4 lines

index a57af7faed..86ebb2618d 100644

drivers/net/intel/iavf/iavf_rxtx.c +0 -0
@@ -1716,6 +1716,14 @@ iavf_recv_scattered_pkts_flex_rxd(void

*rx_queue, struct rte_mbuf **rx_pkts,

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts_flex_rxd(void · line 1717

Quoted 2 lines
drivers/net/intel/iavf/iavf_rxtx.c +0 -0
 				rxm->data_len = (uint16_t)(rx_packet_len -
 
	RTE_ETHER_CRC_LEN);
Quoted 15 lines

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts_flex_rxd(void *rx_queue, struct rte_mbuf **rx_pkts, · line 1728

Quoted 11 lines
drivers/net/intel/iavf/iavf_rxtx.c +8 -0
 			}
+		} else if (unlikely(rx_packet_len == 0)) {
+			/*
+			 * NIC split CRC bytes into a trailing segment which is
+			 * now empty after hardware CRC stripping. Free it.
+			 */
+			rte_pktmbuf_free_seg(rxm);
+			first_seg->nb_segs--;
+			last_seg->next = NULL;
 		}
 

The vector paths also handle scattered packets (via reassembly). Do they need a fix for this? What about the other drivers that work on the PF, such as ice/i40e?

The vector paths use the common ci_rx_reassemble_packets which already handles the zero-length trailing segment case correctly. When crc_len == 0 and the last segment has data_len == 0, the empty segment is freed.

Quoted 6 lines

The ice scalar path had the same issue but it was patched in 2022:
https://git.dpdk.org/dpdk/commit/?id=90ba4442058a14763e57ca96d03ab1e6044e3e5c
I cannot reproduce the behaviour on i40e hardware (either PF or VF) so I don't think it needs to be patched as the HW seems to behave differently.

Thanks for clarifying.

As an asside for future work: we should consider if we can also convert the scalar Rx paths for our drivers to match that of the vector, where we do a simplified receive per descriptor, pretending that each descriptor is its own packet, and then use the reassemble_packets call to put any scattered packets back together. I would if that would lead to better scalar Rx performance.

/Bruce

#4 lore raw
Quoted 69 lines · Bruce Richardson
Quoted 61 lines · Ciara
Quoted 40 lines

Subject: Re: [PATCH] net/iavf: fix scalar Rx path zero-length segment

Quoted 13 lines · Ciara Loftus

When hardware CRC stripping is active, a frame whose on-wire size is an exact multiple of the Rx buffer size can cause the NIC to fill the final data descriptor and place the four CRC bytes into a separate trailing descriptor. After hardware stripping, that descriptor carries zero bytes of payload.

The existing CRC cleanup code only handles a zero-length trailing segment when software CRC stripping is enabled. When hardware stripping is active, the zero-length mbuf is silently chained to the reassembled packet. Forwarding such a packet causes a zero-length Tx descriptor, triggering a Malicious Driver Detection event on the PF and resetting the VF.

Quoted 5 lines

Fix by adding logic to detect a zero-length final segment when hardware CRC stripping is active, and freeing it.

Fixes a2b29a7733ef ("net/avf: enable basic Rx Tx")
Fixes b8b4c54ef9b0 ("net/iavf: support flexible Rx descriptor in normal

path")

Review

Quoted 9 lines
---
 drivers/net/intel/iavf/iavf_rxtx.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
(quoted diff) +0 -0

b/drivers/net/intel/iavf/iavf_rxtx.c

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts_flex_rxd(void

Quoted 4 lines

index a57af7faed..86ebb2618d 100644

drivers/net/intel/iavf/iavf_rxtx.c +0 -0
@@ -1716,6 +1716,14 @@ iavf_recv_scattered_pkts_flex_rxd(void

*rx_queue, struct rte_mbuf **rx_pkts,

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts_flex_rxd(void · line 1717

Quoted 2 lines
drivers/net/intel/iavf/iavf_rxtx.c +0 -0
 				rxm->data_len = (uint16_t)(rx_packet_len -
 
	RTE_ETHER_CRC_LEN);
Quoted 15 lines

drivers/net/intel/iavf/iavf_rxtx.c iavf_recv_scattered_pkts_flex_rxd(void *rx_queue, struct rte_mbuf **rx_pkts, · line 1728

Quoted 11 lines
drivers/net/intel/iavf/iavf_rxtx.c +8 -0
 			}
+		} else if (unlikely(rx_packet_len == 0)) {
+			/*
+			 * NIC split CRC bytes into a trailing segment which is
+			 * now empty after hardware CRC stripping. Free it.
+			 */
+			rte_pktmbuf_free_seg(rxm);
+			first_seg->nb_segs--;
+			last_seg->next = NULL;
 		}
 

The vector paths also handle scattered packets (via reassembly). Do they need a fix for this? What about the other drivers that work on the PF, such as ice/i40e?

The vector paths use the common ci_rx_reassemble_packets which already handles the zero-length trailing segment case correctly. When crc_len == 0 and the last segment has data_len == 0, the empty segment is freed.

Quoted 6 lines

The ice scalar path had the same issue but it was patched in 2022:
https://git.dpdk.org/dpdk/commit/?id=90ba4442058a14763e57ca96d03ab1e6044e3e5c
I cannot reproduce the behaviour on i40e hardware (either PF or VF) so I don't think it needs to be patched as the HW seems to behave differently.

Quoted 4 lines

Thanks for clarifying.

Applied to dpdk-next-net-intel.

thanks,
/Bruce