From owner-svn-src-stable-11@freebsd.org Thu May 14 20:23:26 2020 Return-Path: Delivered-To: svn-src-stable-11@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5E30F2DE4BE; Thu, 14 May 2020 20:23:26 +0000 (UTC) (envelope-from erj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49NNKB1wfTz3NjS; Thu, 14 May 2020 20:23:26 +0000 (UTC) (envelope-from erj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3C92518D17; Thu, 14 May 2020 20:23:26 +0000 (UTC) (envelope-from erj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04EKNQww078242; Thu, 14 May 2020 20:23:26 GMT (envelope-from erj@FreeBSD.org) Received: (from erj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04EKNQpL078241; Thu, 14 May 2020 20:23:26 GMT (envelope-from erj@FreeBSD.org) Message-Id: <202005142023.04EKNQpL078241@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: erj set sender to erj@FreeBSD.org using -f From: Eric Joyner Date: Thu, 14 May 2020 20:23:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r361057 - stable/11/sys/net X-SVN-Group: stable-11 X-SVN-Commit-Author: erj X-SVN-Commit-Paths: stable/11/sys/net X-SVN-Commit-Revision: 361057 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 May 2020 20:23:26 -0000 Author: erj Date: Thu May 14 20:23:25 2020 New Revision: 361057 URL: https://svnweb.freebsd.org/changeset/base/361057 Log: Partially MFC r353967: iflib: call ether_ifdetach and netmap_detach before stop This MFCs most of the patch except for the parts where the new iflib_unregister_vlan_handlers() function is called in the pseudo device register/deregister functions since those functions don't exist in FreeBSD 11. This re-ordering can fix a potential panic. Sponsored by: Intel Corporation Modified: stable/11/sys/net/iflib.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/net/iflib.c ============================================================================== --- stable/11/sys/net/iflib.c Thu May 14 20:17:09 2020 (r361056) +++ stable/11/sys/net/iflib.c Thu May 14 20:23:25 2020 (r361057) @@ -731,6 +731,8 @@ static int iflib_legacy_setup(if_ctx_t ctx, driver_fil static void iflib_txq_check_drain(iflib_txq_t txq, int budget); static uint32_t iflib_txq_can_drain(struct ifmp_ring *); static int iflib_register(if_ctx_t); +static void iflib_deregister(if_ctx_t); +static void iflib_unregister_vlan_handlers(if_ctx_t ctx); static void iflib_init_locked(if_ctx_t ctx); static void iflib_add_device_sysctl_pre(if_ctx_t ctx); static void iflib_add_device_sysctl_post(if_ctx_t ctx); @@ -4546,18 +4548,16 @@ iflib_device_deregister(if_ctx_t ctx) ctx->ifc_flags |= IFC_IN_DETACH; STATE_UNLOCK(ctx); + /* Unregister VLAN handlers before calling iflib_stop() */ + iflib_unregister_vlan_handlers(ctx); + + iflib_netmap_detach(ifp); + ether_ifdetach(ifp); + CTX_LOCK(ctx); iflib_stop(ctx); CTX_UNLOCK(ctx); - /* Unregister VLAN events */ - if (ctx->ifc_vlan_attach_event != NULL) - EVENTHANDLER_DEREGISTER(vlan_config, ctx->ifc_vlan_attach_event); - if (ctx->ifc_vlan_detach_event != NULL) - EVENTHANDLER_DEREGISTER(vlan_unconfig, ctx->ifc_vlan_detach_event); - - iflib_netmap_detach(ifp); - ether_ifdetach(ifp); if (ctx->ifc_led_dev != NULL) led_destroy(ctx->ifc_led_dev); /* XXX drain any dependent tasks */ @@ -4825,6 +4825,43 @@ iflib_register(if_ctx_t ctx) return (0); } +static void +iflib_unregister_vlan_handlers(if_ctx_t ctx) +{ + /* Unregister VLAN events */ + if (ctx->ifc_vlan_attach_event != NULL) { + EVENTHANDLER_DEREGISTER(vlan_config, ctx->ifc_vlan_attach_event); + ctx->ifc_vlan_attach_event = NULL; + } + if (ctx->ifc_vlan_detach_event != NULL) { + EVENTHANDLER_DEREGISTER(vlan_unconfig, ctx->ifc_vlan_detach_event); + ctx->ifc_vlan_detach_event = NULL; + } + +} + +static void +iflib_deregister(if_ctx_t ctx) +{ + if_t ifp = ctx->ifc_ifp; + + /* Remove all media */ + ifmedia_removeall(&ctx->ifc_media); + + /* Ensure that VLAN event handlers are unregistered */ + iflib_unregister_vlan_handlers(ctx); + + /* Release kobject reference */ + kobj_delete((kobj_t) ctx, NULL); + + /* Free the ifnet structure */ + if_free(ifp); + + STATE_LOCK_DESTROY(ctx); + + /* ether_ifdetach calls if_qflush - lock must be destroy afterwards*/ + CTX_LOCK_DESTROY(ctx); +} static int iflib_queues_alloc(if_ctx_t ctx)