Date: Fri, 16 May 2025 02:34:48 GMT From: Adrian Chadd <adrian@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: c8e97aa6ac77 - main - e6000sw: fix bus ordering; don't panic if miibus devices are destroyed Message-ID: <202505160234.54G2YmIw026308@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by adrian: URL: https://cgit.FreeBSD.org/src/commit/?id=c8e97aa6ac77fa5cce7afc06849685599795c982 commit c8e97aa6ac77fa5cce7afc06849685599795c982 Author: Adrian Chadd <adrian@FreeBSD.org> AuthorDate: 2025-05-11 02:31:16 +0000 Commit: Adrian Chadd <adrian@FreeBSD.org> CommitDate: 2025-05-16 02:34:26 +0000 e6000sw: fix bus ordering; don't panic if miibus devices are destroyed Unloading the e6000sw driver with a "fixed" ixgbe (which is doing MDIO transfers faster than 8ms per) has exposed another fun race condition - the MII busses were being torn down before the etherswitch device. * Modify e6000sw_miiforphy() to return NULL if the mii bus device isn't setup, which stops the panic * Change the module order so the e6000sw module is detached first, before the miibus entries and attached PHYs are destroyed. This ensures that the miibus entries aren't destroyed outside of the driver lock, and e6000sw_tick() doesn't try dereferencing dead miibus device_t's. Differential Revision: https://reviews.freebsd.org/D50294 Reviewed by: jhb --- sys/dev/etherswitch/e6000sw/e6000sw.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/dev/etherswitch/e6000sw/e6000sw.c b/sys/dev/etherswitch/e6000sw/e6000sw.c index 0041119ca300..d26fc32ed6a6 100644 --- a/sys/dev/etherswitch/e6000sw/e6000sw.c +++ b/sys/dev/etherswitch/e6000sw/e6000sw.c @@ -196,8 +196,8 @@ DEFINE_CLASS_0(e6000sw, e6000sw_driver, e6000sw_methods, sizeof(e6000sw_softc_t)); DRIVER_MODULE(e6000sw, mdio, e6000sw_driver, 0, 0); -DRIVER_MODULE(etherswitch, e6000sw, etherswitch_driver, 0, 0); DRIVER_MODULE(miibus, e6000sw, miibus_driver, 0, 0); +DRIVER_MODULE_ORDERED(etherswitch, e6000sw, etherswitch_driver, 0, 0, SI_ORDER_ANY); MODULE_DEPEND(e6000sw, mdio, 1, 1, 1); MODULE_DEPEND(e6000sw, etherswitch, 1, 1, 1); @@ -1402,11 +1402,17 @@ e6000sw_getvgroup(device_t dev, etherswitch_vlangroup_t *vg) static __inline struct mii_data* e6000sw_miiforphy(e6000sw_softc_t *sc, unsigned int phy) { + device_t mii_dev; if (!e6000sw_is_phyport(sc, phy)) return (NULL); + mii_dev = sc->miibus[phy]; + if (mii_dev == NULL) + return (NULL); + if (device_get_state(mii_dev) != DS_ATTACHED) + return (NULL); - return (device_get_softc(sc->miibus[phy])); + return (device_get_softc(mii_dev)); } static int
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202505160234.54G2YmIw026308>