๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25268

Re: [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock

#25268
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 12:57
222 lines
16241 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท 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_queue, a transmit FIFO with no length
  limit, and drains it in a loop with no quota.
- [Low] The commit message gives the wrong reason why hdlc_x25 can
  transmit inline while lapbeth has to defer to NAPI.
- [Low] The patch adds a new member to struct lapb_register_struct
  (schedule_tx) and a new exported entry point (lapb_transmit_pending()).
- [Low] In net/lapb/lapb_iface.c, lapb_tx_unlock() is defined with
  `__releases(&lapb->lock)`.

--

net: lapb: transmit frames outside the protocol lock

LAPB now queues outgoing frames on a new per-instance tx_queue while
lapb->lock is held, and hands them to the driver once the lock is dropped.
lapbeth defers the drain to its NAPI poll through a new schedule_tx()
callback, while hdlc_x25 drains right after the unlock. On
NETDEV_GOING_DOWN the queue is flushed, and frames produced after that are
dropped.

> diff --git a/include/linux/lapb.h b/include/linux/lapb.h
> index b5333f9413dca..06e050d9ace62 100644
> --- a/include/linux/lapb.h
> +++ b/include/linux/lapb.h
> @@ -36,6 +36,8 @@ struct lapb_register_struct {
>  	void (*disconnect_indication)(struct net_device *dev, int reason);
>  	int  (*data_indication)(struct net_device *dev, struct sk_buff *skb);
>  	void (*data_transmit)(struct net_device *dev, struct sk_buff *skb);
> +	/* If set, schedule lapb_transmit_pending() outside the device TX lock. */
> +	void (*schedule_tx)(struct net_device *dev);
>  };

[Severity: Low]
The commit message says:

  hdlc_x25 sends the frames right after the lock is dropped. lapbeth
  calls into LAPB with its TX lock and up_lock held, so it sets the new
  schedule_tx() callback and sends them from its NAPI poll instead.

Is that the real difference between the two drivers? x25_xmit() in
drivers/net/wan/hdlc_x25.c is the hdlc device's ndo_start_xmit, so it also
runs under the netdev TX lock. It also calls into LAPB with up_lock held:

drivers/net/wan/hdlc_x25.c:x25_xmit() {
    ...
	spin_lock_bh(&x25st->up_lock);
    ...
		result = lapb_data_request(dev, skb);
		if (result != LAPB_OK)
			dev_kfree_skb(skb);
		spin_unlock_bh(&x25st->up_lock);
    ...
}

That looks the same as lapbeth_xmit().

The difference seems to be the data_transmit callback.
lapbeth_data_transmit() calls dev_queue_xmit() on the lower device, which
can loop back into lapbeth_xmit() and LAPB. x25_data_transmit() hands the
frame straight to the hardware driver:

drivers/net/wan/hdlc_x25.c:x25_data_transmit() {
    ...
	if (dev_nit_active(dev))
		dev_queue_xmit_nit(skb, dev);

	hdlc->xmit(skb, dev); /* Ignore return value :-( */
}

The new comment on schedule_tx uses the same TX lock wording. Could the
comment say instead that schedule_tx should be set when data_transmit() can
re-enter the network stack or LAPB? Could the commit message be updated to
match?

> @@ -57,6 +59,7 @@ extern int lapb_getparms(struct net_device *dev, struct lapb_parms_struct *parms
>  extern int lapb_setparms(struct net_device *dev, struct lapb_parms_struct *parms);
>  extern int lapb_connect_request(struct net_device *dev);
>  extern int lapb_disconnect_request(struct net_device *dev);
> +void lapb_transmit_pending(struct net_device *dev);

[Severity: Low]
Should Documentation/networking/lapb-module.rst be updated as part of this
patch? It lists the members of struct lapb_register_struct and every LAPB
function and callback. It does not mention schedule_tx or
lapb_transmit_pending().

It also still describes data_transmit as:

  This is called by the LAPB module when data is to be transmitted to the
  remote system by the device driver.

With this patch, frames are queued on lapb->tx_queue and sent later. A
driver that sets schedule_tx must later call lapb_transmit_pending()
outside its TX lock. If it doesn't, the frames stay on tx_queue until
another LAPB entry point drains them or lapb_unregister() purges them.

Once NETDEV_GOING_DOWN sets tx_stopped, lapb_data_transmit() returns 0 and
the frames never reach the driver.

[ ... ]

> diff --git a/include/net/lapb.h b/include/net/lapb.h
> index 6c07420644e45..08cb5ae934398 100644
> --- a/include/net/lapb.h
> +++ b/include/net/lapb.h

[ ... ]

> @@ -109,6 +114,7 @@ struct lapb_cb {
>  };
>  
>  /* lapb_iface.c */
> +void lapb_tx_unlock(struct lapb_cb *lapb);

[Severity: Low]
Should this prototype also carry the __releases() annotation? The
definition in net/lapb/lapb_iface.c has it:

void lapb_tx_unlock(struct lapb_cb *lapb)
	__releases(&lapb->lock)

net/lapb/lapb_timer.c only sees this prototype. lapb_t1timer_expiry() and
lapb_t2timer_expiry() take the lock with spin_lock_bh(&lapb->lock), and now
release it only through lapb_tx_unlock().

With CONFIG_WARN_CONTEXT_ANALYSIS and CONFIG_WARN_CONTEXT_ANALYSIS_ALL,
clang context analysis checks call sites against the declaration it can
see. Would it then report both timer callbacks as returning with lapb->lock
still held?

Other headers put the annotation on the prototype, for example
mutex_unlock() in include/linux/mutex.h.

[ ... ]

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

[ ... ]

> @@ -282,6 +285,61 @@ int lapb_setparms(struct net_device *dev, struct lapb_parms_struct *parms)
>  }
>  EXPORT_SYMBOL(lapb_setparms);
>  
> +/* Preserve the TX nesting level if another caller sends the frame. */
> +#define LAPB_TX_DEPTH(skb) ((skb)->cb[0])
> +
> +/* One caller drains the FIFO. Other producers leave their frames to it. */
> +static void lapb_xmit_queued(struct lapb_cb *lapb)
> +{
> +	struct sk_buff *skb;
> +
> +	lockdep_assert_held(&lapb->lock);
> +	if (lapb->tx_running)
> +		return;
> +
> +	WRITE_ONCE(lapb->tx_running, true);
> +	while ((skb = __skb_dequeue(&lapb->tx_queue))) {
> +		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);
> +		for (i = 0; i < depth; i++)
> +			dev_xmit_recursion_dec();
> +		spin_lock(&lapb->lock);
> +	}

[Severity: Medium]
Can this loop run without bound? It runs with BH disabled and has no quota
or need_resched() check. Each time it drops lapb->lock, other contexts can
add more frames to tx_queue:

lapbeth_rcv()->lapb_data_received()->lapb_data_input()->...
    ->lapb_send_control()->lapb_data_transmit()->__skb_queue_tail()

The t1/t2 timers and lapbeth_xmit()->lapb_data_request() add frames the
same way. With schedule_tx set, these producers only queue the frame and
call napi_schedule(). All of the dev_queue_xmit() work falls on this single
drainer.

lapb_data_transmit() also has no length cap or drop policy for tx_queue:

	__skb_queue_tail(&lapb->tx_queue, skb);
	return 1;

For lapbeth, the drain runs from lapbeth_napi_poll() before the budget
loop:

	lapb_transmit_pending(lapbeth->axdev);

	for (; processed < budget; ++processed) {

so neither the NAPI budget nor the net_rx_action() time limit applies to it.

A remote L2 peer can send ETH_P_DEC frames that each produce a response
frame. For example, in state 0 LAPB answers every DISC with UA, and every
SABM with DM or UA. If the producers keep up with the drainer, could one
CPU stay in softirq (soft lockup, RCU stall) while tx_queue keeps growing?

Before this patch, each producer called dev_queue_xmit() inline, and the
lower device's qdisc limited the backlog. Should tx_queue have a cap, and
should this loop stop after a budget and reschedule itself?

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/tencent_BFB53B9AEE4AF90B99337798FB43DACAC506%40qq.com
Technical Details
Message-ID: <179612987367.3146.17593233623166891863@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375072-linux-kernel-netdev=dewy.ru
References: <tencent_13BADC934C9BDBCE7D204DEAA2DC1D403705@qq.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375072-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock
Date: Tue, 01 Dec 2026 12:57:53 +0000
Organization: Usenet Network
Message-ID: <179612987367.3146.17593233623166891863@kernel.org>
References: <tencent_13BADC934C9BDBCE7D204DEAA2DC1D403705@qq.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1714669"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:SYPTI+Syn85QwU6tzGMxEWjrl4g= sha256:QTy5aNjBP94+1GjMBE21qIyjdESPU4s140eKtIu4MLc=
	sha1:9pDc7bm3bBLrmfH/o8FDCAXbbPM= sha256:Py4TpgAaHH9Nt8yVVhqksKaI8xO43Ye6YcbM03kxppk=
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 D65D611739F; Tue,  1 Dec 2026 15:58:12 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, 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 LQS-uyRnrZTd;
	Tue,  1 Dec 2026 15:58:08 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375072-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id CD3F711739E; Tue,  1 Dec 2026 15:57:58 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id CCBA32C9B2; Tue,  1 Dec 2026 12:57:56 +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=1796129876;
	b=LT0W3g/I0k9/QkWsAK0/xW6GTwqdchfcsIzgZS1roRTvqx4eAxG3n3ug0M40Tn9l0kk/
	 Tg7YOwI3FUUPjUPsDlRxhW63esuwMe9ZQfC7EQCFaZzLbdFPnELK69bu4cr4NYddkW07C
	 bd+bSKTdpjcuQF84298BXv+nd5GaDz5y2I/y+hvyXMwHISz1GpDd/c7qViGNoFXnazgmd
	 bMzECerChRBsroxSKJ03tdGBTUn/ZGcf/vLAFtQtlcvzA5bqANt/zmsfCTJfOjbBJ5+y+
	 WL0TkMwEaNIFQPkoM4hjZfuYqCiXhqFjevqIn95MBZgd85ojkJ6FwDKKXG+a9EQDDQA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796129876;
	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=myj3b/bWHLsh5+DWIh/2IQ03XHqJ2RfvAgoEKEMnxg0=;
	b=qgPHLl2Y0D7n70Ja22qcNgI+E/ao3NmgNnatdGUkUng8z8coBIZR1JA7gXYD0Es0uEPH
	 QNDiL5jY6PVDFXpQq66uG1cKAw8CBF78Gb6YbIqAdwwBl2xfBC5kKebRqs4FYJ9+eo9iM
	 YQzcIbr5LWxYT+a9g7ypzZBUDabVhAcK5dHN/XVMpSOYPq9h16V2s3lsMa/ZoSpJO6Zl5
	 dAct+7qcqTHFAls3RyULq096nfkQ4zGqqwzutW5Pb61dCVatLeRZAVSUx0emY3X5i0qMA
	 mGx9JoHTFqM9e1+zwmMkbZzmCsGJkJe0AN9TgGPOlBcyAn5lWn7vygamKwyuXoMYEdQ==
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=GaU13VDq;
	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 1DFAA606A32E;
	Tue,  1 Dec 2026 12:57:56 +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=GaU13VDq
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=1796129875;
	b=kgOZkf9xfIAKNmjoKX5tB2srpcfLZYOAhbv2skiDwVUzDzpSpnDoJrXh+43x482+3vXG
	 a0+NouR6u5q46E5HFW6yIFr833Vkhg2wbtXypS6zds7MvDhpWkhDKEPi/CNS2RpTXDVU2
	 PZRC6uhc78vUa8tz77gyKkAUAdG79nT1C7UCD26s4+lLNMLooCuUA/rwO+Zn5wGnHMlkd
	 M/HdBbb4OdxjuNuEb473t05fiijuChroFp4p4/rqYNc3L3owI3P7ZBk++QH4Ld2bIJlnf
	 3Ri+GjAQ+2zMDPNu2WDsAflraV5XImrxE31HsUPv8YxiNe9Q4Aho8WgpBwLa38ccYWw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796129875;
	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=myj3b/bWHLsh5+DWIh/2IQ03XHqJ2RfvAgoEKEMnxg0=;
	b=TEXBI0lxdmG7GatFD2+MrOUkXsxM30UPxdzL+FEcnqcdUnYHQZidCOTczV3rik6xgl3v
	 HYcF7a5Be6/88IMUovsK7cc8/D9kju+GBExn7qDNnNLChB6o0G/kkxSuxOsB0VyPbEiKx
	 EQnA1Flk9AIJh8fUQNSTXQKlqIYLBgZHVsNNZ00ffMhJIYAiwXE7PCPp0rxb7rx6YdmsT
	 fzi7dc02p3WdFTpvqT6PAP4chQFh88uQMLZH1J6Rch/faTEZbgTbTI7r4hF3qkOumosIR
	 7seE+T8FtvISHYAnSWabjtRDpeUH8/1fkGntYd+N8D+yAQr5CsuIocURiZU6G0NmeAA==
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=GaU13VDq;
	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 3AAB3606A320;
	Tue,  1 Dec 2026 12:57:55 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 202691F00893;
	Tue,  1 Dec 2026 12:57:54 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796129874;
	bh=myj3b/bWHLsh5+DWIh/2IQ03XHqJ2RfvAgoEKEMnxg0=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=GaU13VDqupMlzG0nD++ukVrpF769UOClF+pHhTMHlEfBAYhMf/J1Pxa/RXsUXPc62
	 5QGAdcpcfW2TJ1hiHOBLv2YGszqPQTNS+gmjTFBVi/HQjB4ckhwcilPG83zUnVlu1R
	 yrBfPUHAzQV0piH7bUNIaLe4VCgy+wlCPQjTZyZASrgV9M/qCF/WKqc55lV89GTs6B
	 zL3OgTADNPmdJ7FvYhUrI23nqBKWcCPbnDhaKxurJT5deY0Rw/uUrcePx7RP4IyCzq
	 LtK8q61JMUjbifBWXclorNUk1d8MKl9t5XEQl1sEkAwmFlu5N/5ejKwPe6Oz/eg3Iz
	 rTnjZPKTx30qg==
X-Cc: ms@dev.tdt.de, netdev@vger.kernel.org,
 syzbot+8328573e4d0514392471@syzkaller.appspotmail.com, edumazet@kernel.org,
 horms@kernel.org, linux-x25@vger.kernel.org, pabeni@redhat.com,
 davem@davemloft.net, kuba@kernel.org, andrew+netdev@lunn.ch, hdanton@sina.com,
 willemb@google.com, xie.he.0141@gmail.com,
 syzbot+059a2795ad4cff2a2695@syzkaller.appspotmail.com
X-In-Reply-To: <tencent_13BADC934C9BDBCE7D204DEAA2DC1D403705@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