🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20424

Re: [PATCH v5 net 3/4] net: hns3: fix interface stuck after OOM with full hardware rx queue

#20424
From: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 13:24
196 lines
15484 bytes
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?

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

[ ... ]

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

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118130330.3026625-1-shaojijie%40huawei.com
Technical Details
Message-ID: <179535384062.3135.791733868582964041@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368693-linux-kernel-netdev=dewy.ru
References: <20261118130330.3026625-4-shaojijie@huawei.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368693-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v5 net 3/4] net: hns3: fix interface stuck after OOM with
 full hardware rx queue
Date: Sun, 22 Nov 2026 13:24:00 +0000
Organization: Usenet Network
Message-ID: <179535384062.3135.791733868582964041@kernel.org>
References: <20261118130330.3026625-4-shaojijie@huawei.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3641311"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:kghazJ2Ubky79RSdMCPsCtHw8rs= sha256:BudHFL+gRtDAkSoE7XaJfws/ObaoMqLb/byfrKfmFnc=
	sha1:ysHgeLUlUwqo2WxvhEV1TMCXbGo= sha256:B4zKFtekmkEAjaHwWUHsu4EL11IqtpF+24DmzPfXO+0=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 9E2D0125D79; Sun, 22 Nov 2026 16:24:20 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id giWODfZdzX2J;
	Sun, 22 Nov 2026 16:24:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-368693-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 7601A125D77; Sun, 22 Nov 2026 16:24:06 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 0D9146056D3; Sun, 22 Nov 2026 13:24:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795353843;
	b=3d/2wnnUBkQGjcE42RUIPoTsSapBvhi/80w92RNnDH7It2s/UXspk2UQlui/EYfkVwZa
	 IB74GF55YxjBum9DFrzB7Wm9hAlXTRfIwn3OXyZRVBtYr7kmA0zZirelRyztuear6ACXJ
	 IGhtNAlv+P3WhK71s6gLy1ZmWCy5wGU1XkgyAwnXDnhlnrFLOHDQrZamlZoyPOZDKSpyw
	 c2GleBekSfJWMy8oglZ2vlDSSyyU+/5LszAM+kKsokE3CCSwZ7C00ZkbBcuEK6wJOkG0l
	 7n8YxjO0Au0wv80evW//4lYhC1UbVoK5S5DbQvPLKqicZ3+3vlfxSDgrUtnh4Cpv84Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795353843;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=PQK6gUTcJDGFmOsJs5LQLSNWPOQXRYFyM0J1ILvMPSk=;
	b=fD+4nNfl6cApTKtL0JwBnUL+tliyyf+yXCaBLIegGTq1TPXom+0t0D/mMzunx/CnB2sZ
	 FBevWp+Xl+g4uVOXGrOI95c3nJCazfifBveDu1DJbSYqmqnaM8wLXtH1AmlmjAgvtGLLK
	 kNkwrtaDCtb4FKFc3RHMubYaNQNev/7i53cWLVH/1lByigIiRszgcPVJiuz/n1om7oaKd
	 o3/t8442ou5nAHSgYLj6VDPjdXm/MjkEO3RMaU3R3G2LUjSZirae2nMN+kWRLT4uBbKCD
	 8h5mSfwBmiLzvaA2Kf5rpuXAXDLyEecHCdEFrxz/BBuSYL49mh2L/E44xSIvcOJP9sg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YjKixtYE;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D58A606A339;
	Sun, 22 Nov 2026 13:24:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YjKixtYE
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795353842;
	b=0pubz7hb8YD47m4KdI+ButHz+PCR5aB2xtQ918X89C5EYLAgD6NoTiH/mPO2INEJ0CRN
	 l7VeX9bLld+69w/pR0KwNCZovj6M8tmtKquM3vv9C84oW325iVDat4Fk2T3WPola166Bq
	 g0ta6OyEe51m/DIe882/1dtmWXRbgSLJ4lp92IaC7MoST3o1Sf7heMTm0Dy6c482lWJLN
	 aHE5AGydUVobbRaZYlJjOcB9RMu618lRYQ5h8JJotez8Vqk1Eagqqka9uMOt40+3KcKsy
	 yNDhw/fO0J6yqXFqXLaVpyLl96Z1qAesvbtXTIoldXS5lejrSzkqyHyD4siDhFkBn4w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795353842;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=PQK6gUTcJDGFmOsJs5LQLSNWPOQXRYFyM0J1ILvMPSk=;
	b=hJFSLC9BgOsPrmr5D0drv7JtuyCkJNTaXyE3wnrCHZxpbKpYrov/Mxb29MMgMEUzjTl5
	 4tDLgGbJoeWGt+1ahO6DtKHB764SE9sov2WYjzOgvK3p2VHaZgc4GfC3P2H6EAeAF8dSS
	 +f/NkFKKz+22cYOutOVZfs+uL+IU4yhDXS61h0PcJmY3BFqF+wsWLxSfe5BBqJI9/6HEa
	 tyo7RBGFYOCtDSH+GIlF5i/HFiADcZ0+O+U1k18p1zOuMRjiZ0lMKVGpxjocRVljLWkBu
	 yIt5eE5y5KPq503JKn5ZhDc8tezdAC6Ch2PnDMsckmovekZC6ZD+PfnQVGPsjLgJ0iQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YjKixtYE;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 674F8606A320;
	Sun, 22 Nov 2026 13:24:02 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1925C1F000C6;
	Sun, 22 Nov 2026 13:24:01 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795353841;
	bh=PQK6gUTcJDGFmOsJs5LQLSNWPOQXRYFyM0J1ILvMPSk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=YjKixtYEZAbNsLetRVKuuSrWcUhQ0gmvwLg9tHviz6aabPdKI/wPsGDWyjwPL3adg
	 CCfNwP3OBVSEqhlYLK58ObeZsnZVR1uOIiLW5h3IcMH9QroK+6RM3wPqGiASpfpMFi
	 q0Y6jR8Jh1rDVlt+I1twhwOfuayq6JflDIS5gv4Z7GQDCCIiN9Ihiuv++H18eXgQwo
	 Q7m6eLC8uhe2flZtDZvGBt6Y97KhtwFzcn32pxigXDZ/gZmWnYJIMbwvgMiCVa7l7I
	 CLlQYJO/9kAZnFBq0zWyUIP8O8u0A8ol3CbmvZxJl7t9cRZBW1e54BGioN7xybFP33
	 7qIFVyeF3fs2w==
X-Cc: 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
X-In-Reply-To: <20261118130330.3026625-4-shaojijie@huawei.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list