From nobody Thu Feb 27 14:17:25 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 4Z3YM93lY5z5qG2N; Thu, 27 Feb 2025 14:17:25 +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 4Z3YM92zTdz3xJv; Thu, 27 Feb 2025 14:17:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740665845; 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=Ptx2sE68wrphsPNQ/AZw/UG0U/I/4cp9qwjiwYCD77k=; b=IuX4XJrGW5Xm85hbIcKoxBYmwvd6UWDSBpfhaVyxLbRY0Juxjn3fK32vtuwsTUpj47n9OX /+NKwk4yMDtHr2e+oQ+mItiT7/6nXes5u/doS90Y5MBOWHPyX+4QdpkIZZnk4WFZFr3Wbr lLbLAiWdLCcZDU/4j+sRXMkRXN605z42lWmT5tnjC2BGbqnPAkguHdE/6v5IhVSQmOBRoj wNX361ERCD5AHfbaVo8dwZv53X7LeHG2BnwxRPR/g7YO41Y/1XQ7sLyaXgcYWdgdh8h1SX 5vkG4u9f5wnLhpBJTNp+pHa7htU+18EvX8tiCi1wwI+BtMoxWg1Nzz8JDYywUQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1740665845; a=rsa-sha256; cv=none; b=hVg25ezeWOvnkHVmUySUn4YhYjRuLUpvmq976XTeix1MnI90CUsHnSzKoWAR5YVdAk8QN3 okx3AQIZVdCpnvJnR1QEVpbu64d6Txkl8YY2YQ7/SMzL1L2Ji5q74V/xv9ncFNYgZ9eP2h L2Rwo3S0RE71f7A+MWGiDNxe8kJipJimhLn/ri0KWqW2t/+eWuYmfOwIa9tF+YKKFW3kCQ /Q6tqogIt1gZFYg0Z24Iv5EdQakR/pnU1CHCZ4rqhcH98MOkDbyBFyo0HBUIzHI1p+TBzi ej81+fPgO4k0EZBiDLVT2tgT3zGhGCMrCpg27o6jZ1pxV8i+fk+hxqeVVwHvvw== 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=1740665845; 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=Ptx2sE68wrphsPNQ/AZw/UG0U/I/4cp9qwjiwYCD77k=; b=pcYmAUdWMDEUtIC8sM3c4RvQK3VFtdjjUPXyLeprEm9vLcsKy/+JRHeHfcl3yl0n2tLZT6 r3WcG0wnVVJva6bR2hOdxNAVdUYBMgzbslFfFHiaWDsGMA3F78+uYCLdTdv8bA7B+9U4Ou lsPkm8iCNtYsCJe3dOMUZAdro0IMqYeEZdhxlnsX2VgM8QHgFzgmxAo8aUz8pSuKYxjLQd kq+SUUBoAXiC3/imqRAR42mjANmqFBT414BVWQp9103PD03ptHGZwfkDvmd0WKXrkPGba0 zz4CynzS5aADu6RCf9fhntNh1M1NacX1JMcyxZLCMueHBdmqAM11nA3rWQ+dWA== 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 4Z3YM92LLWzmqX; Thu, 27 Feb 2025 14:17:25 +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 51REHPR1017334; Thu, 27 Feb 2025 14:17:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51REHPGo017331; Thu, 27 Feb 2025 14:17:25 GMT (envelope-from git) Date: Thu, 27 Feb 2025 14:17:25 GMT Message-Id: <202502271417.51REHPGo017331@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 92e593668608 - stable/14 - pci_host_generic: Tolerate range resource allocation failures 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 92e593668608efde40dc1b6d97b60f01a9ce89fe Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=92e593668608efde40dc1b6d97b60f01a9ce89fe commit 92e593668608efde40dc1b6d97b60f01a9ce89fe Author: John Baldwin AuthorDate: 2024-04-09 21:55:40 +0000 Commit: John Baldwin CommitDate: 2025-02-27 13:09:23 +0000 pci_host_generic: Tolerate range resource allocation failures QEMU for armv7 includes a PCI memory range whose CPU address is greater than 4GB. This falls outside the range of armv7's global mem_rman used by the nexus driver. As a result, pcib0 fails to attach blocking all PCI devices. Instead, change the driver to be a bit more tolerant. If allocating a resource for a range fails, don't fail attaching the entire driver, but do skip adding the associated PCI range to the relevant rman in the pcib driver. This will prevent child devices from using BARs that allocate from this range. In the case of QEMU on armv7 devices can still allocate from an earlier PCI memory range that is within the 32-bit address space (and in fact none of the firmware-assigned memory BARs use addresses from the upper range). While here, reorder the operations on I/O ranges a bit: 1) print the range under bootverbose first (rather than last) so that the range is printed before any relevant errors for the range, 2) move rman_manage_region last after the parent resource has been set and allocated. Reported by: markj, Jenkins Reviewed by: markj Fixes: d79b6b8ec267 pci_host_generic: Don't rewrite resource start address for translation Differential Revision: https://reviews.freebsd.org/D44698 (cherry picked from commit 03713f805a91749eabcfb2e23e86489b2d4034df) --- sys/dev/pci/pci_host_generic.c | 55 ++++++++++++------------------------------ 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/sys/dev/pci/pci_host_generic.c b/sys/dev/pci/pci_host_generic.c index da49edcf91f5..4b7a1cb8ab39 100644 --- a/sys/dev/pci/pci_host_generic.c +++ b/sys/dev/pci/pci_host_generic.c @@ -80,6 +80,7 @@ pci_host_generic_core_attach(device_t dev) struct resource_map map; #endif struct generic_pcie_core_softc *sc; + struct rman *rm; uint64_t phys_base; uint64_t pci_base; uint64_t size; @@ -183,75 +184,51 @@ pci_host_generic_core_attach(device_t dev) range_descr = "prefetch"; flags = RF_PREFETCHABLE; type = SYS_RES_MEMORY; - error = rman_manage_region(&sc->pmem_rman, - pci_base, pci_base + size - 1); + rm = &sc->pmem_rman; break; case FLAG_TYPE_MEM: range_descr = "memory"; flags = 0; type = SYS_RES_MEMORY; - error = rman_manage_region(&sc->mem_rman, - pci_base, pci_base + size - 1); + rm = &sc->mem_rman; break; case FLAG_TYPE_IO: range_descr = "I/O port"; flags = 0; type = SYS_RES_IOPORT; - error = rman_manage_region(&sc->io_rman, - pci_base, pci_base + size - 1); + rm = &sc->io_rman; break; default: continue; } - if (error) { - device_printf(dev, "rman_manage_region() failed." - "error = %d\n", error); - goto err_rman_manage; - } + if (bootverbose) + device_printf(dev, + "PCI addr: 0x%jx, CPU addr: 0x%jx, Size: 0x%jx, Type: %s\n", + pci_base, phys_base, size, range_descr); error = bus_set_resource(dev, type, rid, phys_base, size); if (error != 0) { device_printf(dev, "failed to set resource for range %d: %d\n", tuple, error); - goto err_rman_manage; + continue; } sc->ranges[tuple].res = bus_alloc_resource_any(dev, type, &rid, RF_ACTIVE | RF_UNMAPPED | flags); if (sc->ranges[tuple].res == NULL) { device_printf(dev, "failed to allocate resource for range %d\n", tuple); - error = ENXIO; - goto err_rman_manage; + continue; + } + error = rman_manage_region(rm, pci_base, pci_base + size - 1); + if (error) { + device_printf(dev, "rman_manage_region() failed." + "error = %d\n", error); + continue; } - if (bootverbose) - device_printf(dev, - "PCI addr: 0x%jx, CPU addr: 0x%jx, Size: 0x%jx, Type: %s\n", - pci_base, phys_base, size, range_descr); } return (0); -err_rman_manage: - for (tuple = 0; tuple < MAX_RANGES_TUPLES; tuple++) { - if (sc->ranges[tuple].size == 0) - continue; /* empty range element */ - switch (FLAG_TYPE(sc->ranges[tuple].flags)) { - case FLAG_TYPE_PMEM: - case FLAG_TYPE_MEM: - type = SYS_RES_MEMORY; - break; - case FLAG_TYPE_IO: - type = SYS_RES_IOPORT; - break; - default: - continue; - } - if (sc->ranges[tuple].res != NULL) - bus_release_resource(dev, type, tuple + 1, - sc->ranges[tuple].res); - bus_delete_resource(dev, type, tuple + 1); - } - rman_fini(&sc->io_rman); err_io_rman: rman_fini(&sc->mem_rman); err_mem_rman: