Skip to contentSkip to conversation

net: hinic3: Bugfix for later patch-set.

PATCH New Fan Gong 1 participant 2 messages Nov 23

Subsystems (4)
lore
Share & tools
lore

Fan Gong

author maintainer
#0 lore raw

v6 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:
* Tested on hinic3 hardware.

v06:
* Enable rx_oom_work in hinic3_qps_irq_init() and disable it with disable_delayed_work_sync() after the NAPI instances are torn down and on the init rollback path, so it cannot be queued again.(AI Review)
* hinic3_rx_oom_work() uses HINIC3_INTF_UP to keep the pending queues and retry.(AI Review)

v05: https://lore.kernel.org/netdev/[email protected]/
* Replace the NAPI busy-poll on RX allocation failure with the software RX OOM recovery: a per-queue bitmap plus a delayed work that re-arms NAPI, so NAPI completes instead of spinning while memory is under pressure.(Jakub Kicinski)
* Return budget only for the LRO replenishment threshold.
* The u64_stats reader, the 80 column wrapping and the max_qps patches of v04 have been merged as 66726ba54a01; this series carries the RX stall fix only.

v04: https://lore.kernel.org/netdev/[email protected]/
* 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 (1):
hinic3: Fix the RX stalls in hinic3_rx_poll()

 .../net/ethernet/huawei/hinic3/hinic3_irq.c   | 10 ++++
 .../net/ethernet/huawei/hinic3/hinic3_main.c  | 59 ++++++++++++++++++-
 .../ethernet/huawei/hinic3/hinic3_nic_dev.h   |  3 +
 .../net/ethernet/huawei/hinic3/hinic3_rx.c    | 26 ++++++--
 4 files changed, 92 insertions(+), 6 deletions(-)

base-commit: 66726ba54a01a2951688a56f5eb4d13d063acbea

Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH v6 1/1 hinic3: Fix the RX stalls in hinic3_rx_poll()

hinic3_rx_poll() leaves the loop early in three cases, and hinic3_poll() then completes NAPI and re-enables the edge triggered MSI-X interrupt:

- 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.

In the first case a completed CQE still sits at the head of the ring, so nothing re-arms the queue when no further packet arrives. A failed napi_alloc_skb() leaves a completed CQE at the head as well, with no WQE consumed and no state advanced, so the next poll would retry the same CQE. A short refill is different: the ring ends up without posted WQEs, and once the device has consumed the rest it writes no CQE and raises no interrupt either, so the queue stays dead until the interface is reset.

Return budget for the LRO case so that hinic3_poll() skips napi_complete_done() and NAPI runs again immediately; every pass consumes CQEs, so the polling terminates.

Doing the same for the two allocation failures would keep NAPI retrying the same CQE, or an empty ring, until the allocator recovers, which spins a CPU under prolonged memory pressure. Keep NAPI out of that loop
instead: record the affected queue in a per-queue bitmap and re-arm NAPI from a delayed work 250ms later, independent of the hardware interrupts. The work calls napi_schedule() for every queue that failed. When the interface is not up yet it keeps the bits and tries again, since hinic3_open() sets HINIC3_INTF_UP only after the vport is enabled, and the teardown path disables the work so that it cannot outlive the channel.

The bitmap is allocated together with the Tx/Rx queues and freed once the work is disabled. hinic3_qps_irq_uninit() cancels the work before the NAPI instances are torn down and disables it after they are gone, and hinic3_qps_irq_init() disables it again on its rollback path, so no poll can queue it once the channel is torn down and it never dereferences a freed irq_cfg. The bitmap is cleared when the queues are brought up, so a queue that is brought up again does not inherit a stale bit.

Fixes 17fcb3dc12bb ("hinic3: module initialization and tx/rx logic")
---
 .../net/ethernet/huawei/hinic3/hinic3_irq.c   | 10 ++++
 .../net/ethernet/huawei/hinic3/hinic3_main.c  | 59 ++++++++++++++++++-
 .../ethernet/huawei/hinic3/hinic3_nic_dev.h   |  3 +
 .../net/ethernet/huawei/hinic3/hinic3_rx.c    | 26 ++++++--
 4 files changed, 92 insertions(+), 6 deletions(-)
drivers/net/ethernet/huawei/hinic3/hinic3_irq.c +10 -0
index e7d6c2033b45..4ff5c97639e8 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 // Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 
+#include <linux/bitmap.h>
 #include <linux/dim.h>
 #include <linux/netdevice.h>
 
@@ -205,6 +206,9 @@ int hinic3_qps_irq_init(struct net_device *netdev)
 	u16 q_id;
 	int err;
 
+	bitmap_zero(nic_dev->rx_oom_bitmap, nic_dev->max_qps);
+	enable_delayed_work(&nic_dev->rx_oom_work);
+
 	for (q_id = 0; q_id < nic_dev->q_params.num_qps; q_id++) {
 		msix_entry = &nic_dev->qps_msix_entries[q_id];
 		irq_cfg = &nic_dev->q_params.irq_cfg[q_id];
@@ -264,6 +268,8 @@ int hinic3_qps_irq_init(struct net_device *netdev)
 		disable_work_sync(&irq_cfg->rxq->dim.work);
 	}
 
+	disable_delayed_work_sync(&nic_dev->rx_oom_work);
+
 	return err;
 }
 
@@ -273,6 +279,8 @@ void hinic3_qps_irq_uninit(struct net_device *netdev)
 	struct hinic3_irq_cfg *irq_cfg;
 	u16 q_id;
 
+	cancel_delayed_work_sync(&nic_dev->rx_oom_work);
+
 	for (q_id = 0; q_id < nic_dev->q_params.num_qps; q_id++) {
 		irq_cfg = &nic_dev->q_params.irq_cfg[q_id];
 		qp_del_napi(irq_cfg);
@@ -288,4 +296,6 @@ void hinic3_qps_irq_uninit(struct net_device *netdev)
 		hinic3_release_irq(irq_cfg);
 		disable_work_sync(&irq_cfg->rxq->dim.work);
 	}
+
+	disable_delayed_work_sync(&nic_dev->rx_oom_work);
 }
drivers/net/ethernet/huawei/hinic3/hinic3_main.c +58 -1

96 lines not on this page · raw message

drivers/net/ethernet/huawei/hinic3/hinic3_nic_dev.h +3 -0
index 9502293ff710..5d6710f13b2c 100644
@@ -112,6 +112,7 @@ struct hinic3_nic_dev {
 	struct hinic3_dyna_txrxq_params q_params;
 	struct hinic3_txq               *txqs;
 	struct hinic3_rxq               *rxqs;
+	unsigned long                   *rx_oom_bitmap;
 
 	enum hinic3_rss_hash_type       rss_hash_type;
 	struct hinic3_rss_type          rss_type;
@@ -126,6 +127,7 @@ struct hinic3_nic_dev {
 
 	struct workqueue_struct         *workq;
 	struct delayed_work             periodic_work;
+	struct delayed_work             rx_oom_work;
 	struct work_struct              rx_mode_work;
 	/* lock for enable/disable port */
 	struct mutex                    port_state_mutex;
@@ -145,6 +147,7 @@ void hinic3_set_netdev_ops(struct net_device *netdev);
 int hinic3_set_hw_features(struct net_device *netdev);
 int hinic3_qps_irq_init(struct net_device *netdev);
 void hinic3_qps_irq_uninit(struct net_device *netdev);
+void hinic3_rx_oom_schedule(struct net_device *netdev, u16 q_id);
 
 void hinic3_set_rx_mode_work(struct work_struct *work);
 void hinic3_clean_mac_list_filter(struct net_device *netdev);
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +21 -5
index 309ab5901379..ad6b65fce9c9 100644
@@ -555,6 +555,8 @@ 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;
+	bool oom = false;
 	u32 num_wqe = 0;
 	int nr_pkts = 0;
 	u16 num_lro;
@@ -571,8 +573,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)) {
+			oom = true;
 			break;
+		}
 
 		nr_pkts++;
 		num_lro = RQ_CQE_STATUS_GET(status, NUM_LRO);
@@ -581,12 +585,24 @@ 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) {
+		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)
+			oom = true;
 	}
 
-	if (rxq->delta >= HINIC3_RX_BUFFER_WRITE)
-		hinic3_rx_fill_buffers(rxq);
+	if (unlikely(oom))
+		hinic3_rx_oom_schedule(rxq->netdev, rxq->q_id);
 
-	return nr_pkts;
+	return poll_again ? budget : nr_pkts;
 }
Signature · 1 line
2.43.0