net: hinic3: Bugfix for later patch-set.
Subsystems (4)
Fan Gong
maintainerPATCH v4 2/4 hinic3: Read the queue counters once per u64_stats retry loop
In reply to Fan Gonghinic3_get_stats64() accumulates the per-queue counters with += inside the u64_stats_fetch_begin()/u64_stats_fetch_retry() sequence. A retry repeats the body, so the values read by an aborted pass would be counted twice. Read the snapshot of one queue into the locals instead, and add it to the rtnl_link_stats64 fields after the loop.
This cannot trigger today: the driver depends on 64BIT, where u64_stats_fetch_retry() always returns false, and the only writers of these counters are the clean_stats() helpers, which run before the queues are used. The change is a prerequisite for the per-queue statistics that will populate them, so it carries no Fixes: tag and reports the same values as before.
While at it, drop the dead stores into the locals before the loops: every iteration overwrites them before they are read.
Also drop the nic_dev->txqs and nic_dev->rxqs NULL checks. Both arrays are allocated by hinic3_sw_init() before register_netdev() and freed by hinic3_sw_uninit() after unregister_netdev(), and the loops are bounded by nic_dev->max_qps, the number of entries they were allocated with.
rx_errors keeps reporting csum_errors + other_errors. Neither counter is populated yet, and the checksum error accounting together with its "csum_bad" queue statistic belongs to the queue-stats work that adds the writer.
--- .../huawei/hinic3/hinic3_netdev_ops.c | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-)
drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c +15 -28
@@ -791,49 +791,36 @@ static void hinic3_get_stats64(struct net_device *netdev,unsigned int start;int i; - bytes =0 ; - packets =0 ; - dropped =0 ;for (i =0 ; i < nic_dev->max_qps; i++) { -if (!nic_dev->txqs) -break ; - txq = &nic_dev->txqs[i]; txq_stats = &txq->txq_stats;do { start =u64_stats_fetch_begin (&txq_stats->syncp); - bytes += txq_stats->bytes; - packets += txq_stats->packets; - dropped += txq_stats->dropped; + bytes = txq_stats->bytes; + packets = txq_stats->packets; + dropped = txq_stats->dropped; }while (u64_stats_fetch_retry (&txq_stats->syncp, start)); + stats->tx_packets += packets; + stats->tx_bytes += bytes; + stats->tx_dropped += dropped; } - stats->tx_packets = packets; - stats->tx_bytes = bytes; - stats->tx_dropped = dropped; - bytes =0 ; - packets =0 ; - errors =0 ; - dropped =0 ;for (i =0 ; i < nic_dev->max_qps; i++) { -if (!nic_dev->rxqs) -break ; - rxq = &nic_dev->rxqs[i]; rxq_stats = &rxq->rxq_stats;do { start =u64_stats_fetch_begin (&rxq_stats->syncp); - bytes += rxq_stats->bytes; - packets += rxq_stats->packets; - errors += rxq_stats->csum_errors + - rxq_stats->other_errors; - dropped += rxq_stats->dropped; + bytes = rxq_stats->bytes; + packets = rxq_stats->packets; + errors = rxq_stats->csum_errors + + rxq_stats->other_errors; + dropped = rxq_stats->dropped; }while (u64_stats_fetch_retry (&rxq_stats->syncp, start)); + stats->rx_packets += packets; + stats->rx_bytes += bytes; + stats->rx_errors += errors; + stats->rx_dropped += dropped; } - stats->rx_packets = packets; - stats->rx_bytes = bytes; - stats->rx_errors = errors; - stats->rx_dropped = dropped; }static void hinic3_nic_set_rx_mode (struct net_device *netdev)
Signature · 1 line
2.43.0
Fan Gong
maintainerPATCH v4 3/4 hinic3: Wrap long lines and rename q_params
In reply to Fan GongWrap the long function signatures of hinic3_alloc_txrxq_resources(), hinic3_free_txrxq_resources(), hinic3_alloc_channel_resources() and hinic3_free_channel_resources() so that they fit in 80 columns.
While at it, rename the trxq_params argument of hinic3_alloc_channel_resources() and hinic3_free_channel_resources() to q_params, matching the name used by the other queue parameter helpers. No expression, call or error path changes.
--- .../huawei/hinic3/hinic3_netdev_ops.c | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-)
drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c +19 -15
@@ -121,8 +121,9 @@ static void hinic3_destroy_num_qps(struct net_device *netdev)kfree (nic_dev->qps_msix_entries); } -static int hinic3_alloc_txrxq_resources (struct net_device *netdev, -struct hinic3_dyna_txrxq_params *q_params) +static int +hinic3_alloc_txrxq_resources (struct net_device *netdev, +struct hinic3_dyna_txrxq_params *q_params) {int err;
@@ -176,8 +177,9 @@ static int hinic3_alloc_txrxq_resources(struct net_device *netdev,return err; } -static void hinic3_free_txrxq_resources (struct net_device *netdev, -struct hinic3_dyna_txrxq_params *q_params) +static void +hinic3_free_txrxq_resources (struct net_device *netdev, +struct hinic3_dyna_txrxq_params *q_params) {hinic3_free_rxqs_res (netdev, q_params->num_qps, q_params->rq_depth, q_params->rxqs_res);
@@ -251,16 +253,17 @@ static void hinic3_remove_configure(struct net_device *netdev)hinic3_rss_uninit (netdev); } -static int hinic3_alloc_channel_resources (struct net_device *netdev, -struct hinic3_dyna_qp_params *qp_params, -struct hinic3_dyna_txrxq_params *trxq_params) +static int +hinic3_alloc_channel_resources (struct net_device *netdev, +struct hinic3_dyna_qp_params *qp_params, +struct hinic3_dyna_txrxq_params *q_params) {struct hinic3_nic_dev *nic_dev =netdev_priv (netdev);int err; - qp_params->num_qps = trxq_params->num_qps; - qp_params->sq_depth = trxq_params->sq_depth; - qp_params->rq_depth = trxq_params->rq_depth; + qp_params->num_qps = q_params->num_qps; + qp_params->sq_depth = q_params->sq_depth; + qp_params->rq_depth = q_params->rq_depth; err =hinic3_alloc_qps (nic_dev, qp_params);if (err) {
@@ -268,7 +271,7 @@ static int hinic3_alloc_channel_resources(struct net_device *netdev,return err; } - err =hinic3_alloc_txrxq_resources (netdev, trxq_params); + err =hinic3_alloc_txrxq_resources (netdev, q_params);if (err) {netdev_err (netdev,"Failed to alloc txrxq resources\n" );hinic3_free_qps (nic_dev, qp_params);
@@ -278,13 +281,14 @@ static int hinic3_alloc_channel_resources(struct net_device *netdev,return 0 ; } -static void hinic3_free_channel_resources (struct net_device *netdev, -struct hinic3_dyna_qp_params *qp_params, -struct hinic3_dyna_txrxq_params *trxq_params) +static void +hinic3_free_channel_resources (struct net_device *netdev, +struct hinic3_dyna_qp_params *qp_params, +struct hinic3_dyna_txrxq_params *q_params) {struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); -hinic3_free_txrxq_resources (netdev, trxq_params); +hinic3_free_txrxq_resources (netdev, q_params);hinic3_free_qps (nic_dev, qp_params); }
Signature · 1 line
2.43.0
Fan Gong
maintainerv4 cover net: hinic3: Bugfix for later patch-set.
These issues were discovered by LLM Gemini-4-Argon and Claude-Opus-5-5. At the same time, LLM recommended submitting an independent patch. These issues were not actually triggered. Based on theoretical analysis and consideration of actual risks, this patch is used to fix the issues.
Testing:
This patch-set has been tested on hinic3 hardware.
v04:
* Fold a short ring refill into the hinic3_rx_poll() repoll decision: with no WQE posted the device raises no interrupt, so returning nr_pkts left the queue dead until the interface is reset.(AI Review)
* Keep csum_errors in rx_errors, and describe the u64_stats reader change as the cleanup it is: the driver depends on 64BIT, so the retry never happens. Drop the Fixes: tag.(AI Review)
* Rewrite "fix some checkpatchs.": name what is wrapped and renamed, and note that the patch has no functional effect.(AI Review)
* Reword "Ensure that the value of max_qps is not changed": max_qps sizes the software arrays, the hardware capacity is nic_io->max_qps, and the change is a design change rather than a fix (no Fixes: tag).(AI Review)
V03: https://lore.kernel.org/all/[email protected]/
* Cleanup checkpatchs in file hinic3_netdev_ops.c.(AI Review)
* nic_svc_cap->max_sqs is already in the range [1, 256].(AI Review)
V02: https://lore.kernel.org/all/[email protected]/
* Rewrite the commit message and provide an explanation for each patch.(AI Review)
* Split checkpatchs in to a separate patch.(AI Review)
* Fix the failure of napi_alloc_skb() in recv_one_pkt().(AI Review)
* READ_ONCE()/WRITE_ONCE() only stop the compiler from tearing or caching the access. They don't order anything against the work item, and they can't stop it from running. So, remove READ_ONCE() and WRITE_ONCE() on nic_dev->adaptive_rx_coal.(AI Review)
V01: https://lore.kernel.org/netdev/[email protected]/
Fan Gong (4):
hinic3: Fix the RX stalls in hinic3_rx_poll()
hinic3: Read the queue counters once per u64_stats retry loop
hinic3: Wrap long lines and rename q_params
hinic3: Keep max_qps at the hardware maximum when RSS setup fails
.../huawei/hinic3/hinic3_netdev_ops.c | 77 ++++++++----------- .../net/ethernet/huawei/hinic3/hinic3_rss.c | 7 +- .../net/ethernet/huawei/hinic3/hinic3_rx.c | 22 ++++-- 3 files changed, 53 insertions(+), 53 deletions(-)
base-commit: 73022f605c447f31610b94ed4a983d2b4bf2c721
Signature · 1 line
2.43.0
Fan Gong
maintainerPATCH v4 1/4 hinic3: Fix the RX stalls in hinic3_rx_poll()
hinic3_rx_poll() can leave the loop with a completed CQE still sitting at the head of the ring, or with no WQE left to receive into, and still return nr_pkts, which is below budget. hinic3_poll() then calls napi_complete_done() and re-enables the MSI-X interrupt, which is edge triggered, so nothing re-arms the queue if no further packet arrives.
Three exits behave this way:
- a large LRO packet consumed enough WQEs to cross lro_replenish_thld;
- napi_alloc_skb() failed in recv_one_pkt();
- hinic3_rx_fill_buffers() posted fewer WQEs than rxq->delta - 1 because page_pool_dev_alloc_frag() failed.
The first two leave a completed CQE unprocessed. The third leaves the device without a WQE to receive into: it then drops every packet and, because no CQE is written, raises no interrupt either, so the queue stays dead until the interface is reset.
Return budget from all three paths so that hinic3_poll() skips napi_complete_done() and NAPI runs again immediately.
When recv_one_pkt() fails no CQE is consumed and no state is advanced, so the same CQE is simply retried on the next poll; this is the only way to make progress, as the completed CQE cannot be dropped. Likewise hinic3_rx_fill_buffers() keeps the WQEs it could not post accounted for in rxq->delta, so the next poll retries the refill and the ring is complete again as soon as a full refill succeeds. All three failures are transient (memory pressure), which bounds the immediate repoll, and i40e, ice and iavf return budget on a ring refill failure in the same way. A deferred refill would need to be serialized against hinic3_rx_poll(), which retries the same WQEs from rxq->delta, so the poll based retry is used instead.
--- .../net/ethernet/huawei/hinic3/hinic3_rx.c | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +17 -5
@@ -555,6 +555,7 @@ int hinic3_rx_poll(struct hinic3_rxq *rxq, int budget)struct hinic3_nic_dev *nic_dev =netdev_priv (rxq->netdev);u32 sw_ci, status, pkt_len, vlan_len;struct hinic3_rq_cqe *rx_cqe; +bool poll_again = false;u32 num_wqe =0 ;int nr_pkts =0 ;u16 num_lro;
@@ -571,8 +572,10 @@ int hinic3_rx_poll(struct hinic3_rxq *rxq, int budget) vlan_len =le32_to_cpu (rx_cqe->vlan_len); pkt_len =RQ_CQE_SGE_GET (vlan_len,LEN ); -if (recv_one_pkt (rxq, rx_cqe, pkt_len, vlan_len, status)) +if (recv_one_pkt (rxq, rx_cqe, pkt_len, vlan_len, status)) { + poll_again = true;break ; + } nr_pkts++; num_lro =RQ_CQE_STATUS_GET (status,NUM_LRO );
@@ -581,12 +584,21 @@ int hinic3_rx_poll(struct hinic3_rxq *rxq, int budget) rx_cqe->status =0 ; -if (num_wqe >= nic_dev->lro_replenish_thld) +if (num_wqe >= nic_dev->lro_replenish_thld) { + poll_again = true;break ; + } } -if (rxq->delta >=HINIC3_RX_BUFFER_WRITE ) -hinic3_rx_fill_buffers (rxq); +if (rxq->delta >=HINIC3_RX_BUFFER_WRITE ) { +u32 free_wqebbs = rxq->delta -1 ; + +/* Refill stops at the first failed allocation, so a short +* refill may leave the ring without any WQE posted. +*/ +if (hinic3_rx_fill_buffers (rxq) != free_wqebbs) + poll_again = true; + } -return nr_pkts; +return poll_again ? budget : nr_pkts; }
Signature · 1 line
2.43.0
Fan Gong
maintainerPATCH v4 4/4 hinic3: Keep max_qps at the hardware maximum when RSS setup fails
In reply to Fan Gongnic_dev->max_qps sizes the per-queue software arrays: txqs, rxqs, intr_coalesce and qps_msix_entries are allocated with one entry per max_qps by hinic3_sw_init() and hinic3_open(). The number of queues the driver uses is nic_dev->q_params.num_qps: decide_num_qps() clamps it to max_qps and hinic3_config_num_qps() forces it to 1 on every open while HINIC3_RSS_ENABLE is clear.
hinic3_try_to_enable_rss() also shrank max_qps to 1 on its error paths. The netdev is created with alloc_etherdev_mq(..., max_qps) queues, while netif_set_real_num_queues() only lowers real_num_{tx,rx}_queues on a successful open, so between probe and the first open the queue count the netdev advertises and the size of these arrays disagreed.
This is a design change, not a bug fix, so it carries no Fixes: tag: the old fallback was self consistent (one txq, one rxq, one coalesce entry, one MSI-X entry and num_qps = 1), and nothing can reach the mismatch today. hinic3_xmit_frame() is bounded by q_params.num_qps and hinic3_get_stats64() by max_qps, and the queue count cannot grow later either, as the driver has no ethtool set_channels or set_rxfh callback. Keeping the arrays at the hardware maximum is what the per-queue statistics that will walk real_num_*_queues need, since they must not be able to index past the end of a one-element array.
After this change nothing sets max_qps to 1 any more. Keep it at hinic3_func_max_qnum() in every branch, which is also the value hinic3_init_nic_io() uses for the hardware queue capacity, and reduce only q_params.num_qps. err_reset_q_params() now sets it to 1 explicitly instead of copying max_qps, since one queue is what the device uses while RSS is disabled.
--- drivers/net/ethernet/huawei/hinic3/hinic3_rss.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/huawei/hinic3/hinic3_rss.c +2 -5
@@ -312,10 +312,8 @@ void hinic3_try_to_enable_rss(struct net_device *netdev) goto err_reset_q_params; err =alloc_rss_resource (netdev); -if (err) { - nic_dev->max_qps =1 ; +if (err) goto err_reset_q_params; - }set_bit (HINIC3_RSS_ENABLE , &nic_dev->flags);decide_num_qps (netdev);
@@ -324,7 +322,6 @@ void hinic3_try_to_enable_rss(struct net_device *netdev)if (err) {dev_err (hwdev->dev,"Failed to set hardware rss parameters\n" );hinic3_clear_rss_config (netdev); - nic_dev->max_qps =1 ; goto err_reset_q_params; }
@@ -332,5 +329,5 @@ void hinic3_try_to_enable_rss(struct net_device *netdev) err_reset_q_params:clear_bit (HINIC3_RSS_ENABLE , &nic_dev->flags); - nic_dev->q_params.num_qps = nic_dev->max_qps; + nic_dev->q_params.num_qps =1 ; }
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerRe: [PATCH net-next v04 1/4] hinic3: Fix the RX stalls in hinic3_rx_poll()
In reply to Fan GongQuoted 5 lines · On Tue, 17 Nov 2026 20:08:31 +0800 Fan Gong wrote:
hinic3_rx_poll()can leave the loop with a completed CQE still sitting at the head of the ring, or with no WQE left to receive into, and still returnnr_pkts, which is below budget.hinic3_poll()then callsnapi_complete_done()and re-enables the MSI-X interrupt, which is edge triggered, so nothing re-arms the queue if no further packet arrives.
Look how you Hauwei coworker is fixing this in hns3:
https://lore.kernel.org/all/[email protected]/
That's much better. Live-locking the system in NAPI when its OOM is pretty bad. My personal preference is to have a work that just checks for Rx buffer queue being empty every few sec.
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Tue, 17 Nov 2026 20:08:30 +0800 you wrote:
These issues were discovered by LLM Gemini-4-Argon and Claude-Opus-5-5. At the same time, LLM recommended submitting an independent patch. These issues were not actually triggered. Based on theoretical analysis and consideration of actual risks, this patch is used to fix the issues.
Testing:
This patch-set has been tested on hinic3 hardware.[...]
Here is the summary with links:
- [net-next,v04,1/4] hinic3: Fix the RX stalls in hinic3_rx_poll() (no matching commit)
- [net-next,v04,2/4] hinic3: Read the queue counters once per u64_stats retry loop
https://git.kernel.org/netdev/net-next/c/0f00324913b4 - [net-next,v04,3/4] hinic3: Wrap long lines and rename q_params https://git.kernel.org/netdev/net-next/c/b4cca5c5238e - [net-next,v04,4/4] hinic3: Keep max_qps at the hardware maximum when RSS setup fails https://git.kernel.org/netdev/net-next/c/453a026487a6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Fan Gong
maintainerRe: [PATCH net-next v04 1/4] hinic3: Fix the RX stalls in hinic3_rx_poll()
In reply to Jakub KicinskiQuoted 7 lines · On Tue, 17 Nov 2026 20:08:31 +0800 Fan Gong wrote:
Quoted 5 lines
hinic3_rx_poll()can leave the loop with a completed CQE still sitting at the head of the ring, or with no WQE left to receive into, and still returnnr_pkts, which is below budget.hinic3_poll()then callsnapi_complete_done()and re-enables the MSI-X interrupt, which is edge triggered, so nothing re-arms the queue if no further packet arrives.
Quoted 5 lines
Look how you Hauwei coworker is fixing this in hns3:
https://lore.kernel.org/all/[email protected]/
That's much better. Live-locking the system in NAPI when its OOM is pretty bad. My personal preference is to have a work that just checks for Rx buffer queue being empty every few sec.
OK