Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3869672pxv; Tue, 13 Jul 2021 05:51:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzskUd+EAT03Pua700G+6UIcwMr/CBOOTjfvwbb4nzVGIiWtTjctjwsb3xG3DPuZpxTPPuS X-Received: by 2002:a92:1942:: with SMTP id e2mr2956444ilm.4.1626180661219; Tue, 13 Jul 2021 05:51:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626180661; cv=none; d=google.com; s=arc-20160816; b=gzfTbcSPat9d3A9NwmYdACOkTzshSfOjAh9B1b7bxxeGVuiCxzlS37elFpV4fqMLLH 6u3PCwgH1ftB1YtTtpnuvZtU1tuPNrQ5tVecYHPdokEWnbLdVXot/+OnEqY3wzOAF0A2 B49eDFpJ2pna42aIbXcH50oBZoO6jXVVfeZEtKo4SGztNxyivQtkCGvKw/ztVDBaSpXx qjcTH3WRS7I3AOL0mGHzZFmWNDKqoEig6lgSuEZGtr/GQum6CHHKCwmrnWCCfmf1EHmH B5cg2+fabqPEdvdil1OvvuOCG+ZLBvIEnPGV/rm0iM7NsFT9U2GdOzTCqlecZM0rsKwG yzsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VKTLYaxwHaurvjQpqIVYOmBUcfv3FuH+zrzCHFmaYmE=; b=t5xMXwSxUlfhaTwAVuQImtpW+ZvZzcj5YfQFRk67eV0U3z41Ao6ZkoVDuW6FquGYUL pcDQQOIzuoGySVXWtwOOpDmdfTlf4Cb6wkGMYbapGzNFM2gqfFzEomv1f7PUWN98p6tq luAR/iXCiaziqm4vlrapope/HhQ2K8yeFdbi5eoPb9Fkvyua9NBqiY+KJquxUXY3iLn7 ZNmHcaLdjKVx3726bvem9hr4piJ9Xu2PauYm5hyKYxjMWVflWDAkYUt1fz3IinnAt9EK sI6mylMsIUMH9f8iLMuc/YLCkFoD249SUi9TZcn/fpM+HgciXjmKLS7L6wVkjHShAbre SPzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=uzd5MPvT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d21si4350152jam.9.2021.07.13.05.50.47; Tue, 13 Jul 2021 05:51:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=uzd5MPvT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236197AbhGMMxJ (ORCPT + 99 others); Tue, 13 Jul 2021 08:53:09 -0400 Received: from smtp-relay-canonical-0.canonical.com ([185.125.188.120]:44434 "EHLO smtp-relay-canonical-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236135AbhGMMxI (ORCPT ); Tue, 13 Jul 2021 08:53:08 -0400 Received: from localhost (1.general.khfeng.us.vpn [10.172.68.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id CCB6840613; Tue, 13 Jul 2021 12:50:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1626180617; bh=VKTLYaxwHaurvjQpqIVYOmBUcfv3FuH+zrzCHFmaYmE=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=uzd5MPvTl0ewwx6lTqNurVMdn+Y98K63CQoEcTf5B5Hvheg2M/IQ1kFuMRngHGNVT ABDgPZi3KmzlSGno2C/xMFqogj/5zqh5y1jyh+yeuvB0D5ryCxSC+9bE+HOHLsPU0l /gtLaG4s/0WbeJQJnnKbdYsE4gKNjDp228D1xai2PS9n+X4YOS4AzIEulR0ZXbi+FL 6nAfwx6H9ueHStP1k3MaKW0H09OrKNsYZfWfs8RJnM4XYRsQtOD5CblaCy/IXscPRq xTXxnulJiCD7fPL/plVm4BL2i99FqrZo0CP5TiqzehRMYzobAK2XJGE/6Pq2vxIUCA ajg598zGCvMOA== From: Kai-Heng Feng To: bhelgaas@google.com Cc: Kai-Heng Feng , Guenter Roeck , linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] PCI: Reinstate "PCI: Coalesce host bridge contiguous apertures" Date: Tue, 13 Jul 2021 20:50:07 +0800 Message-Id: <20210713125007.1260304-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210713075726.1232938-1-kai.heng.feng@canonical.com> References: <20210713075726.1232938-1-kai.heng.feng@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Built-in graphics on HP EliteDesk 805 G6 doesn't work because graphics can't get the BAR it needs: pci_bus 0000:00: root bus resource [mem 0x10020200000-0x100303fffff window] pci_bus 0000:00: root bus resource [mem 0x10030400000-0x100401fffff window] pci 0000:00:08.1: bridge window [mem 0xd2000000-0xd23fffff] pci 0000:00:08.1: bridge window [mem 0x10030000000-0x100401fffff 64bit pref] pci 0000:00:08.1: can't claim BAR 15 [mem 0x10030000000-0x100401fffff 64bit pref]: no compatible bridge window pci 0000:00:08.1: [mem 0x10030000000-0x100401fffff 64bit pref] clipped to [mem 0x10030000000-0x100303fffff 64bit pref] pci 0000:00:08.1: bridge window [mem 0x10030000000-0x100303fffff 64bit pref] pci 0000:07:00.0: can't claim BAR 0 [mem 0x10030000000-0x1003fffffff 64bit pref]: no compatible bridge window pci 0000:07:00.0: can't claim BAR 2 [mem 0x10040000000-0x100401fffff 64bit pref]: no compatible bridge window However, the root bus has two contiguous apertures that can contain the child resource requested. Coalesce contiguous apertures so we can allocate from the entire contiguous region. This is the second take of commit 65db04053efe ("PCI: Coalesce host bridge contiguous apertures"). The original approach sorts the apertures by address, but that makes NVMe stop working on QEMU ppc:sam460ex: PCI host bridge to bus 0002:00 pci_bus 0002:00: root bus resource [io 0x0000-0xffff] pci_bus 0002:00: root bus resource [mem 0xd80000000-0xdffffffff] (bus address [0x80000000-0xffffffff]) pci_bus 0002:00: root bus resource [mem 0xc0ee00000-0xc0eefffff] (bus address [0x00000000-0x000fffff]) After the offending commit: PCI host bridge to bus 0002:00 pci_bus 0002:00: root bus resource [io 0x0000-0xffff] pci_bus 0002:00: root bus resource [mem 0xc0ee00000-0xc0eefffff] (bus address [0x00000000-0x000fffff]) pci_bus 0002:00: root bus resource [mem 0xd80000000-0xdffffffff] (bus address [0x80000000-0xffffffff]) Since the apertures on HP EliteDesk 805 G6 are already in ascending order, doing a precautious sorting is not necessary. Remove the sorting part to avoid the regression on ppc:sam460ex. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=212013 Cc: Guenter Roeck Suggested-by: Bjorn Helgaas Signed-off-by: Kai-Heng Feng --- v2: - Bring back the original commit message. drivers/pci/probe.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 79177ac37880..5de157600466 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -877,11 +877,11 @@ static void pci_set_bus_msi_domain(struct pci_bus *bus) static int pci_register_host_bridge(struct pci_host_bridge *bridge) { struct device *parent = bridge->dev.parent; - struct resource_entry *window, *n; + struct resource_entry *window, *next, *n; struct pci_bus *bus, *b; - resource_size_t offset; + resource_size_t offset, next_offset; LIST_HEAD(resources); - struct resource *res; + struct resource *res, *next_res; char addr[64], *fmt; const char *name; int err; @@ -961,11 +961,34 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) if (nr_node_ids > 1 && pcibus_to_node(bus) == NUMA_NO_NODE) dev_warn(&bus->dev, "Unknown NUMA node; performance will be reduced\n"); + /* Coalesce contiguous windows */ + resource_list_for_each_entry_safe(window, n, &resources) { + if (list_is_last(&window->node, &resources)) + break; + + next = list_next_entry(window, node); + offset = window->offset; + res = window->res; + next_offset = next->offset; + next_res = next->res; + + if (res->flags != next_res->flags || offset != next_offset) + continue; + + if (res->end + 1 == next_res->start) { + next_res->start = res->start; + res->flags = res->start = res->end = 0; + } + } + /* Add initial resources to the bus */ resource_list_for_each_entry_safe(window, n, &resources) { - list_move_tail(&window->node, &bridge->windows); offset = window->offset; res = window->res; + if (!res->end) + continue; + + list_move_tail(&window->node, &bridge->windows); if (res->flags & IORESOURCE_BUS) pci_bus_insert_busn_res(bus, bus->number, res->end); -- 2.31.1