From nobody Sat Aug 22 00:25:39 2026 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hRdHl3f0Yz6ppds for ; Sat, 22 Aug 2026 00:25:39 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hRdHl2ypdz3CS1 for ; Sat, 22 Aug 2026 00:25:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787358339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vfMAX5PLVL3WFQr6T8ma7XruUF2HAocSPR9DsexfMcw=; b=nefuO6rgcn9xN1OhsOIBOnVD8uRMkKEB3+E9RnfN/Sd5gMb2WCI9KoqZQMVh/tIPwlp+bb Ay1A0PmanPgTNoB337EQHMOkjENWFhF3Ye78z/IJCdhgd9SRMbz4zCOvAcW8PedxgiLRda 3bYet63sY1THwsiAZ8DKz9zJk8rT4AjpRVvMJAvdEHXe9FfN124GdFTYLSACSmYFEt03u/ BJoJQRXC7vjQk5uVL6tyb86ovpGOVkaOd4DcksnrUULvOh/x0pj+BhNWzUs/nQZeZXHanT jx3QZWRjFdJARvbLlfA6/lIJLdD3lD3/8I10vVi4irbuIAtQ+pVr9xBe+5pOPQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1787358339; a=rsa-sha256; cv=none; b=S80Afj16LkwdsQb2/lW6xrfza1xXTBWRan//5jELqkL/JmTTQ5g6t6yJHQoPyBeIFMMBDo m/X5yiQECInAshLA/qyPb0GxABogX/Zs+/wMCw7kFSBc2ISlTKXtjCdaxhnqsqB9ajulyN rTQkHggIyAkP5Ggcti5GgpSiNDJ+/7Q+NVEx39e3pjcc6WrA+cTy4HdFtJtwIPNdM/utUd Vf+P44BmC3ARQdL7DPBSMs2MrJ9u8lezcDPsnRBquuBCHC2rIeL3BJKnD1dYRV3+TM7sH0 N5uYNvLz7hMQP1b/wMikrsM4CopFdxWjoKdH77u4g+bI6Xft4gdC7d0rGofnzw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787358339; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vfMAX5PLVL3WFQr6T8ma7XruUF2HAocSPR9DsexfMcw=; b=oKLA7+JYDGIpCDrpBH/pbcGr/KHbCrwRNkcP2nHnGplcnlD2u2ArANIEeYZvU30C1KSFl7 51LaVD6brYVDMxkJ8BHoZJvVsg5QS7JHzCoqC+GsInM2EkMnzlxIpNNDtA3sN0MXN/Q9Og XksGGHlFkLkxC6A/uF89ZFAeBQVTSoDJbToWbvu0i52+ySAeY50W9j8s/3J5K1pEppZgan AmlJPtMzfPPywkhMxN95fJISNj4v/dyAHN0EUo0myKR26uuSJI6TzXDBQGrhaffzymbqdS hm4H6oQTVUUSR3U2zwSIz11+xV2B1c9Ftmb24FvRLXc0W4SMAgDeVVIVlDAHkQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hRdHl1qs6zB75 for ; Sat, 22 Aug 2026 00:25:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 244da by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 22 Aug 2026 00:25:39 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kevin Bowling Subject: git: 2eaebe07e287 - stable/15 - enic: Correct queue and attach resource ownership List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kbowling X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 2eaebe07e287091f3dc8bba3edb7b96c27cef947 Auto-Submitted: auto-generated Date: Sat, 22 Aug 2026 00:25:39 +0000 Message-Id: <6a88ec83.244da.1049168d@gitrepo.freebsd.org> The branch stable/15 has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=2eaebe07e287091f3dc8bba3edb7b96c27cef947 commit 2eaebe07e287091f3dc8bba3edb7b96c27cef947 Author: Kevin Bowling AuthorDate: 2026-08-08 04:14:53 +0000 Commit: Kevin Bowling CommitDate: 2026-08-22 00:25:29 +0000 enic: Correct queue and attach resource ownership Completion queues are allocated by attach_pre but released by queues_free. An iflib failure between those stages leaks the allocation, while the original size expression also underallocates the array. Move completion queue allocation into the TX queue callback, correct its size, and unwind it with TX state if RX allocation fails. Make interrupt cleanup tolerate an unavailable array and reuse the array allocated during device initialization instead of replacing and leaking it. Release the DMA, multicast, and lock resources owned by a successful attach_pre during detach. Avoid allocating the statistics DMA area a second time near the end of attach_pre. (cherry picked from commit a97e1c2450ae62a73a3e0a2a2284e591cd82180a) --- sys/dev/enic/if_enic.c | 68 +++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/sys/dev/enic/if_enic.c b/sys/dev/enic/if_enic.c index 35620fece6bf..74e3ff6f8721 100644 --- a/sys/dev/enic/if_enic.c +++ b/sys/dev/enic/if_enic.c @@ -493,26 +493,6 @@ enic_attach_pre(if_ctx_t ctx) ifmedia_add(softc->media, IFM_ETHER | IFM_40G_SR4, 0, NULL); ifmedia_add(softc->media, IFM_ETHER | IFM_10_FL, 0, NULL); - /* - * Allocate the CQ here since TX is called first before RX. - */ - if (softc->enic.cq == NULL) - softc->enic.cq = malloc(sizeof(struct vnic_cq) * - softc->enic.wq_count + softc->enic.rq_count, M_DEVBUF, - M_NOWAIT | M_ZERO); - if (softc->enic.cq == NULL) - return (ENOMEM); - - /* - * Allocate the consistent memory for stats and counters upfront so - * both primary and secondary processes can access them. - */ - err = vnic_dev_alloc_stats_mem(enic->vdev); - if (err) { - dev_err(enic, "Failed to allocate cmd memory, aborting\n"); - goto err_out_dev_close; - } - err = enic_allocate_msix(softc); if (err) { dev_err(enic, "Failed to allocate MSIX, aborting\n"); @@ -555,10 +535,13 @@ enic_msix_intr_assign(if_ctx_t ctx, int msix) vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSIX); ENIC_UNLOCK(softc); - enic->intr_queues = malloc(sizeof(*enic->intr_queues) * - enic->conf_intr_count, M_DEVBUF, M_NOWAIT | M_ZERO); + if (enic->intr_queues == NULL) + enic->intr_queues = malloc(sizeof(*enic->intr_queues) * + enic->conf_intr_count, M_DEVBUF, M_NOWAIT | M_ZERO); enic->intr = malloc(sizeof(*enic->intr) * msix, M_DEVBUF, M_NOWAIT | M_ZERO); + if (enic->intr_queues == NULL || enic->intr == NULL) + return (ENOMEM); for (i = 0; i < scctx->isc_nrxqsets; i++) { snprintf(irq_name, sizeof(irq_name), "erxq%d:%d", i, device_get_unit(softc->dev)); @@ -647,14 +630,19 @@ enic_free_irqs(struct enic_softc *softc) scctx = softc->scctx; enic = &softc->enic; - for (i = 0; i < scctx->isc_nrxqsets + scctx->isc_ntxqsets; i++) { - iflib_irq_free(softc->ctx, &enic->intr_queues[i].intr_irq); + if (enic->intr_queues != NULL) { + for (i = 0; + i < scctx->isc_nrxqsets + scctx->isc_ntxqsets; i++) + iflib_irq_free(softc->ctx, + &enic->intr_queues[i].intr_irq); } iflib_irq_free(softc->ctx, &softc->enic_event_intr_irq); iflib_irq_free(softc->ctx, &softc->enic_err_intr_irq); free(enic->intr_queues, M_DEVBUF); + enic->intr_queues = NULL; free(enic->intr, M_DEVBUF); + enic->intr = NULL; } static int @@ -697,9 +685,21 @@ enic_detach(if_ctx_t ctx) vnic_dev_close(enic->vdev); vnic_dev_deinit_devcmd2(enic->vdev); free(softc->vdev.devcmd, M_DEVBUF); + softc->vdev.devcmd = NULL; pci_disable_busmaster(softc->dev); enic_pci_mapping_free(softc); ENIC_UNLOCK(softc); + if (softc->vdev.stats_res.idi_size != 0) { + iflib_dma_free(&softc->vdev.stats_res); + softc->vdev.stats = NULL; + } + if (softc->vdev.flow_counters_res.idi_size != 0) { + iflib_dma_free(&softc->vdev.flow_counters_res); + softc->vdev.flow_counters = NULL; + } + free(softc->mta, M_DEVBUF); + softc->mta = NULL; + mtx_destroy(&softc->enic_lock); return 0; } @@ -712,11 +712,19 @@ enic_tx_queues_alloc(if_ctx_t ctx, caddr_t * vaddrs, uint64_t * paddrs, int q; softc = iflib_get_softc(ctx); + softc->enic.cq = malloc(sizeof(*softc->enic.cq) * + (softc->enic.wq_count + softc->enic.rq_count), M_DEVBUF, + M_NOWAIT | M_ZERO); + if (softc->enic.cq == NULL) + return (ENOMEM); /* Allocate the array of transmit queues */ softc->enic.wq = malloc(sizeof(struct vnic_wq) * ntxqsets, M_DEVBUF, M_NOWAIT | M_ZERO); - if (softc->enic.wq == NULL) + if (softc->enic.wq == NULL) { + free(softc->enic.cq, M_DEVBUF); + softc->enic.cq = NULL; return (ENOMEM); + } /* Initialize driver state for each transmit queue */ @@ -787,8 +795,13 @@ enic_rx_queues_alloc(if_ctx_t ctx, caddr_t * vaddrs, uint64_t * paddrs, /* Allocate the array of receive queues */ softc->enic.rq = malloc(sizeof(struct vnic_rq) * nrxqsets, M_DEVBUF, M_NOWAIT | M_ZERO); - if (softc->enic.rq == NULL) + if (softc->enic.rq == NULL) { + free(softc->enic.wq, M_DEVBUF); + softc->enic.wq = NULL; + free(softc->enic.cq, M_DEVBUF); + softc->enic.cq = NULL; return (ENOMEM); + } /* Initialize driver state for each receive queue */ @@ -851,8 +864,11 @@ enic_queues_free(if_ctx_t ctx) softc = iflib_get_softc(ctx); free(softc->enic.rq, M_DEVBUF); + softc->enic.rq = NULL; free(softc->enic.wq, M_DEVBUF); + softc->enic.wq = NULL; free(softc->enic.cq, M_DEVBUF); + softc->enic.cq = NULL; } static int