]> git.proxmox.com Git - pve-kernel.git/blame - patches/kernel/0009-PCI-Reinstate-PCI-Coalesce-host-bridge-contiguous-ap.patch
update sources to Ubuntu-5.13.0-21.21
[pve-kernel.git] / patches / kernel / 0009-PCI-Reinstate-PCI-Coalesce-host-bridge-contiguous-ap.patch
CommitLineData
a7de27ff
FG
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Kai-Heng Feng <kai.heng.feng@canonical.com>
3Date: Tue, 13 Jul 2021 20:50:07 +0800
4Subject: [PATCH] PCI: Reinstate "PCI: Coalesce host bridge contiguous
5 apertures"
6MIME-Version: 1.0
7Content-Type: text/plain; charset=UTF-8
8Content-Transfer-Encoding: 8bit
9
10Built-in graphics on HP EliteDesk 805 G6 doesn't work because graphics
11can't get the BAR it needs:
12 pci_bus 0000:00: root bus resource [mem 0x10020200000-0x100303fffff window]
13 pci_bus 0000:00: root bus resource [mem 0x10030400000-0x100401fffff window]
14
15 pci 0000:00:08.1: bridge window [mem 0xd2000000-0xd23fffff]
16 pci 0000:00:08.1: bridge window [mem 0x10030000000-0x100401fffff 64bit pref]
17 pci 0000:00:08.1: can't claim BAR 15 [mem 0x10030000000-0x100401fffff 64bit pref]: no compatible bridge window
18 pci 0000:00:08.1: [mem 0x10030000000-0x100401fffff 64bit pref] clipped to [mem 0x10030000000-0x100303fffff 64bit pref]
19 pci 0000:00:08.1: bridge window [mem 0x10030000000-0x100303fffff 64bit pref]
20 pci 0000:07:00.0: can't claim BAR 0 [mem 0x10030000000-0x1003fffffff 64bit pref]: no compatible bridge window
21 pci 0000:07:00.0: can't claim BAR 2 [mem 0x10040000000-0x100401fffff 64bit pref]: no compatible bridge window
22
23However, the root bus has two contiguous apertures that can contain the
24child resource requested.
25
26Coalesce contiguous apertures so we can allocate from the entire contiguous
27region.
28
29This is the second take of commit 65db04053efe ("PCI: Coalesce host
30bridge contiguous apertures"). The original approach sorts the apertures
31by address, but that makes NVMe stop working on QEMU ppc:sam460ex:
32 PCI host bridge to bus 0002:00
33 pci_bus 0002:00: root bus resource [io 0x0000-0xffff]
34 pci_bus 0002:00: root bus resource [mem 0xd80000000-0xdffffffff] (bus address [0x80000000-0xffffffff])
35 pci_bus 0002:00: root bus resource [mem 0xc0ee00000-0xc0eefffff] (bus address [0x00000000-0x000fffff])
36
37After the offending commit:
38 PCI host bridge to bus 0002:00
39 pci_bus 0002:00: root bus resource [io 0x0000-0xffff]
40 pci_bus 0002:00: root bus resource [mem 0xc0ee00000-0xc0eefffff] (bus address [0x00000000-0x000fffff])
41 pci_bus 0002:00: root bus resource [mem 0xd80000000-0xdffffffff] (bus address [0x80000000-0xffffffff])
42
43Since the apertures on HP EliteDesk 805 G6 are already in ascending
44order, doing a precautious sorting is not necessary.
45
46Remove the sorting part to avoid the regression on ppc:sam460ex.
47
48Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=212013
49Cc: Guenter Roeck <linux@roeck-us.net>
50Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
51Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
52Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
53---
54 drivers/pci/probe.c | 31 +++++++++++++++++++++++++++----
55 1 file changed, 27 insertions(+), 4 deletions(-)
56
57diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
58index be51670572fa..133f5d2b189d 100644
59--- a/drivers/pci/probe.c
60+++ b/drivers/pci/probe.c
61@@ -877,11 +877,11 @@ static void pci_set_bus_msi_domain(struct pci_bus *bus)
62 static int pci_register_host_bridge(struct pci_host_bridge *bridge)
63 {
64 struct device *parent = bridge->dev.parent;
65- struct resource_entry *window, *n;
66+ struct resource_entry *window, *next, *n;
67 struct pci_bus *bus, *b;
68- resource_size_t offset;
69+ resource_size_t offset, next_offset;
70 LIST_HEAD(resources);
71- struct resource *res;
72+ struct resource *res, *next_res;
73 char addr[64], *fmt;
74 const char *name;
75 int err;
76@@ -959,11 +959,34 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge)
77 if (nr_node_ids > 1 && pcibus_to_node(bus) == NUMA_NO_NODE)
78 dev_warn(&bus->dev, "Unknown NUMA node; performance will be reduced\n");
79
80+ /* Coalesce contiguous windows */
81+ resource_list_for_each_entry_safe(window, n, &resources) {
82+ if (list_is_last(&window->node, &resources))
83+ break;
84+
85+ next = list_next_entry(window, node);
86+ offset = window->offset;
87+ res = window->res;
88+ next_offset = next->offset;
89+ next_res = next->res;
90+
91+ if (res->flags != next_res->flags || offset != next_offset)
92+ continue;
93+
94+ if (res->end + 1 == next_res->start) {
95+ next_res->start = res->start;
96+ res->flags = res->start = res->end = 0;
97+ }
98+ }
99+
100 /* Add initial resources to the bus */
101 resource_list_for_each_entry_safe(window, n, &resources) {
102- list_move_tail(&window->node, &bridge->windows);
103 offset = window->offset;
104 res = window->res;
105+ if (!res->end)
106+ continue;
107+
108+ list_move_tail(&window->node, &bridge->windows);
109
110 if (res->flags & IORESOURCE_BUS)
111 pci_bus_insert_busn_res(bus, bus->number, res->end);