Skip to contentSkip to conversation

eth: fbnic: miscellaneous driver fixes

PATCH Applied Dimitri Daskalakis 4 participants 14 messages Nov 17 – Nov 21

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover eth: fbnic: miscellaneous driver fixes

From: Dimitri Daskalakis <[email protected]>

AI identified several bugs while I was working on unrelated parts of the driver. fbnic_queue_stop() always waits on queue 0 to idle for rx queues. fbnic_get_ts_stats() dereferences a NULL pointer when the interface is down. And fbnic_{set|reset}_netif_napi does not account for disabled rings.

All bugs were verified on HW, and a new stats selftest was added to identify other drivers with the same timestamp stats mishandling.

v2:
- Add .get_ts_stats() support to netdevsim
- v1: https://lore.kernel.org/all/[email protected]/

Dimitri Daskalakis (5):
eth: fbnic: wait on the correct queues in fbnic_queue_stop()
eth: fbnic: skip disabled Tx rings when setting the queue NAPI
eth: fbnic: skip freed Tx rings in fbnic_get_ts_stats()
netdevsim: report fake timestamping stats
selftests: drv-net: stats: query timestamping stats while down

 .../net/ethernet/meta/fbnic/fbnic_ethtool.c   |  3 +++
 drivers/net/ethernet/meta/fbnic/fbnic_txrx.c  | 20 ++++++++++++---
 drivers/net/netdevsim/ethtool.c               |  9 +++++++
 tools/testing/selftests/drivers/net/stats.py  | 25 ++++++++++++++++++-
 4 files changed, 52 insertions(+), 5 deletions(-)
Signature · 1 line
2.52.1
#1 lore raw

PATCH v2 1/5 eth: fbnic: wait on the correct queues in fbnic_queue_stop()

From: Dimitri Daskalakis <[email protected]>

fbnic_queue_stop() waits for every queue of the NAPI vector to go idle before tearing it down, using sub0.q_idx as the queue index. We set q_idx on submission queues for Tx, and completion queues on Rx, so this waits on queue 0 for every Rx queue.

For non-combined channels, stopping an Rx queue always stops/wakes Tx queue 0.

Set the queue id on Tx completion rings so we don't have to distinguish between ring types to get the correct queue id, and don't stop/wake disabled rings.

This bug was found by AI and verified on HW.

Reproduced by binding a devmem dmabuf to one Rx queue (netdev bind-rx). Added a printk to fbnic_wait_queue_idle(), and traced Tx queue stop/wake with bpftrace.

combined 79, bind rxq 1:
before:
netif_stop_subqueue(1)
fbnic_wait_queue_idle(tx, 1)
fbnic_wait_queue_idle(rx, 0)
netif_wake_subqueue(1)
after:
netif_stop_subqueue(1)
fbnic_wait_queue_idle(tx, 1)
fbnic_wait_queue_idle(rx, 1)
netif_wake_subqueue(1)

rx 34 tx 34, bind rxq 5:
before:
netif_stop_subqueue(0)
fbnic_wait_queue_idle(tx, 0) fbnic_wait_queue_idle(rx, 0) netif_wake_subqueue(0)
after:
fbnic_wait_queue_idle(tx, 39) fbnic_wait_queue_idle(rx, 5)
^ no more stop/wake of Tx queue 0
(tx 39 is the XDP Tx queue of rxq 5's vector,
Rx queues always get an XDP Tx queue)

Fixes da43127a8edc ("eth: fbnic: support queue ops / zero-copy Rx")
---
 drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +10 -4
index 07d4b2e92362..5efed21e5932 100644
@@ -1772,7 +1772,7 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net *fbn,
 
 		/* Configure Tx completion queue */
 		db = &uc_addr[FBNIC_QUEUE(txq_idx) + FBNIC_QUEUE_TCQ_HEAD];
-		fbnic_ring_init(&qt->cmpl, db, 0, 0);
+		fbnic_ring_init(&qt->cmpl, db, txq_idx, 0);
 
 		/* Update Tx queue index */
 		txt_count--;
@@ -3047,8 +3047,11 @@ static void __fbnic_nv_restart(struct fbnic_net *fbn,
 	fbnic_wr32(fbd, FBNIC_INTR_SET(nv->v_idx / 32), BIT(nv->v_idx % 32));
 	fbnic_wrfl(fbd);
 
-	for (i = 0; i < nv->txt_count; i++)
+	for (i = 0; i < nv->txt_count; i++) {
+		if (nv->qt[i].sub0.flags & FBNIC_RING_F_DISABLED)
+			continue;
 		netif_wake_subqueue(fbn->netdev, nv->qt[i].sub0.q_idx);
+	}
 	fbnic_dbg_nv_init(nv);
 }
 
@@ -3089,13 +3092,16 @@ static int fbnic_queue_stop(struct net_device *dev, void *qmem, int idx)
 	napi_disable_locked(&nv->napi);
 	fbnic_nv_irq_disable(nv);
 
-	for (i = 0; i < nv->txt_count; i++)
+	for (i = 0; i < nv->txt_count; i++) {
+		if (nv->qt[i].sub0.flags & FBNIC_RING_F_DISABLED)
+			continue;
 		netif_stop_subqueue(dev, nv->qt[i].sub0.q_idx);
+	}
 	fbnic_nv_disable(fbn, nv);
 
 	for (t = 0; t < nv->txt_count + nv->rxt_count; t++) {
 		err = fbnic_wait_queue_idle(fbn, t >= nv->txt_count,
-					    nv->qt[t].sub0.q_idx);
+					    nv->qt[t].cmpl.q_idx);
 		if (err)
 			goto err_restart;
 	}
Signature · 1 line
2.52.1
Reviewed-by on v2 1/5
#2 lore raw

Re: [PATCH net v2 1/5] eth: fbnic: wait on the correct queues in fbnic_queue_stop()

Quoted 7 lines · Dimitri Daskalakis

From: Dimitri Daskalakis <[email protected]>

fbnic_queue_stop() waits for every queue of the NAPI vector to go idle before tearing it down, using sub0.q_idx as the queue index. We set q_idx on submission queues for Tx, and completion queues on Rx, so this waits on queue 0 for every Rx queue.

Quoted 8 lines

For non-combined channels, stopping an Rx queue always stops/wakes Tx queue 0.

Set the queue id on Tx completion rings so we don't have to distinguish between ring types to get the correct queue id, and don't stop/wake disabled rings.

This bug was found by AI and verified on HW.

The LLMs I run complained about this as well -- nice to see it verified on HW. Also, this fix is much cleaner than what my clanker suggested!

#3 lore raw

Re: [PATCH net v2 1/5] eth: fbnic: wait on the correct queues in fbnic_queue_stop()

In reply to Dimitri Daskalakis
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] After this patch, fbnic_queue_stop() passes nv->qt[t].cmpl.q_idx to fbnic_wait_queue_idle().

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but fbnic_queue_stop() stops the vector's netdev Tx queues with a bare…

--

eth: fbnic: wait on the correct queues in fbnic_queue_stop()

This patch sets q_idx on Tx completion rings. fbnic_queue_stop() now passes cmpl.q_idx to fbnic_wait_queue_idle(), so Rx queues no longer wait on queue 0. It also skips stop and wake of Tx rings that are marked FBNIC_RING_F_DISABLED.

Quoted 4 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +0 -0
index 07d4b2e923627..5efed21e59329 100644

[ ... ]

drivers/net/ethernet/meta/fbnic/fbnic_txrx.c static int fbnic_queue_stop(struct net_device *dev, void *qmem, int idx) · line 3100

Quoted 11 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +4 -1
@@ -3089,13 +3092,16 @@ static int fbnic_queue_stop(struct net_device *dev, void *qmem, int idx)
 	napi_disable_locked(&nv->napi);
 	fbnic_nv_irq_disable(nv);
 
-	for (i = 0; i < nv->txt_count; i++)
+	for (i = 0; i < nv->txt_count; i++) {
+		if (nv->qt[i].sub0.flags & FBNIC_RING_F_DISABLED)
+			continue;
 		netif_stop_subqueue(dev, nv->qt[i].sub0.q_idx);
+	}
 	fbnic_nv_disable(fbn, nv);

[Severity: High]
This isn't a bug introduced by this patch, but does anything here wait for an fbnic_xmit_frame() call that is already running on another CPU?

netif_stop_subqueue() only sets __QUEUE_STATE_DRV_XOFF. Nothing calls __netif_tx_lock() or synchronize_net() before fbnic_nv_disable(), fbnic_wait_queue_idle() and fbnic_nv_flush() run. Only the full-down path in fbnic_pci.c uses netif_tx_disable().

A sender may pass the netif_xmit_frozen_or_stopped() check before the bit is set. It can then still be inside fbnic_tx_map(), writing tx_buf[], ring->tail and the BQL state, and ringing the doorbell.

Suppose it sets ring->tail after fbnic_nv_flush() has run:

fbnic_nv_flush()

    fbnic_clean_twq0(nv, 0, &qt->sub0, true, qt->sub0.tail);
    ...
    netdev_tx_reset_queue(tx_queue);

Is the skb and its DMA mapping then leaked once __fbnic_nv_restart() re-enables the ring and fbnic_enable_twq0() resets head/tail to 0? BQL would also keep in-flight bytes that never complete, and that can stall the Tx queue.

Now suppose the sender is delayed until after fbnic_enable_twq0() has done this:

	twq->tail = 0;
	twq->head = 0;

It would then write a stale ring->tail and ring the doorbell, and the hardware would fetch old descriptors whose buffers are already unmapped. Could those completions make fbnic_clean_twq0() read a NULL ring->tx_buf[] entry and dereference FBNIC_XMIT_CB(skb)->desc_count on it?

To hit this, a queue restart (netdev bind-rx devmem, io_uring zcrx) has to run on an Rx queue whose NAPI vector also serves a combined Tx queue, while another CPU is sending on that Tx queue.

drivers/net/ethernet/meta/fbnic/fbnic_txrx.c static int fbnic_queue_stop(struct net_device *dev, void *qmem, int idx) · line 3104

Quoted 5 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +1 -1
 	for (t = 0; t < nv->txt_count + nv->rxt_count; t++) {
 		err = fbnic_wait_queue_idle(fbn, t >= nv->txt_count,
-					    nv->qt[t].sub0.q_idx);
+					    nv->qt[t].cmpl.q_idx);

[Severity: Medium]
On an Rx-only vector the Tx triad has sub0 disabled and carries only the XDP TWQ1 ring, so this call becomes fbnic_wait_queue_idle(fbn, false, txq_idx). Does fbnic_wait_queue_idle() actually cover TWQ1 of that queue?

It builds a single bit from the queue index and tests that bit in all four Tx idle arrays:

fbnic_wait_queue_idle() {
    ...
	off = idx / 32;
	mask = BIT(idx % 32);
    ...
}

The TWQ, TQS and TDE idle arrays are twice as wide as the TCQ one:

#define FBNIC_QM_TWQ_IDLE_CNT 8
#define FBNIC_QM_TCQ_IDLE_CNT 4
#define FBNIC_QM_TQS_IDLE_CNT 8
#define FBNIC_QM_TDE_IDLE_CNT 8

There are 128 queues with two work queues each (TWQ0 and TWQ1), so this looks like one bit per TWQ. fbnic_wait_all_queues_idle() reads all 8 registers, but fbnic_wait_queue_idle() only reads registers 0 to 3.

If bit idx maps to TWQ0, it is always idle here, because TWQ0 is FBNIC_RING_F_DISABLED on this triad. The TWQ1 ring that carries XDP_TX traffic would then never be polled.

Next, fbnic_queue_stop() calls fbnic_nv_flush(), which runs fbnic_clean_twq1() and unmaps the XDP buffers. Could the hardware still be fetching TWQ1 descriptors at that point?

The bit layout isn't documented in-tree, so the answer depends on the hardware. The commit message gives "fbnic_wait_queue_idle(tx, 39)" as the wait on the vector's XDP Tx queue. Is that wait enough to cover TWQ1?

Quoted 3 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +0 -0
 		if (err)
 			goto err_restart;
 	}
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117215416.1901246-1-dimitri.daskalakis1%40gmail.com
#4 lore raw

Re: [PATCH net v2 1/5] eth: fbnic: wait on the correct queues in fbnic_queue_stop()

Quoted 88 lines · On 11/19/26 1:54 AM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] After this patch, fbnic_queue_stop() passes nv->qt[t].cmpl.q_idx to fbnic_wait_queue_idle().

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but fbnic_queue_stop() stops the vector's netdev Tx queues with a bare…

--

eth: fbnic: wait on the correct queues in fbnic_queue_stop()

This patch sets q_idx on Tx completion rings. fbnic_queue_stop() now passes cmpl.q_idx to fbnic_wait_queue_idle(), so Rx queues no longer wait on queue 0. It also skips stop and wake of Tx rings that are marked FBNIC_RING_F_DISABLED.

Quoted 4 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +0 -0
index 07d4b2e923627..5efed21e59329 100644

[ ... ]

drivers/net/ethernet/meta/fbnic/fbnic_txrx.c static int fbnic_queue_stop(struct net_device *dev, void *qmem, int idx) · line 3100

Quoted 11 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +4 -1
@@ -3089,13 +3092,16 @@ static int fbnic_queue_stop(struct net_device *dev, void *qmem, int idx)
 	napi_disable_locked(&nv->napi);
 	fbnic_nv_irq_disable(nv);
 
-	for (i = 0; i < nv->txt_count; i++)
+	for (i = 0; i < nv->txt_count; i++) {
+		if (nv->qt[i].sub0.flags & FBNIC_RING_F_DISABLED)
+			continue;
 		netif_stop_subqueue(dev, nv->qt[i].sub0.q_idx);
+	}
 	fbnic_nv_disable(fbn, nv);

[Severity: High]
This isn't a bug introduced by this patch, but does anything here wait for an fbnic_xmit_frame() call that is already running on another CPU?

netif_stop_subqueue() only sets __QUEUE_STATE_DRV_XOFF. Nothing calls __netif_tx_lock() or synchronize_net() before fbnic_nv_disable(), fbnic_wait_queue_idle() and fbnic_nv_flush() run. Only the full-down path in fbnic_pci.c uses netif_tx_disable().

A sender may pass the netif_xmit_frozen_or_stopped() check before the bit is set. It can then still be inside fbnic_tx_map(), writing tx_buf[], ring->tail and the BQL state, and ringing the doorbell.

Suppose it sets ring->tail after fbnic_nv_flush() has run:

fbnic_nv_flush()

    fbnic_clean_twq0(nv, 0, &qt->sub0, true, qt->sub0.tail);
    ...
    netdev_tx_reset_queue(tx_queue);

Is the skb and its DMA mapping then leaked once __fbnic_nv_restart() re-enables the ring and fbnic_enable_twq0() resets head/tail to 0? BQL would also keep in-flight bytes that never complete, and that can stall the Tx queue.

Now suppose the sender is delayed until after fbnic_enable_twq0() has done this:

	twq->tail = 0;
	twq->head = 0;

It would then write a stale ring->tail and ring the doorbell, and the hardware would fetch old descriptors whose buffers are already unmapped. Could those completions make fbnic_clean_twq0() read a NULL ring->tx_buf[] entry and dereference FBNIC_XMIT_CB(skb)->desc_count on it?

To hit this, a queue restart (netdev bind-rx devmem, io_uring zcrx) has to run on an Rx queue whose NAPI vector also serves a combined Tx queue, while another CPU is sending on that Tx queue.

Quoted 1 line
Quoted 5 lines

drivers/net/ethernet/meta/fbnic/fbnic_txrx.c static int fbnic_queue_stop(struct net_device *dev, void *qmem, int idx) · line 3104

Quoted 4 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +1 -1
 	for (t = 0; t < nv->txt_count + nv->rxt_count; t++) {
 		err = fbnic_wait_queue_idle(fbn, t >= nv->txt_count,
-					    nv->qt[t].sub0.q_idx);
+					    nv->qt[t].cmpl.q_idx);

This finding looks legit. I'd prefer to submit a fix for this separately, and I can try to repro on HW in the meantime.

Quoted 31 lines

[Severity: Medium]
On an Rx-only vector the Tx triad has sub0 disabled and carries only the XDP TWQ1 ring, so this call becomes fbnic_wait_queue_idle(fbn, false, txq_idx). Does fbnic_wait_queue_idle() actually cover TWQ1 of that queue?

It builds a single bit from the queue index and tests that bit in all four Tx idle arrays:

fbnic_wait_queue_idle() {
    ...
	off = idx / 32;
	mask = BIT(idx % 32);
    ...
}

The TWQ, TQS and TDE idle arrays are twice as wide as the TCQ one:

#define FBNIC_QM_TWQ_IDLE_CNT 8
#define FBNIC_QM_TCQ_IDLE_CNT 4
#define FBNIC_QM_TQS_IDLE_CNT 8
#define FBNIC_QM_TDE_IDLE_CNT 8

There are 128 queues with two work queues each (TWQ0 and TWQ1), so this looks like one bit per TWQ. fbnic_wait_all_queues_idle() reads all 8 registers, but fbnic_wait_queue_idle() only reads registers 0 to 3.

If bit idx maps to TWQ0, it is always idle here, because TWQ0 is FBNIC_RING_F_DISABLED on this triad. The TWQ1 ring that carries XDP_TX traffic would then never be polled.

Quoted 13 lines

Next, fbnic_queue_stop() calls fbnic_nv_flush(), which runs fbnic_clean_twq1() and unmaps the XDP buffers. Could the hardware still be fetching TWQ1 descriptors at that point?

The bit layout isn't documented in-tree, so the answer depends on the hardware. The commit message gives "fbnic_wait_queue_idle(tx, 39)" as the wait on the vector's XDP Tx queue. Is that wait enough to cover TWQ1?

Quoted 3 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +0 -0
 		if (err)
 			goto err_restart;
 	}

This also looks legit, and I can submit a fix in a subsequent series.

#5 lore raw

PATCH v2 2/5 eth: fbnic: skip disabled Tx rings when setting the queue NAPI

In reply to Dimitri Daskalakis

From: Dimitri Daskalakis <[email protected]>

When Rx and Tx channels are not combined, each Rx vector gets a Tx triad whose sub0 is disabled with a q_idx of 0. fbnic_set_netif_napi() and fbnic_reset_netif_napi() don't skip it, so every Rx vector associates Tx queue 0 with its own NAPI, and the netlink queue info reports the wrong NAPI for Tx queue 0.

This bug was found by AI and verified on HW.

Reproduced with "ethtool -L eth0 combined 0 rx 34 tx 34", and reading the NAPI IDs with "ynl --family netdev --dump queue-get":

before: tx 0 napi-id 580, tx 1 napi-id 514, rx 33 napi-id 580

                       ^^^ rx 33's NAPI, not vector 0's

after: tx 0 napi-id 513, tx 1 napi-id 514, rx 33 napi-id 580

Fixes cf4facfb132a ("eth: fbnic: Add support for XDP queues")
---
 drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +6 -0
index 5efed21e5932..89e7b806363b 100644
@@ -2184,6 +2184,9 @@ static void fbnic_set_netif_napi(struct fbnic_napi_vector *nv)
 	for (i = 0; i < nv->txt_count; i++) {
 		struct fbnic_q_triad *qt = &nv->qt[i];
 
+		if (qt->sub0.flags & FBNIC_RING_F_DISABLED)
+			continue;
+
 		netif_queue_set_napi(nv->napi.dev, qt->sub0.q_idx,
 				     NETDEV_QUEUE_TYPE_TX, &nv->napi);
 	}
@@ -2205,6 +2208,9 @@ static void fbnic_reset_netif_napi(struct fbnic_napi_vector *nv)
 	for (i = 0; i < nv->txt_count; i++) {
 		struct fbnic_q_triad *qt = &nv->qt[i];
 
+		if (qt->sub0.flags & FBNIC_RING_F_DISABLED)
+			continue;
+
 		netif_queue_set_napi(nv->napi.dev, qt->sub0.q_idx,
 				     NETDEV_QUEUE_TYPE_TX, NULL);
 	}
Signature · 1 line
2.52.1
Reviewed-by on v2 2/5
#6 lore raw

Re: [PATCH net v2 2/5] eth: fbnic: skip disabled Tx rings when setting the queue NAPI

Quoted 13 lines · Dimitri Daskalakis

From: Dimitri Daskalakis <[email protected]>

When Rx and Tx channels are not combined, each Rx vector gets a Tx triad whose sub0 is disabled with a q_idx of 0. fbnic_set_netif_napi() and fbnic_reset_netif_napi() don't skip it, so every Rx vector associates Tx queue 0 with its own NAPI, and the netlink queue info reports the wrong NAPI for Tx queue 0.

This bug was found by AI and verified on HW.

Reproduced with "ethtool -L eth0 combined 0 rx 34 tx 34", and reading the NAPI IDs with "ynl --family netdev --dump queue-get":

Quoted 6 lines

before: tx 0 napi-id 580, tx 1 napi-id 514, rx 33 napi-id 580

                       ^^^ rx 33's NAPI, not vector 0's

after: tx 0 napi-id 513, tx 1 napi-id 514, rx 33 napi-id 580

Fixes cf4facfb132a ("eth: fbnic: Add support for XDP queues")
#7 lore raw

PATCH v2 3/5 eth: fbnic: skip freed Tx rings in fbnic_get_ts_stats()

In reply to Dimitri Daskalakis

From: Dimitri Daskalakis <[email protected]>

fbnic_stop() frees the NAPI vectors, which clears fbn->tx[] while num_tx_queues is left unchanged. fbnic_get_ts_stats() walks fbn->tx[] without checking for NULL, so asking for timestamping statistics while the interface is down dereferences a NULL ring.

This was found by AI and reproduced on HW.

  # ip link set dev eth0 down; ethtool -I -T eth0
  BUG: kernel NULL pointer dereference, address: 0000000000000050
  RIP: 0010:fbnic_get_ts_stats+0x38/0x60
  Call Trace:
   tsinfo_prepare_data+0x82/0xb0
   ethnl_default_doit+0x213/0x470
   genl_family_rcv_msg_doit+0xdd/0x110
   ...
Fixes 96f358f75d1a ("eth: fbnic: add ethtool timestamping statistics")
---
 drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +3 -0
index e774740fcb5d..0cd03cbf2713 100644
@@ -1740,6 +1740,9 @@ static void fbnic_get_ts_stats(struct net_device *netdev,
 	ts_stats->lost = fbn->tx_stats.twq.ts_lost;
 	for (i = 0; i < fbn->num_tx_queues; i++) {
 		ring = fbn->tx[i];
+		if (!ring)
+			continue;
+
 		do {
 			start = u64_stats_fetch_begin(&ring->stats.syncp);
 			ts_packets = ring->stats.twq.ts_packets;
Signature · 1 line
2.52.1
Reviewed-by on v2 3/5
#8 lore raw

Re: [PATCH net v2 3/5] eth: fbnic: skip freed Tx rings in fbnic_get_ts_stats()

Quoted 18 lines · Dimitri Daskalakis

From: Dimitri Daskalakis <[email protected]>

fbnic_stop() frees the NAPI vectors, which clears fbn->tx[] while num_tx_queues is left unchanged. fbnic_get_ts_stats() walks fbn->tx[] without checking for NULL, so asking for timestamping statistics while the interface is down dereferences a NULL ring.

This was found by AI and reproduced on HW.

  # ip link set dev eth0 down; ethtool -I -T eth0
  BUG: kernel NULL pointer dereference, address: 0000000000000050
  RIP: 0010:fbnic_get_ts_stats+0x38/0x60
  Call Trace:
   tsinfo_prepare_data+0x82/0xb0
   ethnl_default_doit+0x213/0x470
   genl_family_rcv_msg_doit+0xdd/0x110
   ...
Quoted 2 lines
Fixes 96f358f75d1a ("eth: fbnic: add ethtool timestamping statistics")
#9 lore raw

PATCH v2 4/5 netdevsim: report fake timestamping stats

In reply to Dimitri Daskalakis

From: Dimitri Daskalakis <[email protected]>

drivers/net selftests can't skip on netdevsim. Implement get_ts_stats with fixed counters so the stats test can read timestamping statistics.

---
 drivers/net/netdevsim/ethtool.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/net/netdevsim/ethtool.c +9 -0
index c3d2bc783d55..e0c4c96209c4 100644
@@ -205,6 +205,14 @@ static int nsim_get_ts_info(struct net_device *dev,
 	return 0;
 }
 
+static void nsim_get_ts_stats(struct net_device *dev,
+			      struct ethtool_ts_stats *ts_stats)
+{
+	ts_stats->pkts = 3;
+	ts_stats->lost = 1;
+	ts_stats->err = 0;
+}
+
 static u32 nsim_get_rxfh_key_size(struct net_device *dev)
 {
 	return NETDEV_RSS_KEY_LEN;
@@ -275,6 +283,7 @@ static const struct ethtool_ops nsim_ethtool_ops = {
 	.set_fecparam			= nsim_set_fecparam,
 	.get_fec_stats			= nsim_get_fec_stats,
 	.get_ts_info			= nsim_get_ts_info,
+	.get_ts_stats			= nsim_get_ts_stats,
 };
 
 static void nsim_ethtool_ring_init(struct netdevsim *ns)
Signature · 1 line
2.52.1
#10 lore raw

PATCH v2 5/5 selftests: drv-net: stats: query timestamping stats while down

In reply to Dimitri Daskalakis

From: Dimitri Daskalakis <[email protected]>

Read timestamping statistics before and after ifdown, to catch drivers that crash while the interface is down. Counters must not go backwards across ifdown; the test does not send timestamped traffic, so a reset is only caught if the counters were already nonzero.

---
 tools/testing/selftests/drivers/net/stats.py | 25 +++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/stats.py +24 -1
index b08e4d48b15c..e61db30b5181 100755
@@ -220,6 +220,28 @@ def check_down(cfg) -> None:
     netfam.qstats_get({"ifindex": cfg.ifindex, "scope": "queue"}, dump=True)
 
 
+@ksft_disruptive
+def check_down_ts_stats(cfg) -> None:
+    """Test timestamping stats are not impacted by ifdown"""
+
+    req = {"header": {"dev-index": cfg.ifindex, "flags": {"stats"}}}
+    try:
+        stats = ethnl.tsinfo_get(req).get("stats")
+    except NlError as e:
+        if e.error == errno.EOPNOTSUPP:
+            raise KsftSkipEx("timestamping not supported by the device") from e
+        raise
+    if not stats:
+        raise KsftSkipEx("timestamping stats not supported by the device")
+
+    ip(f"link set dev {cfg.dev['ifname']} down")
+    defer(ip, f"link set dev {cfg.dev['ifname']} up")
+
+    stats2 = ethnl.tsinfo_get(req).get("stats", {})
+    for k in stats:
+        ksft_ge(stats2[k], stats[k], comment=f"{k} went backwards on device down")
+
+
 def __run_inf_loop(body):
     body = body.strip()
     if body[-1] != ';':
@@ -311,7 +333,8 @@ def main() -> None:
 
     with NetDrvEnv(__file__, queue_count=100) as cfg:
         ksft_run([check_pause, check_fec, check_fec_hist, pkt_byte_sum,
-		  qstat_by_ifindex, check_down, procfs_hammer,
+		  qstat_by_ifindex, check_down, check_down_ts_stats,
+		  procfs_hammer,
 		  procfs_downup_hammer],
                  args=(cfg, ))
     ksft_exit()
Signature · 1 line
2.52.1
#11 lore raw

Re: [PATCH net v2 5/5] selftests: drv-net: stats: query timestamping stats while down

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In check_down_ts_stats() (tools/testing/selftests/drivers/net/stats.py), if a counter present…

--

selftests: drv-net: stats: query timestamping stats while down

This patch adds check_down_ts_stats() to the drv-net stats selftest. The test reads timestamping stats over ethtool netlink before and after taking the link down. It then checks that no counter went backwards.

Quoted 5 lines
tools/testing/selftests/drivers/net/stats.py +0 -0
index b08e4d48b15ce..e61db30b51817 100755
@@ -220,6 +220,28 @@ def check_down(cfg) -> None:

[ ... ]

tools/testing/selftests/drivers/net/stats.py def check_down(cfg) -> None: · line 242

Quoted 6 lines
tools/testing/selftests/drivers/net/stats.py +6 -0
+    ip(f"link set dev {cfg.dev['ifname']} down")
+    defer(ip, f"link set dev {cfg.dev['ifname']} up")
+
+    stats2 = ethnl.tsinfo_get(req).get("stats", {})
+    for k in stats:
+        ksft_ge(stats2[k], stats[k], comment=f"{k} went backwards on device down")

[Severity: Low]
What happens here if a counter that was reported while the link was up is missing from the reply after ifdown?

The kernel only puts counters in the reply when the driver filled them in. tsinfo_prepare_data() resets every counter on each query:

net/ethtool/tsinfo.c:tsinfo_prepare_data() {
    ...
	ethtool_stats_init((u64 *)&data->stats,
				   sizeof(data->stats) / sizeof(u64));
    ...
}

Then tsinfo_put_stat() skips any counter that is still unset:

net/ethtool/tsinfo.c:tsinfo_put_stat() {
	if (val == ETHTOOL_STAT_NOT_SET)
		return 0;
    ...
}

So the second reply can contain fewer keys than the first. When that happens, stats2[k] raises KeyError before ksft_ge() runs.

This already happens with wangxun ngbe/txgbe. On ifdown, ngbe_close() and txgbe_close() call wx_ptp_stop(), which does:

	if (wx->ptp_clock) {
		ptp_clock_unregister(wx->ptp_clock);
		wx->ptp_clock = NULL;
		...
	}

After that, wx_get_ptp_stats() fills nothing while the link is down:

	if (wx->ptp_clock) {
		ts_stats->pkts = wx->tx_hwtstamp_pkts;
		...
	}

ksft_run() catches the KeyError and still marks the test as failed. The output is a Python traceback, though, and not the "went backwards on device down" message.

Would it be better to check that the key is present first, for example with ksft_in(k, stats2, ...), before calling ksft_ge()?

Also, when ETHTOOL_FLAG_STATS is set, tsinfo_fill_reply()->tsinfo_put_stats() always adds the stats nest to the reply. The {} default in .get("stats", {}) therefore never takes effect, and it can be dropped.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117215416.1901246-1-dimitri.daskalakis1%40gmail.com
#12 lore raw

Re: [PATCH net v2 5/5] selftests: drv-net: stats: query timestamping stats while down

Quoted 77 lines · On 11/19/26 1:54 AM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In check_down_ts_stats() (tools/testing/selftests/drivers/net/stats.py), if a counter present…

--

selftests: drv-net: stats: query timestamping stats while down

This patch adds check_down_ts_stats() to the drv-net stats selftest. The test reads timestamping stats over ethtool netlink before and after taking the link down. It then checks that no counter went backwards.

Quoted 5 lines
tools/testing/selftests/drivers/net/stats.py +0 -0
index b08e4d48b15ce..e61db30b51817 100755
@@ -220,6 +220,28 @@ def check_down(cfg) -> None:

[ ... ]

tools/testing/selftests/drivers/net/stats.py def check_down(cfg) -> None: · line 242

Quoted 6 lines
tools/testing/selftests/drivers/net/stats.py +6 -0
+    ip(f"link set dev {cfg.dev['ifname']} down")
+    defer(ip, f"link set dev {cfg.dev['ifname']} up")
+
+    stats2 = ethnl.tsinfo_get(req).get("stats", {})
+    for k in stats:
+        ksft_ge(stats2[k], stats[k], comment=f"{k} went backwards on device down")

[Severity: Low]
What happens here if a counter that was reported while the link was up is missing from the reply after ifdown?

The kernel only puts counters in the reply when the driver filled them in. tsinfo_prepare_data() resets every counter on each query:

net/ethtool/tsinfo.c:tsinfo_prepare_data() {
    ...
	ethtool_stats_init((u64 *)&data->stats,
				   sizeof(data->stats) / sizeof(u64));
    ...
}

Then tsinfo_put_stat() skips any counter that is still unset:

net/ethtool/tsinfo.c:tsinfo_put_stat() {
	if (val == ETHTOOL_STAT_NOT_SET)
		return 0;
    ...
}

So the second reply can contain fewer keys than the first. When that happens, stats2[k] raises KeyError before ksft_ge() runs.

This already happens with wangxun ngbe/txgbe. On ifdown, ngbe_close() and txgbe_close() call wx_ptp_stop(), which does:

	if (wx->ptp_clock) {
		ptp_clock_unregister(wx->ptp_clock);
		wx->ptp_clock = NULL;
		...
	}

After that, wx_get_ptp_stats() fills nothing while the link is down:

	if (wx->ptp_clock) {
		ts_stats->pkts = wx->tx_hwtstamp_pkts;
		...
	}

ksft_run() catches the KeyError and still marks the test as failed. The output is a Python traceback, though, and not the "went backwards on device down" message.

Quoted 7 lines

Would it be better to check that the key is present first, for example with ksft_in(k, stats2, ...), before calling ksft_ge()?

Also, when ETHTOOL_FLAG_STATS is set, tsinfo_fill_reply()->tsinfo_put_stats() always adds the stats nest to the reply. The {} default in .get("stats", {}) therefore never takes effect, and it can be dropped.

The preference is for the test to fail, as this is unexpected behavior.

#13 lore raw
In reply to Dimitri Daskalakis
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 17 Nov 2026 13:54:11 -0800 you wrote:

From: Dimitri Daskalakis <[email protected]>

AI identified several bugs while I was working on unrelated parts of the driver. fbnic_queue_stop() always waits on queue 0 to idle for rx queues. fbnic_get_ts_stats() dereferences a NULL pointer when the interface is down. And fbnic_{set|reset}_netif_napi does not account for disabled rings.

[...]

Here is the summary with links:
- [net,v2,1/5] eth: fbnic: wait on the correct queues in fbnic_queue_stop()

    https://git.kernel.org/netdev/net/c/7bc16d84facd
  - [net,v2,2/5] eth: fbnic: skip disabled Tx rings when setting the queue NAPI
    https://git.kernel.org/netdev/net/c/561175f45a23
  - [net,v2,3/5] eth: fbnic: skip freed Tx rings in fbnic_get_ts_stats()
    https://git.kernel.org/netdev/net/c/729f807b58f6
  - [net,v2,4/5] netdevsim: report fake timestamping stats
    https://git.kernel.org/netdev/net/c/a6c99fc2d6dc
  - [net,v2,5/5] selftests: drv-net: stats: query timestamping stats while down
    https://git.kernel.org/netdev/net/c/43cb59e7a47b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html