* [PATCH net] net/ncsi: fix channel loop termination when Channel Count is 0
@ 2026-11-19 10:06 Sihyeon Park
0 siblings, 0 replies; only message in thread
From: Sihyeon Park @ 2026-11-19 10:06 UTC (permalink / raw)
To: sam, fercerpav
Cc: netdev, linux-kernel, davem, edumazet, kuba, pabeni, horms,
delphine_cc_chiu, Sihyeon Park
ncsi_probe_channel() and ncsi_suspend_channel() (state
ncsi_dev_state_suspend_gls) walk the channels of a package by
incrementing ndp->channel_probe_id and stop only when it becomes equal to
ndp->channel_count. channel_count is copied unchecked from the Channel
Count field of the Get Capabilities response in ncsi_rsp_handler_gc().
If a Network Controller reports Channel Count 0, channel_probe_id is
already 1 when it is first compared in the suspend_gls state, so the
equality never holds. The driver then keeps sending Get Link Status to
channel IDs 0, 1, 2, ... and never reaches Disable Channel Network Tx /
Disable Channel, so the reconfiguration started by a single link-down
AEN never completes and NC-SI does not recover when the link comes back.
If the link flaps (down/up/down) inside that window, the driver
additionally logs
Invalid state 0x3 on 0:0
NCSI: Handler for AEN type 0x0 returned -22
Wrong NCSI state 0x100 in workqueue
and channel monitoring stays stopped.
DSP0222 defines Channel Count as the number of channels supported by the
controller, so a conforming controller reports at least 1; this is a
robustness fix for non-conforming controllers, firmware bugs and
emulators. One such emulator is libslirp's NC-SI responder (used by QEMU
user networking for the Aspeed BMC machines), whose Get Capabilities
response leaves Channel Count at 0.
The probe loop uses the same comparison. In the tests below it did not
hang, because the Get Capabilities response was processed before the
check that follows the GC command, so 0 == 0 held and probing moved on to
Deselect Package. Whether it can hang depends on that ordering; no hang
was observed in the probe path.
Use ">=" instead of "==" in both termination checks so that neither loop
can run past the reported channel count. The suspend path change fixes
the observed hang; the probe path change keeps the two loops consistent
and removes the ordering dependency.
Channel Count is not validated in ncsi_rsp_handler_gc() instead, because
rejecting or clamping a count of 0 would mean deciding what that value
should mean for a non-conforming controller. Fixing the loop bounds
handles any reported value where it is used and does not change
behaviour for conforming controllers.
Tested on QEMU 11.1.3 romulus-bmc (aspeed_g5_defconfig, net tree at
e203d8a4751d) with a minimal initramfs and a loopback NC-SI controller
emulator (1 package, 1 channel) reporting Channel Count 0 or 1. Events:
(A) link-down AEN, link-up 15 s later; (B) down, up, down 0.5 s apart,
link-up 15 s later. Result measured 180 s after the final link-up:
kernel count event after the event ch0 GLS/60 s
unpatched 0 A GLS to ch 0,1,2,..., no DCNT/DC 1
unpatched 0 B GLS stops, monitor stopped 0
unpatched 1 A, B DCNT, DC, DP, ..., EC, AE 58
patched 0 A, B DCNT, DC, DP, ..., EC, AE 58
patched 1 A, B DCNT, DC, DP, ..., EC, AE 58
(GLS: Get Link Status, DCNT: Disable Channel Network Tx, DC: Disable
Channel, DP: Deselect Package, EC: Enable Channel, AE: AEN Enable)
With the patch, Channel Count 0 behaves exactly like Channel Count 1
(same command counts); Channel Count 1 is unchanged.
An AI coding assistant (Claude Code) was used to analyze the problem,
reproduce it in QEMU and draft this patch; I reviewed the change and
the test results.
Fixes: e85e271dec02 ("net/ncsi: Fix the multi thread manner of NCSI driver")
Signed-off-by: Sihyeon Park <me@7xz.dev>
---
net/ncsi/ncsi-manage.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
index 1d63958c4429..c5cf2ca0385c 100644
--- a/net/ncsi/ncsi-manage.c
+++ b/net/ncsi/ncsi-manage.c
@@ -520,7 +520,7 @@ static void ncsi_suspend_channel(struct ncsi_dev_priv *ndp)
goto error;
ndp->channel_probe_id++;
- if (ndp->channel_probe_id == ndp->channel_count) {
+ if (ndp->channel_probe_id >= ndp->channel_count) {
ndp->channel_probe_id = 0;
nd->state = ncsi_dev_state_suspend_dcnt;
}
@@ -1491,7 +1491,7 @@ static void ncsi_probe_channel(struct ncsi_dev_priv *ndp)
ndp->channel_probe_id++;
}
- if (ndp->channel_probe_id == ndp->channel_count) {
+ if (ndp->channel_probe_id >= ndp->channel_count) {
ndp->channel_probe_id = 0;
nd->state = ncsi_dev_state_probe_dp;
}
--
2.56.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-19 10:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 10:06 [PATCH net] net/ncsi: fix channel loop termination when Channel Count is 0 Sihyeon Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®