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, hdanton@sina.com,
	davem@davemloft.net, horms@kernel.org, xie.he.0141@gmail.com,
	andrew+netdev@lunn.ch, edumazet@kernel.org, corbet@lwn.net,
	willemb@google.com,
	syzbot+8328573e4d0514392471@syzkaller.appspotmail.com,
	linux-doc@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
	linux-x25@vger.kernel.org,
	syzbot+059a2795ad4cff2a2695@syzkaller.appspotmail.com
Subject: Re: [PATCH net v3 3/3] net: lapb: transmit frames outside the protocol lock
Date: Sat, 05 Dec 2026 17:39:15 +0000	[thread overview]
Message-ID: <179649235593.3146.905729325799246245@kernel.org> (raw)
In-Reply-To: <20261202-lapb-unlock-v3-v3-3-65b6ce65141b@qq.com>

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

      reply	other threads:[~2026-12-05 17:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 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=179649235593.3146.905729325799246245@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=SuperSkidder@qq.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hdanton@sina.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.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