[RFC PATCH 2/3] NTB: ntb_transport: Retry link setup on a zero peer MW size
From: Oguzhan KAYNAK
Date: Sun Dec 06 2026 - 02:11:07 EST
ntb_transport_link_work() reads the peer's memory window sizes from the
scratchpads and passes them to ntb_set_mw(), which returns -EINVAL for a
zero size. link_work then frees the MWs and stops retrying, as it does
for an allocation failure, so the link never comes up.
The peer writes VERSION last, but a link cleanup on our side clears all
our scratchpads, and when that lands while the peer is writing them,
VERSION can be set while a size is still zero. That is not a failure:
retry the link setup, the peer writes the scratchpads again on its next
try.
Seen with a test-only delay of the cleanup work on two KVM guests joined
by an emulated NTB device (qemu-ntb), with only the previous patch
applied: a trace showed VERSION read as set and the MW0 size as zero,
after which link_work gave up. The next patch avoids the clear before
the first link-up, but a cleanup after it still clears everything.
A peer that reports a zero size for good now keeps link_work retrying
instead of stopping it.
Written with an AI coding assistant (Claude); not tested on NTB hardware.
Fixes: 84f766855f61 ("ntb: stop link work when we do not have memory")
Signed-off-by: Oguzhan KAYNAK <kaynak.oguzhan0@xxxxxxxxx>
---
drivers/ntb/ntb_transport.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index 31c214d14..478f2f6a3 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -1172,6 +1172,14 @@ static void ntb_transport_link_work(struct work_struct *work)
dev_dbg(&pdev->dev, "Remote MW%d size = %#llx\n", i, val64);
+ /*
+ * A zero size is not a failure: a link cleanup on our side
+ * cleared the scratchpads while the peer was writing them.
+ * Retry; the peer writes them again on its next try.
+ */
+ if (!val64)
+ goto out;
+
rc = ntb_set_mw(nt, i, val64);
if (rc)
goto out1;
--
2.34.1