Bug 1416

Summary: net/af_packet: tx_burst() can modify packets
Product: DPDK Reporter: Konstantin Ananyev (konstantin.v.ananyev)
Component: ethdevAssignee: dev
Status: RESOLVED INVALID    
Severity: normal CC: konstantin.v.ananyev, linville
Priority: Normal    
Version: 24.03   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Konstantin Ananyev 2024-04-16 12:29:53 CEST
According to the ethdev doc, in general, PMD tx_burst() should not modify mbuf contents. To be more specific:

ethdev/rte_ethdev.h:6396
...
 * @note This function must not modify mbufs (including packets data)
 * unless the refcnt is 1.
 * An exception is the bonding PMD, which does not have "Tx prepare" support,
 * in this case, mbufs may be modified.
...

Though why looking at eth_af_packet_tx(), it looks to me like it does modify
the packet contents without any checks for refcnt, etc.:

static uint16_t
eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
{
	...
	for (i = 0; i < nb_pkts; i++) {
		mbuf = *bufs++;

		...

		/* insert vlan info if necessary */
		if (mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
			if (rte_vlan_insert(&mbuf)) {
				rte_pktmbuf_free(mbuf);
				continue; 

AFAIU, it does copy of mbuf contents into pbuf anyway (just few line below).
So the fix might be - simply insert VLAN tag at copying stage.
Feel free to correct me, if I missed something.
Comment 1 Konstantin Ananyev 2024-04-16 17:58:33 CEST
As Stephen Hemminger <stephen@networkplumber.org> pointed out:

vlan_insert will fail if the mbuf is has refcnt > 1.

static inline int rte_vlan_insert(struct rte_mbuf **m)
{
	struct rte_ether_hdr *oh, *nh;
	struct rte_vlan_hdr *vh;

	/* Can't insert header if mbuf is shared */
	if (!RTE_MBUF_DIRECT(*m) || rte_mbuf_refcnt_read(*m) > 1)
		return -EINVAL;

So closing as not a bug.