mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jijie Shao <shaojijie@huawei.com>
To: <netdev-bot+sashiko@kernel.org>
Cc: <shaojijie@huawei.com>, <davem@davemloft.net>,
	<edumazet@kernel.org>, <kuba@kernel.org>, <pabeni@redhat.com>,
	<andrew+netdev@lunn.ch>, <shenjian15@huawei.com>,
	<liuyonglong@huawei.com>, <chenhao418@huawei.com>,
	<yangshuaisong@h-partners.com>, <ningwei15@huawei.com>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 net 3/4] net: hns3: fix interface stuck after OOM with full hardware rx queue
Date: Mon, 23 Nov 2026 15:33:39 +0800	[thread overview]
Message-ID: <a727a596-2718-4aaa-8baf-69b1aee9df43@huawei.com> (raw)
In-Reply-To: <179535384062.3135.791733868582964041@kernel.org>


on 2026/11/22 21:24, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 3 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 2 · Low: 0
>
> 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] hns3_oom_task() (hns3_enet.c:4456-4470) reads
>    HNS3_NIC_STATE_DOWN once into the local `down` at entry.
> - [Medium] The patch adds a new private ethtool -S string,
>    HNS3_TQP_STAT("rx_oom_cnt", rx_oom_cnt), to hns3_rxq_stats[] in…
> - [Medium] rx_oom_cnt can be incremented twice in one NAPI poll, which
>    contradicts the stated v5 semantics ("Count rx_oom_cnt for each NAPI…
>
> --
>
> net: hns3: fix interface stuck after OOM with full hardware rx queue
>
> This patch adds a 250ms delayed_work that re-schedules NAPI for RX rings
> that hit an allocation failure. A per-ring bitmap tracks those rings. The
> patch also replaces the earlier approach of returning budget from
> hns3_clean_rx_ring() on allocation failure, and adds a per-ring rx_oom_cnt
> ethtool counter.
>
>> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
>> index 5677e32fc3da4..60fc296020ab2 100644
>> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
>> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c
> [ ... ]
>
>> @@ -4161,6 +4163,7 @@ static int hns3_add_frag(struct hns3_enet_ring *ring)
>>   			if (unlikely(!new_skb)) {
>>   				hns3_rl_err(ring_to_netdev(ring),
>>   					    "alloc rx fraglist skb fail\n");
>> +				hns3_ring_set_oom_state(ring);
>>   				return -ENXIO;
>>   			}
>>   
>> @@ -4450,6 +4453,30 @@ static int hns3_handle_rx_bd(struct hns3_enet_ring *ring)
>>   	return 0;
>>   }
>>   
>> +static void hns3_oom_task(struct work_struct *work)
>> +{
>> +	struct hns3_nic_priv *priv = container_of(work, struct hns3_nic_priv,
>> +						  oom_task.work);
>> +	bool down = test_bit(HNS3_NIC_STATE_DOWN, &priv->state);
>> +	struct hnae3_handle *h = priv->ae_handle;
>> +	struct hns3_enet_ring *ring;
>> +	u16 i;
>> +
>> +	for (i = 0; i < h->kinfo.num_tqps; i++)
>> +		if (test_and_clear_bit(i, priv->rx_ring_oom_bm) && !down) {
>> +			ring = &priv->ring[i + h->kinfo.num_tqps];
>> +			napi_schedule(&ring->tqp_vector->napi);
>> +		}
>> +}
> [Severity: High]
> Can the stale down value here lose a recovery bit that was set after the
> interface came back up?
>
> hns3_nic_net_down() doesn't cancel oom_task, so an instance can still be
> running while hns3_nic_net_up() runs. Consider this sequence:
>
> hns3_oom_task()
>    down = test_bit(HNS3_NIC_STATE_DOWN, ...);   /* true */
>    <preempted before reaching ring i>
>
>                      hns3_nic_net_up()
>                        clear_bit(HNS3_NIC_STATE_DOWN, &priv->state);
>                        hns3_enable_irqs_and_tqps(netdev);
>
>                      NAPI poll on ring i, allocation fails
>                      hns3_clean_rx_ring()
>                        hns3_ring_set_oom_state(ring);  /* sets bit i */
>                        hns3_oom_task_schedule(ring);   /* queues new run */
>                        return recv_pkts;               /* NAPI completes */
>
> hns3_oom_task() resumes
>    test_and_clear_bit(i, ...) returns true, but down is still true,
>    so napi_schedule() is skipped and bit i is now clear
>
> 250ms later the newly queued instance finds bit i clear and does nothing.
>
> hns3_clean_rx_ring() now returns recv_pkts instead of budget, so NAPI has
> already exited. If ring i has no armed RX buffers left, the hardware won't
> raise another RX interrupt. Wouldn't the ring then stay stuck? That is the
> condition this patch is meant to fix.
>
> The commit message says:
>
>    If it runs while DOWN is set, it clears the per-ring bits without
>    scheduling NAPI. [ ... ] Both outcomes are harmless.
>
> That doesn't seem to hold for this interleaving. Two possible ways to
> close the window:
>
> - return early without clearing any bits when DOWN is set, or
> - re-check DOWN after each test_and_clear_bit() and set the bit again.
>
> Would either of these work here?

I don't think this is reachable.  hns3_nic_net_up() rebuilds the rings
before it clears HNS3_NIC_STATE_DOWN:

	ret = hns3_nic_reset_all_ring(h);
	if (ret)
		return ret;
	clear_bit(HNS3_NIC_STATE_DOWN, &priv->state);

If the rebuild fails, DOWN stays set and net_open() returns an error, so
the interface never comes up.  If it succeeds, hns3_nic_reset_all_ring()
calls hns3_reuse_buffer() on every descriptor, so the ring is full when
the interface comes up.


>
>> +
>> +static void hns3_oom_task_schedule(struct hns3_enet_ring *ring)
>> +{
> [ ... ]
>
>> @@ -4489,10 +4519,15 @@ int hns3_clean_rx_ring(struct hns3_enet_ring *ring, int budget,
>>   	 * FBD number with head pointer
>>   	 */
>>   	if (unused_count > 0)
>> -		failure = failure ||
>> -			  hns3_nic_alloc_rx_buffers(ring, unused_count);
>> +		failure |= hns3_nic_alloc_rx_buffers(ring, unused_count);
>> +
>> +	if (unlikely(failure))
>> +		hns3_ring_set_oom_state(ring);
> [Severity: Medium]
> Can rx_oom_cnt be incremented twice in a single NAPI poll here?
>
> The commit message says the counter is "incremented for each NAPI poll
> that hits an RX allocation failure". When the fraglist napi_alloc_skb()
> fails in hns3_add_frag(), the path looks like this:
>
> hns3_clean_rx_ring()
>    hns3_handle_rx_bd()
>      hns3_add_frag()
>        hns3_ring_set_oom_state(ring);   /* rx_oom_cnt++ */
>        return -ENXIO;
>    goto out;
>    failure |= hns3_nic_alloc_rx_buffers(ring, unused_count);
>    if (unlikely(failure))
>        hns3_ring_set_oom_state(ring);   /* rx_oom_cnt++ again */
>
> -ENXIO doesn't match the new err == -ENOMEM check. But failure can still
> be true, either from a failed exit refill or from an earlier failed
> in-loop refill. Under the memory pressure that caused the fraglist
> failure, the refill is likely to fail too.
>
> hns3_ring_set_oom_state() has no per-poll dedup, so in this case the
> counter goes up by two for one poll.

The second increment only happens when a second allocation actually
failed.  hns3_add_frag() counts its failed napi_alloc_skb() and returns
-ENXIO, which doesn't set `failure`, so the exit refill still runs and
bumps the counter again only if it fails too.  Two increments mean two
failures.  I agree "for each NAPI poll" can read as at most once per
poll, that's just imprecise wording.


>
> [ ... ]
>
>> diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
>> index 7b92a3c73ef6d..14642f81efe1a 100644
>> --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
>> +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c
>> @@ -62,6 +62,7 @@ static const struct hns3_stats hns3_rxq_stats[] = {
>>   	HNS3_TQP_STAT("non_reuse_pg", non_reuse_pg),
>>   	HNS3_TQP_STAT("frag_alloc_err", frag_alloc_err),
>>   	HNS3_TQP_STAT("frag_alloc", frag_alloc),
>> +	HNS3_TQP_STAT("rx_oom_cnt", rx_oom_cnt),
> [Severity: Medium]
> Should this value go through the standard per-queue rx-alloc-fail qstat
> rather than a new ethtool -S string?
>
> hns3_ring_set_oom_state() increments rx_oom_cnt on RX skb and buffer
> allocation failures. That is the event the alloc_fail field of struct
> netdev_queue_stats_rx tracks. Documentation/netlink/specs/netdev.yaml
> describes rx-alloc-fail as:
>
>    Number of times skb or buffer allocation failed on the Rx datapath.
>    Allocation failure may, or may not result in a packet drop, depending
>    on driver implementation and whether system recovers quickly.
>
> The commit message says:
>
>    It is a diagnostic counter for this recovery path, not the standard
>    rx-alloc-fail qstat.
>
> Counting per poll instead of per allocation looks like a granularity
> choice, and the standard definition leaves that choice to the driver.
>
> hns3 doesn't implement netdev_stat_ops or get_queue_stats_rx yet.
> Implementing them would expose this value through the standard uAPI.
>
> The same failures already increment the existing sw_err_cnt ("dropped")
> counter in hns3_alloc_skb() and hns3_nic_alloc_rx_buffers().
>
> This patch carries a Fixes: tag, and the new user-visible counter makes it
> harder to take through the net tree as-is. Could the counter be split out
> of this fix?

I answered this in v4 and the reasoning still holds.  hns3 has no
netdev_stat_ops, alloc_fail is an exact failure count while this is a
diagnostic for the recovery path, and the existing per-queue stats and
customer tooling read ethtool -S.  The new string is additive and
doesn't change any existing one.




  reply	other threads:[~2026-11-23  7:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 13:03 [PATCH net v5 0/4] net: hns3: fix multiple bugs in reset/error paths Jijie Shao
2026-11-18 13:03 ` [PATCH v5 net 1/4] net: hns3: fix vector resource leak in hns3_nic_alloc_vector_data Jijie Shao
2026-11-18 13:03 ` [PATCH v5 net 2/4] net: hns3: fix page_pool leak in hns3_alloc_ring_memory error path Jijie Shao
2026-11-18 13:03 ` [PATCH v5 net 3/4] net: hns3: fix interface stuck after OOM with full hardware rx queue Jijie Shao
2026-11-22 13:24   ` netdev-bot+sashiko
2026-11-23  7:33     ` Jijie Shao [this message]
2026-11-18 13:03 ` [PATCH v5 net 4/4] net: hns3: fix use-after-free in debugfs read during reset/unload Jijie Shao
2026-11-22 13:24   ` netdev-bot+sashiko
2026-11-23  7:43     ` Jijie Shao

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=a727a596-2718-4aaa-8baf-69b1aee9df43@huawei.com \
    --to=shaojijie@huawei.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=chenhao418@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liuyonglong@huawei.com \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ningwei15@huawei.com \
    --cc=pabeni@redhat.com \
    --cc=shenjian15@huawei.com \
    --cc=yangshuaisong@h-partners.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

all inboxes | Powered by JetHome®