Every pmd RX function need keep the EXTERNAL_MBUF flag in mbuf.ol_flags, and can't overwrite it when filling ol_flags from descriptor to mbuf, otherwise, it probably cause to crash when freeing a mbuf and trying to freeing its attached external buffer, say, from guest space.
Signed-off-by: Changchun Ouyang <changchun.ouyang at intel.com> --- lib/librte_pmd_e1000/igb_rxtx.c | 5 +++-- lib/librte_pmd_i40e/i40e_rxtx.c | 8 +++++--- lib/librte_pmd_ixgbe/ixgbe_rxtx.c | 8 +++++--- lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c | 12 ++++++++---- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/librte_pmd_e1000/igb_rxtx.c b/lib/librte_pmd_e1000/igb_rxtx.c index f09c525..4123310 100644 --- a/lib/librte_pmd_e1000/igb_rxtx.c +++ b/lib/librte_pmd_e1000/igb_rxtx.c @@ -786,7 +786,7 @@ eth_igb_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(hlen_type_rss); pkt_flags = pkt_flags | rx_desc_status_to_pkt_flags(staterr); pkt_flags = pkt_flags | rx_desc_error_to_pkt_flags(staterr); - rxm->ol_flags = pkt_flags; + rxm->ol_flags = pkt_flags | (rxm->ol_flags & EXTERNAL_MBUF); /* * Store the mbuf address into the next entry of the array @@ -1020,7 +1020,8 @@ eth_igb_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(hlen_type_rss); pkt_flags = pkt_flags | rx_desc_status_to_pkt_flags(staterr); pkt_flags = pkt_flags | rx_desc_error_to_pkt_flags(staterr); - first_seg->ol_flags = pkt_flags; + first_seg->ol_flags = pkt_flags | + (first_seg->ol_flags & EXTERNAL_MBUF); /* Prefetch data of first segment, if configured to do so. */ rte_packet_prefetch((char *)first_seg->buf_addr + diff --git a/lib/librte_pmd_i40e/i40e_rxtx.c b/lib/librte_pmd_i40e/i40e_rxtx.c index 2b53677..68c3695 100644 --- a/lib/librte_pmd_i40e/i40e_rxtx.c +++ b/lib/librte_pmd_i40e/i40e_rxtx.c @@ -637,7 +637,8 @@ i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq) pkt_flags = i40e_rxd_status_to_pkt_flags(qword1); pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1); pkt_flags |= i40e_rxd_ptype_to_pkt_flags(qword1); - mb->ol_flags = pkt_flags; + mb->ol_flags = pkt_flags | + (mb->ol_flags & EXTERNAL_MBUF); if (pkt_flags & PKT_RX_RSS_HASH) mb->hash.rss = rte_le_to_cpu_32(\ rxdp->wb.qword0.hi_dword.rss); @@ -873,7 +874,7 @@ i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) pkt_flags = i40e_rxd_status_to_pkt_flags(qword1); pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1); pkt_flags |= i40e_rxd_ptype_to_pkt_flags(qword1); - rxm->ol_flags = pkt_flags; + rxm->ol_flags = pkt_flags | (rxm->ol_flags & EXTERNAL_MBUF); if (pkt_flags & PKT_RX_RSS_HASH) rxm->hash.rss = rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss); @@ -1027,7 +1028,8 @@ i40e_recv_scattered_pkts(void *rx_queue, pkt_flags = i40e_rxd_status_to_pkt_flags(qword1); pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1); pkt_flags |= i40e_rxd_ptype_to_pkt_flags(qword1); - first_seg->ol_flags = pkt_flags; + first_seg->ol_flags = pkt_flags | + (first_seg->ol_flags & EXTERNAL_MBUF); if (pkt_flags & PKT_RX_RSS_HASH) rxm->hash.rss = rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss); diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx.c index 1aefe5c..77e8689 100644 --- a/lib/librte_pmd_ixgbe/ixgbe_rxtx.c +++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx.c @@ -949,7 +949,8 @@ ixgbe_rx_scan_hw_ring(struct igb_rx_queue *rxq) /* reuse status field from scan list */ pkt_flags |= rx_desc_status_to_pkt_flags(s[j]); pkt_flags |= rx_desc_error_to_pkt_flags(s[j]); - mb->ol_flags = pkt_flags; + mb->ol_flags = pkt_flags | + (mb->ol_flags & EXTERNAL_MBUF); if (likely(pkt_flags & PKT_RX_RSS_HASH)) mb->hash.rss = rxdp[j].wb.lower.hi_dword.rss; @@ -1271,7 +1272,7 @@ ixgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(hlen_type_rss); pkt_flags = pkt_flags | rx_desc_status_to_pkt_flags(staterr); pkt_flags = pkt_flags | rx_desc_error_to_pkt_flags(staterr); - rxm->ol_flags = pkt_flags; + rxm->ol_flags = pkt_flags | (rxm->ol_flags & EXTERNAL_MBUF); if (likely(pkt_flags & PKT_RX_RSS_HASH)) rxm->hash.rss = rxd.wb.lower.hi_dword.rss; @@ -1515,7 +1516,8 @@ ixgbe_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, rx_desc_status_to_pkt_flags(staterr)); pkt_flags = (uint16_t)(pkt_flags | rx_desc_error_to_pkt_flags(staterr)); - first_seg->ol_flags = pkt_flags; + first_seg->ol_flags = pkt_flags | + (first_seg->ol_flags & EXTERNAL_MBUF); if (likely(pkt_flags & PKT_RX_RSS_HASH)) first_seg->hash.rss = rxd.wb.lower.hi_dword.rss; diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c index e813e43..af7b1cd 100644 --- a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c +++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c @@ -156,10 +156,14 @@ desc_to_olflags_v(__m128i descs[4], struct rte_mbuf **rx_pkts) ptype1 = _mm_or_si128(ptype1, vtag1); vol.dword = _mm_cvtsi128_si64(ptype1) & OLFLAGS_MASK_V; - rx_pkts[0]->ol_flags = vol.e[0]; - rx_pkts[1]->ol_flags = vol.e[1]; - rx_pkts[2]->ol_flags = vol.e[2]; - rx_pkts[3]->ol_flags = vol.e[3]; + rx_pkts[0]->ol_flags = vol.e[0] | + (rx_pkts[0]->ol_flags & EXTERNAL_MBUF); + rx_pkts[1]->ol_flags = vol.e[1] | + (rx_pkts[1]->ol_flags & EXTERNAL_MBUF); + rx_pkts[2]->ol_flags = vol.e[2] | + (rx_pkts[2]->ol_flags & EXTERNAL_MBUF); + rx_pkts[3]->ol_flags = vol.e[3] | + (rx_pkts[3]->ol_flags & EXTERNAL_MBUF); } #else #define desc_to_olflags_v(desc, rx_pkts) do {} while (0) -- 1.8.4.2