From nobody Mon Aug 10 08:49:38 2026 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 4hJT2p4cSNz6nP3P for ; Mon, 10 Aug 2026 08:49:38 +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 4hJT2p2GDdz3kHt for ; Mon, 10 Aug 2026 08:49:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1786351778; 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=YybjHDv3ELfYCWEnoyug0Ki9UYsQTCe5+oQMljJPcdk=; b=llI4yFj7zURddVyO+DX+0rI6oPOqv4piNOlLROa9+00GsI9atMvayjUBeR2vnEp5ySiOmM 6bK/rqK1g6Ay7bG4wSRJ0d+L4/npHldKX6+1y9iRyBnZGykFgqE6gZ5/GPl1T3rQUDPg0+ tlMNwLmF2do2q/bsKLNN+4xJfn8XTelF/DL6eKry5nJwi3WRggg6y4HqGObUq/T0ZV4NKw 9V9XpZ6Iq0nMrDoF33KapU+AWhcDCpIWrsMUJWtYnk4CE2BYf7D8s9os09GasEfKCtQZHJ dR8qrzIOUWx+b4URxe+fGCwCl4Twv/urKQ43hf8DNielfWlvJ7gYGCHACDXj8g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1786351778; a=rsa-sha256; cv=none; b=ds7RL/kMrnKi5LRmAwBRg42xGdSMlxxsFsG2UlM7P9eaTowTBx/caisK+rQI4RiAL2aS2Z 4rAmww8Pu6sGI2qr3WK/H+4EYVzj987uQdDmpFYoI6MPQ8jkvJkzl44kl8rWsOOsImV5EC 8oACpesceoudp5w2p5LEG3evY0HjIQZWAa9fmjBiOIv1EeDr/nmF5XURXTNP3L4dMM5s6l CCffYVEN62cbjI8ltPQmgVyxJ+OCoceIvG65CBqULBs+k59tN8rt1PYQ0nKhXldPyKpzC4 F8BOSGT5Ull9HQT9TfkH9AGZKpb27Yi2nA2Ci4wUQMOPhFh1HHJH52TgToTCyw== 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=1786351778; 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=YybjHDv3ELfYCWEnoyug0Ki9UYsQTCe5+oQMljJPcdk=; b=FwPYiV1S9YRTTBKHvQK81jwweLpAvPSue0a/5hVtIcefmt+n0A+YWIUctEKl1c70m6Nmf2 uLT1T/Y1JfmmTUZNZkRyvDwdwaNTfICv/DHrjyyH7+iIuMXxftqHvvEykP1biBuI76LsOa 6c+GXdvW0r4cAVaJhZM4FdIB66eULre0NY3J7moRW3P1ctXyDqWfmERKX9Yy+2EkdeXKQf 6ePrsS8Vb6innCRj0QAkFthCvctWvcAXUNa4UEgIqOtm3L5PHTXwYSPcVpxQHJIVu4TM8V bP2G1wWQowr1ps3ZsrxluJPtgf+GkyOSOisXLQyHcJ4WJWN3OPkNYUb25ikk1A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hJT2p0gdWz12Wn for ; Mon, 10 Aug 2026 08:49:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 248f5 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 10 Aug 2026 08:49:38 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kevin Bowling Subject: git: 4b195f1a25d5 - main - pci_iov: Roll back failed VF enumeration 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 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: 4b195f1a25d5003117653a1a323ad19561dc8705 Auto-Submitted: auto-generated Date: Mon, 10 Aug 2026 08:49:38 +0000 Message-Id: <6a7990a2.248f5.44124fad@gitrepo.freebsd.org> The branch main has been updated by kbowling: URL: https://cgit.FreeBSD.org/src/commit/?id=4b195f1a25d5003117653a1a323ad19561dc8705 commit 4b195f1a25d5003117653a1a323ad19561dc8705 Author: Kevin Bowling AuthorDate: 2026-08-10 04:53:55 +0000 Commit: Kevin Bowling CommitDate: 2026-08-10 08:47:59 +0000 pci_iov: Roll back failed VF enumeration pci_iov_enumerate_vfs() logged a failed VF creation or driver configuration but still reported the whole SR-IOV configuration as successful. The PF remained enabled with the requested NumVFs and driver state even though one or more VF children were absent. Make VF enumeration atomic. Delete children created by the failed attempt, invoke the PF driver cleanup, disable VF memory space and VF Enable, release the IOV resources, and return the original error to iovctl. Also treat failure to create a VF child as an error instead of silently accepting a partial configuration. MFC after: 2 weeks --- sys/dev/pci/pci_iov.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/sys/dev/pci/pci_iov.c b/sys/dev/pci/pci_iov.c index 545d91e372f4..5d39de605c22 100644 --- a/sys/dev/pci/pci_iov.c +++ b/sys/dev/pci/pci_iov.c @@ -619,16 +619,16 @@ pci_iov_setup_bars(struct pci_devinfo *dinfo) return (0); } -static void +static int pci_iov_enumerate_vfs(struct pci_devinfo *dinfo, const nvlist_t *config, uint16_t first_rid, uint16_t rid_stride) { char device_name[VF_MAX_NAME]; const nvlist_t *device, *driver_config, *iov_config; - device_t bus, dev, vf; + device_t bus, dev, vf, *vfs; struct pcicfg_iov *iov; struct pci_devinfo *vfinfo; - int i, error; + int error, i, ncreated; uint16_t vid, did, next_rid; iov = dinfo->cfg.iov; @@ -637,6 +637,9 @@ pci_iov_enumerate_vfs(struct pci_devinfo *dinfo, const nvlist_t *config, next_rid = first_rid; vid = pci_get_vendor(dev); did = IOV_READ(dinfo, PCIR_SRIOV_VF_DID, 2); + vfs = mallocarray(iov->iov_num_vfs, sizeof(*vfs), M_SRIOV, + M_WAITOK | M_ZERO); + ncreated = 0; for (i = 0; i < iov->iov_num_vfs; i++, next_rid += rid_stride) { snprintf(device_name, sizeof(device_name), VF_PREFIX"%d", i); @@ -645,8 +648,11 @@ pci_iov_enumerate_vfs(struct pci_devinfo *dinfo, const nvlist_t *config, driver_config = nvlist_get_nvlist(device, DRIVER_CONFIG_NAME); vf = PCI_CREATE_IOV_CHILD(bus, dev, next_rid, vid, did); - if (vf == NULL) - break; + if (vf == NULL) { + error = ENXIO; + goto fail; + } + vfs[ncreated++] = vf; /* * If we are creating passthrough devices then force the ppt @@ -666,11 +672,19 @@ pci_iov_enumerate_vfs(struct pci_devinfo *dinfo, const nvlist_t *config, error = PCI_IOV_ADD_VF(dev, i, driver_config); if (error != 0) { device_printf(dev, "Failed to add VF %d\n", i); - device_delete_child(bus, vf); + goto fail; } } bus_attach_children(bus); + free(vfs, M_SRIOV); + return (0); + +fail: + for (i = 0; i < ncreated; i++) + device_delete_child(bus, vfs[i]); + free(vfs, M_SRIOV); + return (error); } static int @@ -799,7 +813,9 @@ pci_iov_config(struct cdev *cdev, struct pci_iov_arg *arg) /* Per specification, we must wait 100ms before accessing VFs. */ pause("iov", roundup(hz, 10)); - pci_iov_enumerate_vfs(dinfo, config, first_rid, rid_stride); + error = pci_iov_enumerate_vfs(dinfo, config, first_rid, rid_stride); + if (error != 0) + goto out; nvlist_destroy(config); iov->iov_flags &= ~IOV_BUSY; @@ -809,6 +825,9 @@ pci_iov_config(struct cdev *cdev, struct pci_iov_arg *arg) out: if (iov_inited) { PCI_IOV_UNINIT(dev); + iov_ctl = IOV_READ(dinfo, PCIR_SRIOV_CTL, 2); + iov_ctl &= ~(PCIM_SRIOV_VF_EN | PCIM_SRIOV_VF_MSE); + IOV_WRITE(dinfo, PCIR_SRIOV_CTL, iov_ctl, 2); IOV_WRITE(dinfo, PCIR_SRIOV_NUM_VFS, 0, 2); }