ntb.lists.linux.dev archive mirror
 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 v2 05/14] NTB: ntb_transport: Avoid losing QP link-up requests
Date: Thu, 10 Sep 2026 04:26:44 +0000	[thread overview]
Message-ID: <20260910042645.7B4711F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910040836.3792333-6-den@valinux.co.jp>

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

Pre-existing issues:
- [High] Race condition between `ntb_qp_link_work` and `ntb_transport_link_down` causes spurious link-up and breaks queue teardown synchronization.
- [High] Missing `dma_rmb()` after checking `DESC_DONE_FLAG` allows speculative reading of stale DMA data.
--

commit 99af086b145ca7c747420cbf914a391c3b3216f2
Author: Koichiro Den <den@valinux.co.jp>

NTB: ntb_transport: Avoid losing QP link-up requests

ntb_netdev_open() can call ntb_transport_link_up() while the transport
worker is completing setup on another CPU. Concurrent transport setup
and a client link-up request can both read the other's flag as false and
leave QP link work unqueued. The QP then stays down until another link
event or client link-up request.

Link: https://lore.kernel.org/r/20260907144701.702E41F00A3A@smtp.kernel.org/

> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index 75d4a2e021f4e..1332d53bcfe7d 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c
> @@ -1104,10 +1104,16 @@ static void ntb_transport_link_work(struct work_struct *work)
>  	/* Publish the link only after every QP has been set up. */
>  	smp_store_release(&nt->link_is_up, true);
>  
> +	/*
> +	 * Prevent both sides from missing each other's flag. Pairs with
> +	 * the barrier in ntb_transport_link_up().
> +	 */
> +	smp_mb();
> +
>  	for (i = 0; i < nt->qp_count; i++) {
>  		struct ntb_transport_qp *qp = &nt->qp_vec[i];
>  
> -		if (qp->client_ready)
> +		if (READ_ONCE(qp->client_ready))
>  			ntb_transport_schedule_qp_link(qp, 0);
>  	}

[Severity: High]
This isn't a bug introduced by this patch, but does the check for
qp->client_ready in ntb_qp_link_work() safely prevent a spurious link-up if
the client simultaneously tears down the link?

If CPU 1 calls ntb_transport_link_down(), clearing qp->client_ready and
calling cancel_delayed_work_sync(&qp->link_work):

drivers/ntb/ntb_transport.c:ntb_transport_link_down() {
	...
	if (qp->link_is_up)
		ntb_send_link_down(qp);
	else
		cancel_delayed_work_sync(&qp->link_work);
}

Could CPU 0, executing ntb_qp_link_work() concurrently, fail to see
qp->client_ready as false before writing to the remote SPAD and firing the
link-up event handler?

drivers/ntb/ntb_transport.c:ntb_qp_link_work() {
	...
	if (val & BIT(qp->qp_num)) {
		dev_info(&pdev->dev, "qp %d: Link Up\n", qp->qp_num);
		qp->link_is_up = true;
	...
}

This sequence bypasses the client's teardown intent, and forcing the link
back up after teardown may lead to use-after-free or data corruption.

[ ... ]

> @@ -2401,7 +2407,10 @@ void ntb_transport_link_up(struct ntb_transport_qp *qp)
>  	if (!qp)
>  		return;
>  
> -	qp->client_ready = true;
> +	WRITE_ONCE(qp->client_ready, true);
> +
> +	/* Pairs with the barrier in ntb_transport_link_work(). */
> +	smp_mb();
>  
>  	ntb_transport_schedule_qp_link(qp, 0);
>  }

[Severity: High]
This is a pre-existing issue, but does ntb_process_rxc() need a dma_rmb()
barrier after checking DESC_DONE_FLAG?

When processing received packets, the done flag is checked:

drivers/ntb/ntb_transport.c:ntb_process_rxc() {
	...
	if (!(hdr->flags & DESC_DONE_FLAG)) {
		dev_dbg(&qp->ndev->pdev->dev, "done flag not set\n");
		qp->rx_ring_empty++;
		return -EAGAIN;
	}

	if (hdr->flags & LINK_DOWN_FLAG) {
	...
}

Without a dma_rmb() here, can weak memory architectures (like ARM64 or
PowerPC) speculatively fetch subsequent header fields and payload data
(such as hdr->ver or hdr->len) before the flag check completes, leading to
processing stale DMA data?

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

  reply	other threads:[~2026-09-10  4:26 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10  4:08 [PATCH v2 00/14] NTB: ntb_transport: Miscellaneous fixes Koichiro Den
2026-09-10  4:08 ` [PATCH v2 01/14] NTB: ntb_transport: Remove the device debugfs directory Koichiro Den
2026-09-10  4:20   ` sashiko-bot
2026-09-10 18:41   ` Frank Li
2026-09-15 17:52   ` Logan Gunthorpe
2026-09-10  4:08 ` [PATCH v2 02/14] NTB: ntb_transport: Start TX offload thread after queue setup Koichiro Den
2026-09-11 16:13   ` Frank Li
2026-09-15 18:08   ` Logan Gunthorpe
2026-09-10  4:08 ` [PATCH v2 03/14] NTB: ntb_transport: Avoid deadlock when cancelling link work Koichiro Den
2026-09-10  4:23   ` sashiko-bot
2026-09-11 16:21   ` Frank Li
2026-09-11 17:41     ` Koichiro Den
2026-09-15 18:19   ` Logan Gunthorpe
2026-09-10  4:08 ` [PATCH v2 04/14] NTB: ntb_transport: Publish link state after QP setup Koichiro Den
2026-09-11 16:39   ` Frank Li
2026-09-15 18:32   ` Logan Gunthorpe
2026-09-10  4:08 ` [PATCH v2 05/14] NTB: ntb_transport: Avoid losing QP link-up requests Koichiro Den
2026-09-10  4:26   ` sashiko-bot [this message]
2026-09-11 16:53   ` Frank Li
2026-09-11 18:04     ` Koichiro Den
2026-09-11 18:21       ` Koichiro Den
2026-09-12  3:20         ` Frank Li
2026-09-12 14:52           ` Koichiro Den
2026-09-10  4:08 ` [PATCH v2 06/14] NTB: ntb_transport: Clear link state before QP cleanup Koichiro Den
2026-09-10  4:27   ` sashiko-bot
2026-09-15 18:55   ` Logan Gunthorpe
2026-09-10  4:08 ` [PATCH v2 07/14] NTB: ntb_transport: Stop QP work before freeing a queue Koichiro Den
2026-09-10  4:23   ` sashiko-bot
2026-09-15 19:59   ` Logan Gunthorpe
2026-09-10  4:08 ` [PATCH v2 08/14] NTB: ntb_transport: Stop RX tasklet scheduling " Koichiro Den
2026-09-10  4:08 ` [PATCH v2 09/14] NTB: ntb_transport: Drain RX tasklets during link cleanup Koichiro Den
2026-09-10  4:23   ` sashiko-bot
2026-09-10  4:08 ` [PATCH v2 10/14] NTB: ntb_transport: Wait for RX completions before resetting a QP Koichiro Den
2026-09-10  4:24   ` sashiko-bot
2026-09-10  4:08 ` [PATCH v2 11/14] NTB: ntb_transport: Prepare remote RX info accesses for MW teardown Koichiro Den
2026-09-10  4:31   ` sashiko-bot
2026-09-10  4:08 ` [PATCH v2 12/14] NTB: ntb_transport: Clear QP pointers when freeing an MW Koichiro Den
2026-09-10  4:32   ` sashiko-bot
2026-09-10  4:08 ` [PATCH v2 13/14] NTB: ntb_transport: Abort link setup on QP MW allocation failure Koichiro Den
2026-09-10  4:40   ` sashiko-bot
2026-09-10  4:08 ` [PATCH v2 14/14] NTB: ntb_transport: Remove clients before freeing transport resources Koichiro Den
2026-09-10  4:36   ` sashiko-bot
2026-09-10  8:48     ` Koichiro Den
2026-09-11 15:49       ` Dave Jiang
2026-09-14  4:27         ` Koichiro Den
2026-09-14 21:02           ` Dave Jiang
2026-09-15  4:01             ` Koichiro Den
2026-09-15 15:50               ` Dave Jiang

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=20260910042645.7B4711F000FF@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;
as well as URLs for NNTP newsgroup(s).