From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796542514; b=hbY1NuqDuDbNnhI5aWXInw6wv9XDxpxFPVQg1U+Gj7m+L04HDdeDGHKKMgWz0dekyeR8 7kXqccZCiW/56+xJ9Et4+tPRYIBLy/cJp+WJhZSUhoPIxRFArU+wW5AiN3e10OrAAbMCh uOaI/yAlqllbkjuLbTaPA/7fOAcqjqhswgCVTn2L6ppzgD/lbSrT3elk4lHErwLLMhptf 7YYm7/BQ0RUhpbOLo4U/26T/81jZvvb1egmSZWyOM+3xaNDFUNmOQRK4Xf6kLzp8nT0Q6 iu+Jh2hy+8F3ZlpZ9fyZ87ti9iT6zRZLiTnkmEsn85WKJt35ZL9qqIKG3fweyzXni5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796542514; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=t4RxnQaUCeO23gFa+uwvCY5ifNF+h2QH0Pen7f3Ywzc=; b=eVWTzONDySJ6S7J1++v4UMcA6tKlVlF7EYjP9Jskb/GXOsN+LepJksu03w3wCAA1x4rF v23aGrnPivQVdRCKC/ZQbw8FqwhlSRN68XMDrn9hm7GBqIir0AoRyAQwGWsbfiWYIpOwN MHq/+ThBSJjiGnj3SgS+yY+nvcPOMoqpzft+SqJJlO0mURFP/qrbucmioiP7NkAR3NuG7 mXz5lGmGzn3muUZWGuGUW6+RQZMyg/KDUpJYszMBoguefQBqAt70uNeXXTO34JRqdEg4b cNY5cNCG5PCMREv75mnVSVw4na9iDYxsmiLD3IzCuD17p5vzsOhGZ8O037moSwU454g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="bO+/PhNj"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0BEC606A31F for ; Sun, 6 Dec 2026 07:35:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bO+/PhNj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B7A61F0092B; Sun, 6 Dec 2026 07:35:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796542514; bh=t4RxnQaUCeO23gFa+uwvCY5ifNF+h2QH0Pen7f3Ywzc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=bO+/PhNjctuoVQWxhSL+n+r3zySAf/cPLDWKN5A53/5iWx2t4sGVSIz4QUsaeicgK 2ndrpJPpqeX9UQhy7FGify0rUjLWEudXiTp5BZY1qz0Gnd0SHEOkmGpxFdB3ACTCe3 7dMGsk8PXSIRLnGnJp9zuugWkYyMjVJO1btuZsFYgHMvQbm6ugWUsWxVUXFNJtMcTl G4UoHJ8VaOk9acIxS4xmo026YAOukmjyvCZsmeTzeVdeuZ4gsqD5FPZ7mfcT5Bp6kd Vx7QR9QuyrbisEv9MOXppVIHNWFJzKHeF8NRrT5iqX5uFSgwD5cHfuD2nozOK0gYa9 0gOkNNqKlFMcg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH 3/3] NTB: ntb_transport: Keep scratchpads in a cleanup before first link-up Reply-To: sashiko-reviews@lists.linux.dev To: "Oguzhan KAYNAK" Cc: ntb@lists.linux.dev In-Reply-To: <20261206070959.8519-4-kaynak.oguzhan0@gmail.com> References: <20261206070959.8519-1-kaynak.oguzhan0@gmail.com> <20261206070959.8519-4-kaynak.oguzhan0@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 07:35:14 +0000 X-Mailing-List: ntb@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 > 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 [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, > =20 > /* 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 =3D ntb_spad_count(nt->ndev); > for (i =3D 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_str= uct *work) > } > =20 > /* Publish the link only after every QP has been set up. */ > + nt->link_was_up =3D true; > atomic_set_release(&nt->link_is_up, true); > =20 > /* [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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206070959.8519= -1-kaynak.oguzhan0@gmail.com?part=3D3