eth: fbnic: miscellaneous driver fixes
Subsystems (4)
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.
Dimitri Daskalakis (4):
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()
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 ++++++++++++--- tools/testing/selftests/drivers/net/stats.py | 25 ++++++++++++++++++- 3 files changed, 43 insertions(+), 5 deletions(-)
Signature · 1 line
2.52.1
PATCH 1/4 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) <- wrong rxq
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,
rxq's alaways get a XDP Tx queue during init)
--- 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
@@ -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
[email protected]
AI reviewRe: [PATCH net 1/4] eth: fbnic: wait on the correct queues in fbnic_queue_stop()
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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] eth: fbnic: fbnic_wait_queue_idle() only polls 128 bits of 256-bit Tx idle regs
- [Low] This patch changes what struct fbnic_ring::q_idx holds for Tx completion rings, but the field's comment still describes the old…
--
eth: fbnic: wait on the correct queues in fbnic_queue_stop()
fbnic_queue_stop() now passes cmpl.q_idx to fbnic_wait_queue_idle(), so each queue triad is checked against its own hardware queue. Before this, sub0.q_idx was used and every Rx triad was checked against queue 0. The patch also sets q_idx on Tx completion rings, and the stop/wake loops now skip disabled Tx rings.
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net *fbn, · line 1775
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +1
-1@@ -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 );
[Severity: Low]
This isn't a bug, but should the comment on struct fbnic_ring::q_idx in fbnic_txrx.h be updated along with this change? It still says:
u8 q_idx; /* Logical netdev ring index */
With this patch, the Tx completion ring's q_idx holds the hardware TCQ number. fbnic_queue_stop() now relies on that, because fbnic_wait_queue_idle() uses idx only as a bit position in the QM idle registers:
off = idx / 32; mask = BIT(idx % 32);
On XDP-only Tx triads (txq_count == 0 in fbnic_alloc_napi_vector(), with sub0 marked FBNIC_RING_F_DISABLED), no netdev Tx queue has this index. In the "rx 34 tx 34" example from the commit message the value is 39, but the netdev has only 34 Tx queues.
Future code that trusts the comment, for example netdev_get_tx_queue(dev, qt->cmpl.q_idx) or fbn->tx[qt->cmpl.q_idx] on a Tx triad, would get the wrong queue or none at all. Could the comment say that q_idx on completion rings is the hardware queue index?
[ ... ]
Quoted 9 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +3
-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);
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c static int fbnic_queue_stop(struct net_device *dev, void *qmem, int idx) · line 3107
Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +2
-1+ }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; }
[Severity: Medium]
Does fbnic_wait_queue_idle() actually wait on the XDP Tx ring here?
The commit message says that in the "rx 34 tx 34" case the vector now waits on tx 39, the XDP Tx queue of rxq 5's vector. That ring is qt->sub1, which is TWQ1 of hardware queue 39. qt->sub0 (TWQ0) on the same triad is marked FBNIC_RING_F_DISABLED. The first Tx triad of every vector with Rx queues has the same XDP sub1 ring, combined or not.
In fbnic_csr.h, FBNIC_QM_TWQ_IDLE, FBNIC_QM_TQS_IDLE and FBNIC_QM_TDE_IDLE each have 8 registers. That is 256 bits, enough for TWQ0 and TWQ1 of all 128 queues. FBNIC_QM_TCQ_IDLE has only 4. fbnic_wait_queue_idle() derives a single offset and mask from idx:
off = idx / 32; mask = BIT(idx % 32);
It applies those to every Tx register base, so it only reads registers 0..3 of the 256-bit arrays.
If the upper half holds the TWQ1 bits, TWQ1 is never polled. fbnic_queue_stop() can then go on to fbnic_nv_flush() and clean up the XDP Tx ring and its buffers while the hardware may still be processing it. If the bits are interleaved per queue instead, the bit polled for idx > 0 is not the TWQ0 bit of that queue at all, and we would either miss the real queue or hit spurious idle timeouts.
The register handling predates this patch. Until now, though, every Rx triad was checked against queue 0, and this patch makes the XDP-only triads depend on this wait. How are the TWQ1 idle bits laid out? Should fbnic_wait_queue_idle() also poll the TWQ1 bit for the TWQ, TQS and TDE registers, perhaps only when sub1 is not FBNIC_RING_F_DISABLED?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116202957.3601684-1-dimitri.daskalakis1%40gmail.com
PATCH 2/4 eth: fbnic: skip disabled Tx rings when setting the queue NAPI
In reply to Dimitri DaskalakisFrom: 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
--- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +6 -0
@@ -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
PATCH 3/4 eth: fbnic: skip freed Tx rings in fbnic_get_ts_stats()
In reply to Dimitri DaskalakisFrom: 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 ...
--- drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +3 -0
@@ -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
PATCH 4/4 selftests: drv-net: stats: query timestamping stats while down
In reply to Dimitri DaskalakisFrom: Dimitri Daskalakis <[email protected]>
Read timestamping statistics before and after ifdown, to catch drivers that crash or reset them while the interface is down.
--- tools/testing/selftests/drivers/net/stats.py | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/stats.py +24 -1
@@ -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
Jakub Kicinski
maintainerRe: [PATCH net 4/4] selftests: drv-net: stats: query timestamping stats while down
Quoted 1 line · On Mon, 16 Nov 2026 12:29:57 -0800 Dimitri Daskalakis wrote:
+def
check_down_ts_stats(cfg)-> None:
This is skipping on netdevsim, you need to add a fake callback to netdevsim as well. drivers/net tests can't skip on netdevsim
Signature · 1 line
pw-bot: cr
Re: [PATCH net 4/4] selftests: drv-net: stats: query timestamping stats while down
Quoted 5 lines · Jakub Kicinski
Quoted 1 line · On Mon, 16 Nov 2026 12:29:57 -0800 Dimitri Daskalakis wrote:
+def
check_down_ts_stats(cfg)-> None:This is skipping on netdevsim, you need to add a fake callback to netdevsim as well.
drivers/nettests can't skip on netdevsim
Ack, will add netdevsim support in v2.
[email protected]
AI reviewRe: [PATCH net 4/4] selftests: drv-net: stats: query timestamping stats while down
In reply to Dimitri DaskalakisThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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] The commit message says check_down_ts_stats() should "catch drivers that crash or reset [timestamping stats] while the interface…
- [Low] In check_down_ts_stats() (tools/testing/selftests/drivers/net/stats.py), a timestamping counter…
--
selftests: drv-net: stats: query timestamping stats while down
This adds check_down_ts_stats() to the drv-net stats.py selftest. The test reads the ethtool tsinfo timestamping statistics, brings the interface down, reads them again, and checks that no counter went backwards.
Quoted 11 lines
tools/testing/selftests/drivers/net/stats.py +3
-0@@ -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"""
tools/testing/selftests/drivers/net/stats.py def check_down(cfg) -> None: · line 235
Quoted 10 lines
tools/testing/selftests/drivers/net/stats.py +10
-0+ + 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")
[Severity: Medium]
Can this test actually detect the reset case that the commit message describes?
"to catch drivers that crash or reset them while the interface is down"
The baseline is read without first enabling hardware TX timestamping, and without sending any packets that request a hardware timestamp. The only source of these counters is the driver's get_ts_stats():
net/ethtool/tsinfo.c:tsinfo_prepare_data() {
...
if (req_base->flags & ETHTOOL_FLAG_STATS) {
ethtool_stats_init((u64 *)&data->stats,
sizeof(data->stats) / sizeof(u64));
if (dev->ethtool_ops->get_ts_stats)
dev->ethtool_ops->get_ts_stats(dev, &data->stats);
}
...
}In fbnic, ice, idpf, bnxt, wangxun and mlx5, tx-pkts, tx-lost and tx-err only count TX packets that asked for a hardware timestamp. In a typical selftest environment the baseline will probably be all zeros.
If the baseline is zero, the ksft_ge(stats2[k], stats[k]) check below still passes when a driver zeroes its counters in ndo_stop. check_down() does not have this problem with the same >= pattern, because the qstats already contain non-zero traffic counts.
The crash-on-query-while-down part does get exercised. Should the test send some hardware-timestamped TX traffic before reading the baseline, so that the reset part is covered too?
tools/testing/selftests/drivers/net/stats.py def check_down(cfg) -> None: · line 242
Quoted 7 lines
tools/testing/selftests/drivers/net/stats.py +7
-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 is in the baseline but missing from the reply after ifdown?
The {} default only helps when the whole nest is missing. That never happens here, because tsinfo_fill_reply() always emits the stats nest when the stats flag is set. What can go missing is individual counters, since tsinfo_put_stat() leaves out unset values:
net/ethtool/tsinfo.c:tsinfo_put_stat() {
if (val == ETHTOOL_STAT_NOT_SET)
return 0;
...
}On wangxun ngbe/txgbe, ndo_stop calls wx_ptp_stop(), which sets wx->ptp_clock to NULL. After that, wx_get_ptp_stats() fills in nothing:
drivers/net/ethernet/wangxun/libwx/wx_ethtool.c:wx_get_ptp_stats() {
...
if (wx->ptp_clock) {
ts_stats->pkts = wx->tx_hwtstamp_pkts;
...
}
}So stats2 comes back empty and stats2[k] raises KeyError.
ksft_run() still counts this as a failure, and the deferred link up still runs. However, the output is a Python traceback instead of the "went backwards on device down" message, and the remaining keys are never compared.
Would checking k in stats2 (or using stats2.get(k)) with ksft_true() or ksft_ge() give a clearer failure? The neighbouring check_down() uses the same qstat2[k] pattern.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116202957.3601684-1-dimitri.daskalakis1%40gmail.com