1. 20 3月, 2014 5 次提交
    • B
      PCI: Change pci_bus_alloc_resource() type_mask to unsigned long · 664c2848
      Bjorn Helgaas 提交于
      The pci_bus_alloc_resource() "type_mask" parameter is used to compare with
      the "flags" member of a struct resource, so it should be the same type,
      namely "unsigned long".
      
      No functional change because all current IORESOURCE_* flags fit in 32 bits.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      664c2848
    • B
      PCI: Check all IORESOURCE_TYPE_BITS in pci_bus_alloc_from_region() · aa11fc58
      Bjorn Helgaas 提交于
      When allocating space from a bus resource, i.e., from apertures leading to
      this bus, make sure the entire resource type matches.  The previous code
      assumed the IORESOURCE_TYPE_BITS field was a bitmask with only a single bit
      set, but this is not true.  IORESOURCE_TYPE_BITS is really an enumeration,
      and we have to check all the bits.
      
      See 72dcb119 ("resources: Add register address resource type").
      
      No functional change.  If we used this path for allocating IRQs, DMA
      channels, or bus numbers, this would fix a bug because those types are
      indistinguishable when masked by IORESOURCE_IO | IORESOURCE_MEM.  But we
      don't, so this shouldn't make any difference.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      aa11fc58
    • B
      PCI: Don't check resource_size() in pci_bus_alloc_resource() · e20fa660
      Bjorn Helgaas 提交于
      Paul reported that after f75b99d5 ("PCI: Enforce bus address limits in
      resource allocation") on a 32-bit kernel (CONFIG_PHYS_ADDR_T_64BIT not
      set), intel-gtt complained "can't ioremap flush page - no chipset
      flushing".  In addition, other PCI resource allocations, e.g., for bridge
      windows, failed.
      
      This happens because we incorrectly skip bus resources of
      [mem 0x00000000-0xffffffff] because we think they are of size zero.
      When resource_size_t is 32 bits wide, resource_size() on
      [mem 0x00000000-0xffffffff] returns 0 because (r->end - r->start + 1)
      overflows.
      
      Therefore, we can't use "resource_size() == 0" to decide that allocation
      from this resource will fail.  allocate_resource() should fail anyway if it
      can't satisfy the address constraints, so we should just depend on that.
      
      A [mem 0x00000000-0xffffffff] bus resource is obviously not really valid,
      but we do fall back to it as a default when we don't have information about
      host bridge apertures.
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=71611
      Fixes: f75b99d5 PCI: Enforce bus address limits in resource allocation
      Reported-and-tested-by: NPaul Bolle <pebolle@tiscali.nl>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      e20fa660
    • B
      PCI: Add "weak" generic pcibios_enable_device() implementation · 8a9d5609
      Bjorn Helgaas 提交于
      Many architectures implement pcibios_enable_device() the same way, so
      provide a default implementation in the core.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      8a9d5609
    • B
      PCI: Don't enable decoding if BAR hasn't been assigned an address · 3cedcc36
      Bjorn Helgaas 提交于
      Don't enable memory or I/O decoding if we haven't assigned or claimed the
      BAR's resource.
      
      If we enable decoding for a BAR that hasn't been assigned an address, we'll
      likely cause bus conflicts.  This declines to enable decoding for resources
      with IORESOURCE_UNSET.
      
      Note that drivers can use pci_enable_device_io() or pci_enable_device_mem()
      if they only care about specific types of BARs.  In that case, we don't
      bother checking whether the corresponding resources are assigned or
      claimed.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      3cedcc36
  2. 28 2月, 2014 6 次提交
    • B
      PCI: Mark 64-bit resource as IORESOURCE_UNSET if we only support 32-bit · c83bd900
      Bjorn Helgaas 提交于
      If we don't support 64-bit addresses, i.e., CONFIG_PHYS_ADDR_T_64BIT is not
      set, we can't deal with BARs above 4GB.  In this case we already pretend
      the BAR contained zero; this patch also sets IORESOURCE_UNSET so we can try
      to reallocate it later.
      
      I don't think this is exactly correct: what we care about here are *bus*
      addresses, not CPU addresses, so the tests of sizeof(resource_size_t)
      probably should be on sizeof(dma_addr_t) instead.  But this is what's been
      in -next, so we'll fix that later.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      c83bd900
    • B
      PCI: Don't try to claim IORESOURCE_UNSET resources · 29003beb
      Bjorn Helgaas 提交于
      If the IORESOURCE_UNSET bit is set, it means we haven't assigned an address
      yet, so don't try to claim the region.
      
      Also, make the error messages more uniform and add info about which BAR is
      involved.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      29003beb
    • B
      PCI: Check IORESOURCE_UNSET before updating BAR · cd8a4d36
      Bjorn Helgaas 提交于
      Check to make sure we don't update a BAR with an address we haven't
      assigned.
      
      If we haven't assigned an address to a resource, we shouldn't write it to a
      BAR.  This isn't a problem for the usual path via pci_assign_resource(),
      which clears IORESOURCE_UNSET before calling pci_update_resource(), but
      paths like pci_restore_bars() can call this for resources we haven't
      assigned.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      cd8a4d36
    • B
      PCI: Don't clear IORESOURCE_UNSET when updating BAR · 434aafc1
      Bjorn Helgaas 提交于
      Clear IORESOURCE_UNSET when we assign an address to a resource, not when we
      write the address to the BAR.
      
      Also, drop the "BAR %d: set to %pR" message; this is mostly redundant with
      the "BAR %d: assigned %pR" message from pci_assign_resource().
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      434aafc1
    • B
      PCI: Mark resources as IORESOURCE_UNSET if we can't assign them · bd064f0a
      Bjorn Helgaas 提交于
      When assigning addresses to resources, mark them with IORESOURCE_UNSET
      before we start and clear IORESOURCE_UNSET if assignment is successful.
      That means that if we print the resource during assignment, we will show
      the size, not a meaningless address.
      
      Also, clear IORESOURCE_UNSET if we do assign an address, so we print the
      address when it is valid.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      bd064f0a
    • B
      PCI: Remove pci_find_parent_resource() use for allocation · f44116ae
      Bjorn Helgaas 提交于
      If the resource hasn't been allocated yet, pci_find_parent_resource() is
      documented as returning the region "where it should be allocated from."
      This is impossible in general because there may be several candidates: a
      prefetchable BAR can be put in either a prefetchable or non-prefetchable
      window, a transparent bridge may have overlapping positively- and
      subtractively-decoded windows, and a root bus may have several windows of
      the same type.
      
      Allocation should be done by pci_bus_alloc_resource(), which iterates
      through all bus resources and looks for the best match, e.g., one with the
      desired prefetchability attributes, and falls back to less-desired
      possibilities.
      
      The only valid use of pci_find_parent_resource() is to find the parent of
      an already-allocated resource so we can claim it via request_resource(),
      and all we need for that is a bus region of the correct type that contains
      the resource.
      
      Note that like 8c8def26 ("PCI: allow matching of prefetchable resources
      to non-prefetchable windows"), this depends on pci_bus_for_each_resource()
      iterating through positively-decoded regions before subtractively-decoded
      ones.  We prefer not to return a subtractively-decoded region because
      requesting from it will likely conflict with the overlapping positively-
      decoded window (see Launchpad report below).
      
      Link: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/424142Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      CC: Linus Torvalds <torvalds@linux-foundation.org>
      f44116ae
  3. 27 2月, 2014 1 次提交
    • B
      resource: Add resource_contains() · 5edb93b8
      Bjorn Helgaas 提交于
      We have two identical copies of resource_contains() already, and more
      places that could use it.  This moves it to ioport.h where it can be
      shared.
      
      resource_contains(struct resource *r1, struct resource *r2) returns true
      iff r1 and r2 are the same type (most callers already checked this
      separately) and the r1 address range completely contains r2.
      
      In addition, the new resource_contains() checks that both r1 and r2 have
      addresses assigned to them.  If a resource is IORESOURCE_UNSET, it doesn't
      have a valid address and can't contain or be contained by another resource.
      Some callers already check this or for res->start.
      
      No functional change.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      5edb93b8
  4. 02 2月, 2014 1 次提交
    • R
      Revert "PCI: Remove from bus_list and release resources in pci_release_dev()" · 04480094
      Rafael J. Wysocki 提交于
      Revert commit ef83b078 "PCI: Remove from bus_list and release
      resources in pci_release_dev()" that made some nasty race conditions
      become possible.  For example, if a Thunderbolt link is unplugged
      and then replugged immediately, the pci_release_dev() resulting from
      the hot-remove code path may be racing with the hot-add code path
      which after that commit causes various kinds of breakage to happen
      (up to and including a hard crash of the whole system).
      
      Moreover, the problem that commit ef83b078 attempted to address
      cannot happen any more after commit 8a4c5c32 "PCI: Check parent
      kobject in pci_destroy_dev()", because pci_destroy_dev() will now
      return immediately if it has already been executed for the given
      device.
      
      Note, however, that the invocation of msi_remove_pci_irq_vectors()
      removed by commit ef83b078 from pci_free_resources() along with
      the other changes made by it is not added back because of subsequent
      code changes depending on that modification.
      
      Fixes: ef83b078 (PCI: Remove from bus_list and release resources in pci_release_dev())
      Reported-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      04480094
  5. 16 1月, 2014 2 次提交
    • R
      PCI: Check parent kobject in pci_destroy_dev() · 8a4c5c32
      Rafael J. Wysocki 提交于
      If pci_stop_and_remove_bus_device() is run concurrently for a device and
      its parent bridge via remove_callback(), both code paths attempt to acquire
      pci_rescan_remove_lock.  If the child device removal acquires it first,
      there will be no problems.  However, if the parent bridge removal acquires
      it first, it will eventually execute pci_destroy_dev() for the child
      device, but that device object will not be freed yet due to the reference
      held by the concurrent child removal.  Consequently, both
      pci_stop_bus_device() and pci_remove_bus_device() will be executed for that
      device unnecessarily and pci_destroy_dev() will see a corrupted list head
      in that object.  Moreover, an excess put_device() will be executed for that
      device in that case which may lead to a use-after-free in the final
      kobject_put() done by sysfs_schedule_callback_work().
      
      To avoid that problem, make pci_destroy_dev() check if the device's parent
      kobject is NULL, which only happens after device_del() has already run for
      it.  Make pci_destroy_dev() return immediately whithout doing anything in
      that case.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      8a4c5c32
    • R
      xen/pcifront: Use global PCI rescan-remove locking · a83919e0
      Rafael J. Wysocki 提交于
      Multiple race conditions are possible between the Xen pcifront device
      addition and removal and the generic PCI device addition and removal that
      can be triggered via sysfs.
      
      To avoid those race conditions make the Xen pcifront code use global PCI
      rescan-remove locking.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      a83919e0
  6. 15 1月, 2014 4 次提交
  7. 14 1月, 2014 9 次提交
  8. 11 1月, 2014 6 次提交
  9. 08 1月, 2014 3 次提交
    • Y
      PCI: Allocate 64-bit BARs above 4G when possible · d56dbf5b
      Yinghai Lu 提交于
      Try to allocate space for 64-bit BARs above 4G first, to preserve the space
      below 4G for 32-bit BARs.  If there's no space above 4G available, fall
      back to allocating anywhere.
      
      [bhelgaas: reworked starting from http://lkml.kernel.org/r/1387485843-17403-2-git-send-email-yinghai@kernel.org]
      Signed-off-by: NYinghai Lu <yinghai@kernel.org>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      d56dbf5b
    • Y
      PCI: Enforce bus address limits in resource allocation · f75b99d5
      Yinghai Lu 提交于
      When allocating space for 32-bit BARs, we previously limited RESOURCE
      addresses so they would fit in 32 bits.  However, the BUS address need not
      be the same as the resource address, and it's the bus address that must fit
      in the 32-bit BAR.
      
      This patch adds:
      
        - pci_clip_resource_to_region(), which clips a resource so it contains
          only the range that maps to the specified bus address region, e.g., to
          clip a resource to 32-bit bus addresses, and
      
        - pci_bus_alloc_from_region(), which allocates space for a resource from
          the specified bus address region,
      
      and changes pci_bus_alloc_resource() to allocate space for 64-bit BARs from
      the entire bus address region, and space for 32-bit BARs from only the bus
      address region below 4GB.
      
      If we had this window:
      
        pci_root HWP0002:0a: host bridge window [mem 0xf0180000000-0xf01fedfffff] (bus address [0x80000000-0xfedfffff])
      
      we previously could not put a 32-bit BAR there, because the CPU addresses
      don't fit in 32 bits.  This patch fixes this, so we can use this space for
      32-bit BARs.
      
      It's also possible (though unlikely) to have resources with 32-bit CPU
      addresses but bus addresses above 4GB.  In this case the previous code
      would allocate space that a 32-bit BAR could not map.
      
      Remove PCIBIOS_MAX_MEM_32, which is no longer used.
      
      [bhelgaas: reworked starting from http://lkml.kernel.org/r/1386658484-15774-3-git-send-email-yinghai@kernel.org]
      Signed-off-by: NYinghai Lu <yinghai@kernel.org>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      f75b99d5
    • B
      PCI: Split out bridge window override of minimum allocation address · 36e097a8
      Bjorn Helgaas 提交于
      pci_bus_alloc_resource() avoids allocating space below the "min" supplied
      by the caller (usually PCIBIOS_MIN_IO or PCIBIOS_MIN_MEM).  This is to
      protect badly documented motherboard resources.  But if we're allocating
      space inside an already-configured PCI-PCI bridge window, we ignore "min".
      
      See 688d1918 ("pci: make bus resource start address override minimum IO
      address").
      
      This patch moves the check to make it more visible and simplify future
      patches.  No functional change.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      36e097a8
  10. 05 1月, 2014 3 次提交