Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Alexander Duyck
Fri, 13 Nov 2026 20:41
[net PATCH 2/6] fbnic: Do not accumulate HW stats from failed register reads
Author: Alexander Duyck
Date: Fri, 13 Nov 2026 20:41
Date: Fri, 13 Nov 2026 20:41
84 lines
14517 bytes
14517 bytes
From: Alexander Duyck <alexanderduyck@fb.com>
The HW stats are kept as a running total that the driver advances by the
difference between the current counter value and the value it last read,
and the fbnic_reset_hw_stats function only rebases that last value after
a reset so the totals carry over.
When a register read fails, as it does for every read once a DPC
containment event takes the link down, the fbnic_rd32 function returns
all ones and disables CSR access, so every later read also returns all
ones until the device is recovered. A stats read in that window adds the
difference between all ones and the last value to the total, which
subtracts the counter's whole value since the last rebase. Hardware
testing with forced AER recovery while reading the stats showed the
64-bit PCIe counters wrapping below zero on the first recovery and
dropping again on every one after it.
Skip the update when CSR access has been disabled by the time the read
returns, which covers the read that failed as well as any after it. The
last value is left alone, so the next good read after recovery, once the
fbnic_reset_hw_stats function has rebased it, picks up where the total
left off.
Fixes: 25ba596d137d ("eth: fbnic: add PCIe hardware statistics")
Fixes: 4eb7f20bcf06 ("eth: fbnic: Add support to fetch group stats")
Signed-off-by: Alexander Duyck <alexanderduyck@fb.com>
---
drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c | 8 ++++++++
drivers/net/ethernet/meta/fbnic/fbnic_mac.c | 8 ++++++++
2 files changed, 16 insertions(+)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c b/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c
index 8b9b2076beec..8084a63dd807 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_hw_stats.c
@@ -22,6 +22,10 @@ static void fbnic_hw_stat_rd32(struct fbnic_dev *fbd, u32 reg,
u32 new_reg_value;
new_reg_value = rd32(fbd, reg);
+ /* A failed read disables CSR access and returns all ones */
+ if (!fbnic_present(fbd))
+ return;
+
stat->value += new_reg_value - stat->u.old_reg_value_32;
stat->u.old_reg_value_32 = new_reg_value;
}
@@ -68,6 +72,10 @@ static void fbnic_hw_stat_rd64(struct fbnic_dev *fbd, u32 reg, s32 offset,
u64 new_reg_value;
new_reg_value = fbnic_stat_rd64(fbd, reg, offset);
+ /* A failed read disables CSR access and returns all ones */
+ if (!fbnic_present(fbd))
+ return;
+
stat->value += new_reg_value - stat->u.old_reg_value_64;
stat->u.old_reg_value_64 = new_reg_value;
}
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
index 16271c717a5a..2aacbf0a6af4 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
@@ -405,6 +405,10 @@ static void __fbnic_mac_stat_rd64(struct fbnic_dev *fbd, bool reset, u32 reg,
u64 new_reg_value;
new_reg_value = fbnic_stat_rd64(fbd, reg, 1);
+ /* A failed read disables CSR access and returns all ones */
+ if (!fbnic_present(fbd))
+ return;
+
if (!reset)
stat->value += new_reg_value - stat->u.old_reg_value_64;
stat->u.old_reg_value_64 = new_reg_value;
@@ -417,6 +421,10 @@ static void fbnic_mac_stat_rd32(struct fbnic_dev *fbd, bool reset, u32 reg,
u32 new_reg_value;
new_reg_value = rd32(fbd, reg);
+ /* A failed read disables CSR access and returns all ones */
+ if (!fbnic_present(fbd))
+ return;
+
if (!reset)
stat->value += new_reg_value - stat->u.old_reg_value_32;
stat->u.old_reg_value_32 = new_reg_value;
Re: [net PATCH 2/6] fbnic: Do not accumulate HW stats from failed register reads
Author: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 21:14
Date: Tue, 17 Nov 2026 21:14
118 lines
12489 bytes
12489 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · 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).
- [High] The fix is incomplete: `fbnic_pcs_rsfec_stat_rd32()` in
drivers/net/ethernet/meta/fbnic/fbnic_mac.c still adds failed reads…
- [Low] The commit message describes the failed-read symptom accurately
only for the 64-bit counters.
--
fbnic: Do not accumulate HW stats from failed register reads
This commit changes the fbnic HW stats helpers so they skip updating the
running totals once a failed register read has disabled CSR access. The
check is added to fbnic_hw_stat_rd32(), fbnic_hw_stat_rd64(),
__fbnic_mac_stat_rd64() and fbnic_mac_stat_rd32().
> When a register read fails, as it does for every read once a DPC
> containment event takes the link down, the fbnic_rd32 function returns
> all ones and disables CSR access, so every later read also returns all
> ones until the device is recovered. A stats read in that window adds the
> difference between all ones and the last value to the total, which
> subtracts the counter's whole value since the last rebase.
[Severity: Low]
Does this description hold for the 32-bit counters?
In fbnic_hw_stat_rd32() and fbnic_mac_stat_rd32() the delta is computed
in u32:
stat->value += new_reg_value - stat->u.old_reg_value_32;
When new_reg_value == 0xffffffff, this gives 0xffffffff - old. That value
is zero-extended and added to the u64 stat->value. So the 32-bit counters
(TMI/TTI/RPC/RXB drops, per-queue HW drops, 32-bit MAC stats) would jump
forward by nearly 2^32 instead of dropping.
Only the 64-bit helpers wrap the total downward, because fbnic_stat_rd64()
returns ~0ULL there. The code change looks correct for both widths. Could
the commit message also mention the forward jump in the 32-bit counters?
> diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
> index 16271c717a5aa..2aacbf0a6af40 100644
> --- a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
> +++ b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
[ ... ]
> @@ -417,6 +421,10 @@ static void fbnic_mac_stat_rd32(struct fbnic_dev *fbd, bool reset, u32 reg,
> u32 new_reg_value;
>
> new_reg_value = rd32(fbd, reg);
> + /* A failed read disables CSR access and returns all ones */
> + if (!fbnic_present(fbd))
> + return;
> +
> if (!reset)
> stat->value += new_reg_value - stat->u.old_reg_value_32;
> stat->u.old_reg_value_32 = new_reg_value;
[Severity: High]
Should fbnic_pcs_rsfec_stat_rd32() in this same file get the same check?
It reads the clear-on-read FEC/PCS counters and never calls
fbnic_present():
drivers/net/ethernet/meta/fbnic/fbnic_mac.c:fbnic_pcs_rsfec_stat_rd32() {
...
pcs_rsfec_stat = rd32(fbd, reg) & 0xffff;
pcs_rsfec_stat |= rd32(fbd, reg + 1) << 16;
/* RFSEC registers clear themselves upon being read so there is no
* need to store the old_reg_value.
*/
if (!reset)
stat->value += pcs_rsfec_stat;
}
After fbnic_rd32() clears uc_addr0, both reads return ~0U, so
pcs_rsfec_stat ends up as 0xffffffff. These counters have no baseline to
subtract. As a result, corrected_blocks, uncorrectable_blocks and every
SymbolErrorDuringCarrier lane would grow by about 4G on each stats poll
while the device is unreachable.
One path that reaches it:
fbnic_get_stats64()
fbnic_get_hw_stats()
__fbnic_get_hw_stats32()
fbnic_get_phy_stats32() /* reset == false */
fbnic_mac_get_fec_stats() / fbnic_mac_get_pcs_stats()
fbnic_pcs_rsfec_stat_rd32()
The service task reaches it the same way through fbnic_get_hw_stats32(),
and so does ethtool through fbnic_get_fec_stats().
dev_get_stats() does not check netif_device_present(). A read of
/proc/net/dev during a DPC/AER outage, or after fbnic_pm_suspend(), would
therefore hit this path.
fbnic_reset_hw_stats() calls these readers only with reset == true. That
skips the add but does not rewind stat->value, so the inflated totals
would remain after recovery.
Would adding the same "if (!fbnic_present(fbd)) return;" after the two
reads in fbnic_pcs_rsfec_stat_rd32() close this gap?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179460241885.8819.7179935130629202331.stgit%40ahduyck-xeon-server.home.arpa
Re: [net PATCH 2/6] fbnic: Do not accumulate HW stats from failed register reads
Author: Alexander Duyck
Date: Tue, 17 Nov 2026 22:11
Date: Tue, 17 Nov 2026 22:11
137 lines
17318 bytes
17318 bytes
On Tue, Nov 17, 2026 at 1:14 PM <netdev-bot+sashiko@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 2 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 0 · 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).
>
> - [High] The fix is incomplete: `fbnic_pcs_rsfec_stat_rd32()` in
> drivers/net/ethernet/meta/fbnic/fbnic_mac.c still adds failed reads…
> - [Low] The commit message describes the failed-read symptom accurately
> only for the 64-bit counters.
>
> --
>
> fbnic: Do not accumulate HW stats from failed register reads
>
> This commit changes the fbnic HW stats helpers so they skip updating the
> running totals once a failed register read has disabled CSR access. The
> check is added to fbnic_hw_stat_rd32(), fbnic_hw_stat_rd64(),
> __fbnic_mac_stat_rd64() and fbnic_mac_stat_rd32().
>
> > When a register read fails, as it does for every read once a DPC
> > containment event takes the link down, the fbnic_rd32 function returns
> > all ones and disables CSR access, so every later read also returns all
> > ones until the device is recovered. A stats read in that window adds the
> > difference between all ones and the last value to the total, which
> > subtracts the counter's whole value since the last rebase.
>
> [Severity: Low]
> Does this description hold for the 32-bit counters?
>
> In fbnic_hw_stat_rd32() and fbnic_mac_stat_rd32() the delta is computed
> in u32:
>
> stat->value += new_reg_value - stat->u.old_reg_value_32;
>
> When new_reg_value == 0xffffffff, this gives 0xffffffff - old. That value
> is zero-extended and added to the u64 stat->value. So the 32-bit counters
> (TMI/TTI/RPC/RXB drops, per-queue HW drops, 32-bit MAC stats) would jump
> forward by nearly 2^32 instead of dropping.
>
> Only the 64-bit helpers wrap the total downward, because fbnic_stat_rd64()
> returns ~0ULL there. The code change looks correct for both widths. Could
> the commit message also mention the forward jump in the 32-bit counters?
If a follow-up is requested we can look at updating the commit
message. The thing to keep in mind is that there aren't that many 32b
registers for the interface, so the much more common visibility to the
issue is the issues seen with the 64b counters.
> > diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
> > index 16271c717a5aa..2aacbf0a6af40 100644
> > --- a/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
> > +++ b/drivers/net/ethernet/meta/fbnic/fbnic_mac.c
>
> [ ... ]
>
> > @@ -417,6 +421,10 @@ static void fbnic_mac_stat_rd32(struct fbnic_dev *fbd, bool reset, u32 reg,
> > u32 new_reg_value;
> >
> > new_reg_value = rd32(fbd, reg);
> > + /* A failed read disables CSR access and returns all ones */
> > + if (!fbnic_present(fbd))
> > + return;
> > +
> > if (!reset)
> > stat->value += new_reg_value - stat->u.old_reg_value_32;
> > stat->u.old_reg_value_32 = new_reg_value;
>
> [Severity: High]
> Should fbnic_pcs_rsfec_stat_rd32() in this same file get the same check?
>
> It reads the clear-on-read FEC/PCS counters and never calls
> fbnic_present():
>
> drivers/net/ethernet/meta/fbnic/fbnic_mac.c:fbnic_pcs_rsfec_stat_rd32() {
> ...
> pcs_rsfec_stat = rd32(fbd, reg) & 0xffff;
> pcs_rsfec_stat |= rd32(fbd, reg + 1) << 16;
>
> /* RFSEC registers clear themselves upon being read so there is no
> * need to store the old_reg_value.
> */
> if (!reset)
> stat->value += pcs_rsfec_stat;
> }
>
> After fbnic_rd32() clears uc_addr0, both reads return ~0U, so
> pcs_rsfec_stat ends up as 0xffffffff. These counters have no baseline to
> subtract. As a result, corrected_blocks, uncorrectable_blocks and every
> SymbolErrorDuringCarrier lane would grow by about 4G on each stats poll
> while the device is unreachable.
>
> One path that reaches it:
>
> fbnic_get_stats64()
> fbnic_get_hw_stats()
> __fbnic_get_hw_stats32()
> fbnic_get_phy_stats32() /* reset == false */
> fbnic_mac_get_fec_stats() / fbnic_mac_get_pcs_stats()
> fbnic_pcs_rsfec_stat_rd32()
>
> The service task reaches it the same way through fbnic_get_hw_stats32(),
> and so does ethtool through fbnic_get_fec_stats().
>
> dev_get_stats() does not check netif_device_present(). A read of
> /proc/net/dev during a DPC/AER outage, or after fbnic_pm_suspend(), would
> therefore hit this path.
>
> fbnic_reset_hw_stats() calls these readers only with reset == true. That
> skips the add but does not rewind stat->value, so the inflated totals
> would remain after recovery.
>
> Would adding the same "if (!fbnic_present(fbd)) return;" after the two
> reads in fbnic_pcs_rsfec_stat_rd32() close this gap?
Yeah, this probably does need the same fix. If possible I would prefer
to do this as a follow-on patch.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads