• Yinghai Lu's avatar
    PCI: Clear bridge resource flags if requested size is 0 · 93d2175d
    Yinghai Lu authored
    During pci remove/rescan testing found:
    
      pci 0000:c0:03.0: PCI bridge to [bus c4-c9]
      pci 0000:c0:03.0:   bridge window [io  0x1000-0x0fff]
      pci 0000:c0:03.0:   bridge window [mem 0xf0000000-0xf00fffff]
      pci 0000:c0:03.0:   bridge window [mem 0xfc180000000-0xfc197ffffff 64bit pref]
      pci 0000:c0:03.0: device not available (can't reserve [io  0x1000-0x0fff])
      pci 0000:c0:03.0: Error enabling bridge (-22), continuing
      pci 0000:c0:03.0: enabling bus mastering
      pci 0000:c0:03.0: setting latency timer to 64
      pcieport 0000:c0:03.0: device not available (can't reserve [io  0x1000-0x0fff])
      pcieport: probe of 0000:c0:03.0 failed with error -22
    
    This bug was caused by commit c8adf9a3 ("PCI: pre-allocate
    additional resources to devices only after successful allocation of
    essential resources.")
    
    After that commit, pci_hotplug_io_size is changed to additional_io_size
    from minium size.  So it will not go through resource_size(res) != 0
    path, and will not be reset.
    
    The root cause is: pci_bridge_check_ranges will set RESOURCE_IO flag for
    pci bridge, and later if children do not need IO resource.  those bridge
    resources will not need to be allocated.  but flags is still there.
    that will confuse the the pci_enable_bridges later.
    
    related code:
    
       static void assign_requested_resources_sorted(struct resource_list *head,
                                        struct resource_list_x *fail_head)
       {
               struct resource *res;
               struct resource_list *list;
               int idx;
    
               for (list = head->next; list; list = list->next) {
                       res = list->res;
                       idx = res - &list->dev->resource[0];
                       if (resource_size(res) && pci_assign_resource(list->dev, idx)) {
       ...
                               reset_resource(res);
                       }
               }
       }
    
    At last, We have to clear the flags in pbus_size_mem/io when requested
    size == 0 and !add_head.  becasue this case it will not go through
    adjust_resources_sorted().
    
    Just make size1 = size0 when !add_head. it will make flags get cleared.
    
    At the same time when requested size == 0, add_size != 0, will still
    have in head and add_list.  because we do not clear the flags for it.
    
    After this, we will get right result:
    
      pci 0000:c0:03.0: PCI bridge to [bus c4-c9]
      pci 0000:c0:03.0:   bridge window [io  disabled]
      pci 0000:c0:03.0:   bridge window [mem 0xf0000000-0xf00fffff]
      pci 0000:c0:03.0:   bridge window [mem 0xfc180000000-0xfc197ffffff 64bit pref]
      pci 0000:c0:03.0: enabling bus mastering
      pci 0000:c0:03.0: setting latency timer to 64
      pcieport 0000:c0:03.0: setting latency timer to 64
      pcieport 0000:c0:03.0: irq 160 for MSI/MSI-X
      pcieport 0000:c0:03.0: Signaling PME through PCIe PME interrupt
      pci 0000:c4:00.0: Signaling PME through PCIe PME interrupt
      pcie_pme 0000:c0:03.0:pcie01: service driver pcie_pme loaded
      aer 0000:c0:03.0:pcie02: service driver aer loaded
      pciehp 0000:c0:03.0:pcie04: Hotplug Controller:
    
    v3: more simple fix. also fix one typo in pbus_size_mem
    Signed-off-by: default avatarYinghai Lu <yinghai@kernel.org>
    Reviewed-by: default avatarRam Pai <linuxram@us.ibm.com>
    Cc: Jesse Barnes <jbarnes@virtuousgeek.org>
    Cc: Bjorn Helgaas <bhelgaas@google.com>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    93d2175d
setup-bus.c 28.8 KB