From nobody Sat Aug 8 06:31:57 2026 X-Original-To: dev-commits-src-main@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 4hHB4s4sKFz6n6m8 for ; Sat, 08 Aug 2026 06:31:57 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hHB4s24gtz3kdN for ; Sat, 08 Aug 2026 06:31:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786170717; 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=FUI3ous+1U6jf8rLC3ekMBkKbMK7ZOXE5WsLdcOh9os=; b=aEjXpw5OSwvVWJoTpG/jrOn8rDe2pJHlDY1+uFB5oMGZWOVh6NDQQ9DhEQqWRpQ85R9huF QonSs6cQn3/J3QiTjztriaE9F29UncM+Sjsn8PuncBr8G3DXnGNtFWo+Uv8oDrz8LJfgR1 t5gKjUt2AB3KYNumBDf7RUHLwP0e1ynsx8d7EKQcBOGxc2qXRnavyqx0eKhreHBNz+cBkS KQlRjU1BCNKuaiKkPDGFh171m+VtRcU+N0aLFFpzuHPMB/dDrmcTH9p+ZKRTk9MR9E6KKh nPF29Yc/s62IyhM/bionfXxYbWUfqb5qJeYzf44nm2JOOgygvOq5BOpTxYNOZQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786170717; a=rsa-sha256; cv=none; b=TdQeujO8Oxwihu2StyJjVocCbVCvz+i+wisEzEnFVV63DRcS9JYr4pPmWfnPFLkLG+sfzQ 7mlsi9AWf8PsQATNL8pkukfHgVg6oJt7dZq8OYCXMszb9YlWKYDjFmkzvOLKAh6bs6ZBDN hSnQZPB6/F+irI+WvcPeqVBaR5UkHfNHAREbGzqD/YUZ0mAh+tKpR1GUXq/UIUP7nEKTEd RBmduXpJv5mj1hu79Ra/kFZs4dp98qmgWQ5LsPBYfIjVU/c6Eydee3a7KMeVSuYZ+co3Ak wAHECk9qPTlAZ43TF2TDqiwbY5QPDFZ7f1S2ivKVIcA5g0dvIAlZ/OMdDnSrmA== 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=1786170717; 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=FUI3ous+1U6jf8rLC3ekMBkKbMK7ZOXE5WsLdcOh9os=; b=GGqWIh5PmiuOKqqK9eMuN/UXdEEzjnDUaW+lCm2rpMh79WupS4Y1k2i8a7bwLPXOiFvPkL /uO8RNNN6ggSqzvaeGORACOexyPUZczUaiMQm35gVbOJ1wkyfPWC5e/vk33vUBnesv3Xlh 3+jxBld3hLVk6hIZfzbjbHiCXwLVVBNjfGFTjCmVsH4wyAvKL6oNl6hJ/N0VJolSbQsmhV EWWW1j+TgNiiDyiEP9Zya8h0Qw6q/ZKSFreawGiS+tXl2MFM0MlP21NFvpxilvgISIgpMD hvY4/1CMrQ9EuvDWapQ9qviLoUq344+KG90MBwajiZanfqaK+FNE+MnQyEm9Yg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hHB4s0PwfzBGN for ; Sat, 08 Aug 2026 06:31:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3d75c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 08 Aug 2026 06:31:57 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kevin Bowling Subject: git: a97e1c2450ae - main - enic: Correct queue and attach resource ownership List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: a97e1c2450ae62a73a3e0a2a2284e591cd82180a Auto-Submitted: auto-generated Date: Sat, 08 Aug 2026 06:31:57 +0000 Message-Id: <6a76cd5d.3d75c.20a1a3b3@gitrepo.freebsd.org> The branch main has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=a97e1c2450ae62a73a3e0a2a2284e591cd82180a commit a97e1c2450ae62a73a3e0a2a2284e591cd82180a Author: Kevin Bowling AuthorDate: 2026-08-08 04:14:53 +0000 Commit: Kevin Bowling CommitDate: 2026-08-08 06:31:47 +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. MFC after: 2 weeks --- 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