🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27459

Re: [PATCH net v3 3/3] net: lapb: transmit frames outside the protocol lock

#27459
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 17:39
270 lines
17936 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 3

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

- [Medium] The patch adds `lapb->tx_running` as a home-made ownership
  lock around data_transmit().
- [Low] lapbeth_napi_poll() (drivers/net/wan/lapbether.c) now calls
  lapb_transmit_pending() on every poll, whatever the budget.
- [Low] Documentation/networking/lapb-module.rst says each
  lapb_transmit_pending() call "sends at most 64 frames".
- [Low] The newly added API documentation in
  Documentation/networking/lapb-module.rst does not match the real…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the new TX
  FIFO drain keeps it in place.

--

net: lapb: transmit frames outside the protocol lock

This patch stops LAPB from calling data_transmit() under lapb->lock.
Frames now go on a per-instance FIFO, which is drained after the lock is
dropped. lapbeth gets a new schedule_tx() callback and drains from its
NAPI poll, while hdlc_x25 drains inline and falls back to a work item.

Closes: https://syzkaller.appspot.com/bug?extid=059a2795ad4cff2a2695
Closes: https://syzkaller.appspot.com/bug?extid=8328573e4d0514392471

> diff --git a/Documentation/networking/lapb-module.rst b/Documentation/networking/lapb-module.rst
> index ff586bc9f005b..f2047e30822d7 100644
> --- a/Documentation/networking/lapb-module.rst
> +++ b/Documentation/networking/lapb-module.rst
> @@ -47,6 +47,7 @@ of the LAPB module::
>  		void (*disconnect_indication)(int token, int reason);
>  		int  (*data_indication)(int token, struct sk_buff *skb);
>  		void (*data_transmit)(int token, struct sk_buff *skb);
> +		void (*schedule_tx)(int token);
>  	};

[Severity: Low]
Do the new prototypes in lapb-module.rst match include/linux/lapb.h? The
struct listing here gives schedule_tx an int token. The Callbacks section
added further down has a different version:

    void (*schedule_tx)(void *token);

and the new entry point is documented as:

    bool lapb_transmit_pending(void *token);

The header actually declares:

    void (*schedule_tx)(struct net_device *dev);
    bool lapb_transmit_pending(struct net_device *dev);

The two new doc prototypes for schedule_tx also disagree with each other
(int vs void *).

[ ... ]

> diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
> index ab71afaaf8482..a438b85e27f13 100644
> --- a/drivers/net/wan/lapbether.c
> +++ b/drivers/net/wan/lapbether.c
> @@ -93,6 +93,10 @@ static int lapbeth_napi_poll(struct napi_struct *napi, int budget)
>  						  napi);
>  	struct sk_buff *skb;
>  	int processed = 0;
> +	bool tx_more;
> +
> +	/* LAPB limits each call, so TX is not charged to the RX budget. */
> +	tx_more = lapb_transmit_pending(lapbeth->axdev);

[Severity: Low]
Should this drain be skipped when budget is 0? netpoll polls with a zero
budget:

net/core/netpoll.c:poll_one_napi() {
    ...
	/* We explicitly pass the polling call a budget of 0 to
	 * indicate that we are clearing the Tx path only.
	 */
	work = napi->poll(napi, 0);
    ...
}

Before this patch a budget-0 poll did nothing here, because the RX loop
is bounded by budget. Now it starts new transmissions:

__netpoll_send_skb()
  netpoll_poll_dev(lapbeth)
    poll_napi()
      poll_one_napi()
        lapbeth_napi_poll(napi, 0)
          lapb_transmit_pending()
            lapb_xmit_queued()
              lapbeth_data_transmit()
                dev_queue_xmit(ethdev)

Each such poll can send up to 64 frames and takes lapb_list_lock and
lapb->lock with the _bh variants, possibly with IRQs disabled.
netpoll_poll_dev() only checks netif_local_xmit_active() for the lapbeth
device, not for the ethdev that data_transmit targets.

Documentation/networking/napi.rst says a budget of 0 means the core
"tries to only process skb Tx completions". This also seems to go against
the new rule in include/linux/lapb.h that lapb_transmit_pending() is
called "without holding any lock its transmit path takes".

netpoll on lapbeth was already unsafe before this patch, because
lapbeth_xmit() takes spin_lock_bh(&lapbeth->up_lock). So this adds a
second path into an existing problem rather than a new one.

Would gating the drain on budget != 0 be enough here?

[ ... ]

> diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
> index 1af36fd50a6c4..a04fd11b0af73 100644
> --- a/net/lapb/lapb_iface.c
> +++ b/net/lapb/lapb_iface.c

[ ... ]

> @@ -282,6 +297,71 @@ int lapb_setparms(struct net_device *dev, struct lapb_parms_struct *parms)

[ ... ]

> +static bool lapb_xmit_queued(struct lapb_cb *lapb)
> +{
> +	int quota = LAPB_TX_QUOTA;
> +	struct sk_buff *skb;
> +
> +	lockdep_assert_held(&lapb->lock);
> +	if (lapb->tx_running)
> +		return false;
> +
> +	WRITE_ONCE(lapb->tx_running, true);
> +	while ((quota-- > 0 || lapb->tx_stopped) &&
> +	       (skb = __skb_dequeue(&lapb->tx_queue))) {

[Severity: Low]
Can a NAPI drainer go past the 64 frame limit here? lapb-module.rst says
each lapb_transmit_pending() call "sends at most 64 frames", and
lapbeth_napi_poll() relies on that:

	/* LAPB limits each call, so TX is not charged to the RX budget. */

Suppose lapbeth's NAPI poll is inside data_transmit() with lapb->lock
dropped while lapb_device_event(NETDEV_GOING_DOWN) runs:

	lapb->tx_stopped = true;
	quiesce = true;

The notifier's own lapb_xmit_queued() returns at once because tx_running
is set. When the NAPI drainer retakes the lock, the quota check is
bypassed for the rest of the loop. That single poll then empties the
whole FIFO, up to LAPB_TX_QUEUE_MAX frames.

This is bounded and only happens at shutdown, but in that case neither
the documented limit nor the lapbeth comment is accurate.

> +		int depth = LAPB_TX_DEPTH(skb) - dev_recursion_level();
> +		int i;
> +
> +		spin_unlock(&lapb->lock);
> +		for (i = 0; i < depth; i++)
> +			dev_xmit_recursion_inc();
> +		lapb->callbacks->data_transmit(lapb->dev, skb);

[Severity: High]
This isn't a bug introduced by this patch, but the new drain paths leave
it in place. For hdlc_x25, data_transmit is x25_data_transmit(), and it
calls the hardware xmit directly:

drivers/net/wan/hdlc_x25.c:x25_data_transmit() {
    ...
	hdlc->xmit(skb, dev); /* Ignore return value :-( */
}

This skips the netdev TX queue and never checks netif_queue_stopped().
The SCA drivers stop the queue when the ring is nearly full. They expect
not to be called again before TX-done:

drivers/net/wan/hd64572.c:sca_xmit() {
    ...
	desc = desc_address(port, port->txin + 1, 1);
	BUG_ON(readb(&desc->stat)); /* previous xmit should stop queue */
    ...
}

hd64570.c has the same BUG_ON. When its ring is full, wanxl_xmit()
returns NETDEV_TX_BUSY without consuming the skb. The return value is
ignored, so the skb leaks and the frame is lost.

LAPB can send far more frames back to back than these rings hold:

- x25_ioctl() allows modulo 128 with a window up to 127.
- lapb_kick() sends a full window at once.
- c101 and wanxl have only 10 TX descriptors.
- On a stalled line, T1 retransmissions through lapb_requeue_frames()
  and lapb_kick() add more frames.

With this patch, a drain sends 64 frames and then reschedules tx_work
right away, and the GOING_DOWN flush ignores the quota for up to 256
frames:

lapb_data_request() / lapb_t1timer_expiry()
  lapb_kick()
  lapb_tx_unlock()
    lapb_xmit_queued()
      x25_data_transmit()
        hdlc->xmit() == sca_xmit()
          BUG_ON() after a previous netif_stop_queue()

The patch adds new deferred drain points (lapb_tx_work() and the
GOING_DOWN flush). Could they apply some backpressure, such as stopping
while the device's TX queue is stopped, instead of handing every queued
frame to hdlc->xmit()?

> +		for (i = 0; i < depth; i++)
> +			dev_xmit_recursion_dec();
> +		spin_lock(&lapb->lock);
> +	}
> +	WRITE_ONCE(lapb->tx_running, false);
> +	if (lapb->tx_stopped)
> +		wake_up_all(&lapb->tx_wait);
> +	return !skb_queue_empty(&lapb->tx_queue);
> +}

[Severity: Medium]
Is tx_running effectively acting as a lock here? It is set on entry,
lapb->lock is dropped around data_transmit(), and it is cleared on exit.
Any other drainer that sees it set returns at once.

That flag is now the only thing serializing data_transmit() callers. It
protects the unlocked ndev->stats.tx_packets++ in lapbeth_data_transmit()
and the direct hdlc->xmit() calls.

lapb_device_event() then sleeps on it uninterruptibly with RTNL held:

	wait_event(lapb->tx_wait, !READ_ONCE(lapb->tx_running));

Lockdep can't see a bool plus a waitqueue. The dependency from LAPB TX
serialization to the locks taken under dev_queue_xmit() or hdlc->xmit()
still exists, but lockdep no longer tracks it. A future cycle through it
would show up as a hung task instead of a lockdep report.

The waiter's check is also a lockless READ_ONCE() with no acquire
ordering. Nothing orders it against the drainer's last data_transmit()
side effects before the notifier moves on to ndo_stop.

I couldn't find a transmit path that takes RTNL today, so this doesn't
look like a concrete deadlock yet. Would a real primitive keep it visible
to lockdep? For example, a dedicated per-lapb TX lock, or
test_and_set_bit()/wait_on_bit() with a lockdep_map.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-lapb-unlock-v3-v3-0-65b6ce65141b%40qq.com
Technical Details
Message-ID: <179649235593.3146.905729325799246245@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378083-linux-kernel-netdev=dewy.ru
References: <20261202-lapb-unlock-v3-v3-3-65b6ce65141b@qq.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378083-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3 3/3] net: lapb: transmit frames outside the protocol lock
Date: Sat, 05 Dec 2026 17:39:15 +0000
Organization: Usenet Network
Message-ID: <179649235593.3146.905729325799246245@kernel.org>
References: <20261202-lapb-unlock-v3-v3-3-65b6ce65141b@qq.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="3081877"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:L9xFfCriGkQmh3cmLmqAAaj5FJs= sha256:uASHHO2HK4gyPKsMqpZCyxoo5n5C9Ohl5k35QJb8crg= sha1:O2aZ/7o7DyMhf9RwEU6uw/FZhBw= sha256:NZ0MPawNTaE6uU7/UFgeS2eo/DDGa+4W5XN1uzSAF0s=
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 E911F117E81; Sat,  5 Dec 2026 20:39:37 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.539
X-Spam-Status: No, score=-3.539 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.14, 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 K8NG-cL6cYIo; Sat,  5 Dec 2026 20:39:34 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-378083-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 98C25117E7E; Sat,  5 Dec 2026 20:39:21 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 090EB27F18; Sat,  5 Dec 2026 17:39:19 +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=1796492358; b=Krvu2+d/LGU7VqkjXn6BvwobMZCIuRCtNFaDhupziHnnR2Xw/C11DLA/xRQKyfSvgYF1 9yxdf5EYT8A61jHF4pq9NZGBkkG0M5l+PU3fuYloGBKTp4ud9VSJhdfXLJW860bJzrdiE bX1GnHYfTF7uAQNr5/5Ji3VYvAZHnXHKPqBYJOwJzNv65RALlKK7g8xFiJYORHEWvvMjs 12End49k3+AZC6YGG5RfjNKvw1i+hbq6cFbXT6rYrEGCwJYmBcPpBEvEC/MvjVKE8GMEk 8s9kg1NVmvrT3uLO3ZjDoyfV5hxw37Me3cPnZwRoJbEZu5I8Mi2IfSS4YYv3nRuH6zw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796492358; 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=5Lg7wDS26V58/9a4T5tThjWXrPYspii6On+rT+w3XIc=; b=T/jMAWhFdX6IfXU+HFSMSgy+9uWTwRGf9T3ye49xdZck3xJ8ntOTgq4c8XypRh1Z/W8C pGvJL2meyrfIqu3wNlOEItR4MXiSUd/Vq0hTWY8UF+KA6yH0/p818vPDt7PYEV4KtExyx bg4v2yZsmTxAPnuzHPW9N5sKhalpsKdrt7wMBpi9M9uYIYM+yRoKGLlrCAsPOgxmJSo1E Gd0pRxCDj9tP3h9KO/bKuL45vemDhUJiDTFzo7e0MQBhM2pZ3xbZWbcBL61rxiaxQpBfT q8lXwm0QMcJZgWnLtVRCVo84c2dSQ1NUSe1xroIYVQUTJ94G+TZMpDKHPqvyg+n+U9g==
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=FO6vsCYo; 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 544A1606A335; Sat,  5 Dec 2026 17:39:18 +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=FO6vsCYo
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=1796492357; b=FTi08KSioLaDvS98B5a8zrk7z/W+0neUvhms8eDi6anVEmxmVauZlb6tyBqAL4tEzDC2 mCIlfzk73m5w5iHdAhsw/HqhFWRth9Cr3LOFMKPOfRy8NqNtjcFhjNa/YSbbgDxTvZjk1 RhGIpDnug+XUnhXe8cq8qM/HOFAmj81ExG359Qq74n4vD2neOb6gpvSZfKGrYdn/Vnsn1 u1wcxrFhykNSAlRmFpJeA0grYwbuutTfEyMDWRJvCDyF0wHSVpxJQS5Dv7Xhls5iFXJRA bRZRRWcFUKJIG4Hhv/q/1XI9Lip4IrO7j9LymWqTJWtex1uU4ASi+lOTPrdiPyqhDuw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796492357; 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=5Lg7wDS26V58/9a4T5tThjWXrPYspii6On+rT+w3XIc=; b=B7sWRfKvBaOlF9r7zt+0hGWYTRkLueJj34SycZJNjs4uVK3qn6v+cbTotdiEzId9gHmf 7gX/rSOFsCIm6zh2iMlGlMy9evPEFQIfQMKABOz9rJeSO+pF/csnccyu/bfYG68bTLHm5 rlddMkAFfiDe14P0+erNKi1/WzSWbftbQNaGpDsHEVQeCNFPFPqgFnNuA0MFHr+SIIsOF L4rgwa8My9lPBCnfNVzBURwRrnbJ7QvdL01QPzUrbUJT4co2sZu/kOtLvveENfKlXnHFE eodZ/+jSBmSjH9SfrRQGUnlixvtrTFsDFhDP0mjWJKF4JCosT1nyb/7k6djQd5mKljw==
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=FO6vsCYo; 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 77787606A33A; Sat,  5 Dec 2026 17:39:17 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5566F1F0092B; Sat,  5 Dec 2026 17:39:16 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796492357; bh=5Lg7wDS26V58/9a4T5tThjWXrPYspii6On+rT+w3XIc=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=FO6vsCYo7Cj8BtvnbS0f1UlYv0a3tjKcPZUOAWCy6aHbjb6QUmfEk1Za9GbedaP+0 eoh+JjPT7QHd91C2gBzdEug7PJ5Z2MWhhcH8nAaBKajAAVpU88fLJCvsW6OOyAK3re YtRYrhQUBZrd/aahj094CY04QX5pnIwWKdjnAplrfn9pqjT9T0EJB2r3R1tahGk2fc C0mqOiC9+OJyrtqlsAI75dQ1d6qvUWhPDRvG+UJHUiXMpQJlRNW1Ta9/VyglaONrN6 nwGm4q48trA7z9aU+5yrv+ff/I7aBaPBPTG4ngb5tM1wfd2qcbPZrTBq2Vm93iUI41 K4vGEXs8QkYNQ==
X-Cc: ms@dev.tdt.de, netdev@vger.kernel.org, hdanton@sina.com, davem@davemloft.net, horms@kernel.org, xie.he.0141@gmail.com, andrew+netdev@lunn.ch, edumazet@kernel.org, corbet@lwn.net, willemb@google.com, syzbot+8328573e4d0514392471@syzkaller.appspotmail.com, linux-doc@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com, linux-x25@vger.kernel.org, syzbot+059a2795ad4cff2a2695@syzkaller.appspotmail.com
X-In-Reply-To: <20261202-lapb-unlock-v3-v3-3-65b6ce65141b@qq.com>
X-sashiko-severity: Medium
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
X-Received-Bytes: 17624