git: c489bd72cdbb - stable/15 - iflib: Reject media changes during suspend

From: Kevin Bowling <kbowling_at_FreeBSD.org>
Date: Thu, 29 Oct 2026 04:58:46 UTC
The branch stable/15 has been updated by kbowling:

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

commit c489bd72cdbba7c5f719cadffe3aeb301e0da830
Author:     Kevin Bowling <kbowling@FreeBSD.org>
AuthorDate: 2026-08-30 08:20:27 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2026-10-29 04:58:36 +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)
    Sponsored by:   BBOX.io
    Differential Revision:  https://reviews.freebsd.org/D59330
    
    (cherry picked from commit 62dd064b03dfe04b727e7d1fdea17eb165b52e9c)
---
 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 b2a6a68b69f1..2fff221023d2 100644
--- a/sys/net/iflib.c
+++ b/sys/net/iflib.c
@@ -2605,6 +2605,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)