* [PATCH net-next v05 1/1] hinic3: Fix the RX stalls in hinic3_rx_poll()
2026-11-20 3:14 [PATCH net-next v05 0/1] net: hinic3: Bugfix for later patch-set Fan Gong
@ 2026-11-20 3:14 ` Fan Gong
0 siblings, 0 replies; 2+ messages in thread
From: Fan Gong @ 2026-11-20 3:14 UTC (permalink / raw)
To: Fan Gong, Wu Di, Teng Peisen, netdev, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Andrew Lunn, Ioana Ciornei, Maxime Chevallier, Mohsin Bashir,
Dimitri Daskalakis, Harshitha Ramamurthy, Larysa Zaremba,
Vadim Fedorenko
Cc: linux-kernel, linux-doc, Zhou Shuai, Wu Like
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. In the other
two the ring ends up without posted WQEs, and a full RX ring makes the
device stop raising interrupts, so the queue stays dead until the
interface is reset.
For the first case return budget so that hinic3_poll() skips
napi_complete_done() and NAPI runs again immediately; every pass consumes
CQEs, so the polling terminates.
Returning budget on the allocation failures as well would keep NAPI
running until the allocator recovers, which spins a CPU under prolonged
memory pressure. Handle those two cases with a software recovery path
instead, the same way hns3 does: 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 and does nothing when the interface is down, so a work that
races with a close only clears the bits.
The bitmap is allocated together with the Tx/Rx queues and freed after
the delayed work is cancelled. hinic3_qps_irq_uninit() cancels the work
before the NAPI instances are torn down and before the channel resources
are released, so the work 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")
Co-developed-by: Wu Di <wudi234@huawei.com>
Signed-off-by: Wu Di <wudi234@huawei.com>
Co-developed-by: Teng Peisen <tengpeisen@huawei.com>
Signed-off-by: Teng Peisen <tengpeisen@huawei.com>
Signed-off-by: Fan Gong <gongfan1@huawei.com>
---
.../net/ethernet/huawei/hinic3/hinic3_irq.c | 5 ++
.../net/ethernet/huawei/hinic3/hinic3_main.c | 51 ++++++++++++++++++-
.../ethernet/huawei/hinic3/hinic3_nic_dev.h | 3 ++
.../net/ethernet/huawei/hinic3/hinic3_rx.c | 26 ++++++++--
4 files changed, 79 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_irq.c b/drivers/net/ethernet/huawei/hinic3/hinic3_irq.c
index e7d6c2033b45..f83c1be0c808 100644
--- a/drivers/net/ethernet/huawei/hinic3/hinic3_irq.c
+++ b/drivers/net/ethernet/huawei/hinic3/hinic3_irq.c
@@ -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,8 @@ 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);
+
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];
@@ -273,6 +276,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);
diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_main.c b/drivers/net/ethernet/huawei/hinic3/hinic3_main.c
index 0a888fe4c975..5cc064f9351a 100644
--- a/drivers/net/ethernet/huawei/hinic3/hinic3_main.c
+++ b/drivers/net/ethernet/huawei/hinic3/hinic3_main.c
@@ -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/etherdevice.h>
#include <linux/netdevice.h>
@@ -33,6 +34,8 @@
#define HINIC3_RX_PENDING_LIMIT_LOW 2
#define HINIC3_RX_PENDING_LIMIT_HIGH 8
+#define HINIC3_RX_OOM_POLL_MS 250
+
static void init_intr_coal_param(struct net_device *netdev)
{
struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
@@ -76,6 +79,35 @@ static void hinic3_free_intr_coalesce(struct net_device *netdev)
kfree(nic_dev->intr_coalesce);
}
+static void hinic3_rx_oom_work(struct work_struct *work)
+{
+ struct hinic3_nic_dev *nic_dev =
+ container_of(work, struct hinic3_nic_dev, rx_oom_work.work);
+ struct hinic3_rxq *rxq;
+ u16 q_id;
+
+ for (q_id = 0; q_id < nic_dev->q_params.num_qps; q_id++) {
+ rxq = &nic_dev->rxqs[q_id];
+
+ if (!test_and_clear_bit(q_id, nic_dev->rx_oom_bitmap))
+ continue;
+
+ if (!test_bit(HINIC3_INTF_UP, &nic_dev->flags))
+ continue;
+
+ napi_schedule(&rxq->irq_cfg->napi);
+ }
+}
+
+void hinic3_rx_oom_schedule(struct net_device *netdev, u16 q_id)
+{
+ struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
+
+ set_bit(q_id, nic_dev->rx_oom_bitmap);
+ schedule_delayed_work(&nic_dev->rx_oom_work,
+ msecs_to_jiffies(HINIC3_RX_OOM_POLL_MS));
+}
+
static int hinic3_alloc_txrxqs(struct net_device *netdev)
{
struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
@@ -94,14 +126,25 @@ static int hinic3_alloc_txrxqs(struct net_device *netdev)
goto err_free_txqs;
}
+ nic_dev->rx_oom_bitmap = bitmap_zalloc(nic_dev->max_qps, GFP_KERNEL);
+ if (!nic_dev->rx_oom_bitmap) {
+ dev_err(hwdev->dev, "Failed to alloc rx oom bitmap\n");
+ err = -ENOMEM;
+ goto err_free_rxqs;
+ }
+ INIT_DELAYED_WORK(&nic_dev->rx_oom_work, hinic3_rx_oom_work);
+
err = hinic3_init_intr_coalesce(netdev);
if (err) {
dev_err(hwdev->dev, "Failed to init_intr_coalesce\n");
- goto err_free_rxqs;
+ goto err_free_bitmap_zalloc;
}
return 0;
+err_free_bitmap_zalloc:
+ bitmap_free(nic_dev->rx_oom_bitmap);
+ nic_dev->rx_oom_bitmap = NULL;
err_free_rxqs:
hinic3_free_rxqs(netdev);
err_free_txqs:
@@ -112,6 +155,12 @@ static int hinic3_alloc_txrxqs(struct net_device *netdev)
static void hinic3_free_txrxqs(struct net_device *netdev)
{
+ struct hinic3_nic_dev *nic_dev = netdev_priv(netdev);
+
+ cancel_delayed_work_sync(&nic_dev->rx_oom_work);
+ bitmap_free(nic_dev->rx_oom_bitmap);
+ nic_dev->rx_oom_bitmap = NULL;
+
hinic3_free_intr_coalesce(netdev);
hinic3_free_rxqs(netdev);
hinic3_free_txqs(netdev);
diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_nic_dev.h b/drivers/net/ethernet/huawei/hinic3/hinic3_nic_dev.h
index 9502293ff710..5d6710f13b2c 100644
--- a/drivers/net/ethernet/huawei/hinic3/hinic3_nic_dev.h
+++ b/drivers/net/ethernet/huawei/hinic3/hinic3_nic_dev.h
@@ -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);
diff --git a/drivers/net/ethernet/huawei/hinic3/hinic3_rx.c b/drivers/net/ethernet/huawei/hinic3/hinic3_rx.c
index 309ab5901379..ad6b65fce9c9 100644
--- a/drivers/net/ethernet/huawei/hinic3/hinic3_rx.c
+++ b/drivers/net/ethernet/huawei/hinic3/hinic3_rx.c
@@ -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;
}
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread