From 3290e27ba6e547ca8b644442e049926fcae242ae Mon Sep 17 00:00:00 2001 From: erj Date: Thu, 28 Mar 2019 20:43:47 +0000 Subject: [PATCH] iflib: hold the CTX lock in iflib_pseudo_register From Jake: The iflib_device_register function takes the CTX lock before calling IFDI_ATTACH_PRE, and releases it upon finishing the registration. Mirror this process in iflib_pseudo_register, so that we always hold the CTX lock during the attach process when registering a pseudo interface or a regular interface. This was caught by code inspection while attempting to analyze where the CTX lock was held. Submitted by: Jacob Keller Reviewed by: shurd@, erj@ MFC after: 1 week Sponsored by: Intel Corporation Differential Revision: https://reviews.freebsd.org/D19604 --- sys/net/iflib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sys/net/iflib.c b/sys/net/iflib.c index 928335506628..0aa9f1db2f3d 100644 --- a/sys/net/iflib.c +++ b/sys/net/iflib.c @@ -4662,10 +4662,10 @@ iflib_pseudo_register(device_t dev, if_shared_ctx_t sctx, if_ctx_t *ctxp, * XXX sanity check that ntxd & nrxd are a power of 2 */ iflib_reset_qvalues(ctx); - + CTX_LOCK(ctx); if ((err = IFDI_ATTACH_PRE(ctx)) != 0) { device_printf(dev, "IFDI_ATTACH_PRE failed %d\n", err); - goto fail_ctx_free; + goto fail_unlock; } if (sctx->isc_flags & IFLIB_GEN_MAC) iflib_gen_mac(ctx); @@ -4819,6 +4819,7 @@ iflib_pseudo_register(device_t dev, if_shared_ctx_t sctx, if_ctx_t *ctxp, if_setgetcounterfn(ctx->ifc_ifp, iflib_if_get_counter); iflib_add_device_sysctl_post(ctx); ctx->ifc_flags |= IFC_INIT_DONE; + CTX_UNLOCK(ctx); return (0); fail_detach: ether_ifdetach(ctx->ifc_ifp); @@ -4827,6 +4828,8 @@ fail_queues: iflib_rx_structures_free(ctx); fail_iflib_detach: IFDI_DETACH(ctx); +fail_unlock: + CTX_UNLOCK(ctx); fail_ctx_free: free(ctx->ifc_softc, M_IFLIB); free(ctx, M_IFLIB);