* [PATCH net v3 0/3] net: lapb: don't call the driver with LAPB locks held
@ 2026-12-01 17:18 Yu Gao via B4 Relay
2026-12-01 17:18 ` [PATCH net v3 1/3] net: lapb: drop lapb_list_lock before waiting for users Yu Gao via B4 Relay
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Yu Gao via B4 Relay @ 2026-12-01 17:18 UTC (permalink / raw)
To: Martin Schiller, netdev
Cc: Hillf Danton, David S. Miller, Simon Horman, Xie He, Andrew Lunn,
Eric Dumazet, Jonathan Corbet, Willem de Bruijn,
syzbot+8328573e4d0514392471, linux-doc, Jakub Kicinski,
Paolo Abeni, linux-x25, syzbot+059a2795ad4cff2a2695
syzbot reports two lock cycles between LAPB and lapbeth. LAPB calls
the driver's transmit callback with lapb->lock held, and a lapbeth
device on a tunnel that routes back into a lapbeth device re-enters
LAPB from there.
Patch 1 stops lapb_unregister() from holding lapb_list_lock while it
waits, patch 2 bounds lapbeth's receive queue, and patch 3 sends
frames after lapb->lock is dropped.
v3:
- cap the TX FIFO and limit each drain (Sashiko, Martin)
- add patch 2: lapbeth's rx_queue has no limit; with only patch 3
applied, a SABM/DISC flood grew slab by about 200 MB in 150 s
- fix the schedule_tx() wording and document the new API (Sashiko)
- add __releases() to the lapb_tx_unlock() prototype (Sashiko)
- Link to v2: https://lore.kernel.org/all/tencent_3E0B7A77095DABF2713232EE51F7A334BF07@qq.com/
(patches: https://lore.kernel.org/all/tencent_BFB53B9AEE4AF90B99337798FB43DACAC506@qq.com/)
v2:
- fix the lock order in LAPB instead of lapbeth (Willem)
- Link to v1: https://lore.kernel.org/all/tencent_AD34C10B65771ADD86725F3221EE31778507@qq.com/
---
Yu Gao (3):
net: lapb: drop lapb_list_lock before waiting for users
net: lapbether: bound the receive queue
net: lapb: transmit frames outside the protocol lock
Documentation/networking/lapb-module.rst | 31 ++++++++
drivers/net/wan/lapbether.c | 26 ++++++
include/linux/lapb.h | 8 ++
include/net/lapb.h | 13 +++
net/lapb/lapb_iface.c | 131 +++++++++++++++++++++++++++----
net/lapb/lapb_timer.c | 4 +-
6 files changed, 194 insertions(+), 19 deletions(-)
---
base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
change-id: 20261202-lapb-unlock-v3-163df89502b8
Best regards,
--
Yu Gao <SuperSkidder@qq.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net v3 1/3] net: lapb: drop lapb_list_lock before waiting for users
2026-12-01 17:18 [PATCH net v3 0/3] net: lapb: don't call the driver with LAPB locks held Yu Gao via B4 Relay
@ 2026-12-01 17:18 ` Yu Gao via B4 Relay
2026-12-01 17:18 ` [PATCH net v3 2/3] net: lapbether: bound the receive queue Yu Gao via B4 Relay
2026-12-01 17:18 ` [PATCH net v3 3/3] net: lapb: transmit frames outside the protocol lock Yu Gao via B4 Relay
2 siblings, 0 replies; 6+ messages in thread
From: Yu Gao via B4 Relay @ 2026-12-01 17:18 UTC (permalink / raw)
To: Martin Schiller, netdev
Cc: Hillf Danton, David S. Miller, Simon Horman, Xie He, Andrew Lunn,
Eric Dumazet, Jonathan Corbet, Willem de Bruijn,
syzbot+8328573e4d0514392471, linux-doc, Jakub Kicinski,
Paolo Abeni, linux-x25, syzbot+059a2795ad4cff2a2695
From: Yu Gao <SuperSkidder@qq.com>
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 transmit change later in this
series removes it.
Fixes: b491e6a7391e ("net: lapb: Add locking to the lapb module")
Suggested-by: Willem de Bruijn <willemb@google.com>
Acked-by: Martin Schiller <ms@dev.tdt.de>
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] 6+ messages in thread
* [PATCH net v3 2/3] net: lapbether: bound the receive queue
2026-12-01 17:18 [PATCH net v3 0/3] net: lapb: don't call the driver with LAPB locks held Yu Gao via B4 Relay
2026-12-01 17:18 ` [PATCH net v3 1/3] net: lapb: drop lapb_list_lock before waiting for users Yu Gao via B4 Relay
@ 2026-12-01 17:18 ` Yu Gao via B4 Relay
2026-12-05 17:39 ` netdev-bot+sashiko
2026-12-01 17:18 ` [PATCH net v3 3/3] net: lapb: transmit frames outside the protocol lock Yu Gao via B4 Relay
2 siblings, 1 reply; 6+ messages in thread
From: Yu Gao via B4 Relay @ 2026-12-01 17:18 UTC (permalink / raw)
To: Martin Schiller, netdev
Cc: Hillf Danton, David S. Miller, Simon Horman, Xie He, Andrew Lunn,
Eric Dumazet, Jonathan Corbet, Willem de Bruijn,
syzbot+8328573e4d0514392471, linux-doc, Jakub Kicinski,
Paolo Abeni, linux-x25, syzbot+059a2795ad4cff2a2695
From: Yu Gao <SuperSkidder@qq.com>
lapbeth queues LAPB's indications on rx_queue and passes them up from
its NAPI poll. Nothing limits that queue, so it grows when a peer
makes LAPB produce indications faster than the poll delivers them.
The transmit change later in this series makes that easier to hit.
Drop received frames in lapbeth_rcv() once the queue reaches
netdev_max_backlog, the limit netif_rx() applied before the commit
below. The frame is dropped before LAPB sees it, so the peer retransmits
it and nothing LAPB has accepted is lost. Purge the queue on close, so
stale entries don't count against the limit after the device is
reopened.
Fixes: 514e1150da9c ("net: x25: Queue received packets in the drivers instead of per-CPU queues")
Signed-off-by: Yu Gao <SuperSkidder@qq.com>
---
drivers/net/wan/lapbether.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
index c3630a8..ab71afa 100644
--- a/drivers/net/wan/lapbether.c
+++ b/drivers/net/wan/lapbether.c
@@ -39,6 +39,7 @@
#include <linux/lapb.h>
#include <linux/init.h>
+#include <net/hotdata.h>
#include <net/netdev_lock.h>
#include <net/x25device.h>
@@ -132,6 +133,16 @@ static int lapbeth_rcv(struct sk_buff *skb, struct net_device *dev,
if (!lapbeth->up)
goto drop_unlock;
+ /* A frame dropped before LAPB sees it is like one lost on the wire,
+ * and the peer retransmits it. This keeps a peer from growing
+ * rx_queue without limit.
+ */
+ if (skb_queue_len_lockless(&lapbeth->rx_queue) >=
+ READ_ONCE(net_hotdata.max_backlog)) {
+ DEV_STATS_INC(lapbeth->axdev, rx_dropped);
+ goto drop_unlock;
+ }
+
len = skb->data[0] + skb->data[1] * 256;
dev->stats.rx_packets++;
dev->stats.rx_bytes += len;
@@ -352,6 +363,7 @@ static int lapbeth_close(struct net_device *dev)
pr_err("lapb_unregister error: %d\n", err);
napi_disable(&lapbeth->napi);
+ skb_queue_purge(&lapbeth->rx_queue);
return 0;
}
--
Git-157)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net v3 3/3] net: lapb: transmit frames outside the protocol lock
2026-12-01 17:18 [PATCH net v3 0/3] net: lapb: don't call the driver with LAPB locks held Yu Gao via B4 Relay
2026-12-01 17:18 ` [PATCH net v3 1/3] net: lapb: drop lapb_list_lock before waiting for users Yu Gao via B4 Relay
2026-12-01 17:18 ` [PATCH net v3 2/3] net: lapbether: bound the receive queue Yu Gao via B4 Relay
@ 2026-12-01 17:18 ` Yu Gao via B4 Relay
2026-12-05 17:39 ` netdev-bot+sashiko
2 siblings, 1 reply; 6+ messages in thread
From: Yu Gao via B4 Relay @ 2026-12-01 17:18 UTC (permalink / raw)
To: Martin Schiller, netdev
Cc: Hillf Danton, David S. Miller, Simon Horman, Xie He, Andrew Lunn,
Eric Dumazet, Jonathan Corbet, Willem de Bruijn,
syzbot+8328573e4d0514392471, linux-doc, Jakub Kicinski,
Paolo Abeni, linux-x25, syzbot+059a2795ad4cff2a2695
From: Yu Gao <SuperSkidder@qq.com>
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 hands frames straight to the hardware, so it sends them right
after the lock is dropped. lapbeth's data_transmit() can loop back into
LAPB through dev_queue_xmit(), so it sets the new schedule_tx()
callback and sends them from its NAPI poll instead.
The FIFO holds at most 256 frames; more are dropped and left to LAPB
retransmission. A drain sends at most 64 frames, then lapbeth's NAPI
poll stays scheduled and hdlc_x25 defers the rest to a work item.
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 this series, the syzbot reproducers 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>
---
Documentation/networking/lapb-module.rst | 31 ++++++++
drivers/net/wan/lapbether.c | 14 ++++
include/linux/lapb.h | 8 ++
include/net/lapb.h | 13 ++++
net/lapb/lapb_iface.c | 123 +++++++++++++++++++++++++++----
net/lapb/lapb_timer.c | 4 +-
6 files changed, 178 insertions(+), 15 deletions(-)
diff --git a/Documentation/networking/lapb-module.rst b/Documentation/networking/lapb-module.rst
index ff586bc..f2047e3 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);
};
Each member of this structure corresponds to a function in the device driver
@@ -224,6 +225,16 @@ LAPB_OK LAPB has accepted the data.
LAPB_BADTOKEN Invalid/unknown LAPB token.
============= ===========================
+::
+
+ bool lapb_transmit_pending(void *token);
+
+Pass queued frames to the device driver through data_transmit (see below).
+Only drivers that provide schedule_tx need to call this. Each call sends at
+most 64 frames and returns true if frames are left, in which case the driver
+should call it again later. It must not be called with a lock held that the
+driver's transmit path also takes.
+
Callbacks
---------
@@ -303,3 +314,23 @@ This is called by the LAPB module when data is to be transmitted to the
remote system by the device driver. The skbuff becomes the property of the
device driver and the LAPB module will not perform any more actions on it.
The skb->data pointer will be pointing to the first byte of the LAPB header.
+
+LAPB queues outgoing frames while it holds its internal lock and calls
+data_transmit only after dropping it, so the frame may be passed to the
+driver some time after the event that produced it. At most 256 frames
+wait; further ones are dropped and left to the LAPB retransmission. When a
+device in the initial network namespace is going down, the queued frames
+are passed to the driver and frames produced after that are dropped.
+
+::
+
+ void (*schedule_tx)(void *token);
+
+Optional. A driver whose data_transmit can re-enter the network stack or the
+LAPB module, for example by calling dev_queue_xmit(), provides this
+callback. LAPB then calls schedule_tx instead of data_transmit from the
+context of the LAPB call, and the driver calls lapb_transmit_pending (see
+above) later from a context that holds none of its transmit locks.
+schedule_tx is called with the LAPB lock held and must not call back into
+the LAPB module. Without it, the caller sends the frames right after LAPB
+drops its lock, and if many are waiting, the rest are sent from a work item.
diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
index ab71afa..a438b85 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);
for (; processed < budget; ++processed) {
skb = skb_dequeue(&lapbeth->rx_queue);
@@ -101,6 +105,8 @@ static int lapbeth_napi_poll(struct napi_struct *napi, int budget)
netif_receive_skb_core(skb);
}
+ if (tx_more)
+ return budget;
if (processed < budget)
napi_complete(napi);
@@ -317,6 +323,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,
@@ -324,6 +337,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..5d793ea 100644
--- a/include/linux/lapb.h
+++ b/include/linux/lapb.h
@@ -36,6 +36,13 @@ 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);
+ /* Set this if data_transmit() can re-enter the network stack or LAPB.
+ * LAPB then calls it instead of sending from the caller's context, and
+ * the driver must call lapb_transmit_pending() later, without holding
+ * any lock its transmit path takes. It is called with the LAPB lock
+ * held and must not call back into LAPB.
+ */
+ void (*schedule_tx)(struct net_device *dev);
};
struct lapb_parms_struct {
@@ -57,6 +64,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);
+bool 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..ce45cf3 100644
--- a/include/net/lapb.h
+++ b/include/net/lapb.h
@@ -3,6 +3,8 @@
#define _LAPB_H
#include <linux/lapb.h>
#include <linux/refcount.h>
+#include <linux/wait.h>
+#include <linux/workqueue.h>
#define LAPB_HEADER_LEN MAX_HEADER /* LAPB over Ethernet + a bit more */
@@ -66,6 +68,11 @@ enum {
#define LAPB_SMODULUS 8
#define LAPB_EMODULUS 128
+/* About two full extended windows. */
+#define LAPB_TX_QUEUE_MAX 256
+/* Frames sent per drain before the rest is deferred. */
+#define LAPB_TX_QUOTA 64
+
/*
* Information about the current frame.
*/
@@ -97,6 +104,11 @@ 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;
+ struct work_struct tx_work;
+ bool tx_running;
+ bool tx_stopped;
unsigned char window;
const struct lapb_register_struct *callbacks;
@@ -109,6 +121,7 @@ struct lapb_cb {
};
/* lapb_iface.c */
+void lapb_tx_unlock(struct lapb_cb *lapb) __releases(&lapb->lock);
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..a04fd11 100644
--- a/net/lapb/lapb_iface.c
+++ b/net/lapb/lapb_iface.c
@@ -105,6 +105,16 @@ static struct lapb_cb *lapb_devtostruct(struct net_device *dev)
return rc;
}
+
+/* Sends what an inline drain left behind when it ran out of quota. */
+static void lapb_tx_work(struct work_struct *work)
+{
+ struct lapb_cb *lapb = container_of(work, struct lapb_cb, tx_work);
+
+ spin_lock_bh(&lapb->lock);
+ lapb_tx_unlock(lapb);
+}
+
/*
* Create an empty LAPB control block.
*/
@@ -117,6 +127,9 @@ 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);
+ INIT_WORK(&lapb->tx_work, lapb_tx_work);
timer_setup(&lapb->t1timer, NULL, 0);
timer_setup(&lapb->t2timer, NULL, 0);
@@ -198,7 +211,9 @@ int lapb_unregister(struct net_device *dev)
/* Wait for running timers to stop */
timer_delete_sync(&lapb->t1timer);
timer_delete_sync(&lapb->t2timer);
+ disable_work_sync(&lapb->tx_work);
+ __skb_queue_purge(&lapb->tx_queue);
lapb_put(lapb);
return LAPB_OK;
out:
@@ -282,6 +297,71 @@ 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.
+ * Returns true if the quota ran out with frames still queued; the caller
+ * then has to schedule another drain. Once tx_stopped is set no frames
+ * are added, so the final flush ignores the quota.
+ */
+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))) {
+ 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);
+ return !skb_queue_empty(&lapb->tx_queue);
+}
+
+/* Returns true if frames are left for the next call. */
+bool lapb_transmit_pending(struct net_device *dev)
+{
+ struct lapb_cb *lapb = lapb_devtostruct(dev);
+ bool more;
+
+ if (!lapb)
+ return false;
+ spin_lock_bh(&lapb->lock);
+ more = lapb_xmit_queued(lapb);
+ spin_unlock_bh(&lapb->lock);
+ lapb_put(lapb);
+ return more;
+}
+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 if (lapb_xmit_queued(lapb))
+ schedule_work(&lapb->tx_work);
+ }
+ spin_unlock_bh(&lapb->lock);
+}
+
int lapb_connect_request(struct net_device *dev)
{
struct lapb_cb *lapb = lapb_devtostruct(dev);
@@ -307,7 +387,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 +437,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 +458,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 +478,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 +522,15 @@ 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;
- }
-
- return used;
+ lockdep_assert_held(&lapb->lock);
+ if (lapb->tx_stopped || !lapb->callbacks->data_transmit ||
+ skb_queue_len(&lapb->tx_queue) >= LAPB_TX_QUEUE_MAX)
+ return 0;
+
+ 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 +539,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;
@@ -488,8 +571,16 @@ static int lapb_device_event(struct notifier_block *this, unsigned long event,
}
break;
case NETDEV_GOING_DOWN:
+ /* Make room for the DISC; the link is closing anyway. */
+ if (skb_queue_len(&lapb->tx_queue) >= LAPB_TX_QUEUE_MAX)
+ kfree_skb(__skb_dequeue(&lapb->tx_queue));
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 +615,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] 6+ messages in thread
* Re: [PATCH net v3 2/3] net: lapbether: bound the receive queue
2026-12-01 17:18 ` [PATCH net v3 2/3] net: lapbether: bound the receive queue Yu Gao via B4 Relay
@ 2026-12-05 17:39 ` netdev-bot+sashiko
0 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 17:39 UTC (permalink / raw)
To: SuperSkidder
Cc: ms, netdev, hdanton, davem, horms, xie.he.0141, andrew+netdev,
edumazet, corbet, willemb, syzbot+8328573e4d0514392471, linux-doc,
kuba, pabeni, linux-x25, syzbot+059a2795ad4cff2a2695
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · 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).
- [Medium] The new limit check in lapbeth_rcv()
(drivers/net/wan/lapbether.c) runs before lapb_data_received() and…
- [Medium] The patch is titled 'bound the receive queue', but the bound
only applies to indications that start in lapbeth_rcv().
--
net: lapbether: bound the receive queue
This patch drops received frames in lapbeth_rcv() once lapbeth->rx_queue
reaches netdev_max_backlog, so a peer cannot grow the queue without limit.
It also purges rx_queue in lapbeth_close(), so stale entries don't count
against the limit after the device is reopened.
> diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
> index c3630a82913bf..ab71afaaf8482 100644
> --- a/drivers/net/wan/lapbether.c
> +++ b/drivers/net/wan/lapbether.c
[ ... ]
> @@ -132,6 +133,16 @@ static int lapbeth_rcv(struct sk_buff *skb, struct net_device *dev,
> if (!lapbeth->up)
> goto drop_unlock;
>
> + /* A frame dropped before LAPB sees it is like one lost on the wire,
> + * and the peer retransmits it. This keeps a peer from growing
> + * rx_queue without limit.
> + */
> + if (skb_queue_len_lockless(&lapbeth->rx_queue) >=
> + READ_ONCE(net_hotdata.max_backlog)) {
> + DEV_STATS_INC(lapbeth->axdev, rx_dropped);
> + goto drop_unlock;
> + }
[Severity: Medium]
Does this comment hold for every frame type dropped here? The check runs
before lapb_data_received(), so while rx_queue is full LAPB sees no
incoming frames at all. That includes I-frames carrying N(R) acks,
RR/RNR/REJ, UA, DM and FRMR responses, and SABM/DISC.
The peer only retransmits its own I-frames and commands. It won't resend
acks or responses that we dropped. Only our local T1 recovers those, and
each T1 expiry in state 3 increments n2count:
net/lapb/lapb_timer.c:lapb_t1timer_expiry() {
...
case LAPB_STATE_3:
if (lapb->n2count == lapb->n2) {
lapb_clear_queues(lapb);
lapb->state = LAPB_STATE_0;
lapb_stop_t2timer(lapb);
lapb_disconnect_indication(lapb, LAPB_TIMEDOUT);
...
}
Because the peer's acks are thrown away, the local TX window also stalls.
Under sustained congestion, can this reset the local link and tear down
every X.25 call?
The commit message also describes this as "the limit netif_rx() applied
before the commit below". Before 514e1150da9c, that limit was applied
after LAPB had parsed the frame. lapbeth_data_indication() returned the
NET_RX_DROP verdict, and lapb_state3_machine() had already processed N(R)
by then. It only skipped the V(R) advance:
net/lapb/lapb_in.c:lapb_state3_machine() {
...
if (lapb->condition & LAPB_PEER_RX_BUSY_CONDITION)
lapb_frames_acked(lapb, frame->nr);
else
lapb_check_iframes_acked(lapb, frame->nr);
if (frame->ns == lapb->vr) {
int cn;
cn = lapb_data_indication(lapb, skb);
queued = 1;
...
if (cn == NET_RX_DROP) {
pr_debug("rx congestion\n");
break;
}
...
}
With that mechanism only the inbound I-frame is deferred, and the peer
retransmits it. That is the behaviour the new comment and the commit
message describe.
Would it work better to apply the limit in lapbeth_data_indication() and
return NET_RX_DROP there, so LAPB's existing congestion handling is used?
If not, could the comment and commit message be changed to describe what
this check actually does?
The later patches in this series don't touch lapbeth_rcv(), so this stays
the same at the end of the series.
[Severity: Medium]
Does this bound cover every producer of rx_queue? lapbeth_connected() and
lapbeth_disconnected() still queue on rx_queue with no length check:
drivers/net/wan/lapbether.c:lapbeth_connected() {
...
skb->protocol = x25_type_trans(skb, dev);
skb_queue_tail(&lapbeth->rx_queue, skb);
napi_schedule(&lapbeth->napi);
}
lapbeth_xmit() reaches both of them without going through lapbeth_rcv():
drivers/net/wan/lapbether.c:lapbeth_xmit() {
...
case X25_IFACE_CONNECT:
err = lapb_connect_request(dev);
if (err == LAPB_CONNECTED)
lapbeth_connected(dev, LAPB_OK);
...
case X25_IFACE_DISCONNECT:
err = lapb_disconnect_request(dev);
if (err == LAPB_NOTCONNECTED)
lapbeth_disconnected(dev, LAPB_OK);
...
}
lapb_connect_request() returns LAPB_CONNECTED on every call while LAPB is
in state 3 or 4. A disconnect request returns LAPB_NOTCONNECTED while LAPB
is in state 0.
So a sender with CAP_NET_RAW and a packet socket on the lapb device can
queue one indication per 1-byte frame it transmits, from several CPUs at
once. Meanwhile lapbeth_napi_poll() drains at most 16 skbs per poll, on
one CPU.
Before 514e1150da9c these indications went through netif_rx() and were
capped by netdev_max_backlog. The rest of the series doesn't change
lapbeth_xmit(), lapbeth_connected() or lapbeth_disconnected().
Would moving the check to the enqueue point, in the indication callbacks,
bound every producer?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-lapb-unlock-v3-v3-0-65b6ce65141b%40qq.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v3 3/3] net: lapb: transmit frames outside the protocol lock
2026-12-01 17:18 ` [PATCH net v3 3/3] net: lapb: transmit frames outside the protocol lock Yu Gao via B4 Relay
@ 2026-12-05 17:39 ` netdev-bot+sashiko
0 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 17:39 UTC (permalink / raw)
To: SuperSkidder
Cc: ms, netdev, hdanton, davem, horms, xie.he.0141, andrew+netdev,
edumazet, corbet, willemb, syzbot+8328573e4d0514392471, linux-doc,
kuba, pabeni, linux-x25, syzbot+059a2795ad4cff2a2695
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-05 17:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 17:18 [PATCH net v3 0/3] net: lapb: don't call the driver with LAPB locks held Yu Gao via B4 Relay
2026-12-01 17:18 ` [PATCH net v3 1/3] net: lapb: drop lapb_list_lock before waiting for users Yu Gao via B4 Relay
2026-12-01 17:18 ` [PATCH net v3 2/3] net: lapbether: bound the receive queue Yu Gao via B4 Relay
2026-12-05 17:39 ` netdev-bot+sashiko
2026-12-01 17:18 ` [PATCH net v3 3/3] net: lapb: transmit frames outside the protocol lock Yu Gao via B4 Relay
2026-12-05 17:39 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox