Linux X.25 subsystem development
 help / color / mirror / Atom feed
* [PATCH net v2 1/2] net: lapb: drop lapb_list_lock before waiting for users
       [not found] <20261130-lapb-unlock-v2-0-6b2e44e3f69a@qq.com>
@ 2026-11-30 12:14 ` Yu Gao
  2026-12-01 13:37   ` Martin Schiller
  2026-11-30 12:14 ` [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock Yu Gao
  1 sibling, 1 reply; 5+ messages in thread
From: Yu Gao @ 2026-11-30 12:14 UTC (permalink / raw)
  To: Martin Schiller, netdev
  Cc: syzbot+8328573e4d0514392471, Eric Dumazet, Simon Horman,
	linux-x25, Paolo Abeni, David S. Miller, Jakub Kicinski,
	Andrew Lunn, Hillf Danton, Willem de Bruijn, Xie He,
	syzbot+059a2795ad4cff2a2695

lapb_unregister() sleeps in usleep_range() under
write_lock_bh(&lapb_list_lock) while waiting for other users of the
control block, and then takes lapb->lock under that lock, which adds

  lapb_list_lock --> &lapb->lock

to the cycle syzbot reports in lapb_connect_request().

Unlink the block and drop lapb_list_lock before waiting. Once the
block is unlinked, nothing can look it up and take a new reference.

Found by code inspection. With this patch alone, the syzbot
reproducers still report a cycle; the next patch removes it.

Fixes: b491e6a7391e ("net: lapb: Add locking to the lapb module")
Suggested-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Yu Gao <SuperSkidder@qq.com>
---
 net/lapb/lapb_iface.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
index 670e085..1af36fd 100644
--- a/net/lapb/lapb_iface.c
+++ b/net/lapb/lapb_iface.c
@@ -179,9 +179,11 @@ int lapb_unregister(struct net_device *dev)
 	if (!lapb)
 		goto out;
 	lapb_put(lapb);
+	__lapb_remove_cb(lapb);
+	write_unlock_bh(&lapb_list_lock);
 
 	/* Wait for other refs to "lapb" to drop */
-	while (refcount_read(&lapb->refcnt) > 2)
+	while (refcount_read(&lapb->refcnt) > 1)
 		usleep_range(1, 10);
 
 	spin_lock_bh(&lapb->lock);
@@ -197,10 +199,8 @@ int lapb_unregister(struct net_device *dev)
 	timer_delete_sync(&lapb->t1timer);
 	timer_delete_sync(&lapb->t2timer);
 
-	__lapb_remove_cb(lapb);
-
 	lapb_put(lapb);
-	rc = LAPB_OK;
+	return LAPB_OK;
 out:
 	write_unlock_bh(&lapb_list_lock);
 	return rc;

-- 
Git-157)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock
       [not found] <20261130-lapb-unlock-v2-0-6b2e44e3f69a@qq.com>
  2026-11-30 12:14 ` [PATCH net v2 1/2] net: lapb: drop lapb_list_lock before waiting for users Yu Gao
@ 2026-11-30 12:14 ` Yu Gao
  2026-12-01 12:57   ` netdev-bot+sashiko
  1 sibling, 1 reply; 5+ messages in thread
From: Yu Gao @ 2026-11-30 12:14 UTC (permalink / raw)
  To: Martin Schiller, netdev
  Cc: syzbot+8328573e4d0514392471, Eric Dumazet, Simon Horman,
	linux-x25, Paolo Abeni, David S. Miller, Jakub Kicinski,
	Andrew Lunn, Hillf Danton, Willem de Bruijn, Xie He,
	syzbot+059a2795ad4cff2a2695

LAPB calls the data_transmit() callback with lapb->lock held. lapbeth
passes the frame to dev_queue_xmit(), and if the underlying device is
a tunnel routed back through a lapbeth device, the frame re-enters
lapbeth_xmit() and LAPB under the TX lock and up_lock. syzbot reports:

  lapb_list_lock --> &lapb->lock --> _xmit_X25#2
  lapb_list_lock --> _xmit_X25#2 --> &lapbeth->up_lock

Queue frames on a per-instance FIFO under lapb->lock and pass them to
the driver after the lock is dropped. One caller drains the FIFO at a
time, which keeps the frames in order.

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.

Each frame records the TX recursion level at which it was queued, and
that level is restored around data_transmit(), so a looped frame still
counts against XMIT_RECURSION_LIMIT.

On NETDEV_GOING_DOWN, LAPB flushes the queued frames, including the
final DISC, and waits for a running sender before ndo_stop. Frames
produced after that are dropped.

With both patches, the syzbot reproducers and tunnel loops through one
or two lapbeth devices no longer report lock cycles. hdlc_x25 was only
build-tested.

Fixes: b491e6a7391e ("net: lapb: Add locking to the lapb module")
Suggested-by: Willem de Bruijn <willemb@google.com>
Reported-by: syzbot+059a2795ad4cff2a2695@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=059a2795ad4cff2a2695
Reported-by: syzbot+8328573e4d0514392471@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=8328573e4d0514392471
Signed-off-by: Yu Gao <SuperSkidder@qq.com>
---
 drivers/net/wan/lapbether.c | 10 +++++
 include/linux/lapb.h        |  3 ++
 include/net/lapb.h          |  6 +++
 net/lapb/lapb_iface.c       | 94 +++++++++++++++++++++++++++++++++++++++------
 net/lapb/lapb_timer.c       |  4 +-
 5 files changed, 103 insertions(+), 14 deletions(-)

diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
index c3630a8..698d1ae 100644
--- a/drivers/net/wan/lapbether.c
+++ b/drivers/net/wan/lapbether.c
@@ -93,6 +93,8 @@ static int lapbeth_napi_poll(struct napi_struct *napi, int budget)
 	struct sk_buff *skb;
 	int processed = 0;
 
+	lapb_transmit_pending(lapbeth->axdev);
+
 	for (; processed < budget; ++processed) {
 		skb = skb_dequeue(&lapbeth->rx_queue);
 		if (!skb)
@@ -306,6 +308,13 @@ static int lapbeth_set_mac_address(struct net_device *dev, void *addr)
 	return 0;
 }
 
+static void lapbeth_schedule_tx(struct net_device *dev)
+{
+	struct lapbethdev *lapbeth = netdev_priv(dev);
+
+	napi_schedule(&lapbeth->napi);
+}
+
 static const struct lapb_register_struct lapbeth_callbacks = {
 	.connect_confirmation    = lapbeth_connected,
 	.connect_indication      = lapbeth_connected,
@@ -313,6 +322,7 @@ static const struct lapb_register_struct lapbeth_callbacks = {
 	.disconnect_indication   = lapbeth_disconnected,
 	.data_indication         = lapbeth_data_indication,
 	.data_transmit           = lapbeth_data_transmit,
+	.schedule_tx             = lapbeth_schedule_tx,
 };
 
 /* open/close a device
diff --git a/include/linux/lapb.h b/include/linux/lapb.h
index b5333f9..06e050d 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);
 };
 
 struct lapb_parms_struct {
@@ -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);
 extern int lapb_data_request(struct net_device *dev, struct sk_buff *skb);
 extern int lapb_data_received(struct net_device *dev, struct sk_buff *skb);
 
diff --git a/include/net/lapb.h b/include/net/lapb.h
index 6c07420..08cb5ae 100644
--- a/include/net/lapb.h
+++ b/include/net/lapb.h
@@ -3,6 +3,7 @@
 #define _LAPB_H 
 #include <linux/lapb.h>
 #include <linux/refcount.h>
+#include <linux/wait.h>
 
 #define	LAPB_HEADER_LEN MAX_HEADER		/* LAPB over Ethernet + a bit more */
 
@@ -97,6 +98,10 @@ struct lapb_cb {
 	/* Internal control information */
 	struct sk_buff_head	write_queue;
 	struct sk_buff_head	ack_queue;
+	struct sk_buff_head	tx_queue;
+	wait_queue_head_t	tx_wait;
+	bool			tx_running;
+	bool			tx_stopped;
 	unsigned char		window;
 	const struct lapb_register_struct *callbacks;
 
@@ -109,6 +114,7 @@ struct lapb_cb {
 };
 
 /* lapb_iface.c */
+void lapb_tx_unlock(struct lapb_cb *lapb);
 void lapb_connect_confirmation(struct lapb_cb *lapb, int);
 void lapb_connect_indication(struct lapb_cb *lapb, int);
 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int);
diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
index 1af36fd..7f17200 100644
--- a/net/lapb/lapb_iface.c
+++ b/net/lapb/lapb_iface.c
@@ -117,6 +117,8 @@ static struct lapb_cb *lapb_create_cb(void)
 
 	skb_queue_head_init(&lapb->write_queue);
 	skb_queue_head_init(&lapb->ack_queue);
+	__skb_queue_head_init(&lapb->tx_queue);
+	init_waitqueue_head(&lapb->tx_wait);
 
 	timer_setup(&lapb->t1timer, NULL, 0);
 	timer_setup(&lapb->t2timer, NULL, 0);
@@ -199,6 +201,7 @@ int lapb_unregister(struct net_device *dev)
 	timer_delete_sync(&lapb->t1timer);
 	timer_delete_sync(&lapb->t2timer);
 
+	__skb_queue_purge(&lapb->tx_queue);
 	lapb_put(lapb);
 	return LAPB_OK;
 out:
@@ -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);
+	}
+	WRITE_ONCE(lapb->tx_running, false);
+	if (lapb->tx_stopped)
+		wake_up_all(&lapb->tx_wait);
+}
+
+void lapb_transmit_pending(struct net_device *dev)
+{
+	struct lapb_cb *lapb = lapb_devtostruct(dev);
+
+	if (!lapb)
+		return;
+	spin_lock_bh(&lapb->lock);
+	lapb_xmit_queued(lapb);
+	spin_unlock_bh(&lapb->lock);
+	lapb_put(lapb);
+}
+EXPORT_SYMBOL(lapb_transmit_pending);
+
+void lapb_tx_unlock(struct lapb_cb *lapb)
+	__releases(&lapb->lock)
+{
+	if (!skb_queue_empty(&lapb->tx_queue)) {
+		if (lapb->callbacks->schedule_tx)
+			lapb->callbacks->schedule_tx(lapb->dev);
+		else
+			lapb_xmit_queued(lapb);
+	}
+	spin_unlock_bh(&lapb->lock);
+}
+
 int lapb_connect_request(struct net_device *dev)
 {
 	struct lapb_cb *lapb = lapb_devtostruct(dev);
@@ -307,7 +365,7 @@ int lapb_connect_request(struct net_device *dev)
 
 	rc = LAPB_OK;
 out_put:
-	spin_unlock_bh(&lapb->lock);
+	lapb_tx_unlock(lapb);
 	lapb_put(lapb);
 out:
 	return rc;
@@ -357,7 +415,7 @@ int lapb_disconnect_request(struct net_device *dev)
 
 	rc = __lapb_disconnect_request(lapb);
 
-	spin_unlock_bh(&lapb->lock);
+	lapb_tx_unlock(lapb);
 	lapb_put(lapb);
 out:
 	return rc;
@@ -378,11 +436,12 @@ int lapb_data_request(struct net_device *dev, struct sk_buff *skb)
 	if (lapb->state != LAPB_STATE_3 && lapb->state != LAPB_STATE_4)
 		goto out_put;
 
+	LAPB_TX_DEPTH(skb) = dev_recursion_level();
 	skb_queue_tail(&lapb->write_queue, skb);
 	lapb_kick(lapb);
 	rc = LAPB_OK;
 out_put:
-	spin_unlock_bh(&lapb->lock);
+	lapb_tx_unlock(lapb);
 	lapb_put(lapb);
 out:
 	return rc;
@@ -397,7 +456,7 @@ int lapb_data_received(struct net_device *dev, struct sk_buff *skb)
 	if (lapb) {
 		spin_lock_bh(&lapb->lock);
 		lapb_data_input(lapb, skb);
-		spin_unlock_bh(&lapb->lock);
+		lapb_tx_unlock(lapb);
 		lapb_put(lapb);
 		rc = LAPB_OK;
 	}
@@ -441,14 +500,13 @@ int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
 
 int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
 {
-	int used = 0;
-
-	if (lapb->callbacks->data_transmit) {
-		lapb->callbacks->data_transmit(lapb->dev, skb);
-		used = 1;
-	}
+	lockdep_assert_held(&lapb->lock);
+	if (lapb->tx_stopped || !lapb->callbacks->data_transmit)
+		return 0;
 
-	return used;
+	LAPB_TX_DEPTH(skb) = max_t(int, LAPB_TX_DEPTH(skb), dev_recursion_level());
+	__skb_queue_tail(&lapb->tx_queue, skb);
+	return 1;
 }
 
 /* Handle device status changes. */
@@ -457,6 +515,7 @@ static int lapb_device_event(struct notifier_block *this, unsigned long event,
 {
 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
 	struct lapb_cb *lapb;
+	bool quiesce = false;
 
 	if (!net_eq(dev_net(dev), &init_net))
 		return NOTIFY_DONE;
@@ -490,6 +549,11 @@ static int lapb_device_event(struct notifier_block *this, unsigned long event,
 	case NETDEV_GOING_DOWN:
 		if (netif_carrier_ok(dev))
 			__lapb_disconnect_request(lapb);
+		/* Hand the final frames to the driver before it closes.
+		 * ndo_stop unregisters this block, so this is not undone.
+		 */
+		lapb->tx_stopped = true;
+		quiesce = true;
 		break;
 	case NETDEV_DOWN:
 		lapb_dbg(0, "(%p) Interface down: %s\n", dev, dev->name);
@@ -524,7 +588,13 @@ static int lapb_device_event(struct notifier_block *this, unsigned long event,
 		break;
 	}
 
-	spin_unlock_bh(&lapb->lock);
+	if (quiesce) {
+		lapb_xmit_queued(lapb);
+		spin_unlock_bh(&lapb->lock);
+		wait_event(lapb->tx_wait, !READ_ONCE(lapb->tx_running));
+	} else {
+		lapb_tx_unlock(lapb);
+	}
 	lapb_put(lapb);
 	return NOTIFY_DONE;
 }
diff --git a/net/lapb/lapb_timer.c b/net/lapb/lapb_timer.c
index 9fde6cf..6acfdd7 100644
--- a/net/lapb/lapb_timer.c
+++ b/net/lapb/lapb_timer.c
@@ -89,7 +89,7 @@ static void lapb_t2timer_expiry(struct timer_list *t)
 	lapb->t2timer_running = false;
 
 out:
-	spin_unlock_bh(&lapb->lock);
+	lapb_tx_unlock(lapb);
 }
 
 static void lapb_t1timer_expiry(struct timer_list *t)
@@ -202,5 +202,5 @@ static void lapb_t1timer_expiry(struct timer_list *t)
 	lapb_start_t1timer(lapb);
 
 out:
-	spin_unlock_bh(&lapb->lock);
+	lapb_tx_unlock(lapb);
 }

-- 
Git-157)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock
  2026-11-30 12:14 ` [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock Yu Gao
@ 2026-12-01 12:57   ` netdev-bot+sashiko
  2026-12-01 13:40     ` Martin Schiller
  0 siblings, 1 reply; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 12:57 UTC (permalink / raw)
  To: SuperSkidder
  Cc: ms, netdev, syzbot+8328573e4d0514392471, edumazet, horms,
	linux-x25, pabeni, davem, kuba, andrew+netdev, hdanton, willemb,
	xie.he.0141, syzbot+059a2795ad4cff2a2695

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net v2 1/2] net: lapb: drop lapb_list_lock before waiting for users
  2026-11-30 12:14 ` [PATCH net v2 1/2] net: lapb: drop lapb_list_lock before waiting for users Yu Gao
@ 2026-12-01 13:37   ` Martin Schiller
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Schiller @ 2026-12-01 13:37 UTC (permalink / raw)
  To: Yu Gao
  Cc: netdev, syzbot+8328573e4d0514392471, Eric Dumazet, Simon Horman,
	linux-x25, Paolo Abeni, David S. Miller, Jakub Kicinski,
	Andrew Lunn, Hillf Danton, Willem de Bruijn, Xie He,
	syzbot+059a2795ad4cff2a2695

Looks good to me, thanks.

Acked-by: Martin Schiller <ms@dev.tdt.de>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock
  2026-12-01 12:57   ` netdev-bot+sashiko
@ 2026-12-01 13:40     ` Martin Schiller
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Schiller @ 2026-12-01 13:40 UTC (permalink / raw)
  To: SuperSkidder
  Cc: netdev, syzbot+8328573e4d0514392471, edumazet, horms, linux-x25,
	pabeni, davem, kuba, andrew+netdev, hdanton, willemb, xie.he.0141,
	syzbot+059a2795ad4cff2a2695, netdev-bot+sashiko

On Tue, 01 Dec 2026 13:57:53 +0100, netdev-bot wrote:
> - [Medium] The patch adds lapb->tx_queue, a transmit FIFO with no length
>   limit, and drains it in a loop with no quota.

I agree, and I'd like to see this one addressed in a v3: the drain
should stop after a budget and reschedule itself, and tx_queue should
get a limit. Before this patch, each producer paid for its own
dev_queue_xmit(), and the lower device's qdisc bounded the backlog.
The three Low points look valid to me as well.

Apart from that, the direction looks right, and with the series on top
of the pending x25_kill_by_neigh() fix, an X.25 end-to-end test over two
lapbether devices on a veth pair passes with lockdep and without
warnings, including "ip link set lapb0 down".

For v3: the cover letter and the patches were again not threaded
together, as the mail server replaces the Message-IDs. Sending through
b4's web submission endpoint avoids that.

pw-bot: changes-requested

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-01 13:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261130-lapb-unlock-v2-0-6b2e44e3f69a@qq.com>
2026-11-30 12:14 ` [PATCH net v2 1/2] net: lapb: drop lapb_list_lock before waiting for users Yu Gao
2026-12-01 13:37   ` Martin Schiller
2026-11-30 12:14 ` [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock Yu Gao
2026-12-01 12:57   ` netdev-bot+sashiko
2026-12-01 13:40     ` Martin Schiller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox