From: sashiko-bot@kernel.org
To: "Oguzhan KAYNAK" <kaynak.oguzhan0@gmail.com>
Cc: ntb@lists.linux.dev
Subject: Re: [RFC PATCH 3/3] NTB: ntb_transport: Keep scratchpads in a cleanup before first link-up
Date: Sun, 06 Dec 2026 07:35:14 +0000 [thread overview]
Message-ID: <sashiko-outbox-252251@kernel.org> (raw)
In-Reply-To: <20261206070959.8519-4-kaynak.oguzhan0@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] NTB: ntb_transport_link_cleanup() skips spad clear after
aborted link setup
- [High] NTB: ntb_transport_probe() leaves stale scratchpads before
ntb_link_enable()
- [Low] NTB: Fixes tag cites 7b4f2d3c3b82 instead of e26a5843f7f5 for
probe link event
--
commit 0fa9c18ea14b2dcf84bc7348aae49eb950b85bed
Author: Oguzhan KAYNAK <kaynak.oguzhan0@gmail.com>
> NTB: ntb_transport: Keep scratchpads in a cleanup before first link-up
>
> ntb_transport_link_cleanup() clears our scratchpads, which hold what the
> peer writes for the link setup. Right after probe, the cleanup for the
> link-down seen at probe time can run while the peer is already writing
> them for the new link. If it clears them in the middle of the peer's
> writes and our link_work then writes ours, the peer reads ours, finishes
> its setup and does not write again; our link_work keeps reading an
> incomplete set and the link stays down.
>
> In a cleanup work before the transport link has been up for the first
> time, keep the scratchpads, except QP_LINKS: a peer that stayed loaded
> may have set a bit in it for an earlier link, and it sets the bit again
> only after reading the information we write once the cleanup is done.
> After the first link-up a cleanup clears everything as before;
> ntb_transport_free() always does.
>
> This assumes the scratchpads hold nothing from an earlier link at probe
> time. That is normally true after our ntb_transport_free() or a device
> reset, but not after a crash or kexec; there the probe-time cleanup used
> to clear them.
>
> Seen with a test-only delay of the cleanup work on two KVM guests joined
> by an emulated NTB device (qemu-ntb): traces showed the peer finishing
> its setup while our MW sizes stayed zero.
>
> Written with an AI coding assistant (Claude); not tested on NTB hardware.
>
> Fixes: 7b4f2d3c3b82 ("NTB: No sleeping in interrupt context")
> Signed-off-by: Oguzhan KAYNAK <kaynak.oguzhan0@gmail.com>
[Severity: Low]
Should the Fixes tag point to e26a5843f7f5 ("NTB: Split ntb_hw_intel and
ntb_transport drivers") instead? In 7b4f2d3c3b82 ("NTB: No sleeping in
interrupt context"), probe only scheduled link_work when the link was up;
the probe-time ntb_link_event() that queues link_cleanup came later.
> diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
> index 478f2f6a399f5..5734a7a841b31 100644
> --- a/drivers/ntb/ntb_transport.c
> +++ b/drivers/ntb/ntb_transport.c
[ ... ]
> @@ -1056,8 +1058,16 @@ static void ntb_transport_link_cleanup(struct ntb_transport_ctx *nt,
>
> /* The scratchpad registers keep the values if the remote side
> * goes down, blast them now to give them a sane value the next
> - * time they are accessed
> + * time they are accessed. Before the first link-up, keep the link
> + * information the peer may already be writing for this link, but
> + * clear QP_LINKS: a peer that stayed loaded may have set a bit in
> + * it for an earlier link, and it sets it again only after reading
> + * the information we write once this cleanup is done.
> */
> + if (for_event && !nt->link_was_up) {
> + ntb_spad_write(nt->ndev, QP_LINKS, 0);
> + return;
> + }
> count = ntb_spad_count(nt->ndev);
> for (i = 0; i < count; i++)
> ntb_spad_write(nt->ndev, i, 0);
[Severity: High]
Can skipping the probe-time scratchpad clear leave stale values from
before probe in place?
ntb_transport_probe() enables the link without zeroing local scratchpads.
Stale values survive without a crash or kexec: ntb_perf fills local
scratchpads with 0xffffffff and only clears PERF_SPAD_CMD on disable, and
ntb_transport_free() clears them before calling ntb_link_disable().
When local use_msi is false while the peer has MSI enabled,
ntb_transport_setup_qp_msi() returns early without clearing the MSI slots.
The peer's ntb_transport_setup_qp_peer_msi() then reads 0xffffffff as
addr_offset and ntb_msi_peer_trigger() writes out of bounds past peer_mws.
Zeroing local scratchpads in ntb_transport_probe() before
ntb_link_enable() and only scheduling link_work if ntb_link_is_up() is
true would avoid both the stale scratchpads and the probe-time race.
> @@ -1193,6 +1203,7 @@ static void ntb_transport_link_work(struct work_struct *work)
> }
>
> /* Publish the link only after every QP has been set up. */
> + nt->link_was_up = true;
> atomic_set_release(&nt->link_is_up, true);
>
> /*
[Severity: High]
Because nt->link_was_up is only set after full setup completes, can a
failed or aborted initial link-up leave peer-written scratchpads uncleaned
across a real link-down?
If the peer writes MW0_SZ_*, NUM_MWS, NUM_QPS, and VERSION and then
ntb_transport_link_work() exits early (for example when ntb_set_mw() fails
with -ENOMEM or the link drops mid-handshake), the subsequent link-down
cleanup still sees !nt->link_was_up and skips clearing those scratchpads.
On the next link-up after the peer reconfigures (such as reducing
max_mw_size), VERSION still matches NTB_TRANSPORT_VERSION.
ntb_transport_link_work() can read stale or torn MW sizes, repeating the
-ENOMEM bailout or configuring the inbound MW and RX ring for the old size.
Similarly, if ntb_msi_setup_mws() fails on the retry and clears
nt->use_msi, ntb_transport_setup_qp_msi() returns early and leaves the
earlier local MSI scratchpads set, so the peer enables MSI against an
unregistered window.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206070959.8519-1-kaynak.oguzhan0@gmail.com?part=3
prev parent reply other threads:[~2026-12-06 7:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 7:09 [RFC PATCH 0/3] NTB: ntb_transport: Lost link-up after a late link cleanup Oguzhan KAYNAK
2026-12-06 7:09 ` [RFC PATCH 1/3] NTB: ntb_transport: Run a pending link cleanup before the next link setup Oguzhan KAYNAK
2026-12-06 7:33 ` sashiko-bot
2026-12-06 7:09 ` [RFC PATCH 2/3] NTB: ntb_transport: Retry link setup on a zero peer MW size Oguzhan KAYNAK
2026-12-06 7:32 ` sashiko-bot
2026-12-06 7:09 ` [RFC PATCH 3/3] NTB: ntb_transport: Keep scratchpads in a cleanup before first link-up Oguzhan KAYNAK
2026-12-06 7:35 ` sashiko-bot [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=sashiko-outbox-252251@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kaynak.oguzhan0@gmail.com \
--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