Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Jul 2026 18:24:13 +0000
From:      Arthur Kiyanovski <akiyano@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Cc:        Gilad Ben Yakov <giladben@amazon.com>
Subject:   git: 74bcb1151bb9 - main - ena: Fix false 'missing TX completions' warnings due to timestamp race
Message-ID:  <6a5921cd.37d9c.4cd795c@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by akiyano:

URL: https://cgit.FreeBSD.org/src/commit/?id=74bcb1151bb94279a4269fc842aa2be00800545e

commit 74bcb1151bb94279a4269fc842aa2be00800545e
Author:     Gilad Ben Yakov <giladben@amazon.com>
AuthorDate: 2026-06-21 12:45:38 +0000
Commit:     Arthur Kiyanovski <akiyano@FreeBSD.org>
CommitDate: 2026-07-16 18:20:41 +0000

    ena: Fix false 'missing TX completions' warnings due to timestamp race
    
    Sporadic 'Found a Tx that wasn't completed on time' warnings appear
    under sustained TX load, always reporting '1 msecs since last cleanup'
    despite the 5-second timeout threshold.
    
    The per-packet TX timestamp uses struct bintime (128 bits: two 64-bit
    fields sec and frac) which is read and written non-atomically. A race
    exists between the missing TX completion check
    (check_missing_comp_in_tx_queue reading the timestamp) and the TX
    submit path or cleanup path writing it on another CPU. Since the two
    fields are not updated atomically, the check can observe a partially
    written timestamp - one field from the old value and one from the new.
    This can produce a timestamp with {sec=0, frac=valid}, causing the
    check to compute a time offset equal to system uptime and falsely
    exceeding the 5-second timeout.
    
    Confirmed by instrumentation showing all occurrences had sec=0 with
    valid frac/mbuf, cleanup_running=0, and ticks==last_cleanup_ticks.
    
    Replace struct bintime with sbintime_t (a single 64-bit value) for
    tx_buf->timestamp. An aligned 64-bit store/load cannot be torn on
    64-bit architectures. Additionally, snapshot the timestamp into a
    local variable in the check path to prevent a read-then-read race
    where the timestamp could be zeroed between the zero-check and the
    offset calculation.
    
    Testing:
    On m6i.large (FreeBSD 15.0-RELEASE-p6 amd64, 2 IO queues), two
    instances with MTU 1500. Ran iperf -P 20 -u -b 320kpps (CPU
    saturated at ~7 Gbps aggregate).
    
    Without the fix: 8 warnings in 6 hours (first at ~72 min).
    With the fix: 0 warnings after 20+ hours under identical conditions.
    
    Fixes: 9b8d05b8ac78 ("Add support for Amazon Elastic Network Adapter (ENA) NIC")
    Submitted by: Gilad Ben Yakov <giladben@amazon.com>
    MFC after: 2 weeks
    Sponsored by: Amazon, Inc.
    Reviewed by: cperciva
    Differential Revision: https://reviews.freebsd.org/D58241
---
 sys/dev/ena/ena.c          | 13 +++++++------
 sys/dev/ena/ena.h          |  2 +-
 sys/dev/ena/ena_datapath.c |  4 ++--
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/sys/dev/ena/ena.c b/sys/dev/ena/ena.c
index 79b9937991c1..060d9e26c1cf 100644
--- a/sys/dev/ena/ena.c
+++ b/sys/dev/ena/ena.c
@@ -3213,7 +3213,7 @@ check_missing_comp_in_tx_queue(struct ena_adapter *adapter,
 {
 	uint32_t missed_tx = 0, new_missed_tx = 0;
 	device_t pdev = adapter->pdev;
-	struct bintime curtime, time;
+	sbintime_t curtime;
 	struct ena_tx_buffer *tx_buf;
 	int time_since_last_cleanup;
 	int missing_tx_comp_to;
@@ -3222,17 +3222,18 @@ check_missing_comp_in_tx_queue(struct ena_adapter *adapter,
 	enum ena_regs_reset_reason_types reset_reason = ENA_REGS_RESET_MISS_TX_CMPL;
 	bool cleanup_scheduled, cleanup_running;
 
-	getbinuptime(&curtime);
+	curtime = getsbinuptime();
 
 	for (i = 0; i < tx_ring->ring_size; i++) {
+		sbintime_t ts;
+
 		tx_buf = &tx_ring->tx_buffer_info[i];
 
-		if (bintime_isset(&tx_buf->timestamp) == 0)
+		ts = atomic_load_64(&tx_buf->timestamp);
+		if (ts == 0)
 			continue;
 
-		time = curtime;
-		bintime_sub(&time, &tx_buf->timestamp);
-		time_offset = bttosbt(time);
+		time_offset = curtime - ts;
 
 		if (unlikely(!atomic_load_8(&tx_ring->first_interrupt) &&
 		    time_offset > 2 * adapter->missing_tx_timeout)) {
diff --git a/sys/dev/ena/ena.h b/sys/dev/ena/ena.h
index ca5abe494e04..77cb8730627f 100644
--- a/sys/dev/ena/ena.h
+++ b/sys/dev/ena/ena.h
@@ -263,7 +263,7 @@ struct ena_tx_buffer {
 	bus_dmamap_t dmamap;
 
 	/* Used to detect missing tx packets */
-	struct bintime timestamp;
+	sbintime_t timestamp;
 	bool print_once;
 
 #ifdef DEV_NETMAP
diff --git a/sys/dev/ena/ena_datapath.c b/sys/dev/ena/ena_datapath.c
index c11006cbc10f..b58779e51fc3 100644
--- a/sys/dev/ena/ena_datapath.c
+++ b/sys/dev/ena/ena_datapath.c
@@ -274,7 +274,7 @@ ena_tx_cleanup(struct ena_ring *tx_ring)
 		mbuf = tx_info->mbuf;
 
 		tx_info->mbuf = NULL;
-		bintime_clear(&tx_info->timestamp);
+		atomic_store_64(&tx_info->timestamp, 0);
 
 		bus_dmamap_sync(adapter->tx_buf_tag, tx_info->dmamap,
 		    BUS_DMASYNC_POSTWRITE);
@@ -1055,7 +1055,7 @@ ena_xmit_mbuf(struct ena_ring *tx_ring, struct mbuf **mbuf)
 	counter_exit();
 
 	tx_info->tx_descs = nb_hw_desc;
-	getbinuptime(&tx_info->timestamp);
+	atomic_store_64(&tx_info->timestamp, getsbinuptime());
 	tx_info->print_once = true;
 
 	tx_ring->next_to_use = ENA_TX_RING_IDX_NEXT(next_to_use,


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a5921cd.37d9c.4cd795c>