From nobody Fri Jan 16 19:41:06 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 4dt9Fh1l8Dz6NlhX for ; Fri, 16 Jan 2026 19:41:12 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dt9FZ1Bq3z3xbD for ; Fri, 16 Jan 2026 19:41:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768592466; 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=f4b8RMJEagW3aYhJzxRSqrb3l5f+KVbhBoilIjZvdzo=; b=iF99wfrZTDnPHFclfKS7K30qcgX3/FBqejLWY60mx0dKhtXXI1eJi2+nf6nYbKU/F8MXkz /lxjZSl4aZe5MELeqDZJHfuyYnnqaAhJbv5MlD9IOs+Qdsu7fXp2oPilBKpxCk/qOd0YXZ yBUo/xwe2rm4uZ01GSklN31TaGNcF/0MQDAHBP6+hKw27Vzpym/wRpwd+NonBoR95zgwvp fKSGjHgmuuonAc6VHMKthIYg0QcyrlPgvpp2xNlKA4VxDW+ZXqluStePkepu8UlAjEZ2lj C+jCmPHyQbAWCXS/wFnC+egw21Ji5S1H8AFQEV22lMUAcTKYRW36a1Theo26zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768592466; 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=f4b8RMJEagW3aYhJzxRSqrb3l5f+KVbhBoilIjZvdzo=; b=WDBlQDhGdlLLikT74KXVYfSWgU5qb8CHjDkapoPohdWZO9Yj3EKtTy9qSmG+iQ1r5H3flv 1j2gIQQH/8VyqcHqq3QPkS6Gq5zjV7vH8EUfCb+okEFEZLDYzYscFpyNvE0AL56cALpYe9 TKDID9JCcUcZp/UeBHiSyS9GRNyPBDu9BJ08wh1qYVSgwt/lxsF1AqQX7/xednEANnFDdu FSETL/MvgcYSa4dq9g5yjtP28trszHPiSdEpTv0+2LU4HkdSZ8Oy+HZL4DWSt5aaRhI46L fL7ofAF1E6qySaCe7IqRjtpsd2Jxodn62KutkayxrKrPN6bqMdqFDCN98ZnRkA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1768592466; a=rsa-sha256; cv=none; b=aoyly62+U/kWbg6ROssqzFAKkS5WBHDOJph8dHvfdycf9TZIl8anvmpCi9pBV0qdY+nZf1 TpXKeLUgh/QQLWwtfk7rLyZ28Iq1ii1hfn5tqr6EoKwXwJvkeic6QmQpJ9d93UtnHK40Mk 3otWLXXanOj4qsEvP9AxRB+W9HaIYBLo6ZKqJ1+Lu53xTSpNzeRuAktraTopYJta59wGyy twWDcXZrcs5INUGW9wZYuepkfWLjuBL/gMEIdN5wMQXM22kli8FMquhvNH1T+BDINU60CM uvAOi0wcrJQkHDtDJGPW7IU82wgyuXxMjq7rJ/fXQRh/uqmGHPrlE3OjfYjaZQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dt9FZ0TBlzCYf for ; Fri, 16 Jan 2026 19:41:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id e140 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 16 Jan 2026 19:41:06 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Bjoern A. Zeeb Subject: git: 2f4700c4dc15 - stable/14 - LinuxKPI: pci: allocate entire pci_dev hiereachy up to root port on attach 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: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 2f4700c4dc1598c1b99996412a932764d5cbac45 Auto-Submitted: auto-generated Date: Fri, 16 Jan 2026 19:41:06 +0000 Message-Id: <696a9452.e140.385619e@gitrepo.freebsd.org> The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=2f4700c4dc1598c1b99996412a932764d5cbac45 commit 2f4700c4dc1598c1b99996412a932764d5cbac45 Author: Bjoern A. Zeeb AuthorDate: 2025-09-04 20:22:00 +0000 Commit: Bjoern A. Zeeb CommitDate: 2026-01-16 19:37:50 +0000 LinuxKPI: pci: allocate entire pci_dev hiereachy up to root port on attach In linux_pci_attach_device() allocate a LinuxKPI pci_dev for each device in the hierarchy up to the root port[1] as we cannot do that later on demand as we may be in a context where we may not sleep. Take special care of DRM as there is a non-PCI device in the chain which needs to be skipped. iwlwifi(4) can hit this case called from a callout. While here leave a comment as the cleanup order of linux_pci_attach_device() needs correction seperately. Sponsored by: The FreeBSD Foundation (initially) PR: 283027 PR: 289647 Suggested by: jhb [1] Reviewed by: dumbbell Differential Revision: https://reviews.freebsd.org/D52069 (cherry picked from commit bbeeb585315645db20118ef349a4e3dc83b148cc) (cherry picked from commit 3860afe99ec39b9942967941181f28f27f3fc548) (cherry picked from commit 123c2dc6e15a62ceba3469caf0f1a6801214a7d3) (cherry picked from commit d8972ad2f6e7113d779d4ec975ce32552030b2a3) --- sys/compat/linuxkpi/common/src/linux_pci.c | 47 +++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_pci.c b/sys/compat/linuxkpi/common/src/linux_pci.c index 824f9a0118ae..1e6278418c83 100644 --- a/sys/compat/linuxkpi/common/src/linux_pci.c +++ b/sys/compat/linuxkpi/common/src/linux_pci.c @@ -343,6 +343,7 @@ lkpi_pci_dev_release(struct device *dev) static int lkpifill_pci_dev(device_t dev, struct pci_dev *pdev) { + struct pci_devinfo *dinfo; int error; error = kobject_init_and_add(&pdev->dev.kobj, &linux_dev_ktype, @@ -363,15 +364,24 @@ lkpifill_pci_dev(device_t dev, struct pci_dev *pdev) pdev->path_name = kasprintf(GFP_KERNEL, "%04d:%02d:%02d.%d", pci_get_domain(dev), pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev)); + pdev->bus = malloc(sizeof(*pdev->bus), M_DEVBUF, M_WAITOK | M_ZERO); - /* - * This should be the upstream bridge; pci_upstream_bridge() - * handles that case on demand as otherwise we'll shadow the - * entire PCI hierarchy. - */ - pdev->bus->self = pdev; pdev->bus->number = pci_get_bus(dev); pdev->bus->domain = pci_get_domain(dev); + + /* Check if we have reached the root to satisfy pci_is_root_bus() */ + dinfo = device_get_ivars(dev); + if (dinfo->cfg.pcie.pcie_location != 0 && + dinfo->cfg.pcie.pcie_type == PCIEM_TYPE_ROOT_PORT) { + pdev->bus->self = NULL; + } else { + /* + * This should be the upstream bridge; pci_upstream_bridge() + * handles that case on demand as otherwise we'll shadow the + * entire PCI hierarchy. + */ + pdev->bus->self = pdev; + } pdev->dev.bsddev = dev; pdev->dev.parent = &linux_root_device; pdev->dev.release = lkpi_pci_dev_release; @@ -396,7 +406,7 @@ lkpinew_pci_dev_release(struct device *dev) pdev = to_pci_dev(dev); if (pdev->root != NULL) pci_dev_put(pdev->root); - if (pdev->bus->self != pdev) + if (pdev->bus->self != pdev && pdev->bus->self != NULL) pci_dev_put(pdev->bus->self); free(pdev->bus, M_DEVBUF); if (pdev->msi_desc != NULL) { @@ -534,6 +544,7 @@ linux_pci_attach_device(device_t dev, struct pci_driver *pdrv, { struct resource_list_entry *rle; device_t parent; + struct pci_dev *pbus, *ppbus; uintptr_t rid; int error; bool isdrm; @@ -577,6 +588,27 @@ linux_pci_attach_device(device_t dev, struct pci_driver *pdrv, list_add(&pdev->links, &pci_devices); spin_unlock(&pci_lock); + /* + * Create the hierarchy now as we cannot on demand later. + * Take special care of DRM as there is a non-PCI device in the chain. + */ + pbus = pdev; + if (isdrm) { + pbus = lkpinew_pci_dev(parent); + if (pbus == NULL) { + error = ENXIO; + goto out_dma_init; + } + } + pcie_find_root_port(pbus); + if (isdrm) + pdev->root = pbus->root; + ppbus = pci_upstream_bridge(pbus); + while (ppbus != NULL && ppbus != pbus) { + pbus = ppbus; + ppbus = pci_upstream_bridge(pbus); + } + if (pdrv != NULL) { error = pdrv->probe(pdev, id); if (error) @@ -584,6 +616,7 @@ linux_pci_attach_device(device_t dev, struct pci_driver *pdrv, } return (0); +/* XXX the cleanup does not match the allocation up there. */ out_probe: free(pdev->bus, M_DEVBUF); spin_lock_destroy(&pdev->pcie_cap_lock);