Skip to contentSkip to conversation

selftests: drv-net: pause: Avoid cleanup failures for unsupported link settings

PATCH Applied Mohsin Bashir 3 participants 4 messages Nov 13 – Nov 17

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 selftests: drv-net: pause: Avoid cleanup failures for unsupported link settings

From: Mohsin Bashir <[email protected]>

pause_setup() saves the initial link settings before tests run. Devices that report link settings but do not support changing them can reject even a no-op restore with EOPNOTSUPP. That turns pause tests that use pause_setup() into cleanup failures.

Fix this by queuing link-setting restores only after a link-setting request has succeeded. Keep pause_test_support coverage for devices that cannot change link settings by falling back to forced MAC pause on the current link. Run the extra link autoneg on/off checks only when those link setting requests are accepted. Tests that force link autoneg off, including pause_autoneg_link_autoneg(), now queue their own autoneg-on restore after the force request succeeds.

Results on fbnic:

Before: # Totals: pass:0 fail:4 xfail:0 xpass:0 skip:24 error:0
After: # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:24 error:0

Fixes cbd8a536cd6d ("selftests: drv-net: Introduce a selftest for ethtool flow control")

---
Changelog:
v3:
- Drop the remaining unconditional autoneg-on restore from pause_setup() and only queue link-setting restores after a link-setting request succeeds.
- Since pause_setup() no longer restores autoneg on, make pause_test_support() and pause_autoneg_link_autoneg() queue their own autoneg-on restores after they successfully force the link.

v2: https://lore.kernel.org/netdev/[email protected]
v1: https://lore.kernel.org/netdev/[email protected]

---
 .../testing/selftests/drivers/net/hw/pause.py | 56 ++++++++++---------
 1 file changed, 30 insertions(+), 26 deletions(-)
tools/testing/selftests/drivers/net/hw/pause.py +30 -26
index ca4a55e59c30..c3398c7452e0 100755
@@ -402,16 +402,13 @@ def pause_setup(cfg):
     if "auto-negotiation" not in link:
         raise KsftSkipEx(f"{cfg.ifname} doesn't report its link modes")
 
-    if link["auto-negotiation"]:
-        defer(cmd, f"ethtool -s {cfg.ifname} autoneg on")
-    elif "speed" in link and "duplex" in link:
-        defer(cmd, f"ethtool -s {cfg.ifname} autoneg off speed {link['speed']} "
-                   f"duplex {link['duplex'].lower()}")
-
     # Local interface admin up, link aneg on
     ip(f"link set {cfg.ifname} up")
     if link["supports-auto-negotiation"] and not link["auto-negotiation"]:
         ethtool(f"-s {cfg.ifname} autoneg on")
+        if "speed" in link and "duplex" in link:
+            defer(cmd, f"ethtool -s {cfg.ifname} autoneg off speed {link['speed']} "
+                       f"duplex {link['duplex'].lower()}")
 
     # Get remote pause params
     ret, params = ethtool_ret(f"-a {cfg.remote_ifname}", host=cfg.remote)
@@ -426,18 +423,14 @@ def pause_setup(cfg):
     if "auto-negotiation" not in link:
         raise KsftSkipEx(f"{cfg.remote_ifname} doesn't report its link modes")
 
-    if link["auto-negotiation"]:
-        defer(cmd, f"ethtool -s {cfg.remote_ifname} autoneg on",
-              host=cfg.remote)
-    elif "speed" in link and "duplex" in link:
-        defer(cmd, f"ethtool -s {cfg.remote_ifname} autoneg off "
-                   f"speed {link['speed']} duplex {link['duplex'].lower()}",
-                   host=cfg.remote)
-
     # Remote interface admin up, link aneg on
     ip(f"link set {cfg.remote_ifname} up", host=cfg.remote)
     if link["supports-auto-negotiation"] and not link["auto-negotiation"]:
         ethtool(f"-s {cfg.remote_ifname} autoneg on", host=cfg.remote)
+        if "speed" in link and "duplex" in link:
+            defer(cmd, f"ethtool -s {cfg.remote_ifname} autoneg off "
+                       f"speed {link['speed']} duplex {link['duplex'].lower()}",
+                       host=cfg.remote)
 
     wait_for_link(cfg)
 
@@ -470,9 +463,12 @@ def pause_test_support(cfg, pauseparams):
 
     forced = forced_link_settings(cfg)
     _, supported = get_local_pause_supported(cfg)
+    link_config_tested = False
 
     # We check that what we can configure in the pause params matches what we
-    # support under various contditions : Link aneg on/off, pause aneg on/off
+    # support under various conditions: link aneg on/off, and pause aneg
+    # on/off. If no link configuration change is supported, fall back to
+    # checking forced MAC pause on the current link.
     ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg on", is_get = False)
     if ret != 0:
         ksft_pr("link autoneg on refused, not tested")
@@ -481,18 +477,23 @@ def pause_test_support(cfg, pauseparams):
                                "link autoneg on")
         expect_pauseparams_set(cfg, pauseparams, True, supported,
                                "link autoneg on")
+        link_config_tested = True
 
     if not forced:
         ksft_pr("link speed unknown, the forced link is not tested")
-        return
-
-    ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg off {forced}", is_get = False)
-    if ret != 0:
-        ksft_pr(f"link autoneg off {forced} refused, not tested")
-        return
-
-    expect_pauseparams_set(cfg, pauseparams, False, supported, "link autoneg off")
-    expect_pauseparams_set(cfg, pauseparams, True, supported, "link autoneg off")
+    else:
+        ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg off {forced}", is_get = False)
+        if ret != 0:
+            ksft_pr(f"link autoneg off {forced} refused, not tested")
+        else:
+            if link_config_tested:
+                defer(cmd, f"ethtool -s {cfg.ifname} autoneg on")
+            expect_pauseparams_set(cfg, pauseparams, False, supported, "link autoneg off")
+            expect_pauseparams_set(cfg, pauseparams, True, supported, "link autoneg off")
+            link_config_tested = True
+
+    if not link_config_tested:
+        expect_pauseparams_set(cfg, pauseparams, False, supported, "current link")
 
 @ksft_variants(pauseparams_variants)
 @ksft_disruptive
@@ -902,11 +903,14 @@ def pause_autoneg_link_autoneg(cfg):
                          is_get=False, host=cfg.remote)
     if ret != 0:
         raise KsftSkipEx(f"Can't force the peer's link at {forced}")
+    remote_restore = defer(cmd, f"ethtool -s {cfg.remote_ifname} autoneg on",
+                           host=cfg.remote)
 
     ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg off {forced}",
                          is_get=False)
     if ret != 0:
         raise KsftSkipEx(f"Can't force the link at {forced}")
+    local_restore = defer(cmd, f"ethtool -s {cfg.ifname} autoneg on")
 
     try:
         wait_for_aneg(cfg)
@@ -917,8 +921,8 @@ def pause_autoneg_link_autoneg(cfg):
     check_local_pauseparams(cfg, True, rx, tx)
 
     # Re-enable autoneg
-    ethtool(f"-s {cfg.remote_ifname} autoneg on", host=cfg.remote)
-    ethtool(f"-s {cfg.ifname} autoneg on")
+    remote_restore.exec()
+    local_restore.exec()
     wait_for_aneg(cfg)
 
     # Pause autoneg must still be on
Signature · 1 line
2.53.0-Meta
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

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] The patch removes the unconditional restore of the pre-test link state from pause_setup(), and pause_test_support() does not…

--

selftests: drv-net: pause: Avoid cleanup failures for unsupported link settings

This patch changes pause.py so that link-setting restores are queued only after a link-setting request has succeeded. Devices that cannot change link settings therefore no longer fail during cleanup. If no link configuration change is accepted, pause_test_support() falls back to checking forced MAC pause on the current link, and pause_autoneg_link_autoneg() now queues its own autoneg-on restores.

Quoted 21 lines
tools/testing/selftests/drivers/net/hw/pause.py +3 -6
index ca4a55e59c30f..c3398c7452e01 100755
@@ -402,16 +402,13 @@ def pause_setup(cfg):
     if "auto-negotiation" not in link:
         raise KsftSkipEx(f"{cfg.ifname} doesn't report its link modes")
 
-    if link["auto-negotiation"]:
-        defer(cmd, f"ethtool -s {cfg.ifname} autoneg on")
-    elif "speed" in link and "duplex" in link:
-        defer(cmd, f"ethtool -s {cfg.ifname} autoneg off speed {link['speed']} "
-                   f"duplex {link['duplex'].lower()}")
-
     # Local interface admin up, link aneg on
     ip(f"link set {cfg.ifname} up")
     if link["supports-auto-negotiation"] and not link["auto-negotiation"]:
         ethtool(f"-s {cfg.ifname} autoneg on")
+        if "speed" in link and "duplex" in link:
+            defer(cmd, f"ethtool -s {cfg.ifname} autoneg off speed {link['speed']} "
+                       f"duplex {link['duplex'].lower()}")

[ ... ]

Quoted 28 lines
tools/testing/selftests/drivers/net/hw/pause.py +5 -7
@@ -470,9 +463,12 @@ def pause_test_support(cfg, pauseparams):
 
     forced = forced_link_settings(cfg)
     _, supported = get_local_pause_supported(cfg)
+    link_config_tested = False
 
     # We check that what we can configure in the pause params matches what we
-    # support under various contditions : Link aneg on/off, pause aneg on/off
+    # support under various conditions: link aneg on/off, and pause aneg
+    # on/off. If no link configuration change is supported, fall back to
+    # checking forced MAC pause on the current link.
     ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg on", is_get = False)
     if ret != 0:
         ksft_pr("link autoneg on refused, not tested")
@@ -481,18 +477,23 @@ def pause_test_support(cfg, pauseparams):
                                "link autoneg on")
         expect_pauseparams_set(cfg, pauseparams, True, supported,
                                "link autoneg on")
+        link_config_tested = True
 
     if not forced:
         ksft_pr("link speed unknown, the forced link is not tested")
-        return
-
-    ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg off {forced}", is_get = False)
-    if ret != 0:
-        ksft_pr(f"link autoneg off {forced} refused, not tested")
-        return

tools/testing/selftests/drivers/net/hw/pause.py def pause_test_support(cfg, pauseparams): · line 490

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/pause.py +7 -3
-
-    expect_pauseparams_set(cfg, pauseparams, False, supported, "link autoneg off")
-    expect_pauseparams_set(cfg, pauseparams, True, supported, "link autoneg off")
+    else:
+        ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg off {forced}", is_get = False)
+        if ret != 0:
+            ksft_pr(f"link autoneg off {forced} refused, not tested")
+        else:
+            if link_config_tested:
+                defer(cmd, f"ethtool -s {cfg.ifname} autoneg on")

[Severity: Medium]
Could this leave the local interface autonegotiating when it started with a forced link?

pause_setup() now queues a restore only when it enables autoneg itself, which happens when supports-auto-negotiation is true and auto-negotiation is false. If the port starts forced and reports
supports-auto-negotiation: false, pause_setup() queues nothing.

pause_test_support() then sends:

ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg on", is_get = False)

If that succeeds, no restore is queued for it. The ethtool netlink core does not check the Autoneg supported bit. In net/ethtool/linkmodes.c, ethnl_update_linkmodes() only does:

    ethnl_update_u8(&lsettings->autoneg, tb[ETHTOOL_A_LINKMODES_AUTONEG], mod);

The change is then passed to ->set_link_ksettings(), so the driver alone decides whether to accept it.

If the driver accepts it and the later autoneg off {forced} request also succeeds, the only restore queued is the hardcoded autoneg on above. Cleanup then leaves the link in autoneg mode.

Before this patch, pause_setup() queued "autoneg off speed X duplex Y" first. That restore ran last and put back the original forced settings.

The commit message says:

Fix this by queuing link-setting restores only after a link-setting request has succeeded.

The first autoneg on request in pause_test_support() can succeed and change the link, but no restore is queued for it. This only happens with a driver that accepts enabling autoneg without advertising Autoneg support.

Should pause_test_support() restore the link state it saw before the test instead of a fixed autoneg on?

Quoted 6 lines
tools/testing/selftests/drivers/net/hw/pause.py +6 -0
+            expect_pauseparams_set(cfg, pauseparams, False, supported, "link autoneg off")
+            expect_pauseparams_set(cfg, pauseparams, True, supported, "link autoneg off")
+            link_config_tested = True
+
+    if not link_config_tested:
+        expect_pauseparams_set(cfg, pauseparams, False, supported, "current link")

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261113022717.1914724-1-mohsin.bashr%40gmail.com
#2 lore raw
Quoted 122 lines · On 11/15/26 6:29 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

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] The patch removes the unconditional restore of the pre-test link state from pause_setup(), and pause_test_support() does not…

--

selftests: drv-net: pause: Avoid cleanup failures for unsupported link settings

This patch changes pause.py so that link-setting restores are queued only after a link-setting request has succeeded. Devices that cannot change link settings therefore no longer fail during cleanup. If no link configuration change is accepted, pause_test_support() falls back to checking forced MAC pause on the current link, and pause_autoneg_link_autoneg() now queues its own autoneg-on restores.

Quoted 21 lines
tools/testing/selftests/drivers/net/hw/pause.py +3 -6
index ca4a55e59c30f..c3398c7452e01 100755
@@ -402,16 +402,13 @@ def pause_setup(cfg):
      if "auto-negotiation" not in link:
          raise KsftSkipEx(f"{cfg.ifname} doesn't report its link modes")
 
-    if link["auto-negotiation"]:
-        defer(cmd, f"ethtool -s {cfg.ifname} autoneg on")
-    elif "speed" in link and "duplex" in link:
-        defer(cmd, f"ethtool -s {cfg.ifname} autoneg off speed {link['speed']} "
-                   f"duplex {link['duplex'].lower()}")
-
      # Local interface admin up, link aneg on
      ip(f"link set {cfg.ifname} up")
      if link["supports-auto-negotiation"] and not link["auto-negotiation"]:
          ethtool(f"-s {cfg.ifname} autoneg on")
+        if "speed" in link and "duplex" in link:
+            defer(cmd, f"ethtool -s {cfg.ifname} autoneg off speed {link['speed']} "
+                       f"duplex {link['duplex'].lower()}")

[ ... ]

Quoted 28 lines
tools/testing/selftests/drivers/net/hw/pause.py +5 -7
@@ -470,9 +463,12 @@ def pause_test_support(cfg, pauseparams):
 
      forced = forced_link_settings(cfg)
      _, supported = get_local_pause_supported(cfg)
+    link_config_tested = False
 
      # We check that what we can configure in the pause params matches what we
-    # support under various contditions : Link aneg on/off, pause aneg on/off
+    # support under various conditions: link aneg on/off, and pause aneg
+    # on/off. If no link configuration change is supported, fall back to
+    # checking forced MAC pause on the current link.
      ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg on", is_get = False)
      if ret != 0:
          ksft_pr("link autoneg on refused, not tested")
@@ -481,18 +477,23 @@ def pause_test_support(cfg, pauseparams):
                                 "link autoneg on")
          expect_pauseparams_set(cfg, pauseparams, True, supported,
                                 "link autoneg on")
+        link_config_tested = True
 
      if not forced:
          ksft_pr("link speed unknown, the forced link is not tested")
-        return
-
-    ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg off {forced}", is_get = False)
-    if ret != 0:
-        ksft_pr(f"link autoneg off {forced} refused, not tested")
-        return

tools/testing/selftests/drivers/net/hw/pause.py def pause_test_support(cfg, pauseparams): · line 490

Quoted 10 lines
tools/testing/selftests/drivers/net/hw/pause.py +7 -3
-
-    expect_pauseparams_set(cfg, pauseparams, False, supported, "link autoneg off")
-    expect_pauseparams_set(cfg, pauseparams, True, supported, "link autoneg off")
+    else:
+        ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg off {forced}", is_get = False)
+        if ret != 0:
+            ksft_pr(f"link autoneg off {forced} refused, not tested")
+        else:
+            if link_config_tested:
+                defer(cmd, f"ethtool -s {cfg.ifname} autoneg on")

[Severity: Medium]
Could this leave the local interface autonegotiating when it started with a forced link?

pause_setup() now queues a restore only when it enables autoneg itself, which happens when supports-auto-negotiation is true and auto-negotiation is false. If the port starts forced and reports
supports-auto-negotiation: false, pause_setup() queues nothing.

pause_test_support() then sends:

ret, _ = ethtool_ret(f"-s {cfg.ifname} autoneg on", is_get = False)

If that succeeds, no restore is queued for it. The ethtool netlink core does not check the Autoneg supported bit. In net/ethtool/linkmodes.c, ethnl_update_linkmodes() only does:

     ethnl_update_u8(&lsettings->autoneg, tb[ETHTOOL_A_LINKMODES_AUTONEG], mod);

The change is then passed to ->set_link_ksettings(), so the driver alone decides whether to accept it.

If the driver accepts it and the later autoneg off {forced} request also succeeds, the only restore queued is the hardcoded autoneg on above. Cleanup then leaves the link in autoneg mode.

Before this patch, pause_setup() queued "autoneg off speed X duplex Y" first. That restore ran last and put back the original forced settings.

The commit message says:

Fix this by queuing link-setting restores only after a link-setting request has succeeded.

Quoted 7 lines

The first autoneg on request in pause_test_support() can succeed and change the link, but no restore is queued for it. This only happens with a driver that accepts enabling autoneg without advertising Autoneg support.

Should pause_test_support() restore the link state it saw before the test instead of a fixed autoneg on?

Thanks for the review. AFAIU this case is only possible if the driver's behavior is inconsistent. The case would require driver to report that it does not support autoneg and still accept AUTONEG_ENABLE. IMHO pause_test_support() is not expected to validate ksetting inconsistencies in a driver. I'd leave it up to the maintainers to decide if it needs a respin.

Quoted 9 lines
Quoted 6 lines
tools/testing/selftests/drivers/net/hw/pause.py +6 -0
+            expect_pauseparams_set(cfg, pauseparams, False, supported, "link autoneg off")
+            expect_pauseparams_set(cfg, pauseparams, True, supported, "link autoneg off")
+            link_config_tested = True
+
+    if not link_config_tested:
+        expect_pauseparams_set(cfg, pauseparams, False, supported, "current link")

[ ... ]

#3 lore raw
In reply to Mohsin Bashir
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 12 Nov 2026 18:27:17 -0800 you wrote:

From: Mohsin Bashir <[email protected]>

pause_setup() saves the initial link settings before tests run. Devices that report link settings but do not support changing them can reject even a no-op restore with EOPNOTSUPP. That turns pause tests that use pause_setup() into cleanup failures.

[...]

Here is the summary with links:
- [net,v3] selftests: drv-net: pause: Avoid cleanup failures for unsupported link settings

    https://git.kernel.org/netdev/net-next/c/4492b608bb75

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html