git: 62dd064b03df - main - iflib: Reject media changes during suspend

From: Kevin Bowling <kbowling_at_FreeBSD.org>
Date: Fri, 11 Sep 2026 20:15:49 UTC
The branch main has been updated by kbowling:

URL: https://cgit.FreeBSD.org/src/commit/?id=62dd064b03dfe04b727e7d1fdea17eb165b52e9c

commit 62dd064b03dfe04b727e7d1fdea17eb165b52e9c
Author:     Kevin Bowling <kbowling@FreeBSD.org>
AuthorDate: 2026-08-30 08:20:27 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2026-09-11 20:14:14 +0000

    iflib: Reject media changes during suspend
    
    iflib gates its built-in administrative and media-status callbacks once
    a power transition starts, but iflib_media_change() could still invoke a
    driver while the device was suspending or suspended.  Several drivers
    perform PHY or firmware I/O directly from this callback.
    
    Return EBUSY before invoking IFDI_MEDIA_CHANGE() unless the device is
    active.  ifmedia then restores the prior selection, avoiding both
    suspended hardware access and an unvalidated configuration that would
    need to be replayed during resume.
    
    Validated with device suspend on 82579LM, I210, and I225-IT
    controllers.  Media-selection requests returned EBUSY on every
    suspended device.  Resume restored the linked management interfaces at
    1 Gbps with working traffic and no watchdogs; unconfigured interfaces
    retained their prior admin and link state.
    
    Reviewed by:    iflib (gallatin)
    MFC after:      2 weeks
    Sponsored by:   BBOX.io
    Differential Revision:  https://reviews.freebsd.org/D59330
---
 share/man/man9/iflibdd.9 | 3 +++
 sys/net/iflib.c          | 4 ++++
 2 files changed, 7 insertions(+)

diff --git a/share/man/man9/iflibdd.9 b/share/man/man9/iflibdd.9
index 3706271352ae..54551c9c7053 100644
--- a/share/man/man9/iflibdd.9
+++ b/share/man/man9/iflibdd.9
@@ -311,6 +311,9 @@ Sets the mtu interface to the value of the second function parameter mtu.
 Function is called when the user changes speed/duplex using the media/mediaopt
 option with
 .Xr ifconfig 8 .
+It is not called while the device is suspending or suspended; iflib rejects
+such a media change with
+.Er EBUSY .
 .It Fn ifdi_promisc_set
 Enables or disables promisc settings depending upon the flags value.
 .Va flags
diff --git a/sys/net/iflib.c b/sys/net/iflib.c
index 0015cbb34a27..d3d25bc13f85 100644
--- a/sys/net/iflib.c
+++ b/sys/net/iflib.c
@@ -2728,6 +2728,10 @@ iflib_media_change(if_t ifp)
 	int err;
 
 	CTX_LOCK(ctx);
+	if (ctx->ifc_pm_state != IFLIB_PM_ACTIVE) {
+		CTX_UNLOCK(ctx);
+		return (EBUSY);
+	}
 	restart = (if_getflags(ifp) & IFF_UP) != 0 ||
 	    ctx->ifc_datapath_state == IFLIB_DP_RUNNING;
 	if ((err = IFDI_MEDIA_CHANGE(ctx)) == 0 && restart)