From: netdev-bot+sashiko@kernel.org
To: gongfan1@huawei.com
Cc: wudi234@huawei.com, tengpeisen@huawei.com,
netdev@vger.kernel.org, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
andrew+netdev@lunn.ch, ioana.ciornei@nxp.com,
maxime.chevallier@bootlin.com, mohsin.bashr@gmail.com,
dimitri.daskalakis1@gmail.com, hramamurthy@google.com,
larysa.zaremba@intel.com, vadim.fedorenko@linux.dev,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
zhoushuai28@huawei.com, wulike1@huawei.com
Subject: Re: [PATCH net-next v19 3/4] hinic3: Add per-queue netdev-genl stats
Date: Sat, 05 Dec 2026 04:17:56 +0000 [thread overview]
Message-ID: <179644427679.3146.16182388388007213592@kernel.org> (raw)
In-Reply-To: <309addcd3195d2a107f91984e5966ff48b04a895.1796348433.git.gongfan1@huawei.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 3 · 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] hinic3: stale free_wqebb in hinic3_send_one_skb() causes TX
queue stall
- [Medium] TX wire-byte accounting is wrong for VXLAN (UDP-tunnel) TSO
skbs, and this patch exports the wrong values through the netdev-genl…
- [Medium] Under LRO, the RX counters exported as qstats `rx-packets` and
`rx-bytes` follow different rules.
- [Medium] hinic3: rx-bytes undercounts coalesced LRO headers in
hinic3_rx_poll()
- [Low] hinic3: hinic3_get_base_stats() duplicates
netdev_stat_queue_sum()
--
hinic3: Add per-queue netdev-genl stats
This commit adds netdev_stat_ops to the hinic3 driver. It implements
get_queue_stats_rx, get_queue_stats_tx and get_base_stats, so per-queue
and device-level counters are exported through the netdev-genl qstats
interface.
> diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c b/drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c
> index 621d8b12e247e..63eb4189e319a 100644
> --- a/drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c
> +++ b/drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c
[ ... ]
> @@ -857,7 +858,112 @@ static const struct net_device_ops hinic3_netdev_ops = {
> .ndo_start_xmit = hinic3_xmit_frame,
> };
>
> +static void hinic3_get_queue_stats_rx(struct net_device *netdev, int i,
> + struct netdev_queue_stats_rx *stats_rx)
> +{
[ ... ]
> + do {
> + start = u64_stats_fetch_begin(&rxq_stats->syncp);
> + stats_rx->bytes = rxq_stats->bytes;
> + stats_rx->packets = rxq_stats->packets;
[Severity: Medium]
With hardware LRO active, rx-bytes here no longer matches rx-packets.
The packet count is per wire segment, but the byte count is for the
coalesced buffer.
For an LRO CQE, hinic3_rx_poll() adds num_lro to rx_packets but only
adds pkt_len to rx_bytes:
num_lro = RQ_CQE_STATUS_GET(status, NUM_LRO);
if (num_lro) {
num_wqe += hinic3_get_sge_num(rxq, pkt_len);
rx_packets += num_lro;
} else {
rx_packets++;
}
rx_bytes += pkt_len;
pkt_len is the length of the merged skb built by
hinic3_fetch_rx_buffer(). That skb has a single Ethernet/IP/TCP
header in front of the coalesced payload. hinic3_lro_set_gso_params()
computes gso_size by dividing that payload across num_lro segments.
The (num_lro - 1) headers that were on the wire are never counted.
netdev.yaml defines rx-packets as wire packets and rx-bytes as the
bytes of those packets. Once this patch exports both as qstats, the
two counters disagree with each other. They also disagree with the
TX side, where hinic3_tx_poll() adds (gso_segs - 1) * hdr_len back.
The same numbers reach ndo_get_stats64 as well.
The older hinic driver handles this in hinic_rx.c by adding
(num_lro - 1) * LRO_PKT_HDR_LEN(cqe) to rx_bytes. hinic3_rx.c already
defines HINIC3_LRO_PKT_HDR_LEN() but never uses it. Should rx_bytes
do the same here for LRO CQEs? Or is there a reason to treat pkt_len
as the wire length?
If the macro does get used, note that it appears to read
cqe->offload_type without a le32_to_cpu() conversion. That would
need fixing for big-endian hosts.
The accounting was added earlier in this series, in "hinic3: Add
ethtool statistic ops part(1/2)". This patch is what makes it part
of the qstats uAPI.
[Severity: Medium]
With LRO enabled, do rx-packets and rx-bytes end up counting different
things here?
hinic3_rx_poll() counts packets per wire segment, but it counts bytes as
the length of the coalesced buffer:
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c:hinic3_rx_poll() {
...
num_lro = RQ_CQE_STATUS_GET(status, NUM_LRO);
if (num_lro) {
num_wqe += hinic3_get_sge_num(rxq, pkt_len);
rx_packets += num_lro;
} else {
rx_packets++;
}
rx_bytes += pkt_len;
...
}
The (num_lro - 1) repeated L2/L3/L4 headers are never added back. The
netdev.yaml spec defines rx-packets as "Number of wire packets", and its
definition of rx-bytes points back to rx-packets. So the byte count
should match the wire packets being counted.
The driver already defines HINIC3_LRO_PKT_HDR_LEN(cqe), which is 66
bytes for IPv4 and 86 for IPv6, but the byte accounting never uses it.
The TX side in hinic3_tx_poll() does add the repeated headers back:
wire_len += (gso_segs - 1) * hdr_len;
Should the RX byte counter also include the per-segment headers, so that
RX and TX use the same semantics in qstats?
This accounting was added earlier in this series, in "hinic3: Add
ethtool statistic ops part(1/2)". This patch exports it through the
qstats uAPI as rx-bytes and rx-packets.
> + stats_rx->csum_bad = rxq_stats->csum_errors;
> + stats_rx->alloc_fail = rxq_stats->alloc_fail;
> + } while (u64_stats_fetch_retry(&rxq_stats->syncp, start));
> +}
> +
> +static void hinic3_get_queue_stats_tx(struct net_device *netdev, int i,
> + struct netdev_queue_stats_tx *stats_tx)
> +{
[ ... ]
> + do {
> + start = u64_stats_fetch_begin(&txq_stats->syncp);
> + stats_tx->bytes = txq_stats->bytes;
> + stats_tx->packets = txq_stats->packets;
> + stats_tx->stop = txq_stats->busy;
> + stats_tx->hw_gso_wire_packets = txq_stats->gso_wire_packets;
> + stats_tx->hw_gso_wire_bytes = txq_stats->gso_wire_bytes;
[Severity: High]
This line only reads busy, but it exports txq_stats->busy as the
standard tx-stop counter. The code that increments busy was added
earlier in this series, in "hinic3: Add ethtool statistic ops
part(1/2)", and it looks like it can wedge a TX queue.
hinic3_send_one_skb() now copies the free WQEBB count into a local
and passes that local to the stop helpers:
free_wqebb = hinic3_wq_free_wqebbs(&txq->sq->wq);
if (unlikely(free_wqebb < wqebb_cnt)) {
...
if (!netif_subqueue_try_stop(netdev, txq->sq->q_id,
free_wqebb,
txq->tx_start_thrs)) {
netif_txq_try_stop() and netif_txq_maybe_stop() stop the queue,
issue smp_mb__after_atomic(), and then evaluate get_desc a second
time. That second check catches completions that raced with the stop.
The kerneldoc in include/net/netdev_queues.h requires get_desc to be
an expression that returns up-to-date information each time it is
evaluated.
With a cached u16, the recheck compares the same value that just
failed the threshold. It can never see space freed by
hinic3_tx_poll(). Consider this sequence:
CPU0 (hinic3_send_one_skb) CPU1 (hinic3_tx_poll)
reads free_wqebb < wqebb_cnt
reclaims all in-flight WQEBBs
netif_subqueue_completed_wake()
sees queue not stopped, no wake
netif_subqueue_try_stop()
stops queue, barrier
recheck uses stale free_wqebb
busy++, return NETDEV_TX_BUSY
The ring is now empty and stopped, so no completion interrupt will
come to wake it. hinic3_tx_timeout() only sets
HINIC3_EVENT_WORK_TX_TIMEOUT when sw_pi != hw_ci, so the watchdog
does not recover an empty ring either. The queue stays stopped for
good.
The netif_subqueue_maybe_stop() call at the end of
hinic3_send_one_skb() has the same problem. It can stop the queue
and bump busy spuriously.
Before this series, both calls passed
hinic3_wq_free_wqebbs(&txq->sq->wq) directly. The busy counter is
already driven by the return value of the macros, so the local copy
does not seem to be needed for that. Was there another reason to
cache it, or can both calls go back to evaluating
hinic3_wq_free_wqebbs() inline?
[Severity: Medium]
Are tx-bytes and tx-hw-gso-wire-bytes correct for VXLAN TSO skbs?
When HINIC3_NIC_F_VXLAN_OFFLOAD is supported,
hinic3_netdev_feature_init() enables NETIF_F_GSO_UDP_TUNNEL and
NETIF_F_GSO_UDP_TUNNEL_CSUM. For encapsulated skbs, hinic3_tso() then
tells the hardware to segment on the inner headers:
drivers/net/ethernet/huawei/hinic3/hinic3_tx.c:hinic3_tso() {
...
ip.hdr = skb_inner_network_header(skb);
l4.hdr = skb_inner_transport_header(skb);
...
}
As a result, the whole header stack is repeated on every segment. That
is the outer Eth/IP/UDP/VXLAN headers plus the inner Eth/IP/TCP headers.
Tunnel TSO skbs also carry SKB_GSO_TCPV4/6, so hinic3_tx_poll() takes
the TCP branch for them:
drivers/net/ethernet/huawei/hinic3/hinic3_tx.c:hinic3_tx_poll() {
...
if (skb_shinfo(tx_info->skb)->gso_type &
(SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
hdr_len = skb_transport_offset(tx_info->skb) +
tcp_hdrlen(tx_info->skb);
wire_len += (gso_segs - 1) * hdr_len;
}
...
}
For an encapsulated skb, the transport header is the outer UDP header.
tcp_hdrlen() reads the doff nibble at byte 12 of that header, which is
the most significant VNI byte of the VXLAN header.
For any VNI below 2^20, doff is 0, so hdr_len is only the outer Eth+IP
length (about 34 bytes). The header actually repeated per segment is
about 104 bytes or more. For larger VNIs the result is effectively
arbitrary, anywhere from 0 to 60 bytes.
When skb->encapsulation is set, should the per-segment header length be
skb_inner_transport_offset() + inner_tcp_hdrlen() instead? That would
match what hinic3_tso() programs into the hardware.
This accounting was added earlier in this series, in "hinic3: Add
ethtool statistic ops part(1/2)". This patch exports
txq_stats->bytes and txq_stats->gso_wire_bytes directly as the standard
tx-bytes and tx-hw-gso-wire-bytes qstats counters.
> + stats_tx->hw_gso_packets = txq_stats->gso_packets;
> + stats_tx->hw_gso_bytes = txq_stats->gso_bytes;
> + stats_tx->wake = txq_stats->wake;
> + } while (u64_stats_fetch_retry(&txq_stats->syncp, start));
> +}
[ ... ]
> @@ -857,7 +858,112 @@ static const struct net_device_ops hinic3_netdev_ops = {
> .ndo_start_xmit = hinic3_xmit_frame,
> };
>
> +static void hinic3_get_queue_stats_rx(struct net_device *netdev, int i,
> + struct netdev_queue_stats_rx *stats_rx)
> +{
> + struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
> + struct hinic3_rxq_stats *rxq_stats;
> + struct hinic3_rxq *rxq;
> + unsigned int start;
> +
> + if (unlikely(i < 0 || i >= nic_dev->max_qps))
> + return;
> +
> + rxq = &nic_dev->rxqs[i];
> + rxq_stats = &rxq->rxq_stats;
> + do {
> + start = u64_stats_fetch_begin(&rxq_stats->syncp);
> + stats_rx->bytes = rxq_stats->bytes;
> + stats_rx->packets = rxq_stats->packets;
> + stats_rx->csum_bad = rxq_stats->csum_errors;
> + stats_rx->alloc_fail = rxq_stats->alloc_fail;
> + } while (u64_stats_fetch_retry(&rxq_stats->syncp, start));
> +}
> +
> +static void hinic3_get_queue_stats_tx(struct net_device *netdev, int i,
> + struct netdev_queue_stats_tx *stats_tx)
> +{
> + struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
> + struct hinic3_txq_stats *txq_stats;
> + struct hinic3_txq *txq;
> + unsigned int start;
> +
> + if (unlikely(i < 0 || i >= nic_dev->max_qps))
> + return;
> +
> + txq = &nic_dev->txqs[i];
> + txq_stats = &txq->txq_stats;
> + do {
> + start = u64_stats_fetch_begin(&txq_stats->syncp);
> + stats_tx->bytes = txq_stats->bytes;
> + stats_tx->packets = txq_stats->packets;
> + stats_tx->stop = txq_stats->busy;
> + stats_tx->hw_gso_wire_packets = txq_stats->gso_wire_packets;
> + stats_tx->hw_gso_wire_bytes = txq_stats->gso_wire_bytes;
> + stats_tx->hw_gso_packets = txq_stats->gso_packets;
> + stats_tx->hw_gso_bytes = txq_stats->gso_bytes;
> + stats_tx->wake = txq_stats->wake;
> + } while (u64_stats_fetch_retry(&txq_stats->syncp, start));
> +}
> +
> +static void hinic3_get_base_stats(struct net_device *netdev,
> + struct netdev_queue_stats_rx *stats_rx,
> + struct netdev_queue_stats_tx *stats_tx)
> +{
> + struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
> + int i;
> +
> + stats_rx->bytes = 0;
> + stats_rx->packets = 0;
> + stats_rx->csum_bad = 0;
> + stats_rx->alloc_fail = 0;
> + stats_tx->bytes = 0;
> + stats_tx->packets = 0;
> + stats_tx->stop = 0;
> + stats_tx->hw_gso_wire_packets = 0;
> + stats_tx->hw_gso_wire_bytes = 0;
> + stats_tx->hw_gso_packets = 0;
> + stats_tx->hw_gso_bytes = 0;
> + stats_tx->wake = 0;
> +
> + /* Match the core: the base range starts at the active queue
> + * count, not at q_params.num_qps, which can lag behind.
> + */
> + for (i = netdev->real_num_rx_queues; i < nic_dev->max_qps; i++) {
> + struct netdev_queue_stats_rx rx = {0};
> +
> + hinic3_get_queue_stats_rx(netdev, i, &rx);
> +
> + stats_rx->bytes += rx.bytes;
> + stats_rx->packets += rx.packets;
> + stats_rx->csum_bad += rx.csum_bad;
> + stats_rx->alloc_fail += rx.alloc_fail;
> + }
> +
> + for (i = netdev->real_num_tx_queues; i < nic_dev->max_qps; i++) {
> + struct netdev_queue_stats_tx tx = {0};
> +
> + hinic3_get_queue_stats_tx(netdev, i, &tx);
> +
> + stats_tx->bytes += tx.bytes;
> + stats_tx->packets += tx.packets;
> + stats_tx->stop += tx.stop;
> + stats_tx->hw_gso_wire_packets += tx.hw_gso_wire_packets;
> + stats_tx->hw_gso_wire_bytes += tx.hw_gso_wire_bytes;
> + stats_tx->hw_gso_packets += tx.hw_gso_packets;
> + stats_tx->hw_gso_bytes += tx.hw_gso_bytes;
> + stats_tx->wake += tx.wake;
> + }
> +}
> +
> +static const struct netdev_stat_ops hinic3_stat_ops = {
> + .get_queue_stats_rx = hinic3_get_queue_stats_rx,
> + .get_queue_stats_tx = hinic3_get_queue_stats_tx,
> + .get_base_stats = hinic3_get_base_stats,
> +};
> +
> void hinic3_set_netdev_ops(struct net_device *netdev)
> {
> netdev->netdev_ops = &hinic3_netdev_ops;
> + netdev->stat_ops = &hinic3_stat_ops;
> }
[Severity: Low]
These two loops open-code netdev_stat_queue_sum(). The core exports
that helper from net/core/netdev-genl.c for this exact case: a
.get_base_stats callback that has to add in the queues the core does
not iterate itself. For each index in the given ranges, it calls the
driver's get_queue_stats_rx/tx and adds every field the driver filled
in. Fields left at NETDEV_STAT_NOT_SET are skipped.
The twelve fields are already zeroed above, so both loops could be
replaced by a single call:
netdev_stat_queue_sum(netdev, netdev->real_num_rx_queues,
nic_dev->max_qps, stats_rx,
netdev->real_num_tx_queues,
nic_dev->max_qps, stats_tx);
As written, every counter appears three times: in the per-queue
getter, in the zeroing block, and in the summing loop. The next
counter added to hinic3_get_queue_stats_rx() or
hinic3_get_queue_stats_tx() can easily be missed here, and the base
stats would then silently drift from the per-queue values. virtio_net
already uses the helper this way in its get_base_stats.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1796348433.git.gongfan1%40huawei.com
next prev parent reply other threads:[~2026-12-05 4:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 4:08 [PATCH net-next v19 0/4] net: hinic3: Support ethtool ops Fan Gong
2026-12-04 4:08 ` [PATCH net-next v19 1/4] hinic3: Add ethtool statistic ops part(1/2) Fan Gong
2026-12-05 4:17 ` netdev-bot+sashiko
2026-12-04 4:08 ` [PATCH net-next v19 2/4] hinic3: Add ethtool statistic ops part(2/2) Fan Gong
2026-12-05 4:17 ` netdev-bot+sashiko
2026-12-04 4:08 ` [PATCH net-next v19 3/4] hinic3: Add per-queue netdev-genl stats Fan Gong
2026-12-05 4:17 ` netdev-bot+sashiko [this message]
2026-12-04 4:08 ` [PATCH net-next v19 4/4] hinic3: Add ethtool pause param ops Fan Gong
2026-12-05 4:17 ` netdev-bot+sashiko
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=179644427679.3146.16182388388007213592@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dimitri.daskalakis1@gmail.com \
--cc=edumazet@google.com \
--cc=gongfan1@huawei.com \
--cc=horms@kernel.org \
--cc=hramamurthy@google.com \
--cc=ioana.ciornei@nxp.com \
--cc=kuba@kernel.org \
--cc=larysa.zaremba@intel.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maxime.chevallier@bootlin.com \
--cc=mohsin.bashr@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tengpeisen@huawei.com \
--cc=vadim.fedorenko@linux.dev \
--cc=wudi234@huawei.com \
--cc=wulike1@huawei.com \
--cc=zhoushuai28@huawei.com \
/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