Bug 1416 - net/af_packet: tx_burst() can modify packets
Summary: net/af_packet: tx_burst() can modify packets
Status: RESOLVED INVALID
Alias: None
Product: DPDK
Classification: Unclassified
Component: ethdev (show other bugs)
Version: 24.03
Hardware: All All
: Normal normal
Target Milestone: ---
Assignee: dev
URL:
Depends on:
Blocks:
 
Reported: 2024-04-16 12:29 CEST by Konstantin Ananyev
Modified: 2024-04-16 17:58 CEST (History)
2 users (show)



Attachments

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.

Note You need to log in before you can comment on or make changes to this bug.