Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: SuperSkidder@qq.com
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
Subject: Re: [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock
Date: Tue, 01 Dec 2026 12:57:53 +0000	[thread overview]
Message-ID: <179612987367.3146.17593233623166891863@kernel.org> (raw)
In-Reply-To: <tencent_13BADC934C9BDBCE7D204DEAA2DC1D403705@qq.com>

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

      reply	other threads:[~2026-12-01 12:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 ` [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock Yu Gao
2026-12-01 12:57   ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179612987367.3146.17593233623166891863@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=SuperSkidder@qq.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hdanton@sina.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-x25@vger.kernel.org \
    --cc=ms@dev.tdt.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=syzbot+059a2795ad4cff2a2695@syzkaller.appspotmail.com \
    --cc=syzbot+8328573e4d0514392471@syzkaller.appspotmail.com \
    --cc=willemb@google.com \
    --cc=xie.he.0141@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox