From nobody Mon Mar 3 20:49:08 2025 X-Original-To: dev-commits-src-all@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 4Z69sK3C8Vz5nfhQ; Mon, 03 Mar 2025 20:49:09 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z69sJ6FrZz3vHq; Mon, 03 Mar 2025 20:49:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741034948; 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=p9tD8t8dfG7pJwQe+cvPgSfUcn8QZpc+8zRzpH8Gqt8=; b=PGHz/3H4nDgc/gueWC2hc/MjkBqZ3+l1psEl9EFcv08qOIEX5FHqepUVWBVmKB9RVjNiZJ qB5d8e9GcyQvjFB8Fg5aMWuDd/sHe4FhFMGquNYXjSkyyJ+3k+L1gjrJkSm7Yv2o9LoC1N ZoqnT3LPEqpr5O+4r8DvqyGkg+urc7SsuI2ZGWU/hIP5i5RPU6r0NFRmKwrR7yYQa/oggt 3+6zLDhe3ehdLTaTkP/OAqP0Yena2Pey5w7q1BwAdLJahDJTez+9RzFOB5rKnn1juCUknU eItosG2yyBosYh9ib7s/UodBnA75fsfG9j7T7Dzir4FR3RfVDMh3qJZper2PuQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1741034948; a=rsa-sha256; cv=none; b=epWxPwXKaEY2feJy1cy82UEjOlXfAerystlN+B9RHvjBpDyX9ck2Qj2NKITPF4enrK+LDc fXyXWob1/BJVV/y206nDMGvlwua+EZZzJ588gWkI6Hv7368eY5C0W6bPn5ND8CnIB2VMe5 VcVz9IoLf0mbgzT4Dcxf8X5Jj9nTdNOGk4no4Z3sBIY6FOD5VwCTTcURQRJxKmHO1soFYd C3ULv4uP37uGOVWTjDjc8SJmn+ZYICwQCdsOmhFlVyBiZo+ld8A6Oc23KilMkRc0TsAKln wSCdVmNGZbqKxms3LXcXH4QPpBM1GDvvKrzWtLkiwqBjSCKXR7MDq3TSzmG1jA== 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=1741034948; 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=p9tD8t8dfG7pJwQe+cvPgSfUcn8QZpc+8zRzpH8Gqt8=; b=gcXqj5xmCOcCjKmXYy4V7AEQxFGxXkSMnBOheQUHeZW0vSeIBVUhWXPD6M1FVg0yyNWz6M cdpnSG/59Z1jEuD4dW7CVSOsCOQG1niL9z+L6oTOWA8tEy4i0DR3ZF9fTTqGSaa/p179d2 Xh3auCrcor2EH9c3DXGG9l77PFTQ2IbgBKrNLFATt/oPsLQtuai4K4BIab4hnUoAJx3vFa A8va2rVpHHoYsQbGag7pqkbIiFNXcr6PDvryfK+jiuwNyJE56nncwoGGDtiJjler37GaAx ZMgIAE5MrrFhnAFlNel15MHTJEFcxB7zjk5B6/ZfQfDRHonZJtRKQ3/jq8KR/Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Z69sJ5hR1z133s; Mon, 03 Mar 2025 20:49:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 523Kn8lL014055; Mon, 3 Mar 2025 20:49:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 523Kn8i0014052; Mon, 3 Mar 2025 20:49:08 GMT (envelope-from git) Date: Mon, 3 Mar 2025 20:49:08 GMT Message-Id: <202503032049.523Kn8i0014052@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Ambrisko Subject: git: 1c9c4a25e600 - main - enic: fix potential panic due to not understanding what iflib had allocated List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: ambrisko X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1c9c4a25e600bcfad3eec891d43221b55ddf7e19 Auto-Submitted: auto-generated The branch main has been updated by ambrisko: URL: https://cgit.FreeBSD.org/src/commit/?id=1c9c4a25e600bcfad3eec891d43221b55ddf7e19 commit 1c9c4a25e600bcfad3eec891d43221b55ddf7e19 Author: Doug Ambrisko AuthorDate: 2025-03-03 20:46:15 +0000 Commit: Doug Ambrisko CommitDate: 2025-03-03 20:49:01 +0000 enic: fix potential panic due to not understanding what iflib had allocated For safety I was trying to clear out the descriptor but the full descriptor was not allocated. Remove any code trying to do that so the same mistake won't be made. This was found when looking to MFC the prior change and having the loader, load the module. Remove cq->ntxqsets since the completion queue is part of the RX and TX sets --- sys/dev/enic/if_enic.c | 19 ++++++++----------- sys/dev/enic/vnic_cq.c | 2 -- sys/dev/enic/vnic_cq.h | 4 ---- sys/dev/enic/vnic_dev.c | 9 ++------- sys/dev/enic/vnic_dev.h | 1 - sys/dev/enic/vnic_rq.c | 2 -- sys/dev/enic/vnic_wq.c | 6 ++---- 7 files changed, 12 insertions(+), 31 deletions(-) diff --git a/sys/dev/enic/if_enic.c b/sys/dev/enic/if_enic.c index 26776244778e..35620fece6bf 100644 --- a/sys/dev/enic/if_enic.c +++ b/sys/dev/enic/if_enic.c @@ -494,8 +494,7 @@ enic_attach_pre(if_ctx_t ctx) ifmedia_add(softc->media, IFM_ETHER | IFM_10_FL, 0, NULL); /* - * Allocate the CQ here since TX is called first before RX for now - * assume RX and TX are the same + * Allocate the CQ here since TX is called first before RX. */ if (softc->enic.cq == NULL) softc->enic.cq = malloc(sizeof(struct vnic_cq) * @@ -504,8 +503,6 @@ enic_attach_pre(if_ctx_t ctx) if (softc->enic.cq == NULL) return (ENOMEM); - softc->enic.cq->ntxqsets = softc->enic.wq_count + softc->enic.rq_count; - /* * Allocate the consistent memory for stats and counters upfront so * both primary and secondary processes can access them. @@ -735,7 +732,7 @@ enic_tx_queues_alloc(if_ctx_t ctx, caddr_t * vaddrs, uint64_t * paddrs, for (q = 0; q < ntxqsets; q++) { struct vnic_wq *wq; struct vnic_cq *cq; - unsigned int cq_wq; + unsigned int cq_wq; wq = &softc->enic.wq[q]; cq_wq = enic_cq_wq(&softc->enic, q); @@ -755,7 +752,6 @@ enic_tx_queues_alloc(if_ctx_t ctx, caddr_t * vaddrs, uint64_t * paddrs, wq->head_idx = 0; wq->tail_idx = 0; - wq->ring.size = wq->ring.desc_count * wq->ring.desc_size; wq->ring.descs = vaddrs[q * ntxqs + 0]; wq->ring.base_addr = paddrs[q * ntxqs + 0]; @@ -768,7 +764,6 @@ enic_tx_queues_alloc(if_ctx_t ctx, caddr_t * vaddrs, uint64_t * paddrs, cq->ring.desc_count = softc->scctx->isc_ntxd[q]; cq->ring.desc_avail = cq->ring.desc_count - 1; - cq->ring.size = cq->ring.desc_count * cq->ring.desc_size; cq->ring.descs = vaddrs[q * ntxqs + 1]; cq->ring.base_addr = paddrs[q * ntxqs + 1]; @@ -824,7 +819,6 @@ enic_rx_queues_alloc(if_ctx_t ctx, caddr_t * vaddrs, uint64_t * paddrs, cq->ring.desc_count = softc->scctx->isc_nrxd[1]; cq->ring.desc_avail = cq->ring.desc_count - 1; - cq->ring.size = cq->ring.desc_count * cq->ring.desc_size; cq->ring.descs = vaddrs[q * nrxqs + 0]; cq->ring.base_addr = paddrs[q * nrxqs + 0]; @@ -840,7 +834,6 @@ enic_rx_queues_alloc(if_ctx_t ctx, caddr_t * vaddrs, uint64_t * paddrs, rq->ring.desc_count = softc->scctx->isc_nrxd[0]; rq->ring.desc_avail = rq->ring.desc_count - 1; - rq->ring.size = rq->ring.desc_count * rq->ring.desc_size; rq->ring.descs = vaddrs[q * nrxqs + 1]; rq->ring.base_addr = paddrs[q * nrxqs + 1]; rq->need_initial_post = true; @@ -1241,7 +1234,9 @@ enic_setup_txq_sysctl(struct vnic_wq *wq, int i, struct sysctl_ctx_list *ctx, { struct sysctl_oid *txsnode; struct sysctl_oid_list *txslist; - struct vnic_stats *stats = wq[i].vdev->stats; + struct vnic_stats *stats; + + stats = wq[i].vdev->stats; txsnode = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "hstats", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Host Statistics"); @@ -1277,7 +1272,9 @@ enic_setup_rxq_sysctl(struct vnic_rq *rq, int i, struct sysctl_ctx_list *ctx, { struct sysctl_oid *rxsnode; struct sysctl_oid_list *rxslist; - struct vnic_stats *stats = rq[i].vdev->stats; + struct vnic_stats *stats; + + stats = rq[i].vdev->stats; rxsnode = SYSCTL_ADD_NODE(ctx, child, OID_AUTO, "hstats", CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, "Host Statistics"); diff --git a/sys/dev/enic/vnic_cq.c b/sys/dev/enic/vnic_cq.c index 72de29e5a381..bd3629530a61 100644 --- a/sys/dev/enic/vnic_cq.c +++ b/sys/dev/enic/vnic_cq.c @@ -40,6 +40,4 @@ void vnic_cq_clean(struct vnic_cq *cq) ENIC_BUS_WRITE_4(cq->ctrl, CQ_HEAD, 0); ENIC_BUS_WRITE_4(cq->ctrl, CQ_TAIL, 0); ENIC_BUS_WRITE_4(cq->ctrl, CQ_TAIL_COLOR, 1); - - vnic_dev_clear_desc_ring(&cq->ring); } diff --git a/sys/dev/enic/vnic_cq.h b/sys/dev/enic/vnic_cq.h index b4549ee58c64..7f875d57ed74 100644 --- a/sys/dev/enic/vnic_cq.h +++ b/sys/dev/enic/vnic_cq.h @@ -71,10 +71,6 @@ struct vnic_cq { unsigned int tobe_rx_coal_timeval; ktime_t prev_ts; #endif - int ntxqsets; - int nrxqsets; - int ntxqsets_start; - int nrxqsets_start; }; void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable, diff --git a/sys/dev/enic/vnic_dev.c b/sys/dev/enic/vnic_dev.c index 2d555cb2b34d..a8228aed69aa 100644 --- a/sys/dev/enic/vnic_dev.c +++ b/sys/dev/enic/vnic_dev.c @@ -168,17 +168,12 @@ unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring, ring->desc_size = VNIC_ALIGN(desc_size, desc_align); - ring->size = ring->desc_count * ring->desc_size; - ring->size_unaligned = ring->size + ring->base_align; + ring->size_unaligned = ring->desc_count * ring->desc_size \ + + ring->base_align; return ring->size_unaligned; } -void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring) -{ - memset(ring->descs, 0, ring->size); -} - static int _vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd, int wait) { diff --git a/sys/dev/enic/vnic_dev.h b/sys/dev/enic/vnic_dev.h index 5e2d01d985f3..66583f4d278d 100644 --- a/sys/dev/enic/vnic_dev.h +++ b/sys/dev/enic/vnic_dev.h @@ -69,7 +69,6 @@ unsigned long vnic_dev_get_res_type_len(struct vnic_dev *vdev, enum vnic_res_type type); unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring, unsigned int desc_count, unsigned int desc_size); -void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring); int vnic_dev_alloc_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring, unsigned int desc_count, unsigned int desc_size); void vnic_dev_free_desc_ring(struct vnic_dev *vdev, diff --git a/sys/dev/enic/vnic_rq.c b/sys/dev/enic/vnic_rq.c index ef30563fa2f3..4c02347579b1 100644 --- a/sys/dev/enic/vnic_rq.c +++ b/sys/dev/enic/vnic_rq.c @@ -93,6 +93,4 @@ void vnic_rq_clean(struct vnic_rq *rq) } ENIC_BUS_WRITE_4(rq->ctrl, RX_POSTED_INDEX, fetch_index); - - vnic_dev_clear_desc_ring(&rq->ring); } diff --git a/sys/dev/enic/vnic_wq.c b/sys/dev/enic/vnic_wq.c index 995af3270a21..1d3120798798 100644 --- a/sys/dev/enic/vnic_wq.c +++ b/sys/dev/enic/vnic_wq.c @@ -37,9 +37,9 @@ int vnic_dev_alloc_desc_ring(struct vnic_dev *vdev, ring->last_count = 0; ring->desc_avail = ring->desc_count - 1; - ring->size = ring->desc_count * ring->desc_size; ring->base_align = 512; - ring->size_unaligned = ring->size + ring->base_align; + ring->size_unaligned = ring->desc_count * ring->desc_size \ + + ring->base_align; return (err); @@ -180,6 +180,4 @@ void vnic_wq_clean(struct vnic_wq *wq) ENIC_BUS_WRITE_4(wq->ctrl, TX_FETCH_INDEX, 0); ENIC_BUS_WRITE_4(wq->ctrl, TX_POSTED_INDEX, 0); ENIC_BUS_WRITE_4(wq->ctrl, TX_ERROR_STATUS, 0); - - vnic_dev_clear_desc_ring(&wq->ring); }