git: 88b7b8512107 - main - ixgbe: Attach the MDIO bus after iflib drops the context lock
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 10 Nov 2026 12:49:21 UTC
The branch main has been updated by rcm:
URL: https://cgit.FreeBSD.org/src/commit/?id=88b7b851210762af4827f71b2757a7d4673006a9
commit 88b7b851210762af4827f71b2757a7d4673006a9
Author: R. Christian McDonald <rcm@FreeBSD.org>
AuthorDate: 2026-11-10 12:48:01 +0000
Commit: R. Christian McDonald <rcm@FreeBSD.org>
CommitDate: 2026-11-10 12:48:01 +0000
ixgbe: Attach the MDIO bus after iflib drops the context lock
ixgbe_mdio_attach() ran from ixgbe_if_attach_post(), which iflib calls
with the context lock held. Attaching the MDIO bus there also probes
and attaches the devices on it, and their register accesses go through
ixgbe_mdio_readreg_c22() and ixgbe_mdio_writereg_c22(), which take the
same lock. A driver on the bus that was in the kernel or loaded by
loader(8) therefore recursed on the non-recursive iflib sx lock as soon
as it touched a register: INVARIANTS kernels panic in _sx_xlock_hard(),
others recurse silently.
Wrap iflib_device_attach() and attach the MDIO bus once it has
returned, so the children take the context lock like any later MDIO
access does.
Reviewed by: kbowling
Fixes: cfec995c87f3 ("ixgbe: add MDIO bus support")
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D61199
---
sys/dev/ixgbe/if_ix.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/sys/dev/ixgbe/if_ix.c b/sys/dev/ixgbe/if_ix.c
index b429fb3992fb..688ff53ebb39 100644
--- a/sys/dev/ixgbe/if_ix.c
+++ b/sys/dev/ixgbe/if_ix.c
@@ -178,6 +178,7 @@ static const pci_vendor_info_t ixgbe_vendor_info_array[] =
};
static void *ixgbe_register(device_t);
+static int ixgbe_attach(device_t);
static int ixgbe_if_attach_pre(if_ctx_t);
static int ixgbe_if_attach_post(if_ctx_t);
static int ixgbe_if_detach(if_ctx_t);
@@ -317,7 +318,7 @@ static device_method_t ix_methods[] = {
/* Device interface */
DEVMETHOD(device_register, ixgbe_register),
DEVMETHOD(device_probe, iflib_device_probe),
- DEVMETHOD(device_attach, iflib_device_attach),
+ DEVMETHOD(device_attach, ixgbe_attach),
DEVMETHOD(device_detach, iflib_device_detach),
DEVMETHOD(device_shutdown, iflib_device_shutdown),
DEVMETHOD(device_suspend, iflib_device_suspend),
@@ -1151,6 +1152,24 @@ ixgbe_register(device_t dev)
return (&ixgbe_sctx_init);
} /* ixgbe_register */
+/************************************************************************
+ * ixgbe_attach - Device attach entry point
+ *
+ * The MDIO bus children are attached here rather than in
+ * ixgbe_if_attach_post(): their register accesses take the iflib
+ * context lock, which iflib holds across IFDI_ATTACH_POST.
+ ************************************************************************/
+static int
+ixgbe_attach(device_t dev)
+{
+ int error;
+
+ error = iflib_device_attach(dev);
+ if (error == 0)
+ ixgbe_mdio_attach(iflib_get_softc(device_get_softc(dev)));
+ return (error);
+} /* ixgbe_attach */
+
/************************************************************************
* ixgbe_if_attach_pre - Device initialization routine, part 1
*
@@ -1459,9 +1478,6 @@ ixgbe_if_attach_post(if_ctx_t ctx)
/* Add sysctls */
ixgbe_add_device_sysctls(ctx);
- /* Add MDIO bus if required / supported */
- ixgbe_mdio_attach(sc);
-
/* Init recovery mode timer and state variable */
if (sc->feat_en & IXGBE_FEATURE_RECOVERY_MODE) {
sc->recovery_mode = 0;