1. 06 5月, 2014 1 次提交
    • S
      device: introduce per device dma_pfn_offset · 8febcaa2
      Santosh Shilimkar 提交于
      On few architectures, there are few restrictions on DMAble area of system
      RAM. That also means that devices needs to know about this restrictions so
      that the dma_masks can be updated accordingly and dma address translation
      helpers can add/subtract the dma offset.
      
      In most of cases DMA addresses can be performed using offset value of
      Bus address space relatively to physical address space as following:
      
      PFN->DMA:  __pfn_to_phys(pfn + [-]dma_pfn_offset)
      DMA->PFN:  __phys_to_pfn(dma_addr) + [-]dma_pfn_offset
      
      So we introduce per device dma_pfn_offset which can be popullated
      by architecture init code while creating the devices.
      
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Russell King <linux@arm.linux.org.uk>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Cc: Olof Johansson <olof@lixom.net>
      Cc: Grant Likely <grant.likely@linaro.org>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Linus Walleij <linus.walleij@linaro.org>
      Reviewed-by: NRob Herring <robh@kernel.org>
      Signed-off-by: NGrygorii Strashko <grygorii.strashko@ti.com>
      Signed-off-by: NSantosh Shilimkar <santosh.shilimkar@ti.com>
      8febcaa2
  2. 26 3月, 2014 1 次提交
  3. 12 2月, 2014 1 次提交
  4. 08 2月, 2014 2 次提交
    • T
      sysfs, driver-core: remove unused {sysfs|device}_schedule_callback_owner() · ce8b04aa
      Tejun Heo 提交于
      All device_schedule_callback_owner() users are converted to use
      device_remove_file_self().  Remove now unused
      {sysfs|device}_schedule_callback_owner().
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ce8b04aa
    • T
      kernfs, sysfs, driver-core: implement kernfs_remove_self() and its wrappers · 6b0afc2a
      Tejun Heo 提交于
      Sometimes it's necessary to implement a node which wants to delete
      nodes including itself.  This isn't straightforward because of kernfs
      active reference.  While a file operation is in progress, an active
      reference is held and kernfs_remove() waits for all such references to
      drain before completing.  For a self-deleting node, this is a deadlock
      as kernfs_remove() ends up waiting for an active reference that itself
      is sitting on top of.
      
      This currently is worked around in the sysfs layer using
      sysfs_schedule_callback() which makes such removals asynchronous.
      While it works, it's rather cumbersome and inherently breaks
      synchronicity of the operation - the file operation which triggered
      the operation may complete before the removal is finished (or even
      started) and the removal may fail asynchronously.  If a removal
      operation is immmediately followed by another operation which expects
      the specific name to be available (e.g. removal followed by rename
      onto the same name), there's no way to make the latter operation
      reliable.
      
      The thing is there's no inherent reason for this to be asynchrnous.
      All that's necessary to do this synchronous is a dedicated operation
      which drops its own active ref and deactivates self.  This patch
      implements kernfs_remove_self() and its wrappers in sysfs and driver
      core.  kernfs_remove_self() is to be called from one of the file
      operations, drops the active ref the task is holding, removes the self
      node, and restores active ref to the dead node so that the ref is
      balanced afterwards.  __kernfs_remove() is updated so that it takes an
      early exit if the target node is already fully removed so that the
      active ref restored by kernfs_remove_self() after removal doesn't
      confuse the deactivation path.
      
      This makes implementing self-deleting nodes very easy.  The normal
      removal path doesn't even need to be changed to use
      kernfs_remove_self() for the self-deleting node.  The method can
      invoke kernfs_remove_self() on itself before proceeding the normal
      removal path.  kernfs_remove() invoked on the node by the normal
      deletion path will simply be ignored.
      
      This will replace sysfs_schedule_callback().  A subtle feature of
      sysfs_schedule_callback() is that it collapses multiple invocations -
      even if multiple removals are triggered, the removal callback is run
      only once.  An equivalent effect can be achieved by testing the return
      value of kernfs_remove_self() - only the one which gets %true return
      value should proceed with actual deletion.  All other instances of
      kernfs_remove_self() will wait till the enclosing kernfs operation
      which invoked the winning instance of kernfs_remove_self() finishes
      and then return %false.  This trivially makes all users of
      kernfs_remove_self() automatically show correct synchronous behavior
      even when there are multiple concurrent operations - all "echo 1 >
      delete" instances will finish only after the whole operation is
      completed by one of the instances.
      
      Note that manipulation of active ref is implemented in separate public
      functions - kernfs_[un]break_active_protection().
      kernfs_remove_self() is the only user at the moment but this will be
      used to cater to more complex cases.
      
      v2: For !CONFIG_SYSFS, dummy version kernfs_remove_self() was missing
          and sysfs_remove_file_self() had incorrect return type.  Fix it.
          Reported by kbuild test bot.
      
      v3: kernfs_[un]break_active_protection() separated out from
          kernfs_remove_self() and exposed as public API.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Cc: kbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6b0afc2a
  5. 14 1月, 2014 2 次提交
  6. 11 1月, 2014 2 次提交
    • T
      sysfs, driver-core: remove unused {sysfs|device}_schedule_callback_owner() · d1ba277e
      Tejun Heo 提交于
      All device_schedule_callback_owner() users are converted to use
      device_remove_file_self().  Remove now unused
      {sysfs|device}_schedule_callback_owner().
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d1ba277e
    • T
      kernfs, sysfs, driver-core: implement kernfs_remove_self() and its wrappers · 1ae06819
      Tejun Heo 提交于
      Sometimes it's necessary to implement a node which wants to delete
      nodes including itself.  This isn't straightforward because of kernfs
      active reference.  While a file operation is in progress, an active
      reference is held and kernfs_remove() waits for all such references to
      drain before completing.  For a self-deleting node, this is a deadlock
      as kernfs_remove() ends up waiting for an active reference that itself
      is sitting on top of.
      
      This currently is worked around in the sysfs layer using
      sysfs_schedule_callback() which makes such removals asynchronous.
      While it works, it's rather cumbersome and inherently breaks
      synchronicity of the operation - the file operation which triggered
      the operation may complete before the removal is finished (or even
      started) and the removal may fail asynchronously.  If a removal
      operation is immmediately followed by another operation which expects
      the specific name to be available (e.g. removal followed by rename
      onto the same name), there's no way to make the latter operation
      reliable.
      
      The thing is there's no inherent reason for this to be asynchrnous.
      All that's necessary to do this synchronous is a dedicated operation
      which drops its own active ref and deactivates self.  This patch
      implements kernfs_remove_self() and its wrappers in sysfs and driver
      core.  kernfs_remove_self() is to be called from one of the file
      operations, drops the active ref and deactivates using
      __kernfs_deactivate_self(), removes the self node, and restores active
      ref to the dead node using __kernfs_reactivate_self() so that the ref
      is balanced afterwards.  __kernfs_remove() is updated so that it takes
      an early exit if the target node is already fully removed so that the
      active ref restored by kernfs_remove_self() after removal doesn't
      confuse the deactivation path.
      
      This makes implementing self-deleting nodes very easy.  The normal
      removal path doesn't even need to be changed to use
      kernfs_remove_self() for the self-deleting node.  The method can
      invoke kernfs_remove_self() on itself before proceeding the normal
      removal path.  kernfs_remove() invoked on the node by the normal
      deletion path will simply be ignored.
      
      This will replace sysfs_schedule_callback().  A subtle feature of
      sysfs_schedule_callback() is that it collapses multiple invocations -
      even if multiple removals are triggered, the removal callback is run
      only once.  An equivalent effect can be achieved by testing the return
      value of kernfs_remove_self() - only the one which gets %true return
      value should proceed with actual deletion.  All other instances of
      kernfs_remove_self() will wait till the enclosing kernfs operation
      which invoked the winning instance of kernfs_remove_self() finishes
      and then return %false.  This trivially makes all users of
      kernfs_remove_self() automatically show correct synchronous behavior
      even when there are multiple concurrent operations - all "echo 1 >
      delete" instances will finish only after the whole operation is
      completed by one of the instances.
      
      v2: For !CONFIG_SYSFS, dummy version kernfs_remove_self() was missing
          and sysfs_remove_file_self() had incorrect return type.  Fix it.
          Reported by kbuild test bot.
      
      v3: Updated to use __kernfs_{de|re}activate_self().
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Cc: kbuild test robot <fengguang.wu@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1ae06819
  7. 15 11月, 2013 1 次提交
    • R
      ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node · 7b199811
      Rafael J. Wysocki 提交于
      Modify struct acpi_dev_node to contain a pointer to struct acpi_device
      associated with the given device object (that is, its ACPI companion
      device) instead of an ACPI handle corresponding to it.  Introduce two
      new macros for manipulating that pointer in a CONFIG_ACPI-safe way,
      ACPI_COMPANION() and ACPI_COMPANION_SET(), and rework the
      ACPI_HANDLE() macro to take the above changes into account.
      Drop the ACPI_HANDLE_SET() macro entirely and rework its users to
      use ACPI_COMPANION_SET() instead.  For some of them who used to
      pass the result of acpi_get_child() directly to ACPI_HANDLE_SET()
      introduce a helper routine acpi_preset_companion() doing an
      equivalent thing.
      
      The main motivation for doing this is that there are things
      represented by struct acpi_device objects that don't have valid
      ACPI handles (so called fixed ACPI hardware features, such as
      power and sleep buttons) and we would like to create platform
      device objects for them and "glue" them to their ACPI companions
      in the usual way (which currently is impossible due to the
      lack of valid ACPI handles).  However, there are more reasons
      why it may be useful.
      
      First, struct acpi_device pointers allow of much better type checking
      than void pointers which are ACPI handles, so it should be more
      difficult to write buggy code using modified struct acpi_dev_node
      and the new macros.  Second, the change should help to reduce (over
      time) the number of places in which the result of ACPI_HANDLE() is
      passed to acpi_bus_get_device() in order to obtain a pointer to the
      struct acpi_device associated with the given "physical" device,
      because now that pointer is returned by ACPI_COMPANION() directly.
      Finally, the change should make it easier to write generic code that
      will build both for CONFIG_ACPI set and unset without adding explicit
      compiler directives to it.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com> # on Haswell
      Reviewed-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      Reviewed-by: Aaron Lu <aaron.lu@intel.com> # for ATA and SDIO part
      7b199811
  8. 30 10月, 2013 1 次提交
  9. 17 10月, 2013 1 次提交
    • J
      devres: add kernel standard devm_k.alloc functions · 64c862a8
      Joe Perches 提交于
      Currently, devm_ managed memory only supports kzalloc.
      
      Convert the devm_kzalloc implementation to devm_kmalloc and remove the
      complete memset to 0 but still set the initial struct devres header and
      whatever padding before data to 0.
      
      Add the other normal alloc variants as static inlines with __GFP_ZERO
      added to the gfp flag where appropriate:
      
      	devm_kzalloc
      	devm_kcalloc
      	devm_kmalloc_array
      
      Add gfp.h to device.h for the newly added static inlines.
      
      akpm: the current API forces us to replace kmalloc() with kzalloc() when
      performing devm_ conversions.  This adds a relatively minor overhead.
      More significantly, it will defeat kmemcheck used-uninitialized checking,
      and for a particular driver, losing used-uninitialised checking for their
      core controlling data structures will significantly degrade kmemcheck
      usefulness.
      Signed-off-by: NJoe Perches <joe@perches.com>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Sangjung Woo <sangjung.woo@samsung.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      64c862a8
  10. 06 10月, 2013 2 次提交
  11. 29 9月, 2013 1 次提交
  12. 28 9月, 2013 1 次提交
  13. 27 9月, 2013 1 次提交
    • T
      sysfs: make attr namespace interface less convoluted · 58292cbe
      Tejun Heo 提交于
      sysfs ns (namespace) implementation became more convoluted than
      necessary while trying to hide ns information from visible interface.
      The relatively recent attr ns support is a good example.
      
      * attr ns tag is determined by sysfs_ops->namespace() callback while
        dir tag is determined by kobj_type->namespace().  The placement is
        arbitrary.
      
      * Instead of performing operations with explicit ns tag, the namespace
        callback is routed through sysfs_attr_ns(), sysfs_ops->namespace(),
        class_attr_namespace(), class_attr->namespace().  It's not simpler
        in any sense.  The only thing this convolution does is traversing
        the whole stack backwards.
      
      The namespace callbacks are unncessary because the operations involved
      are inherently synchronous.  The information can be provided in in
      straight-forward top-down direction and reversing that direction is
      unnecessary and against basic design principles.
      
      This backward interface is unnecessarily convoluted and hinders
      properly separating out sysfs from driver model / kobject for proper
      layering.  This patch updates attr ns support such that
      
      * sysfs_ops->namespace() and class_attr->namespace() are dropped.
      
      * sysfs_{create|remove}_file_ns(), which take explicit @ns param, are
        added and sysfs_{create|remove}_file() are now simple wrappers
        around the ns aware functions.
      
      * ns handling is dropped from sysfs_chmod_file().  Nobody uses it at
        this point.  sysfs_chmod_file_ns() can be added later if necessary.
      
      * Explicit @ns is propagated through class_{create|remove}_file_ns()
        and netdev_class_{create|remove}_file_ns().
      
      * driver/net/bonding which is currently the only user of attr
        namespace is updated to use netdev_class_{create|remove}_file_ns()
        with @bh->net as the ns tag instead of using the namespace callback.
      
      This patch should be an equivalent conversion without any functional
      difference.  It makes the code easier to follow, reduces lines of code
      a bit and helps proper separation and layering.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Kay Sievers <kay@vrfy.org>
      Acked-by: NDavid S. Miller <davem@davemloft.net>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      58292cbe
  14. 30 8月, 2013 1 次提交
    • R
      driver core / ACPI: Avoid device hot remove locking issues · 5e33bc41
      Rafael J. Wysocki 提交于
      device_hotplug_lock is held around the acpi_bus_trim() call in
      acpi_scan_hot_remove() which generally removes devices (it removes
      ACPI device objects at least, but it may also remove "physical"
      device objects through .detach() callbacks of ACPI scan handlers).
      Thus, potentially, device sysfs attributes are removed under that
      lock and to remove those attributes it is necessary to hold the
      s_active references of their directory entries for writing.
      
      On the other hand, the execution of a .show() or .store() callback
      from a sysfs attribute is carried out with that attribute's s_active
      reference held for reading.  Consequently, if any device sysfs
      attribute that may be removed from within acpi_scan_hot_remove()
      through acpi_bus_trim() has a .store() or .show() callback which
      acquires device_hotplug_lock, the execution of that callback may
      deadlock with the removal of the attribute.  [Unfortunately, the
      "online" device attribute of CPUs and memory blocks is one of them.]
      
      To avoid such deadlocks, make all of the sysfs attribute callbacks
      that need to lock device hotplug, for example store_online(), use
      a special function, lock_device_hotplug_sysfs(), to lock device
      hotplug and return the result of that function immediately if it is
      not zero.  This will cause the s_active reference of the directory
      entry in question to be released and the syscall to be restarted
      if device_hotplug_lock cannot be acquired.
      
      [show_online() actually doesn't need to lock device hotplug, but
      it is useful to serialize it with respect to device_offline() and
      device_online() for the same device (in case user space attempts to
      run them concurrently) which can be done with the help of
      device_lock().]
      Reported-by: NYasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
      Reported-and-tested-by: NGu Zheng <guz.fnst@cn.fujitsu.com>
      Suggested-by: NTejun Heo <tj@kernel.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Acked-by: NToshi Kani <toshi.kani@hp.com>
      5e33bc41
  15. 29 8月, 2013 1 次提交
    • D
      dev-core: fix build break when DEBUG is enabled · 8ef2d651
      Dmitry Kasatkin 提交于
      When DEBUG is defined, dev_dbg_ratelimited uses dynamic debug data
      structures even when CONFIG_DYNAMIC_DEBUG is not defined.
      It leads to build break.
      For example, when I try to use dev_dbg_ratelimited in USB code and
      CONFIG_USB_DEBUG is enabled, but CONFIG_DYNAMIC_DEBUG is not, I get:
      
        CC [M]  drivers/usb/host/xhci-ring.o
        drivers/usb/host/xhci-ring.c: In function ‘xhci_queue_intr_tx’:
        drivers/usb/host/xhci-ring.c:3059:3: error: implicit declaration of function ‘DEFINE_DYNAMIC_DEBUG_METADATA’ [-Werror=implicit-function-declaration]
        drivers/usb/host/xhci-ring.c:3059:3: error: ‘descriptor’ undeclared (first use in this function)
        drivers/usb/host/xhci-ring.c:3059:3: note: each undeclared identifier is reported only once for each function it appears in
        drivers/usb/host/xhci-ring.c:3059:3: error: implicit declaration of function ‘__dynamic_pr_debug’ [-Werror=implicit-function-declaration]
        drivers/usb/host/xhci-ring.c: In function ‘xhci_queue_isoc_tx_prepare’:
        drivers/usb/host/xhci-ring.c:3847:3: error: ‘descriptor’ undeclared (first use in this function)
        cc1: some warnings being treated as errors
        make[2]: *** [drivers/usb/host/xhci-ring.o] Error 1
        make[1]: *** [drivers/usb/host] Error 2
        make: *** [drivers/usb/] Error 2
      
      This patch separates definition for CONFIG_DYNAMIC_DEBUG and DEBUG cases.
      
      [Note, Sarah moved the comment above the macro to avoid checkpatch
      warnings.]
      Signed-off-by: NDmitry Kasatkin <d.kasatkin@samsung.com>
      Signed-off-by: NSarah Sharp <sarah.a.sharp@linux.intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8ef2d651
  16. 27 8月, 2013 1 次提交
  17. 24 8月, 2013 1 次提交
  18. 13 8月, 2013 3 次提交
  19. 17 7月, 2013 3 次提交
  20. 26 6月, 2013 1 次提交
    • M
      driver core: device.h: fix doc compilation warnings · bfd63cd2
      Michael Opdenacker 提交于
      This patch fixes the below 3 warnings running "make htmldocs",
      by adding descriptions for recently added structure members:
      
      DOCPROC Documentation/DocBook/device-drivers.xml
      Warning(/work/git.free-electrons.com/users/michael-opdenacker/linux//include/linux/device.h:116): No description found for parameter 'lock_key'
      Warning(/work/git.free-electrons.com/users/michael-opdenacker/linux//include/linux/device.h:723): No description found for parameter 'cma_area'
      Warning(/work/git.free-electrons.com/users/michael-opdenacker/linux//include/linux/device.h:723): No description found for parameter 'iommu_group'
      
      Don't hesitate to propose better descriptions!
      Signed-off-by: NMichael Opdenacker <michael.opdenacker@free-electrons.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bfd63cd2
  21. 12 5月, 2013 1 次提交
    • R
      Driver core: Add offline/online device operations · 4f3549d7
      Rafael J. Wysocki 提交于
      In some cases, graceful hot-removal of devices is not possible,
      although in principle the devices in question support hotplug.
      For example, that may happen for the last CPU in the system or
      for memory modules holding kernel memory.
      
      In those cases it is nice to be able to check if the given device
      can be gracefully hot-removed before triggering a removal procedure
      that cannot be aborted or reversed.  Unfortunately, however, the
      kernel currently doesn't provide any support for that.
      
      To address that deficiency, introduce support for offline and
      online operations that can be performed on devices, respectively,
      before a hot-removal and in case when it is necessary (or convenient)
      to put a device back online after a successful offline (that has not
      been followed by removal).  The idea is that the offline will fail
      whenever the given device cannot be gracefully removed from the
      system and it will not be allowed to use the device after a
      successful offline (until a subsequent online) in analogy with the
      existing CPU offline/online mechanism.
      
      For now, the offline and online operations are introduced at the
      bus type level, as that should be sufficient for the most urgent use
      cases (CPUs and memory modules).  In the future, however, the
      approach may be extended to cover some more complicated device
      offline/online scenarios involving device drivers etc.
      
      The lock_device_hotplug() and unlock_device_hotplug() functions are
      introduced because subsequent patches need to put larger pieces of
      code under device_hotplug_lock to prevent race conditions between
      device offline and removal from happening.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Reviewed-by: NToshi Kani <toshi.kani@hp.com>
      4f3549d7
  22. 12 4月, 2013 1 次提交
  23. 08 4月, 2013 1 次提交
    • K
      driver core: add uid and gid to devtmpfs · 3c2670e6
      Kay Sievers 提交于
      Some drivers want to tell userspace what uid and gid should be used for
      their device nodes, so allow that information to percolate through the
      driver core to userspace in order to make this happen.  This means that
      some systems (i.e.  Android and friends) will not need to even run a
      udev-like daemon for their device node manager and can just rely in
      devtmpfs fully, reducing their footprint even more.
      Signed-off-by: NKay Sievers <kay@vrfy.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3c2670e6
  24. 13 3月, 2013 2 次提交
    • M
      device: separate all subsys mutexes · be871b7e
      Michal Hocko 提交于
      ca22e56d (driver-core: implement 'sysdev' functionality for regular
      devices and buses) has introduced bus_register macro with a static
      key to distinguish different subsys mutex classes.
      
      This however doesn't work for different subsys which use a common
      registering function. One example is subsys_system_register (and
      mce_device and cpu_device).
      
      In the end this leads to the following lockdep splat:
      [  207.271924] ======================================================
      [  207.271932] [ INFO: possible circular locking dependency detected ]
      [  207.271942] 3.9.0-rc1-0.7-default+ #34 Not tainted
      [  207.271948] -------------------------------------------------------
      [  207.271957] bash/10493 is trying to acquire lock:
      [  207.271963]  (subsys mutex){+.+.+.}, at: [<ffffffff8134af27>] bus_remove_device+0x37/0x1c0
      [  207.271987]
      [  207.271987] but task is already holding lock:
      [  207.271995]  (cpu_hotplug.lock){+.+.+.}, at: [<ffffffff81046ccf>] cpu_hotplug_begin+0x2f/0x60
      [  207.272012]
      [  207.272012] which lock already depends on the new lock.
      [  207.272012]
      [  207.272023]
      [  207.272023] the existing dependency chain (in reverse order) is:
      [  207.272033]
      [  207.272033] -> #4 (cpu_hotplug.lock){+.+.+.}:
      [  207.272044]        [<ffffffff810ae329>] lock_acquire+0xe9/0x120
      [  207.272056]        [<ffffffff814ad807>] mutex_lock_nested+0x37/0x360
      [  207.272069]        [<ffffffff81046ba9>] get_online_cpus+0x29/0x40
      [  207.272082]        [<ffffffff81185210>] drain_all_stock+0x30/0x150
      [  207.272094]        [<ffffffff811853da>] mem_cgroup_reclaim+0xaa/0xe0
      [  207.272104]        [<ffffffff8118775e>] __mem_cgroup_try_charge+0x51e/0xcf0
      [  207.272114]        [<ffffffff81188486>] mem_cgroup_charge_common+0x36/0x60
      [  207.272125]        [<ffffffff811884da>] mem_cgroup_newpage_charge+0x2a/0x30
      [  207.272135]        [<ffffffff81150531>] do_wp_page+0x231/0x830
      [  207.272147]        [<ffffffff8115151e>] handle_pte_fault+0x19e/0x8d0
      [  207.272157]        [<ffffffff81151da8>] handle_mm_fault+0x158/0x1e0
      [  207.272166]        [<ffffffff814b6153>] do_page_fault+0x2a3/0x4e0
      [  207.272178]        [<ffffffff814b2578>] page_fault+0x28/0x30
      [  207.272189]
      [  207.272189] -> #3 (&mm->mmap_sem){++++++}:
      [  207.272199]        [<ffffffff810ae329>] lock_acquire+0xe9/0x120
      [  207.272208]        [<ffffffff8114c5ad>] might_fault+0x6d/0x90
      [  207.272218]        [<ffffffff811a11e3>] filldir64+0xb3/0x120
      [  207.272229]        [<ffffffffa013fc19>] call_filldir+0x89/0x130 [ext3]
      [  207.272248]        [<ffffffffa0140377>] ext3_readdir+0x6b7/0x7e0 [ext3]
      [  207.272263]        [<ffffffff811a1519>] vfs_readdir+0xa9/0xc0
      [  207.272273]        [<ffffffff811a15cb>] sys_getdents64+0x9b/0x110
      [  207.272284]        [<ffffffff814bb599>] system_call_fastpath+0x16/0x1b
      [  207.272296]
      [  207.272296] -> #2 (&type->i_mutex_dir_key#3){+.+.+.}:
      [  207.272309]        [<ffffffff810ae329>] lock_acquire+0xe9/0x120
      [  207.272319]        [<ffffffff814ad807>] mutex_lock_nested+0x37/0x360
      [  207.272329]        [<ffffffff8119c254>] link_path_walk+0x6f4/0x9a0
      [  207.272339]        [<ffffffff8119e7fa>] path_openat+0xba/0x470
      [  207.272349]        [<ffffffff8119ecf8>] do_filp_open+0x48/0xa0
      [  207.272358]        [<ffffffff8118d81c>] file_open_name+0xdc/0x110
      [  207.272369]        [<ffffffff8118d885>] filp_open+0x35/0x40
      [  207.272378]        [<ffffffff8135c76e>] _request_firmware+0x52e/0xb20
      [  207.272389]        [<ffffffff8135cdd6>] request_firmware+0x16/0x20
      [  207.272399]        [<ffffffffa03bdb91>] request_microcode_fw+0x61/0xd0 [microcode]
      [  207.272416]        [<ffffffffa03bd554>] microcode_init_cpu+0x104/0x150 [microcode]
      [  207.272431]        [<ffffffffa03bd61c>] mc_device_add+0x7c/0xb0 [microcode]
      [  207.272444]        [<ffffffff8134a419>] subsys_interface_register+0xc9/0x100
      [  207.272457]        [<ffffffffa04fc0f4>] 0xffffffffa04fc0f4
      [  207.272472]        [<ffffffff81000202>] do_one_initcall+0x42/0x180
      [  207.272485]        [<ffffffff810bbeff>] load_module+0x19df/0x1b70
      [  207.272499]        [<ffffffff810bc376>] sys_init_module+0xe6/0x130
      [  207.272511]        [<ffffffff814bb599>] system_call_fastpath+0x16/0x1b
      [  207.272523]
      [  207.272523] -> #1 (umhelper_sem){++++.+}:
      [  207.272537]        [<ffffffff810ae329>] lock_acquire+0xe9/0x120
      [  207.272548]        [<ffffffff814ae9c4>] down_read+0x34/0x50
      [  207.272559]        [<ffffffff81062bff>] usermodehelper_read_trylock+0x4f/0x100
      [  207.272575]        [<ffffffff8135c7dd>] _request_firmware+0x59d/0xb20
      [  207.272587]        [<ffffffff8135cdd6>] request_firmware+0x16/0x20
      [  207.272599]        [<ffffffffa03bdb91>] request_microcode_fw+0x61/0xd0 [microcode]
      [  207.272613]        [<ffffffffa03bd554>] microcode_init_cpu+0x104/0x150 [microcode]
      [  207.272627]        [<ffffffffa03bd61c>] mc_device_add+0x7c/0xb0 [microcode]
      [  207.272641]        [<ffffffff8134a419>] subsys_interface_register+0xc9/0x100
      [  207.272654]        [<ffffffffa04fc0f4>] 0xffffffffa04fc0f4
      [  207.272666]        [<ffffffff81000202>] do_one_initcall+0x42/0x180
      [  207.272678]        [<ffffffff810bbeff>] load_module+0x19df/0x1b70
      [  207.272690]        [<ffffffff810bc376>] sys_init_module+0xe6/0x130
      [  207.272702]        [<ffffffff814bb599>] system_call_fastpath+0x16/0x1b
      [  207.272715]
      [  207.272715] -> #0 (subsys mutex){+.+.+.}:
      [  207.272729]        [<ffffffff810ae002>] __lock_acquire+0x13b2/0x15f0
      [  207.272740]        [<ffffffff810ae329>] lock_acquire+0xe9/0x120
      [  207.272751]        [<ffffffff814ad807>] mutex_lock_nested+0x37/0x360
      [  207.272763]        [<ffffffff8134af27>] bus_remove_device+0x37/0x1c0
      [  207.272775]        [<ffffffff81349114>] device_del+0x134/0x1f0
      [  207.272786]        [<ffffffff813491f2>] device_unregister+0x22/0x60
      [  207.272798]        [<ffffffff814a24ea>] mce_cpu_callback+0x15e/0x1ad
      [  207.272812]        [<ffffffff814b6402>] notifier_call_chain+0x72/0x130
      [  207.272824]        [<ffffffff81073d6e>] __raw_notifier_call_chain+0xe/0x10
      [  207.272839]        [<ffffffff81498f76>] _cpu_down+0x1d6/0x350
      [  207.272851]        [<ffffffff81499130>] cpu_down+0x40/0x60
      [  207.272862]        [<ffffffff8149cc55>] store_online+0x75/0xe0
      [  207.272874]        [<ffffffff813474a0>] dev_attr_store+0x20/0x30
      [  207.272886]        [<ffffffff812090d9>] sysfs_write_file+0xd9/0x150
      [  207.272900]        [<ffffffff8118e10b>] vfs_write+0xcb/0x130
      [  207.272911]        [<ffffffff8118e924>] sys_write+0x64/0xa0
      [  207.272923]        [<ffffffff814bb599>] system_call_fastpath+0x16/0x1b
      [  207.272936]
      [  207.272936] other info that might help us debug this:
      [  207.272936]
      [  207.272952] Chain exists of:
      [  207.272952]   subsys mutex --> &mm->mmap_sem --> cpu_hotplug.lock
      [  207.272952]
      [  207.272973]  Possible unsafe locking scenario:
      [  207.272973]
      [  207.272984]        CPU0                    CPU1
      [  207.272992]        ----                    ----
      [  207.273000]   lock(cpu_hotplug.lock);
      [  207.273009]                                lock(&mm->mmap_sem);
      [  207.273020]                                lock(cpu_hotplug.lock);
      [  207.273031]   lock(subsys mutex);
      [  207.273040]
      [  207.273040]  *** DEADLOCK ***
      [  207.273040]
      [  207.273055] 5 locks held by bash/10493:
      [  207.273062]  #0:  (&buffer->mutex){+.+.+.}, at: [<ffffffff81209049>] sysfs_write_file+0x49/0x150
      [  207.273080]  #1:  (s_active#150){.+.+.+}, at: [<ffffffff812090c2>] sysfs_write_file+0xc2/0x150
      [  207.273099]  #2:  (x86_cpu_hotplug_driver_mutex){+.+.+.}, at: [<ffffffff81027557>] cpu_hotplug_driver_lock+0x17/0x20
      [  207.273121]  #3:  (cpu_add_remove_lock){+.+.+.}, at: [<ffffffff8149911c>] cpu_down+0x2c/0x60
      [  207.273140]  #4:  (cpu_hotplug.lock){+.+.+.}, at: [<ffffffff81046ccf>] cpu_hotplug_begin+0x2f/0x60
      [  207.273158]
      [  207.273158] stack backtrace:
      [  207.273170] Pid: 10493, comm: bash Not tainted 3.9.0-rc1-0.7-default+ #34
      [  207.273180] Call Trace:
      [  207.273192]  [<ffffffff810ab373>] print_circular_bug+0x223/0x310
      [  207.273204]  [<ffffffff810ae002>] __lock_acquire+0x13b2/0x15f0
      [  207.273216]  [<ffffffff812086b0>] ? sysfs_hash_and_remove+0x60/0xc0
      [  207.273227]  [<ffffffff810ae329>] lock_acquire+0xe9/0x120
      [  207.273239]  [<ffffffff8134af27>] ? bus_remove_device+0x37/0x1c0
      [  207.273251]  [<ffffffff814ad807>] mutex_lock_nested+0x37/0x360
      [  207.273263]  [<ffffffff8134af27>] ? bus_remove_device+0x37/0x1c0
      [  207.273274]  [<ffffffff812086b0>] ? sysfs_hash_and_remove+0x60/0xc0
      [  207.273286]  [<ffffffff8134af27>] bus_remove_device+0x37/0x1c0
      [  207.273298]  [<ffffffff81349114>] device_del+0x134/0x1f0
      [  207.273309]  [<ffffffff813491f2>] device_unregister+0x22/0x60
      [  207.273321]  [<ffffffff814a24ea>] mce_cpu_callback+0x15e/0x1ad
      [  207.273332]  [<ffffffff814b6402>] notifier_call_chain+0x72/0x130
      [  207.273344]  [<ffffffff81073d6e>] __raw_notifier_call_chain+0xe/0x10
      [  207.273356]  [<ffffffff81498f76>] _cpu_down+0x1d6/0x350
      [  207.273368]  [<ffffffff81027557>] ? cpu_hotplug_driver_lock+0x17/0x20
      [  207.273380]  [<ffffffff81499130>] cpu_down+0x40/0x60
      [  207.273391]  [<ffffffff8149cc55>] store_online+0x75/0xe0
      [  207.273402]  [<ffffffff813474a0>] dev_attr_store+0x20/0x30
      [  207.273413]  [<ffffffff812090d9>] sysfs_write_file+0xd9/0x150
      [  207.273425]  [<ffffffff8118e10b>] vfs_write+0xcb/0x130
      [  207.273436]  [<ffffffff8118e924>] sys_write+0x64/0xa0
      [  207.273447]  [<ffffffff814bb599>] system_call_fastpath+0x16/0x1b
      
      Which reports a false possitive deadlock because it sees:
      1) load_module -> subsys_interface_register -> mc_deveice_add (*) -> subsys->p->mutex -> link_path_walk -> lookup_slow -> i_mutex
      2) sys_write -> _cpu_down -> cpu_hotplug_begin -> cpu_hotplug.lock -> mce_cpu_callback -> mce_device_remove(**) -> device_unregister -> bus_remove_device -> subsys mutex
      3) vfs_readdir -> i_mutex -> filldir64 -> might_fault -> might_lock_read(mmap_sem) -> page_fault -> mmap_sem -> drain_all_stock -> cpu_hotplug.lock
      
      but
      1) takes cpu_subsys subsys (*) but 2) takes mce_device subsys (**) so
      the deadlock is not possible AFAICS.
      
      The fix is quite simple. We can pull the key inside bus_type structure
      because they are defined per device so the pointer will be unique as
      well. bus_register doesn't need to be a macro anymore so change it
      to the inline. We could get rid of __bus_register as there is no other
      caller but maybe somebody will want to use a different key so keep it
      around for now.
      Reported-by: NLi Zefan <lizefan@huawei.com>
      Signed-off-by: NMichal Hocko <mhocko@suse.cz>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      be871b7e
    • T
      driver/base: implement subsys_virtual_register() · d73ce004
      Tejun Heo 提交于
      Kay tells me the most appropriate place to expose workqueues to
      userland would be /sys/devices/virtual/workqueues/WQ_NAME which is
      symlinked to /sys/bus/workqueue/devices/WQ_NAME and that we're lacking
      a way to do that outside of driver core as virtual_device_parent()
      isn't exported and there's no inteface to conveniently create a
      virtual subsystem.
      
      This patch implements subsys_virtual_register() by factoring out
      subsys_register() from subsys_system_register() and using it with
      virtual_device_parent() as the origin directory.  It's identical to
      subsys_system_register() other than the origin directory but we aren't
      gonna restrict the device names which should be used under it.
      
      This will be used to expose workqueue attributes to userland.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Kay Sievers <kay.sievers@vrfy.org>
      d73ce004
  25. 26 2月, 2013 1 次提交
  26. 07 2月, 2013 1 次提交
  27. 23 1月, 2013 2 次提交
    • L
      drivers/pinctrl: grab default handles from device core · ab78029e
      Linus Walleij 提交于
      This makes the device core auto-grab the pinctrl handle and set
      the "default" (PINCTRL_STATE_DEFAULT) state for every device
      that is present in the device model right before probe. This will
      account for the lion's share of embedded silicon devcies.
      
      A modification of the semantics for pinctrl_get() is also done:
      previously if the pinctrl handle for a certain device was already
      taken, the pinctrl core would return an error. Now, since the
      core may have already default-grabbed the handle and set its
      state to "default", if the handle was already taken, this will
      be disregarded and the located, previously instanitated handle
      will be returned to the caller.
      
      This way all code in drivers explicitly requesting their pinctrl
      handlers will still be functional, and drivers that want to
      explicitly retrieve and switch their handles can still do that.
      But if the desired functionality is just boilerplate of this
      type in the probe() function:
      
      struct pinctrl  *p;
      
      p = devm_pinctrl_get_select_default(&dev);
      if (IS_ERR(p)) {
         if (PTR_ERR(p) == -EPROBE_DEFER)
              return -EPROBE_DEFER;
              dev_warn(&dev, "no pinctrl handle\n");
      }
      
      The discussion began with the addition of such boilerplate
      to the omap4 keypad driver:
      http://marc.info/?l=linux-input&m=135091157719300&w=2
      
      A previous approach using notifiers was discussed:
      http://marc.info/?l=linux-kernel&m=135263661110528&w=2
      This failed because it could not handle deferred probes.
      
      This patch alone does not solve the entire dilemma faced:
      whether code should be distributed into the drivers or
      if it should be centralized to e.g. a PM domain. But it
      solves the immediate issue of the addition of boilerplate
      to a lot of drivers that just want to grab the default
      state. As mentioned, they can later explicitly retrieve
      the handle and set different states, and this could as
      well be done by e.g. PM domains as it is only related
      to a certain struct device * pointer.
      
      ChangeLog v4->v5 (Stephen):
      - Simplified the devicecore grab code.
      - Deleted a piece of documentation recommending that pins
        be mapped to a device rather than hogged.
      ChangeLog v3->v4 (Linus):
      - Drop overzealous NULL checks.
      - Move kref initialization to pinctrl_create().
      - Seeking Tested-by from Stephen Warren so we do not disturb
        the Tegra platform.
      - Seeking ACK on this from Greg (and others who like it) so I
        can merge it through the pinctrl subsystem.
      ChangeLog v2->v3 (Linus):
      - Abstain from using IS_ERR_OR_NULL() in the driver core,
        Russell recently sent a patch to remove it. Handle the
        NULL case explicitly even though it's a bogus case.
      - Make sure we handle probe deferral correctly in the device
        core file. devm_kfree() the container on error so we don't
        waste memory for devices without pinctrl handles.
      - Introduce reference counting into the pinctrl core using
        <linux/kref.h> so that we don't release pinctrl handles
        that have been obtained for two or more places.
      ChangeLog v1->v2 (Linus):
      - Only store a pointer in the device struct, and only allocate
        this if it's really used by the device.
      
      Cc: Felipe Balbi <balbi@ti.com>
      Cc: Benoit Cousson <b-cousson@ti.com>
      Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
      Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
      Cc: Mitch Bradley <wmb@firmworks.com>
      Cc: Ulf Hansson <ulf.hansson@linaro.org>
      Cc: Rafael J. Wysocki <rjw@sisk.pl>
      Cc: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
      Cc: Rickard Andersson <rickard.andersson@stericsson.com>
      Cc: Russell King <linux@arm.linux.org.uk>
      Reviewed-by: NMark Brown <broonie@opensource.wolfsonmicro.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      [swarren: fixed and simplified error-handling in pinctrl_bind_pins(), to
      correctly handle deferred probe. Removed admonition from docs not to use
      pinctrl hogs for devices]
      Signed-off-by: NStephen Warren <swarren@nvidia.com>
      Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
      ab78029e
    • T
      lib: devres: Introduce devm_ioremap_resource() · 75096579
      Thierry Reding 提交于
      The devm_request_and_ioremap() function is very useful and helps avoid a
      whole lot of boilerplate. However, one issue that keeps popping up is
      its lack of a specific error code to determine which of the steps that
      it performs failed. Furthermore, while the function gives an example and
      suggests what error code to return on failure, a wide variety of error
      codes are used throughout the tree.
      
      In an attempt to fix these problems, this patch adds a new function that
      drivers can transition to. The devm_ioremap_resource() returns a pointer
      to the remapped I/O memory on success or an ERR_PTR() encoded error code
      on failure. Callers can check for failure using IS_ERR() and determine
      its cause by extracting the error code using PTR_ERR().
      
      devm_request_and_ioremap() is implemented as a wrapper around the new
      API and return NULL on failure as before. This ensures that backwards
      compatibility is maintained until all users have been converted to the
      new API, at which point the old devm_request_and_ioremap() function
      should be removed.
      
      A semantic patch is included which can be used to convert from the old
      devm_request_and_ioremap() API to the new devm_ioremap_resource() API.
      Some non-trivial cases may require manual intervention, though.
      Signed-off-by: NThierry Reding <thierry.reding@avionic-design.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Acked-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      75096579
  28. 21 11月, 2012 1 次提交
  29. 15 11月, 2012 1 次提交
    • M
      driver core / ACPI: Move ACPI support to core device and driver types · 06f64c8f
      Mika Westerberg 提交于
      With ACPI 5 we are starting to see devices that don't natively support
      discovery but can be enumerated with the help of the ACPI namespace.
      Typically, these devices can be represented in the Linux device driver
      model as platform devices or some serial bus devices, like SPI or I2C
      devices.
      
      Since we want to re-use existing drivers for those devices, we need a
      way for drivers to specify the ACPI IDs of supported devices, so that
      they can be matched against device nodes in the ACPI namespace.  To
      this end, it is sufficient to add a pointer to an array of supported
      ACPI device IDs, that can be provided by the driver, to struct device.
      
      Moreover, things like ACPI power management need to have access to
      the ACPI handle of each supported device, because that handle is used
      to invoke AML methods associated with the corresponding ACPI device
      node.  The ACPI handles of devices are now stored in the archdata
      member structure of struct device whose definition depends on the
      architecture and includes the ACPI handle only on x86 and ia64. Since
      the pointer to an array of supported ACPI IDs is added to struct
      device_driver in an architecture-independent way, it is logical to
      move the ACPI handle from archdata to struct device itself at the same
      time.  This also makes code more straightforward in some places and
      follows the example of Device Trees that have a poiter to struct
      device_node in there too.
      
      This changeset is based on Mika Westerberg's work.
      Signed-off-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Acked-by: NH. Peter Anvin <hpa@zytor.com>
      Acked-by: NTony Luck <tony.luck@intel.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      06f64c8f
  30. 26 10月, 2012 1 次提交