From: sashiko-bot@kernel.org
To: "Koichiro Den" <den@valinux.co.jp>
Cc: ntb@lists.linux.dev
Subject: Re: [PATCH net-next v4 05/10] NTB: ntb_transport: Exchange client capabilities at link-up
Date: Tue, 15 Sep 2026 08:50:12 +0000 [thread overview]
Message-ID: <20260915085012.E9C8E1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260914084838.2158249-6-den@valinux.co.jp>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing write memory barrier (dma_wmb) between writing capabilities and advertising QP readiness leads to a race condition on weakly-ordered architectures.
--
commit b1a0deb57c0951e9f08d12fad27aa18c65b97771
Author: Koichiro Den <den@valinux.co.jp>
NTB: ntb_transport: Exchange client capabilities at link-up
This commit updates the NTB transport to exchange 31-bit opaque
capabilities during QP link setup using scratchpads. The capabilities
are passed to the client along with the link-up event.
Link: https://lore.kernel.org/r/xsaocp32a6siggahziu4jqbwgmdasmp6v64pd5aujfkoxhiqws@n5luestlntzc/
> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index 0b47285ef48b6..ea89eb336472a 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c
> @@ -937,7 +942,7 @@ static void ntb_qp_link_cleanup(struct ntb_transport_qp *qp)
> ntb_qp_link_down_reset(qp);
>
> if (qp->event_handler)
> - qp->event_handler(qp->cb_data, qp->link_is_up);
> + qp->event_handler(qp->cb_data, qp->link_is_up, 0);
> }
[Severity: High]
This isn't a bug introduced by this patch, but does this cleanup path
contain a deadlock?
The transport cleanup work ntb_transport_link_cleanup_work() acquires
nt->link_event_lock and calls ntb_transport_link_cleanup(). That function
synchronously waits for nt->link_work via cancel_delayed_work_sync().
However, if ntb_transport_link_work() executes concurrently, its very first
action is to attempt to acquire nt->link_event_lock. This lock inversion
can deadlock the workqueues and hang the subsystem.
[Severity: High]
This is also a pre-existing issue, but is there a use-after-free risk
when a queue is freed?
If a client frees a queue using ntb_transport_free_queue(), the
qp->link_cleanup work is never cancelled. If the transport is subsequently
removed, ntb_transport_link_cleanup() only cancels works for currently
allocated QPs, skipping the one the client already freed. When the
transport then frees the nt->qp_vec array, the workqueue subsystem might
subsequently attempt to execute the pending link_cleanup work for the
freed queue, causing a use-after-free crash.
[ ... ]
> @@ -1141,10 +1146,19 @@ static void ntb_qp_link_work(struct work_struct *work)
> link_work.work);
> struct pci_dev *pdev = qp->ndev->pdev;
> struct ntb_transport_ctx *nt = qp->transport;
> + u32 peer_caps = 0;
> int val;
>
> WARN_ON(!nt->link_is_up);
>
> + /* Pair with the release store in ntb_transport_link_up(). */
> + if (!smp_load_acquire(&qp->client_ready))
> + return;
> +
> + /* Publish capabilities before QP readiness. */
> + if (qp->caps_spad)
> + ntb_peer_spad_write(nt->ndev, PIDX, qp->caps_spad,
> + READ_ONCE(qp->local_caps) | QP_CAPS_VALID);
> val = ntb_spad_read(nt->ndev, QP_LINKS);
>
> ntb_qp_up_request(qp, true);
[Severity: High]
Is a write memory barrier needed here between writing capabilities and
advertising QP readiness?
On weakly ordered architectures, the CPU or interconnect can reorder
consecutive memory writes. Without a barrier like dma_wmb(), the peer
might observe the readiness bit from ntb_qp_up_request() before the
capabilities land in memory-backed SPADs. The read side has a dma_rmb(),
but shouldn't the write side also need a dma_wmb() to guarantee order?
[ ... ]
> @@ -2439,12 +2480,17 @@ void ntb_transport_link_down(struct ntb_transport_qp *qp)
>
> qp->client_ready = false;
>
> + if (!qp->link_is_up)
> + cancel_delayed_work_sync(&qp->link_work);
> +
[Severity: High]
This isn't a bug introduced by this patch, but does skipping work
cancellation here create a race condition?
If qp->link_is_up is true, we skip cancel_delayed_work_sync(). If
ntb_qp_link_work() happens to be executing concurrently and gets preempted
right after successfully checking client_ready, the concurrent link_down
will set client_ready to false and clear the SPADs. When ntb_qp_link_work()
later resumes, it will overwrite the cleared SPADs with valid capabilities,
corrupting the teardown state.
> + /* Stop advertising capabilities before withdrawing QP readiness. */
> + if (qp->caps_spad)
> + ntb_peer_spad_write(qp->ndev, PIDX, qp->caps_spad, 0);
> +
> ntb_qp_up_request(qp, false);
[Severity: High]
Similar to the link-up path, is a dma_wmb() needed here?
Without a write barrier, the peer could observe the withdrawal of QP
readiness before the capabilities are actually zeroed out in the SPADs.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260914084838.2158249-1-den@valinux.co.jp?part=5
next prev parent reply other threads:[~2026-09-15 8:50 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 8:48 [PATCH net-next v4 00/10] net: ntb_netdev: Preserve checksum offload across NTB Koichiro Den
2026-09-14 8:48 ` [PATCH net-next v4 01/10] NTB: ntb_transport: Order RX descriptor reads after completion Koichiro Den
2026-09-19 0:36 ` Joe Damato
2026-09-19 12:37 ` Koichiro Den
2026-09-14 8:48 ` [PATCH net-next v4 02/10] NTB: ntb_transport: Use little-endian shared fields Koichiro Den
2026-09-19 0:54 ` Joe Damato
2026-09-19 13:06 ` Koichiro Den
2026-09-14 8:48 ` [PATCH net-next v4 03/10] NTB: ntb_transport: Order RX entry completion Koichiro Den
2026-09-19 1:10 ` Joe Damato
2026-09-19 12:53 ` Koichiro Den
2026-09-14 8:48 ` [PATCH net-next v4 04/10] NTB: ntb_transport: Keep local QP link requests separate Koichiro Den
2026-09-17 20:49 ` netdev-bot+sashiko
2026-09-14 8:48 ` [PATCH net-next v4 05/10] NTB: ntb_transport: Exchange client capabilities at link-up Koichiro Den
2026-09-15 8:50 ` sashiko-bot [this message]
2026-09-19 12:51 ` Koichiro Den
2026-09-17 20:49 ` netdev-bot+sashiko
2026-09-14 8:48 ` [PATCH net-next v4 06/10] NTB: ntb_transport: Add per-payload client metadata Koichiro Den
2026-09-14 8:48 ` [PATCH net-next v4 07/10] net: ntb_netdev: Reject short RX frames Koichiro Den
2026-09-19 1:14 ` Joe Damato
2026-09-14 8:48 ` [PATCH net-next v4 08/10] net: ntb_netdev: Factor out RX statistics update Koichiro Den
2026-09-14 8:48 ` [PATCH net-next v4 09/10] net: ntb_netdev: Introduce an optional packet header, ntb_netdev_hdr Koichiro Den
2026-09-17 20:49 ` netdev-bot+sashiko
2026-09-14 8:48 ` [PATCH net-next v4 10/10] net: ntb_netdev: Preserve CHECKSUM_PARTIAL across NTB Koichiro Den
2026-09-17 20:49 ` netdev-bot+sashiko
2026-10-09 5:10 ` [PATCH net-next v4 00/10] net: ntb_netdev: Preserve checksum offload " Koichiro Den
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=20260915085012.E9C8E1F000FF@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