Linux PCI Non-Transparent Bridge framework and drivers
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Koichiro Den" <den@valinux.co.jp>
Cc: ntb@lists.linux.dev
Subject: Re: [PATCH net 3/4] NTB: ntb_transport: Fail TX enqueue when the QP link is down
Date: Tue, 18 Aug 2026 05:35:42 +0000	[thread overview]
Message-ID: <20260818053542.9EC751F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260817053519.4135287-4-den@valinux.co.jp>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Data race and state corruption during concurrent link down and packet transmission.
- [Medium] Silent memory leak of SKBs when the QP link transitions down.
--

--- Patch [3]: [PATCH net 3/4] NTB: ntb_transport: Fail TX enqueue when the QP link is down ---
commit d31ae522b81066694c3712e62ed7ae6b70c6a06a
Author: Koichiro Den <den@valinux.co.jp>

NTB: ntb_transport: Fail TX enqueue when the QP link is down

Commit f195a1a6fe41 meant to make ntb_transport_tx_enqueue() drop packets
submitted while the qp link is down, but it only returns 0 without
consuming the packet. This patch returns an error instead, restoring the
contract that a non-zero return leaves the buffer owned by the caller.

Fixes: f195a1a6fe41 ("ntb: Drop packets when qp link is down")
Cc: stable@vger.kernel.org

> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index e92b96f4afad8..4bdd81edcb87a 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c
> @@ -2353,9 +2353,8 @@ int ntb_transport_tx_enqueue(struct ntb_transport_qp *qp, void *cb, void *data,
>  	if (!qp || !len)
>  		return -EINVAL;
>  
> -	/* If the qp link is down already, just ignore. */
>  	if (!qp->link_is_up)
> -		return 0;
> +		return -ENOLINK;

[Severity: High]
This isn't a bug introduced by this patch, but does the lockless qp reset in
ntb_transport_link_down() race with concurrent packet transmission?

If an administrator changes the mtu, ntb_netdev_change_mtu() calls
ntb_transport_link_down() without first stopping the tx queues via
netif_tx_disable():

drivers/net/ntb_netdev.c:ntb_netdev_change_mtu() {
	/* Bring down the link and dispose of posted rx entries */
	for (q = 0; q < dev->num_queues; q++)
		ntb_transport_link_down(dev->queues[q].qp);
}

Concurrently, the network stack can call ntb_netdev_start_xmit() and reach
ntb_transport_tx_enqueue(), which processes tx entries.
Meanwhile, ntb_transport_link_down() triggers ntb_send_link_down() and
ntb_qp_link_down_reset(), which resets qp->tx_index to 0 locklessly.

drivers/ntb/ntb_transport.c:ntb_send_link_down() {
	rc = ntb_process_tx(qp, entry);
	...
	ntb_qp_link_down_reset(qp);
}

Since ntb_async_tx() writes to tx_index without synchronization:

drivers/ntb/ntb_transport.c:ntb_async_tx() {
	WRITE_ONCE(qp->tx_index, (qp->tx_index + 1) % qp->tx_max_entry);
}

Could this lead to concurrent modifications of qp->tx_index, qp->tx_pkts, and
hardware io memory window corruption?

[Severity: Medium]
This is a pre-existing issue, but does dropping the client_ready flag in
ntb_transport_link_down() cause a silent memory leak of skb objects?

When the interface link goes down, ntb_transport_link_down() disables the
client:

drivers/ntb/ntb_transport.c:ntb_transport_link_down() {
	qp->client_ready = false;
}

Later, the receive tasklet ntb_complete_rxc() processes dma completions from
rx_post_q. Since client_ready is false, it skips calling the network receive
handler that would normally free the skb:

drivers/ntb/ntb_transport.c:ntb_complete_rxc() {
		if (qp->rx_handler && qp->client_ready)
			qp->rx_handler(qp, qp->cb_data, cb_data, len);
}

The cleanup function only drains rx_pend_q:

drivers/ntb/ntb_transport.c:ntb_transport_rx_remove() {
	entry = ntb_list_rm(&qp->ntb_rx_q_lock, &qp->rx_pend_q);
}

Does this leave skb objects in rx_post_q stranded without being freed?

>  
>  	entry = ntb_list_rm(&qp->ntb_tx_free_q_lock, &qp->tx_free_q);
>  	if (!entry) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260817053519.4135287-1-den@valinux.co.jp?part=3

  reply	other threads:[~2026-08-18  5:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  5:35 [PATCH net 0/4] net: ntb_netdev: Fix TX completion and error handling Koichiro Den
2026-08-17  5:35 ` [PATCH net 1/4] NTB: ntb_transport: Recycle TX entries before client callbacks Koichiro Den
2026-08-18  5:35   ` sashiko-bot
2026-08-17  5:35 ` [PATCH net 2/4] net: ntb_netdev: Fix TX busy and drop handling Koichiro Den
2026-08-17  5:35 ` [PATCH net 3/4] NTB: ntb_transport: Fail TX enqueue when the QP link is down Koichiro Den
2026-08-18  5:35   ` sashiko-bot [this message]
2026-08-17  5:35 ` [PATCH net 4/4] NTB: ntb_transport: Reject oversized TX buffers Koichiro Den
2026-08-18  5:35   ` sashiko-bot

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=20260818053542.9EC751F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=den@valinux.co.jp \
    --cc=ntb@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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