From nobody Tue Jul 29 19:10:17 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 4bs4fy2bWpz63HwC; Tue, 29 Jul 2025 19:10:18 +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 4bs4fy084Hz3nfs; Tue, 29 Jul 2025 19:10:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753816218; 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=Arkk2zJ0U2UXaRIyQOVMncE5Ju/p0tO3ZI/ZIW3LVUI=; b=lQh3Mzu4Brz8ScQ1ucjmU9FrzK+vc/fqT46FshY7D+Q1172a6HnDYtW5ZWW7+Z/+ut+ynB L9kGu6a3abalzwmbbajmPzTIYwV6+k6h5qrxV3PJxe5/2E7ZDstTlQEYvDfvSw3kdteBXb JYiWhjdF3Yb81psa7KnaJIiDrAOfLvZ4RibCCS4ltcd5RuBP+0gXIJ7/UYDG+WNvJTkbxq uiMfVQ6sbXews/nGANd4cv6a49KufU+wBtOuH07RBoLzgw8zMgbQqAruWPDSR76ARTG6V0 ELEtEToJOrS+q/OVSxWVEGEi2SHABDysWyM+BBLuBCC9ojPFwb7ssZtfLBNUGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753816218; 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=Arkk2zJ0U2UXaRIyQOVMncE5Ju/p0tO3ZI/ZIW3LVUI=; b=KUS+GvnAQ9GoBJoOmnAcl0fMrbVX02h2fx1LIXTnouGLrDj8rbkK8CayyhSY4JUR/M/BHd dz/N9f5D8u4FSSJwBSHw8VZBHaHqx8ovP/g3EBV76ZxwYhVJOLrv0vzr4NZHDvZKDI/sYy sJ5IZYstxNkUeFrcVxUOJKQFv3WdG5qH+FybCLYNusDbfuMN52oXKT1xFjHC99j9qpDMBR Echrd90gd1TW5rek7cevHBQrGIS1Kz8mgm+tUwOyXy9ht9Xr2tEm+s8XfSo75YWGdBO/ou vvK3PPzR4uWiHRbkw+xeAutaOfSUJ8OnofbroSig4cfBR5MzU+TA5ZEisbeJlg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753816218; a=rsa-sha256; cv=none; b=VF6gkRxD2JPSM0QcbXT/QAgWOzZ5rBnry5uLd6JCjS/MZtlgCQdKXeViQW0ULVdCOh9pmz zmfikcJLDFuHhpoXjK/yNBt/lWWeCmfQ1a7Xtlzu/QRLrNcDJnDQFLEzqMXO8O3nDwPlMS kum1/rLawLZ9K4j9L2HYjZqcZvayEGmHQK1cAGd4MQ+t4bFgZDykDIlZ4bSjnrWlgAGWLw nszKFNdZmxrjnXs3It8jMA/7mpD9MAyfBPQdF8KfCRyjTHPoktSBrslEdHLP/fuiAE87dP L8+mGnyn5/X1xlrhPnjK9imgIwyLOjag/hSkaRXuSM05wpTtfbcislCT9cxbpw== 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 4bs4fx6PxFzkhq; Tue, 29 Jul 2025 19:10:17 +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 56TJAHSB062506; Tue, 29 Jul 2025 19:10:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56TJAHl6062497; Tue, 29 Jul 2025 19:10:17 GMT (envelope-from git) Date: Tue, 29 Jul 2025 19:10:17 GMT Message-Id: <202507291910.56TJAHl6062497@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: f7951799877c - main - pci_iov: Support dynamic subordinate bus growth during VF creation 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f7951799877c16cb901be1acc8d6643f0693cec4 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=f7951799877c16cb901be1acc8d6643f0693cec4 commit f7951799877c16cb901be1acc8d6643f0693cec4 Author: Chandrakanth Patil AuthorDate: 2025-07-29 00:28:51 +0000 Commit: John Baldwin CommitDate: 2025-07-29 19:09:53 +0000 pci_iov: Support dynamic subordinate bus growth during VF creation Certain SR-IOV devices enumerate Virtual Functions (VFs) on a different PCIe bus than their parent Physical Function (PF). In such cases, the default subordinate bus range assigned by BIOS may be insufficient to cover all VFs. This patch dynamically expands the subordinate bus range by: - Allocating additional bus numbers using bus_alloc_resource() when VFs are initialized - Releasing the reserved bus range during VF deletion via bus_release_resource() Reviewed by: jhb --- sys/dev/pci/pci_iov.c | 25 +++++++++++++++++++++---- sys/dev/pci/pci_iov_private.h | 2 ++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/sys/dev/pci/pci_iov.c b/sys/dev/pci/pci_iov.c index 1f72391fb6b4..0efcfeac9eff 100644 --- a/sys/dev/pci/pci_iov.c +++ b/sys/dev/pci/pci_iov.c @@ -734,11 +734,18 @@ pci_iov_config(struct cdev *cdev, struct pci_iov_arg *arg) first_rid = pci_get_rid(dev) + rid_off; last_rid = first_rid + (num_vfs - 1) * rid_stride; - /* We don't yet support allocating extra bus numbers for VFs. */ if (pci_get_bus(dev) != PCI_RID2BUS(last_rid)) { - device_printf(dev, "not enough PCIe bus numbers for VFs\n"); - error = ENOSPC; - goto out; + int rid = 0; + uint16_t last_rid_bus = PCI_RID2BUS(last_rid); + + iov->iov_bus_res = bus_alloc_resource(bus, PCI_RES_BUS, &rid, + last_rid_bus, last_rid_bus, 1, RF_ACTIVE); + if (iov->iov_bus_res == NULL) { + device_printf(dev, + "failed to allocate PCIe bus number for VFs\n"); + error = ENOSPC; + goto out; + } } if (!ari_enabled && PCI_RID2SLOT(last_rid) != 0) { @@ -786,6 +793,11 @@ out: } } + if (iov->iov_bus_res != NULL) { + bus_release_resource(bus, iov->iov_bus_res); + iov->iov_bus_res = NULL; + } + if (iov->iov_flags & IOV_RMAN_INITED) { rman_fini(&iov->rman); iov->iov_flags &= ~IOV_RMAN_INITED; @@ -896,6 +908,11 @@ pci_iov_delete_iov_children(struct pci_devinfo *dinfo) } } + if (iov->iov_bus_res != NULL) { + bus_release_resource(bus, iov->iov_bus_res); + iov->iov_bus_res = NULL; + } + if (iov->iov_flags & IOV_RMAN_INITED) { rman_fini(&iov->rman); iov->iov_flags &= ~IOV_RMAN_INITED; diff --git a/sys/dev/pci/pci_iov_private.h b/sys/dev/pci/pci_iov_private.h index 7ae2219b936d..ecf0a9b21be5 100644 --- a/sys/dev/pci/pci_iov_private.h +++ b/sys/dev/pci/pci_iov_private.h @@ -39,6 +39,8 @@ struct pcicfg_iov { struct cdev *iov_cdev; nvlist_t *iov_schema; + struct resource *iov_bus_res; + struct pci_iov_bar iov_bar[PCIR_MAX_BAR_0 + 1]; struct rman rman; char rman_name[64];