* [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side
@ 2026-11-23 20:14 Maxime Chevallier (Netdev Foundation)
2026-11-24 11:29 ` Matthieu Baerts
2026-11-24 20:16 ` netdev-bot+sashiko
0 siblings, 2 replies; 7+ messages in thread
From: Maxime Chevallier (Netdev Foundation) @ 2026-11-23 20:14 UTC (permalink / raw)
To: Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet,
Willem de Bruijn, Paolo Abeni, Simon Horman, Russell King,
Shuah Khan, Bobby Eshleman, Stanislav Fomichev, Breno Leitao,
matttbe
Cc: Maxime Chevallier (Netdev Foundation),
thomas.petazzoni, netdev, linux-kernel, linux-kselftest
The logic used to detect if the kselftest remote we're interacting with
is directly connected to us uses link renegotiation to flap the link,
that way we know if there's a switch between the remote and the DUT.
However the current logic is racy. It triggers a link renegotiation,
wait for the link to come back up locally, and looks on the remote if
the link flap counter changed.
It's possible that this entire cycle happens locally before the peer
reports the link flap, in which case it reports that we're not directly
connected to the peer when we actually are.
Solve that by reversing the logic : Trigger a link renegotiation on the
peer, and check if we see the link flap locally. The current
wait_for_aneg() already waits for a full "up - down - up" cycle, so
it doens't really matter which side of the link flaps first here.
This was found in the stmmac CI setup, between an Intel I350-T4 card and
an iMX8mp + KSZ9131 board. The Pause test was failing seemingly at
random, due to the link flap occuring either on the host or the remote
first.
Fixes: 8f897f26ef34 ("selftests: drv-net: pause: Validate the pause autonegotiation with a partner")
Signed-off-by: Maxime Chevallier (Netdev Foundation) <maxime.chevallier@bootlin.com>
---
.../testing/selftests/drivers/net/hw/pause.py | 20 +++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/hw/pause.py b/tools/testing/selftests/drivers/net/hw/pause.py
index ca4a55e59c30..31518b7ec53b 100755
--- a/tools/testing/selftests/drivers/net/hw/pause.py
+++ b/tools/testing/selftests/drivers/net/hw/pause.py
@@ -90,8 +90,8 @@ def controllable_lp(cfg):
For low level ethtool tests, we need to have the remote directly connected
to the local host (i.e. not through a switch).
- This is tested by taking triggering a link renegotiation and checking the
- carrier_changes counter on the partner.
+ This is tested by triggering a link renegotiation on the remote and
+ checking that the local link flaps.
:returns: True if the remote is our link partner
"""
@@ -99,17 +99,17 @@ def controllable_lp(cfg):
if controllable is not None:
return controllable
- before = int(cmd(f"cat /sys/class/net/{cfg.remote_ifname}/carrier_changes",
- host=cfg.remote).stdout)
-
- ret, _ = ethtool_ret(f"-r {cfg.ifname}", is_get=False)
+ ret, _ = ethtool_ret(f"-r {cfg.remote_ifname}", is_get=False,
+ host=cfg.remote)
if ret != 0:
- raise KsftSkipEx(f"ethtool -r {cfg.ifname} failed: {errno.errorcode.get(ret, ret)}")
+ raise KsftSkipEx(f"ethtool -r {cfg.remote_ifname} failed: {errno.errorcode.get(ret, ret)}")
- wait_for_aneg(cfg, link_drop=True)
+ try:
+ wait_for_aneg(cfg, link_drop=True)
+ cfg.lp_controllable = True
+ except TimeoutError:
+ cfg.lp_controllable = False
- cfg.lp_controllable = int(cmd(f"cat /sys/class/net/{cfg.remote_ifname}/carrier_changes",
- host=cfg.remote).stdout) > before
return cfg.lp_controllable
def require_controllable_lp(cfg):
--
2.56.1
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side 2026-11-23 20:14 [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side Maxime Chevallier (Netdev Foundation) @ 2026-11-24 11:29 ` Matthieu Baerts 2026-11-24 14:28 ` Maxime Chevallier 2026-11-24 20:16 ` netdev-bot+sashiko 1 sibling, 1 reply; 7+ messages in thread From: Matthieu Baerts @ 2026-11-24 11:29 UTC (permalink / raw) To: Maxime Chevallier (Netdev Foundation) Cc: Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet, Willem de Bruijn, Paolo Abeni, Simon Horman, Russell King, Shuah Khan, Bobby Eshleman, Stanislav Fomichev, Breno Leitao, thomas.petazzoni, netdev, linux-kernel, linux-kselftest Hi Maxime, On 23/11/2026 21:14, Maxime Chevallier (Netdev Foundation) wrote: > The logic used to detect if the kselftest remote we're interacting with > is directly connected to us uses link renegotiation to flap the link, > that way we know if there's a switch between the remote and the DUT. > > However the current logic is racy. It triggers a link renegotiation, > wait for the link to come back up locally, and looks on the remote if > the link flap counter changed. > > It's possible that this entire cycle happens locally before the peer > reports the link flap, in which case it reports that we're not directly > connected to the peer when we actually are. > > Solve that by reversing the logic : Trigger a link renegotiation on the > peer, and check if we see the link flap locally. The current > wait_for_aneg() already waits for a full "up - down - up" cycle, so > it doens't really matter which side of the link flaps first here. > > This was found in the stmmac CI setup, between an Intel I350-T4 card and > an iMX8mp + KSZ9131 board. The Pause test was failing seemingly at > random, due to the link flap occuring either on the host or the remote > first. Thank you for the fix, but it looks like it is introducing new issues on BCM57508: https://netdev.bots.linux.dev/branch_deltas/net-next-hw-2026-11-24--08-00.html Do you mind looking at that, and mask this test on your side for the two boards you mentioned, please? :) pw-bot: cr Cheers, Matt ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side 2026-11-24 11:29 ` Matthieu Baerts @ 2026-11-24 14:28 ` Maxime Chevallier 2026-11-24 16:15 ` Matthieu Baerts 0 siblings, 1 reply; 7+ messages in thread From: Maxime Chevallier @ 2026-11-24 14:28 UTC (permalink / raw) To: Matthieu Baerts Cc: Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet, Willem de Bruijn, Paolo Abeni, Simon Horman, Russell King, Shuah Khan, Bobby Eshleman, Stanislav Fomichev, Breno Leitao, thomas.petazzoni, netdev, linux-kernel, linux-kselftest On 11/24/26 12:29, Matthieu Baerts wrote: > Hi Maxime, > > On 23/11/2026 21:14, Maxime Chevallier (Netdev Foundation) wrote: >> The logic used to detect if the kselftest remote we're interacting with >> is directly connected to us uses link renegotiation to flap the link, >> that way we know if there's a switch between the remote and the DUT. >> >> However the current logic is racy. It triggers a link renegotiation, >> wait for the link to come back up locally, and looks on the remote if >> the link flap counter changed. >> >> It's possible that this entire cycle happens locally before the peer >> reports the link flap, in which case it reports that we're not directly >> connected to the peer when we actually are. >> >> Solve that by reversing the logic : Trigger a link renegotiation on the >> peer, and check if we see the link flap locally. The current >> wait_for_aneg() already waits for a full "up - down - up" cycle, so >> it doens't really matter which side of the link flaps first here. >> >> This was found in the stmmac CI setup, between an Intel I350-T4 card and >> an iMX8mp + KSZ9131 board. The Pause test was failing seemingly at >> random, due to the link flap occuring either on the host or the remote >> first. > > Thank you for the fix, but it looks like it is introducing new issues on > BCM57508: > > > https://netdev.bots.linux.dev/branch_deltas/net-next-hw-2026-11-24--08-00.html Arg seems that on this setup, the remote (I don't know which one it is) doesn't support 'ethtool -r', damn :( I'll take another approach then. > > Do you mind looking at that, and mask this test on your side for the two > boards you mentioned, please? :) Np, tests are masked on all boards though, I've done more runs and the race shows on all of them (all are now connected to the same type of NIC). Thanks for the report ! Maxime > pw-bot: cr > > Cheers, > Matt ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side 2026-11-24 14:28 ` Maxime Chevallier @ 2026-11-24 16:15 ` Matthieu Baerts 2026-11-24 16:26 ` Maxime Chevallier 0 siblings, 1 reply; 7+ messages in thread From: Matthieu Baerts @ 2026-11-24 16:15 UTC (permalink / raw) To: Maxime Chevallier Cc: Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet, Willem de Bruijn, Paolo Abeni, Simon Horman, Russell King, Shuah Khan, Bobby Eshleman, Stanislav Fomichev, Breno Leitao, thomas.petazzoni, netdev, linux-kernel, linux-kselftest On 24/11/2026 15:28, Maxime Chevallier wrote: > On 11/24/26 12:29, Matthieu Baerts wrote: >> Hi Maxime, >> >> On 23/11/2026 21:14, Maxime Chevallier (Netdev Foundation) wrote: >>> The logic used to detect if the kselftest remote we're interacting with >>> is directly connected to us uses link renegotiation to flap the link, >>> that way we know if there's a switch between the remote and the DUT. >>> >>> However the current logic is racy. It triggers a link renegotiation, >>> wait for the link to come back up locally, and looks on the remote if >>> the link flap counter changed. >>> >>> It's possible that this entire cycle happens locally before the peer >>> reports the link flap, in which case it reports that we're not directly >>> connected to the peer when we actually are. >>> >>> Solve that by reversing the logic : Trigger a link renegotiation on the >>> peer, and check if we see the link flap locally. The current >>> wait_for_aneg() already waits for a full "up - down - up" cycle, so >>> it doens't really matter which side of the link flaps first here. >>> >>> This was found in the stmmac CI setup, between an Intel I350-T4 card and >>> an iMX8mp + KSZ9131 board. The Pause test was failing seemingly at >>> random, due to the link flap occuring either on the host or the remote >>> first. >> >> Thank you for the fix, but it looks like it is introducing new issues on >> BCM57508: >> >> >> https://netdev.bots.linux.dev/branch_deltas/net-next-hw-2026-11-24--08-00.html > > Arg seems that on this setup, the remote (I don't know which one it is) doesn't > support 'ethtool -r', damn :( These hosts are running Fedora 44. They have ethtool 7.0. I can upgrade to the latest from F44 repos (7.2) if it can help. > I'll take another approach then. > >> >> Do you mind looking at that, and mask this test on your side for the two >> boards you mentioned, please? :) > > Np, tests are masked on all boards though, I've done more runs and the race > shows on all of them (all are now connected to the same type of NIC). Thanks! Cheers, Matt ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side 2026-11-24 16:15 ` Matthieu Baerts @ 2026-11-24 16:26 ` Maxime Chevallier 2026-11-24 17:29 ` Andrew Lunn 0 siblings, 1 reply; 7+ messages in thread From: Maxime Chevallier @ 2026-11-24 16:26 UTC (permalink / raw) To: Matthieu Baerts Cc: Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet, Willem de Bruijn, Paolo Abeni, Simon Horman, Russell King, Shuah Khan, Bobby Eshleman, Stanislav Fomichev, Breno Leitao, thomas.petazzoni, netdev, linux-kernel, linux-kselftest On 11/24/26 17:15, Matthieu Baerts wrote: > On 24/11/2026 15:28, Maxime Chevallier wrote: >> On 11/24/26 12:29, Matthieu Baerts wrote: >>> Hi Maxime, >>> >>> On 23/11/2026 21:14, Maxime Chevallier (Netdev Foundation) wrote: >>>> The logic used to detect if the kselftest remote we're interacting with >>>> is directly connected to us uses link renegotiation to flap the link, >>>> that way we know if there's a switch between the remote and the DUT. >>>> >>>> However the current logic is racy. It triggers a link renegotiation, >>>> wait for the link to come back up locally, and looks on the remote if >>>> the link flap counter changed. >>>> >>>> It's possible that this entire cycle happens locally before the peer >>>> reports the link flap, in which case it reports that we're not directly >>>> connected to the peer when we actually are. >>>> >>>> Solve that by reversing the logic : Trigger a link renegotiation on the >>>> peer, and check if we see the link flap locally. The current >>>> wait_for_aneg() already waits for a full "up - down - up" cycle, so >>>> it doens't really matter which side of the link flaps first here. >>>> >>>> This was found in the stmmac CI setup, between an Intel I350-T4 card and >>>> an iMX8mp + KSZ9131 board. The Pause test was failing seemingly at >>>> random, due to the link flap occuring either on the host or the remote >>>> first. >>> >>> Thank you for the fix, but it looks like it is introducing new issues on >>> BCM57508: >>> >>> >>> https://netdev.bots.linux.dev/branch_deltas/net-next-hw-2026-11-24--08-00.html >> >> Arg seems that on this setup, the remote (I don't know which one it is) doesn't >> support 'ethtool -r', damn :( > > These hosts are running Fedora 44. They have ethtool 7.0. I can upgrade > to the latest from F44 repos (7.2) if it can help. Looks like it's rather the HW or driver that doesn't support this :( But that's OK, I think we should ask the least possible features from the remotes, the rest of the selftest should already handle the missing capabilities just fine, Thanks :) Maxime ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side 2026-11-24 16:26 ` Maxime Chevallier @ 2026-11-24 17:29 ` Andrew Lunn 0 siblings, 0 replies; 7+ messages in thread From: Andrew Lunn @ 2026-11-24 17:29 UTC (permalink / raw) To: Maxime Chevallier Cc: Matthieu Baerts, Jakub Kicinski, davem, Eric Dumazet, Willem de Bruijn, Paolo Abeni, Simon Horman, Russell King, Shuah Khan, Bobby Eshleman, Stanislav Fomichev, Breno Leitao, thomas.petazzoni, netdev, linux-kernel, linux-kselftest > Looks like it's rather the HW or driver that doesn't support this :( > > But that's OK, I think we should ask the least possible features from the > remotes, the rest of the selftest should already handle the missing capabilities > just fine, Supporting nway_reset is trivial, at least for drivers using phylink/phylib. So we should encourage it. So i would say if the device we are trying to test does not support it, the test should fail. If the link peer does not have it, then i would be more forgiving, we don't want a developer to be forced to hack on somebody else driver in order to get their own driver to pass. Andrew ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side 2026-11-23 20:14 [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side Maxime Chevallier (Netdev Foundation) 2026-11-24 11:29 ` Matthieu Baerts @ 2026-11-24 20:16 ` netdev-bot+sashiko 1 sibling, 0 replies; 7+ messages in thread From: netdev-bot+sashiko @ 2026-11-24 20:16 UTC (permalink / raw) To: maxime.chevallier Cc: andrew, kuba, davem, edumazet, willemb, pabeni, horms, linux, skhan, bobbyeshleman, sdf, leitao, matttbe, thomas.petazzoni, netdev, linux-kernel, linux-kselftest Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 4 · Low: 1 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] In controllable_lp() (tools/testing/selftests/drivers/net/hw/pause.py, lines 107-111), the… - [Medium] Before this patch, controllable_lp() ran `ethtool -r {cfg.ifname}` on the local device and turned any failure into… - [Medium] The new detection in controllable_lp() can still return a false 'not directly connected', the same failure the commit claims to… - [Medium] The new controllable_lp() decides the remote is the link partner if it sees any local carrier drop followed by link-up within… - [Low] controllable_lp() now runs `ethtool -r` on the remote instead of the local device (lines 102-105). -- selftests: drv-net: pause: detect the link partner from the remote side This commit reverses the direct-link detection in controllable_lp(). The old code renegotiated locally and then checked the remote's carrier_changes counter. The new code runs ethtool -r on the remote and waits for the local carrier to drop and come back up. A TimeoutError from wait_for_aneg() is now taken to mean the remote is not the link partner. > diff --git a/tools/testing/selftests/drivers/net/hw/pause.py b/tools/testing/selftests/drivers/net/hw/pause.py > index ca4a55e59c30f..31518b7ec53ba 100755 > --- a/tools/testing/selftests/drivers/net/hw/pause.py > +++ b/tools/testing/selftests/drivers/net/hw/pause.py [ ... ] > @@ -99,17 +99,17 @@ def controllable_lp(cfg): > if controllable is not None: > return controllable > > - before = int(cmd(f"cat /sys/class/net/{cfg.remote_ifname}/carrier_changes", > - host=cfg.remote).stdout) > - > - ret, _ = ethtool_ret(f"-r {cfg.ifname}", is_get=False) > + ret, _ = ethtool_ret(f"-r {cfg.remote_ifname}", is_get=False, > + host=cfg.remote) > if ret != 0: > - raise KsftSkipEx(f"ethtool -r {cfg.ifname} failed: {errno.errorcode.get(ret, ret)}") > + raise KsftSkipEx(f"ethtool -r {cfg.remote_ifname} failed: {errno.errorcode.get(ret, ret)}") [Severity: Medium] Before this change, the local ethtool -r also checked that the local device supports renegotiation. If it failed, every require_controllable_lp() user was skipped. Now that the probe runs on the remote, is that guarantee gone? pause_autoneg_off_while_link_autoneg_on() still depends on it: require_link_autoneg(cfg) pause_setup(cfg) require_controllable_lp(cfg) ... ethtool(f"-r {cfg.ifname}") wait_for_aneg(cfg, link_drop=True) This ethtool() call runs with fail=True. require_link_autoneg() only checks supports-auto-negotiation. If the local driver has no .nway_reset (for example gianfar, mlx5 or enetc), ethtool_nway_reset() returns -EOPNOTSUPP: net/ethtool/ioctl.c:ethtool_nway_reset() { ... if (!dev->ethtool_ops->nway_reset) return -EOPNOTSUPP; ... } Take such a DUT paired with a remote that does support ethtool -r. Would this test now fail with CmdExitFailure where it used to skip? [Severity: Low] The skip condition here also moves from the local device to the remote one, and the commit message doesn't mention it. pause_advertising_test() only uses the result to decide whether to also check the peer's lp_advertising: pause_setup(cfg) lp = controllable_lp(cfg) controllable_lp() raises KsftSkipEx instead of returning False. So when the remote driver has no .nway_reset, every variant of pause_advertising_test() is now skipped, even though the local advertising checks don't need the peer. Is that intended? In a switched setup, the old code saw the local flap within a few seconds. The new code only flaps the remote's switch port. It then waits the full 15 second deadline in wait_for_aneg() for a local drop that never comes. Could the commit message mention these trade-offs? Right now it only says: it doens't really matter which side of the link flaps first here. > > - wait_for_aneg(cfg, link_drop=True) > + try: > + wait_for_aneg(cfg, link_drop=True) > + cfg.lp_controllable = True [Severity: Medium] Can a flap that only happened on the local side be taken for the remote's renegotiation? Any local carrier drop followed by link-up inside this window gives lp_controllable = True. Nothing shows where the drop came from. The first call to controllable_lp(), whose result is cached, is in pause_advertising_test(). That test runs right after pause_test_support(), which only reconfigures the local port: link autoneg on and off, forced speed, and repeated ethtool -A. Its deferred cleanup restores ethtool -s <ifname> autoneg on and the original pause settings, and either of these can restart local aneg. pause_setup() then ends with: wait_for_link(cfg) This only checks that carrier reads 1. It does not wait for a pending renegotiation to settle. Some drivers report link-down asynchronously: polled C45 PHYs, phylink resolve work, firmware or watchdog link handling. With those, the late local drop can land inside this polling window. In a switched topology, would that cache lp_controllable = True? The LP-dependent tests would then treat the switch port as the link partner, and their lp_advertising and pause resolution checks would fail. The old approach read the remote's carrier_changes, which a local-only flap behind a switch cannot change. > + except TimeoutError: > + cfg.lp_controllable = False [Severity: Medium] Does this except clause catch more than the "not directly connected" case? wait_for_aneg() can raise TimeoutError in two places, and both come from wait_file(): def wait_for_aneg(cfg, link_drop=False, timeout=15): ... try: wait_file(f"/sys/class/net/{cfg.ifname}/carrier", lambda x: x.strip() == "0", deadline=timeout if link_drop else 2) except TimeoutError: if link_drop: raise wait_for_link(cfg, timeout) Only the first one means the remote isn't the link partner. Suppose the local carrier does drop after the remote ethtool -r, but the link doesn't come back within 15 seconds. The TimeoutError from wait_for_link() also lands here, and lp_controllable = False is cached. Every later require_controllable_lp() caller would then skip with "... is not directly connected to ...". pause_advertising_test() would carry on with lp=False. Before this patch, that timeout propagated and the test reported an error. Should the link-up wait stay outside the try block? [Severity: Medium] Can this still give a false "not directly connected" result, which is the problem this patch sets out to fix? The remote renegotiation goes through Remote.cmd(), which starts a new ssh process for each command. nway_reset implementations usually just set ANRESTART and return. Local polling only begins after the ssh process exits. wait_for_aneg(link_drop=True) then polls the carrier level through wait_file(), sleeping 5ms between reads. The local link might go down and come back up before the first read, or between two reads. Then carrier never reads "0", the 15 second deadline expires, and lp_controllable = False is cached. The commit message says: The current wait_for_aneg() already waits for a full "up - down - up" cycle, so it doens't really matter which side of the link flaps first here. That only seems to hold if the link is still down when polling starts. On 1000BASE-T copper, aneg takes more than a second, so the setup described in the commit message probably won't hit this. Faster links might. Would it help to read the local /sys/class/net/<ifname>/carrier_changes before the remote ethtool -r, and then wait for it to increase and for carrier to read 1? That way the test doesn't depend on catching the down state as it happens. [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123201406.479904-1-maxime.chevallier%40bootlin.com ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-24 20:16 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-23 20:14 [PATCH net] selftests: drv-net: pause: detect the link partner from the remote side Maxime Chevallier (Netdev Foundation) 2026-11-24 11:29 ` Matthieu Baerts 2026-11-24 14:28 ` Maxime Chevallier 2026-11-24 16:15 ` Matthieu Baerts 2026-11-24 16:26 ` Maxime Chevallier 2026-11-24 17:29 ` Andrew Lunn 2026-11-24 20:16 ` netdev-bot+sashiko
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®