From nobody Tue Apr 09 21:56:05 2024 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 4VDfsy0FVzz5G5fb; Tue, 9 Apr 2024 21:56:06 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VDfsx6p85z57N2; Tue, 9 Apr 2024 21:56:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712699766; 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=FWKrGnJdR8wb1xSKoQPi3iTEGVS40rZr7HRzh5XH94Q=; b=isDEEHvnJCFTQ4jV07OXpQ7ENUJob0inZXYtcOOwP5cI/fK2CzWs+0q09RMZJWXpvgZjSe IzHp4A5tQgiciQpmAvU+geGqNvuRZG2VJ1AVBnnC+c14i6q6XBmxVE32AQixo3eFamTj/F opR1l2waM3TQvk9deQ58qpQN2+ReqdHKQzE3hvQPgKeTg6k+YEUahS/YQ4ZmJOf8ZfnnIa xiQ06bTiTv7FGBkog0sSxnrhk1QmSRZvanaEYNhkBuZ7oWBf0CgPCJLj6AHGz0tfLI2Yx2 CBz55KGz3ZXqPwjtihWTFUIQUlpasxP7N2JXdjYGPQt6leXYww1tUa1aO3sHYQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712699766; a=rsa-sha256; cv=none; b=mYi74uw1FKZITooaGQVbmGzBu8BRwjSzYRD23VlQ7lwmjXexG/yfEdUMBQeQTMebsNS7G4 h4KiwkaHOUADl3kq5ChP4MbrDM88Qu/bdlHwl+Qj0BR150fzIOxpKpF41oOvQJrhd6dhW2 xvqbbD49x8+Zyx6rFrFUovDD8QBRjnU69kgoWepgTonwZf724bji68BPn/VElvyrh+LvmT MJs+/vt5OYierkygDCs3ZzmQHYa7bEXEF6A5hl/tHMBR39auxtiYtzSnPEi5xsKdVqhKy4 e7fAcr5QeXzK4QQWI789obX9LtPCBB7a4mrcTyhqLPPg51eniFUEuELqPX1PqA== 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=1712699766; 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=FWKrGnJdR8wb1xSKoQPi3iTEGVS40rZr7HRzh5XH94Q=; b=Ly7B57a2VcMMkxqAP77fmB464LKtT9rWD5W5/AUvU5ajO0TV/KwL66kOPotwU8ZbmcdKlC 1geMt9Rw1bds+Gogvg+ykYuyP0r7mF58aCbq1+I0KeSQXYgjBVSfs0WgQc2ixPwOMDwDqx th4bT9IOZ1Jw16wBmcfaF+p4viY3LbngWhGQ9WulT+ZFOMCZGj/lt1GSdORV/WM8lD5yTz LFElFxwRJ0zOkcIklcgjR7qi0SIWtVjWmnp7r1+YSmq9BTIljRDO+A5iVudFfA6oTYIi3d PrWgt3Jm4znroUtfI67kOlJ/UKZSLsUcuPAkm3l2eJtmpaf/jleNcAPtKapd2g== 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 4VDfsx6PWcz1B5X; Tue, 9 Apr 2024 21:56:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 439Lu5eJ031470; Tue, 9 Apr 2024 21:56:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 439Lu5bu031467; Tue, 9 Apr 2024 21:56:05 GMT (envelope-from git) Date: Tue, 9 Apr 2024 21:56:05 GMT Message-Id: <202404092156.439Lu5bu031467@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: 03713f805a91 - main - 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: Sender: dev-commits-src-all+owner@freebsd.org X-BeenThere: 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: 03713f805a91749eabcfb2e23e86489b2d4034df Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=03713f805a91749eabcfb2e23e86489b2d4034df commit 03713f805a91749eabcfb2e23e86489b2d4034df Author: John Baldwin AuthorDate: 2024-04-09 21:55:40 +0000 Commit: John Baldwin CommitDate: 2024-04-09 21:55:40 +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 --- 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 0bdc121f9727..82ed51460621 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: