From: Scott Mitchell <scott.k.mitch1@gmail.com>
To: dev@dpdk.org
Cc: stephen@networkplumber.org, thomas@monjalon.net,
david.marchand@redhat.com, mb@smartsharesystems.com,
Scott Mitchell <scott.k.mitch1@gmail.com>,
linville@tuxdriver.com, stable@dpdk.org
Subject: [PATCH v8 1/8] net/af_packet: fix frame status memory ordering
Date: Wed, 2 Dec 2026 09:17:57 -0800 [thread overview]
Message-ID: <20261202171804.50287-2-scott.k.mitch1@gmail.com> (raw)
In-Reply-To: <20261202171804.50287-1-scott.k.mitch1@gmail.com>
tp_status hands each ring frame between the kernel and the driver, but
it was read and written with plain accesses. On weakly ordered CPUs, RX
could read frame data older than the status it just saw, and TX could
publish SEND_REQUEST before the frame contents were visible to the
kernel.
Load tp_status with acquire and store it with release, as libpcap does
for the same ring.
Fixes: 364e08f2bbc0 ("af_packet: add PMD for AF_PACKET-based virtual devices")
Cc: linville@tuxdriver.com
Cc: stable@dpdk.org
Signed-off-by: Scott Mitchell <scott.k.mitch1@gmail.com>
---
drivers/net/af_packet/rte_eth_af_packet.c | 32 ++++++++++++++++++-----
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index fbaea57615..4a8afe08c7 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -9,6 +9,7 @@
#include <rte_common.h>
#include <rte_string_fns.h>
#include <rte_mbuf.h>
+#include <rte_stdatomic.h>
#include <ethdev_driver.h>
#include <ethdev_vdev.h>
#include <rte_malloc.h>
@@ -174,6 +175,21 @@ eth_af_packet_rx_scatter(struct rte_mempool *mb_pool, struct rte_mbuf *mbuf,
return 0;
}
+/* tp_status hands a frame between the kernel and us; order frame accesses */
+static inline uint32_t
+tpacket_read_status(struct tpacket2_hdr *ppd)
+{
+ return rte_atomic_load_explicit((RTE_ATOMIC(uint32_t) *)&ppd->tp_status,
+ rte_memory_order_acquire);
+}
+
+static inline void
+tpacket_write_status(struct tpacket2_hdr *ppd, uint32_t status)
+{
+ rte_atomic_store_explicit((RTE_ATOMIC(uint32_t) *)&ppd->tp_status, status,
+ rte_memory_order_release);
+}
+
static uint16_t
eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
{
@@ -187,6 +203,7 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
unsigned long num_rx_bytes = 0;
unsigned int framecount, framenum;
uint32_t pkt_len;
+ uint32_t tp_status;
if (unlikely(nb_pkts == 0))
return 0;
@@ -200,7 +217,8 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
for (i = 0; i < nb_pkts; i++) {
/* point at the next incoming frame */
ppd = (struct tpacket2_hdr *) pkt_q->rd[framenum].iov_base;
- if ((ppd->tp_status & TP_STATUS_USER) == 0)
+ tp_status = tpacket_read_status(ppd);
+ if ((tp_status & TP_STATUS_USER) == 0)
break;
/* skip outgoing frames if ignore_outgoing is set */
@@ -243,7 +261,7 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
rte_pktmbuf_pkt_len(mbuf) = pkt_len;
/* check for vlan info */
- if (ppd->tp_status & TP_STATUS_VLAN_VALID) {
+ if (tp_status & TP_STATUS_VLAN_VALID) {
uint16_t tpid;
mbuf->vlan_tci = ppd->tp_vlan_tci;
@@ -252,7 +270,7 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
if (pkt_q->vlan_strip) {
mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN_STRIPPED;
} else {
- tpid = (ppd->tp_status & TP_STATUS_VLAN_TPID_VALID) ?
+ tpid = (tp_status & TP_STATUS_VLAN_TPID_VALID) ?
ppd->tp_vlan_tpid : RTE_ETHER_TYPE_VLAN;
if (rte_vlan_insert_tpid(&mbuf, tpid) != 0) {
PMD_LOG(ERR, "Failed to reinsert VLAN tag");
@@ -280,7 +298,7 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
release_frame:
/* release incoming frame and advance ring buffer */
- ppd->tp_status = TP_STATUS_KERNEL;
+ tpacket_write_status(ppd, TP_STATUS_KERNEL);
if (++framenum >= framecount)
framenum = 0;
}
@@ -355,7 +373,7 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
}
/* point at the next incoming frame */
- if (!tx_ring_status_available(ppd->tp_status)) {
+ if (!tx_ring_status_available(tpacket_read_status(ppd))) {
if (poll(&pfd, 1, -1) < 0)
break;
@@ -378,7 +396,7 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
*
* This results in poll() returning POLLOUT.
*/
- if (!tx_ring_status_available(ppd->tp_status))
+ if (!tx_ring_status_available(tpacket_read_status(ppd)))
break;
/* copy the tx frame data */
@@ -397,7 +415,7 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
ppd->tp_snaplen = mbuf->pkt_len;
/* release incoming frame and advance ring buffer */
- ppd->tp_status = TP_STATUS_SEND_REQUEST;
+ tpacket_write_status(ppd, TP_STATUS_SEND_REQUEST);
if (++framenum >= framecount)
framenum = 0;
ppd = (struct tpacket2_hdr *) pkt_q->rd[framenum].iov_base;
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-12-02 17:19 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-27 18:13 [PATCH v1 0/3] net/af_packet: correctness fixes and improvements scott.k.mitch1
2026-01-27 18:13 ` [PATCH v1 1/3] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-01-27 18:39 ` Stephen Hemminger
2026-01-28 1:35 ` Scott Mitchell
2026-01-27 18:13 ` [PATCH v1 2/3] net/af_packet: RX/TX rte_memcpy, bulk free, prefetch scott.k.mitch1
2026-01-27 18:54 ` Stephen Hemminger
2026-01-28 1:23 ` Scott Mitchell
2026-01-28 9:49 ` Morten Brørup
2026-01-28 15:37 ` Scott Mitchell
2026-01-28 16:57 ` Stephen Hemminger
2026-01-27 18:13 ` [PATCH v1 3/3] net/af_packet: software checksum and tx poll control scott.k.mitch1
2026-01-27 18:57 ` Stephen Hemminger
2026-01-28 7:05 ` Scott Mitchell
2026-01-28 17:36 ` Stephen Hemminger
2026-01-28 18:59 ` Scott Mitchell
2026-01-27 20:45 ` [REVIEW] " Stephen Hemminger
2026-01-28 9:36 ` [PATCH v2 0/4] af_packet correctness, performance, cksum scott.k.mitch1
2026-01-28 9:36 ` [PATCH v2 1/4] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-01-28 16:59 ` Stephen Hemminger
2026-01-28 18:00 ` Scott Mitchell
2026-01-28 18:28 ` Stephen Hemminger
2026-01-28 9:36 ` [PATCH v2 2/4] net/af_packet: RX/TX unlikely, bulk free, prefetch scott.k.mitch1
2026-01-28 9:36 ` [PATCH v2 3/4] net/af_packet: tx poll control scott.k.mitch1
2026-01-28 9:36 ` [PATCH v2 4/4] net/af_packet: software checksum scott.k.mitch1
2026-01-28 18:27 ` Stephen Hemminger
2026-01-28 19:08 ` Scott Mitchell
2026-01-28 19:10 ` [PATCH v3 0/4] af_packet correctness, performance, cksum scott.k.mitch1
2026-01-28 19:10 ` [PATCH v3 1/4] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-01-28 19:10 ` [PATCH v3 2/4] net/af_packet: RX/TX unlikely, bulk free, prefetch scott.k.mitch1
2026-01-29 1:07 ` Stephen Hemminger
2026-02-02 5:29 ` Scott Mitchell
2026-01-28 19:10 ` [PATCH v3 3/4] net/af_packet: tx poll control scott.k.mitch1
2026-01-28 19:10 ` [PATCH v3 4/4] net/af_packet: software checksum scott.k.mitch1
2026-01-28 21:57 ` [REVIEW] " Stephen Hemminger
2026-02-02 7:55 ` Scott Mitchell
2026-02-02 16:58 ` Stephen Hemminger
2026-02-02 8:14 ` [PATCH v4 0/4] af_packet correctness, performance, cksum scott.k.mitch1
2026-02-02 8:14 ` [PATCH v4 1/4] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-02-02 8:14 ` [PATCH v4 2/4] net/af_packet: RX/TX bulk free, unlikely hint scott.k.mitch1
2026-02-02 8:14 ` [PATCH v4 3/4] net/af_packet: tx poll control scott.k.mitch1
2026-02-02 8:14 ` [PATCH v4 4/4] net/af_packet: add software checksum offload support scott.k.mitch1
2026-02-02 17:00 ` Stephen Hemminger
2026-02-02 18:47 ` Stephen Hemminger
2026-02-03 6:41 ` Scott Mitchell
2026-02-02 18:53 ` [PATCH v4 0/4] af_packet correctness, performance, cksum Stephen Hemminger
2026-02-03 7:07 ` [PATCH v5 " scott.k.mitch1
2026-02-03 7:07 ` [PATCH v5 1/4] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-02-03 7:07 ` [PATCH v5 2/4] net/af_packet: RX/TX bulk free, unlikely hint scott.k.mitch1
2026-02-03 7:07 ` [PATCH v5 3/4] net/af_packet: tx poll control scott.k.mitch1
2026-02-03 7:07 ` [PATCH v5 4/4] net/af_packet: add software checksum offload support scott.k.mitch1
2026-02-03 8:20 ` Scott Mitchell
2026-02-03 14:12 ` Stephen Hemminger
2026-02-04 2:59 ` Scott Mitchell
2026-02-03 14:13 ` Stephen Hemminger
2026-02-04 1:39 ` Scott Mitchell
2026-02-05 21:27 ` Stephen Hemminger
2026-02-06 1:11 ` [PATCH v6 0/4] af_packet correctness, performance, cksum scott.k.mitch1
2026-02-06 1:11 ` [PATCH v6 1/4] net/af_packet: fix thread safety and frame calculations scott.k.mitch1
2026-02-06 1:11 ` [PATCH v6 2/4] net/af_packet: RX/TX bulk free, unlikely hint scott.k.mitch1
2026-02-06 1:11 ` [PATCH v6 3/4] net/af_packet: tx poll control scott.k.mitch1
2026-02-06 1:11 ` [PATCH v6 4/4] net/af_packet: add software checksum offload support scott.k.mitch1
2026-02-06 1:49 ` [PATCH v6 0/4] af_packet correctness, performance, cksum Stephen Hemminger
2026-02-06 4:45 ` Scott Mitchell
2026-02-06 14:36 ` Morten Brørup
2026-02-06 16:11 ` Stephen Hemminger
2026-12-01 22:24 ` [PATCH v7 0/4] net/af_packet: " Scott Mitchell
2026-12-01 22:24 ` [PATCH v7 1/4] net/af_packet: fix thread safety and frame calculations Scott Mitchell
2026-12-01 22:24 ` [PATCH v7 2/4] net/af_packet: RX/TX bulk free, unlikely hint Scott Mitchell
2026-12-01 22:24 ` [PATCH v7 3/4] net/af_packet: tx poll control Scott Mitchell
2026-12-01 22:24 ` [PATCH v7 4/4] net/af_packet: add software checksum offload support Scott Mitchell
2026-12-01 23:22 ` Scott Mitchell
2026-12-01 22:32 ` [PATCH v7 0/4] net/af_packet: correctness, performance, cksum Scott Mitchell
2026-12-02 7:09 ` Stephen Hemminger
2026-12-02 8:01 ` Morten Brørup
2026-12-02 16:11 ` Scott Mitchell
2026-12-02 17:17 ` [PATCH v8 0/8] net/af_packet fixes and Tx features Scott Mitchell
2026-12-02 17:17 ` Scott Mitchell [this message]
2026-12-02 17:26 ` [PATCH v8 1/8] net/af_packet: fix frame status memory ordering Stephen Hemminger
2026-12-02 17:17 ` [PATCH v8 2/8] net/af_packet: fix frame address with unused block tail Scott Mitchell
2026-12-02 17:17 ` [PATCH v8 3/8] net/af_packet: fix maximum Rx packet length Scott Mitchell
2026-12-02 17:18 ` [PATCH v8 4/8] test/af_packet: add frame layout tests Scott Mitchell
2026-12-02 17:18 ` [PATCH v8 5/8] net/af_packet: reject invalid ring parameters at probe Scott Mitchell
2026-12-02 17:29 ` Stephen Hemminger
2026-12-02 17:18 ` [PATCH v8 6/8] net/af_packet: clean up Tx and bulk free mbufs Scott Mitchell
2026-12-02 17:18 ` [PATCH v8 7/8] net/af_packet: do not block in Tx when the ring is full Scott Mitchell
2026-12-02 17:18 ` [PATCH v8 8/8] net/af_packet: add Tx checksum offload Scott Mitchell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202171804.50287-2-scott.k.mitch1@gmail.com \
--to=scott.k.mitch1@gmail.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=linville@tuxdriver.com \
--cc=mb@smartsharesystems.com \
--cc=stable@dpdk.org \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox