1. 21 3月, 2020 1 次提交
    • S
      driver core: Add device links from fwnode only for the primary device · 4dbe191c
      Saravana Kannan 提交于
      Sometimes, more than one (generally two) device can point to the same
      fwnode.  However, only one device is set as the fwnode's device
      (fwnode->dev) and can be looked up from the fwnode.
      
      Typically, only one of these devices actually have a driver and actually
      probe. If we create device links for all these devices, then the
      suppliers' of these devices (with the same fwnode) will never get a
      sync_state() call because one of their consumer devices will never probe
      (because they don't have a driver).
      
      So, create device links only for the device that is considered as the
      fwnode's device.
      
      One such example of this is the PCI bridge platform_device and the
      corresponding pci_bus device. Both these devices will have the same
      fwnode. It's the platform_device that is registered first and is set as
      the fwnode's device. Also the platform_device is the one that actually
      probes. Without this patch none of the suppliers of a PCI bridge
      platform_device would get a sync_state() callback.
      
      Cc: Bjorn Helgaas <bhelgaas@google.com>
      Cc: linux-pci@vger.kernel.org
      Reviewed-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NSaravana Kannan <saravanak@google.com>
      Link: https://lore.kernel.org/r/20200321045448.15192-1-saravanak@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4dbe191c
  2. 05 3月, 2020 5 次提交
  3. 04 3月, 2020 2 次提交
  4. 15 11月, 2019 1 次提交
  5. 03 11月, 2019 3 次提交
  6. 10 10月, 2019 1 次提交
    • R
      cpufreq: Avoid cpufreq_suspend() deadlock on system shutdown · 65650b35
      Rafael J. Wysocki 提交于
      It is incorrect to set the cpufreq syscore shutdown callback pointer
      to cpufreq_suspend(), because that function cannot be run in the
      syscore stage of system shutdown for two reasons: (a) it may attempt
      to carry out actions depending on devices that have already been shut
      down at that point and (b) the RCU synchronization carried out by it
      may not be able to make progress then.
      
      The latter issue has been present since commit 45975c7d ("rcu:
      Define RCU-sched API in terms of RCU for Tree RCU PREEMPT builds"),
      but the former one has been there since commit 90de2a4a ("cpufreq:
      suspend cpufreq governors on shutdown") regardless.
      
      Fix that by dropping cpufreq_syscore_ops altogether and making
      device_shutdown() call cpufreq_suspend() directly before shutting
      down devices, which is along the lines of what system-wide power
      management does.
      
      Fixes: 45975c7d ("rcu: Define RCU-sched API in terms of RCU for Tree RCU PREEMPT builds")
      Fixes: 90de2a4a ("cpufreq: suspend cpufreq governors on shutdown")
      Reported-by: NVille Syrjälä <ville.syrjala@linux.intel.com>
      Tested-by: NVille Syrjälä <ville.syrjala@linux.intel.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NViresh Kumar <viresh.kumar@linaro.org>
      Cc: 4.0+ <stable@vger.kernel.org> # 4.0+
      65650b35
  7. 04 10月, 2019 3 次提交
    • S
      driver core: Add sync_state driver/bus callback · fc5a251d
      Saravana Kannan 提交于
      This sync_state driver/bus callback is called once all the consumers
      of a supplier have probed successfully.
      
      This allows the supplier device's driver/bus to sync the supplier
      device's state to the software state with the guarantee that all the
      consumers are actively managing the resources provided by the supplier
      device.
      
      To maintain backwards compatibility and ease transition from existing
      frameworks and resource cleanup schemes, late_initcall_sync is the
      earliest when the sync_state callback might be called.
      
      There is no upper bound on the time by which the sync_state callback
      has to be called. This is because if a consumer device never probes,
      the supplier has to maintain its resources in the state left by the
      bootloader. For example, if the bootloader leaves the display
      backlight at a fixed voltage and the backlight driver is never probed,
      you don't want the backlight to ever be turned off after boot up.
      
      Also, when multiple devices are added after kernel init, some
      suppliers could be added before their consumer devices get added. In
      these instances, the supplier devices could get their sync_state
      callback called right after they probe because the consumers devices
      haven't had a chance to create device links to the suppliers.
      
      To handle this correctly, this change also provides APIs to
      pause/resume sync state callbacks so that when multiple devices are
      added, their sync_state callback evaluation can be postponed to happen
      after all of them are added.
      
      kbuild test robot reported missing documentation for device.state_synced
      Reported-by: Nkbuild test robot <lkp@intel.com>
      Signed-off-by: NSaravana Kannan <saravanak@google.com>
      Link: https://lore.kernel.org/r/20190904211126.47518-5-saravanak@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fc5a251d
    • S
      driver core: Add support for linking devices during device addition · e2ae9bcc
      Saravana Kannan 提交于
      The firmware corresponding to a device (dev.fwnode) might be able to
      provide functional dependency information between a device and its
      supplier and consumer devices.  Tracking this functional dependency
      allows optimizing device probe order and informing a supplier when all
      its consumers have probed (and thereby actively managing their
      resources).
      
      The existing device links feature allows tracking and using
      supplier-consumer relationships. So, this patch adds the add_links()
      fwnode callback to allow firmware to create device links for each
      device as the device is added.
      
      However, when consumer devices are added, they might not have a supplier
      device to link to despite needing mandatory resources/functionality from
      one or more suppliers. A waiting_for_suppliers list is created to track
      such consumers and retry linking them when new devices get added.
      Signed-off-by: NSaravana Kannan <saravanak@google.com>
      Link: https://lore.kernel.org/r/20190904211126.47518-3-saravanak@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e2ae9bcc
    • S
      driver core: Add fwnode_to_dev() to look up device from fwnode · 372a67c0
      Saravana Kannan 提交于
      It's often useful to look up a device that corresponds to a fwnode. So
      add an API to do that irrespective of the bus on which the device has
      been added to.
      Signed-off-by: NSaravana Kannan <saravanak@google.com>
      Link: https://lore.kernel.org/r/20190904211126.47518-2-saravanak@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      372a67c0
  8. 28 8月, 2019 3 次提交
  9. 14 8月, 2019 1 次提交
  10. 01 8月, 2019 3 次提交
    • S
      driver core: Add sync_state driver/bus callback · 8f8184d6
      Saravana Kannan 提交于
      This sync_state driver/bus callback is called once all the consumers
      of a supplier have probed successfully.
      
      This allows the supplier device's driver/bus to sync the supplier
      device's state to the software state with the guarantee that all the
      consumers are actively managing the resources provided by the supplier
      device.
      
      To maintain backwards compatibility and ease transition from existing
      frameworks and resource cleanup schemes, late_initcall_sync is the
      earliest when the sync_state callback might be called.
      
      There is no upper bound on the time by which the sync_state callback
      has to be called. This is because if a consumer device never probes,
      the supplier has to maintain its resources in the state left by the
      bootloader. For example, if the bootloader leaves the display
      backlight at a fixed voltage and the backlight driver is never probed,
      you don't want the backlight to ever be turned off after boot up.
      
      Also, when multiple devices are added after kernel init, some
      suppliers could be added before their consumer devices get added. In
      these instances, the supplier devices could get their sync_state
      callback called right after they probe because the consumers devices
      haven't had a chance to create device links to the suppliers.
      
      To handle this correctly, this change also provides APIs to
      pause/resume sync state callbacks so that when multiple devices are
      added, their sync_state callback evaluation can be postponed to happen
      after all of them are added.
      
      kbuild test robot reported missing documentation for device.state_synced
      Reported-by: Nkbuild test robot <lkp@intel.com>
      Signed-off-by: NSaravana Kannan <saravanak@google.com>
      Link: https://lore.kernel.org/r/20190731221721.187713-5-saravanak@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8f8184d6
    • S
      driver core: Add edit_links() callback for drivers · 134b23ee
      Saravana Kannan 提交于
      The driver core/bus adding supplier-consumer dependencies by default
      enables functional dependencies to be tracked correctly even when the
      consumer devices haven't had their drivers registered or loaded (if they
      are modules).
      
      However, when the bus incorrectly adds dependencies that it shouldn't
      have added, the devices might never probe.
      
      For example, if device-C is a consumer of device-S and they have
      phandles to each other in DT, the following could happen:
      
      1.  Device-S get added first.
      2.  The bus add_links() callback will (incorrectly) try to link it as
          a consumer of device-C.
      3.  Since device-C isn't present, device-S will be put in
          "waiting-for-supplier" list.
      4.  Device-C gets added next.
      5.  All devices in "waiting-for-supplier" list are retried for linking.
      6.  Device-S gets linked as consumer to Device-C.
      7.  The bus add_links() callback will (correctly) try to link it as
          a consumer of device-S.
      8.  This isn't allowed because it would create a cyclic device links.
      
      Neither devices will get probed since the supplier is marked as
      dependent on the consumer. And the consumer will never probe because the
      consumer can't get resources from the supplier.
      
      Without this patch, things stay in this broken state. However, with this
      patch, the execution will continue like this:
      
      9.  Device-C's driver is loaded.
      10. Device-C's driver removes Device-S as a consumer of Device-C.
      11. Device-C's driver adds Device-C as a consumer of Device-S.
      12. Device-S probes.
      14. Device-C probes.
      
      kbuild test robot reported missing documentation for device.has_edit_links
      Reported-by: Nkbuild test robot <lkp@intel.com>
      Signed-off-by: NSaravana Kannan <saravanak@google.com>
      Link: https://lore.kernel.org/r/20190731221721.187713-3-saravanak@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      134b23ee
    • S
      driver core: Add support for linking devices during device addition · 5302dd7d
      Saravana Kannan 提交于
      When devices are added, the bus might want to create device links to track
      functional dependencies between supplier and consumer devices. This
      tracking of supplier-consumer relationship allows optimizing device probe
      order and tracking whether all consumers of a supplier are active. The
      add_links bus callback is added to support this.
      
      However, when consumer devices are added, they might not have a supplier
      device to link to despite needing mandatory resources/functionality from
      one or more suppliers. A waiting_for_suppliers list is created to track
      such consumers and retry linking them when new devices get added.
      Signed-off-by: NSaravana Kannan <saravanak@google.com>
      Link: https://lore.kernel.org/r/20190731221721.187713-2-saravanak@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5302dd7d
  11. 31 7月, 2019 1 次提交
    • M
      driver core: Fix use-after-free and double free on glue directory · ac43432c
      Muchun Song 提交于
      There is a race condition between removing glue directory and adding a new
      device under the glue dir. It can be reproduced in following test:
      
      CPU1:                                         CPU2:
      
      device_add()
        get_device_parent()
          class_dir_create_and_add()
            kobject_add_internal()
              create_dir()    // create glue_dir
      
                                                    device_add()
                                                      get_device_parent()
                                                        kobject_get() // get glue_dir
      
      device_del()
        cleanup_glue_dir()
          kobject_del(glue_dir)
      
                                                      kobject_add()
                                                        kobject_add_internal()
                                                          create_dir() // in glue_dir
                                                            sysfs_create_dir_ns()
                                                              kernfs_create_dir_ns(sd)
      
            sysfs_remove_dir() // glue_dir->sd=NULL
            sysfs_put()        // free glue_dir->sd
      
                                                                // sd is freed
                                                                kernfs_new_node(sd)
                                                                  kernfs_get(glue_dir)
                                                                  kernfs_add_one()
                                                                  kernfs_put()
      
      Before CPU1 remove last child device under glue dir, if CPU2 add a new
      device under glue dir, the glue_dir kobject reference count will be
      increase to 2 via kobject_get() in get_device_parent(). And CPU2 has
      been called kernfs_create_dir_ns(), but not call kernfs_new_node().
      Meanwhile, CPU1 call sysfs_remove_dir() and sysfs_put(). This result in
      glue_dir->sd is freed and it's reference count will be 0. Then CPU2 call
      kernfs_get(glue_dir) will trigger a warning in kernfs_get() and increase
      it's reference count to 1. Because glue_dir->sd is freed by CPU1, the next
      call kernfs_add_one() by CPU2 will fail(This is also use-after-free)
      and call kernfs_put() to decrease reference count. Because the reference
      count is decremented to 0, it will also call kmem_cache_free() to free
      the glue_dir->sd again. This will result in double free.
      
      In order to avoid this happening, we also should make sure that kernfs_node
      for glue_dir is released in CPU1 only when refcount for glue_dir kobj is
      1 to fix this race.
      
      The following calltrace is captured in kernel 4.14 with the following patch
      applied:
      
      commit 726e4109 ("drivers: core: Remove glue dirs from sysfs earlier")
      
      --------------------------------------------------------------------------
      [    3.633703] WARNING: CPU: 4 PID: 513 at .../fs/kernfs/dir.c:494
                      Here is WARN_ON(!atomic_read(&kn->count) in kernfs_get().
      ....
      [    3.633986] Call trace:
      [    3.633991]  kernfs_create_dir_ns+0xa8/0xb0
      [    3.633994]  sysfs_create_dir_ns+0x54/0xe8
      [    3.634001]  kobject_add_internal+0x22c/0x3f0
      [    3.634005]  kobject_add+0xe4/0x118
      [    3.634011]  device_add+0x200/0x870
      [    3.634017]  _request_firmware+0x958/0xc38
      [    3.634020]  request_firmware_into_buf+0x4c/0x70
      ....
      [    3.634064] kernel BUG at .../mm/slub.c:294!
                      Here is BUG_ON(object == fp) in set_freepointer().
      ....
      [    3.634346] Call trace:
      [    3.634351]  kmem_cache_free+0x504/0x6b8
      [    3.634355]  kernfs_put+0x14c/0x1d8
      [    3.634359]  kernfs_create_dir_ns+0x88/0xb0
      [    3.634362]  sysfs_create_dir_ns+0x54/0xe8
      [    3.634366]  kobject_add_internal+0x22c/0x3f0
      [    3.634370]  kobject_add+0xe4/0x118
      [    3.634374]  device_add+0x200/0x870
      [    3.634378]  _request_firmware+0x958/0xc38
      [    3.634381]  request_firmware_into_buf+0x4c/0x70
      --------------------------------------------------------------------------
      
      Fixes: 726e4109 ("drivers: core: Remove glue dirs from sysfs earlier")
      Signed-off-by: NMuchun Song <smuchun@gmail.com>
      Reviewed-by: NMukesh Ojha <mojha@codeaurora.org>
      Signed-off-by: NPrateek Sood <prsood@codeaurora.org>
      Link: https://lore.kernel.org/r/20190727032122.24639-1-smuchun@gmail.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ac43432c
  12. 30 7月, 2019 6 次提交
  13. 25 7月, 2019 1 次提交
    • R
      driver core: Remove device link creation limitation · 515db266
      Rafael J. Wysocki 提交于
      If device_link_add() is called for a consumer/supplier pair with an
      existing device link between them and the existing link's type is
      not in agreement with the flags passed to that function by its
      caller, NULL will be returned.  That is seriously inconvenient,
      because it forces the callers of device_link_add() to worry about
      what others may or may not do even if that is not relevant to them
      for any other reasons.
      
      It turns out, however, that this limitation can be made go away
      relatively easily.
      
      The underlying observation is that if DL_FLAG_STATELESS has been
      passed to device_link_add() in flags for the given consumer/supplier
      pair at least once, calling either device_link_del() or
      device_link_remove() to release the link returned by it should work,
      but there are no other requirements associated with that flag.  In
      turn, if at least one of the callers of device_link_add() for the
      given consumer/supplier pair has not passed DL_FLAG_STATELESS to it
      in flags, the driver core should track the status of the link and act
      on it as appropriate (ie. the link should be treated as "managed").
      This means that DL_FLAG_STATELESS needs to be set for managed device
      links and it should be valid to call device_link_del() or
      device_link_remove() to drop references to them in certain
      sutiations.
      
      To allow that to happen, introduce a new (internal) device link flag
      called DL_FLAG_MANAGED and make device_link_add() set it automatically
      whenever DL_FLAG_STATELESS is not passed to it.  Also make it take
      additional references to existing device links that were previously
      stateless (that is, with DL_FLAG_STATELESS set and DL_FLAG_MANAGED
      unset) and will need to be managed going forward and initialize
      their status (which has been DL_STATE_NONE so far).
      
      Accordingly, when a managed device link is dropped automatically
      by the driver core, make it clear DL_FLAG_MANAGED, reset the link's
      status back to DL_STATE_NONE and drop the reference to it associated
      with DL_FLAG_MANAGED instead of just deleting it right away (to
      allow it to stay around in case it still needs to be released
      explicitly by someone).
      
      With that, since setting DL_FLAG_STATELESS doesn't mean that the
      device link in question is not managed any more, replace all of the
      status-tracking checks against DL_FLAG_STATELESS with analogous
      checks against DL_FLAG_MANAGED and update the documentation to
      reflect these changes.
      
      While at it, make device_link_add() reject flags that it does not
      recognize, including DL_FLAG_MANAGED.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: NSaravana Kannan <saravanak@google.com>
      Tested-by: NMarek Szyprowski <m.szyprowski@samsung.com>
      Review-by: NSaravana Kannan <saravanak@google.com>
      Link: https://lore.kernel.org/r/2305283.AStDPdUUnE@kreacherSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      515db266
  14. 19 7月, 2019 2 次提交
    • D
      driver-core, libnvdimm: Let device subsystems add local lockdep coverage · 87a30e1f
      Dan Williams 提交于
      For good reason, the standard device_lock() is marked
      lockdep_set_novalidate_class() because there is simply no sane way to
      describe the myriad ways the device_lock() ordered with other locks.
      However, that leaves subsystems that know their own local device_lock()
      ordering rules to find lock ordering mistakes manually. Instead,
      introduce an optional / additional lockdep-enabled lock that a subsystem
      can acquire in all the same paths that the device_lock() is acquired.
      
      A conversion of the NFIT driver and NVDIMM subsystem to a
      lockdep-validate device_lock() scheme is included. The
      debug_nvdimm_lock() implementation implements the correct lock-class and
      stacking order for the libnvdimm device topology hierarchy.
      
      Yes, this is a hack, but hopefully it is a useful hack for other
      subsystems device_lock() debug sessions. Quoting Greg:
      
          "Yeah, it feels a bit hacky but it's really up to a subsystem to mess up
           using it as much as anything else, so user beware :)
      
           I don't object to it if it makes things easier for you to debug."
      
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Ira Weiny <ira.weiny@intel.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Dave Jiang <dave.jiang@intel.com>
      Cc: Keith Busch <keith.busch@intel.com>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Vishal Verma <vishal.l.verma@intel.com>
      Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NDan Williams <dan.j.williams@intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Reviewed-by: NIra Weiny <ira.weiny@intel.com>
      Link: https://lore.kernel.org/r/156341210661.292348.7014034644265455704.stgit@dwillia2-desk3.amr.corp.intel.com
      87a30e1f
    • D
      drivers/base: Introduce kill_device() · 00289cd8
      Dan Williams 提交于
      The libnvdimm subsystem arranges for devices to be destroyed as a result
      of a sysfs operation. Since device_unregister() cannot be called from
      an actively running sysfs attribute of the same device libnvdimm
      arranges for device_unregister() to be performed in an out-of-line async
      context.
      
      The driver core maintains a 'dead' state for coordinating its own racing
      async registration / de-registration requests. Rather than add local
      'dead' state tracking infrastructure to libnvdimm device objects, export
      the existing state tracking via a new kill_device() helper.
      
      The kill_device() helper simply marks the device as dead, i.e. that it
      is on its way to device_del(), or returns that the device was already
      dead. This can be used in advance of calling device_unregister() for
      subsystems like libnvdimm that might need to handle multiple user
      threads racing to delete a device.
      
      This refactoring does not change any behavior, but it is a pre-requisite
      for follow-on fixes and therefore marked for -stable.
      
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: "Rafael J. Wysocki" <rafael@kernel.org>
      Fixes: 4d88a97a ("libnvdimm, nvdimm: dimm driver and base libnvdimm device-driver...")
      Cc: <stable@vger.kernel.org>
      Tested-by: NJane Chu <jane.chu@oracle.com>
      Reviewed-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Link: https://lore.kernel.org/r/156341207332.292348.14959761496009347574.stgit@dwillia2-desk3.amr.corp.intel.comSigned-off-by: NDan Williams <dan.j.williams@intel.com>
      00289cd8
  15. 24 6月, 2019 1 次提交
    • S
      drivers: Add generic helper to match by of_node · 65b66682
      Suzuki K Poulose 提交于
      Add a helper to match device by the of_node. This will be later used
      to provide wrappers to the device iterators for {bus/class/driver}_find_device().
      Convert other users to reuse this new helper.
      
      Cc: Alan Tull <atull@kernel.org>
      Cc: Andrew Lunn <andrew@lunn.ch>
      Cc: Daniel Vetter <daniel@ffwll.ch>
      Cc: David Airlie <airlied@linux.ie>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: devicetree@vger.kernel.org
      Cc: dri-devel@lists.freedesktop.org
      Cc: Florian Fainelli <f.fainelli@gmail.com>
      Cc: Frank Rowand <frowand.list@gmail.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Heiner Kallweit <hkallweit1@gmail.com>
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: Jonathan Hunter <jonathanh@nvidia.com>
      Cc: Lee Jones <lee.jones@linaro.org>
      Cc: Liam Girdwood <lgirdwood@gmail.com>
      Cc: linux-fpga@vger.kernel.org
      Cc: linux-i2c@vger.kernel.org
      Cc: linux-spi@vger.kernel.org
      Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
      Cc: Mark Brown <broonie@kernel.org>
      Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
      Cc: Maxime Ripard <maxime.ripard@bootlin.com>
      Cc: Moritz Fischer <mdf@kernel.org>
      Cc: Peter Rosin <peda@axentia.se>
      Cc: Rob Herring <robh+dt@kernel.org>
      Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
      Cc: Thierry Reding <thierry.reding@gmail.com>
      Cc: Thor Thayer <thor.thayer@linux.intel.com>
      Cc: Wolfram Sang <wsa@the-dreams.de>
      Cc: "Rafael J. Wysocki" <rafael@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Ulf Hansson <ulf.hansson@linaro.org>
      Cc: Joe Perches <joe@perches.com>
      Signed-off-by: NSuzuki K Poulose <suzuki.poulose@arm.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      65b66682
  16. 03 6月, 2019 1 次提交
  17. 26 4月, 2019 1 次提交
  18. 20 2月, 2019 1 次提交
    • R
      driver core: Fix PM-runtime for links added during consumer probe · 36003d4c
      Rafael J. Wysocki 提交于
      Commit 4c06c4e6 ("driver core: Fix possible supplier PM-usage
      counter imbalance") introduced a regression that causes suppliers
      to be suspended prematurely for device links added during consumer
      driver probe if the initial PM-runtime status of the consumer is
      "suspended" and the consumer is resumed after adding the link and
      before pm_runtime_put_suppliers() is called.  In that case,
      pm_runtime_put_suppliers() will drop the rpm_active refcount for
      the link by one and (since rpm_active is equal to two after the
      preceding consumer resume) the supplier's PM-runtime usage counter
      will be decremented, which may cause the supplier to suspend even
      though the consumer's PM-runtime status is "active".
      
      For this reason, partially revert commit 4c06c4e6 as the problem
      it tried to fix needs to be addressed somewhat differently, and
      change pm_runtime_get_suppliers() and pm_runtime_put_suppliers() so
      that the latter only drops rpm_active references acquired by the
      former.  [This requires adding a new field to struct device_link,
      but I coulnd't find a cleaner way to address the issue that would
      work in all cases.]
      
      This causes pm_runtime_put_suppliers() to effectively ignore device
      links added during consumer probe, so device_link_add() doesn't need
      to worry about ensuring that suppliers will remain active after
      pm_runtime_put_suppliers() for links created with DL_FLAG_RPM_ACTIVE
      set and it only needs to bump up rpm_active by one for those links,
      so pm_runtime_active_link() is not necessary any more.
      
      Fixes: 4c06c4e6 ("driver core: Fix possible supplier PM-usage counter imbalance")
      Reported-by: NJon Hunter <jonathanh@nvidia.com>
      Tested-by: NJon Hunter <jonathanh@nvidia.com>
      Tested-by: NUlf Hansson <ulf.hansson@linaro.org>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Tested-by: NThierry Reding <treding@nvidia.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      36003d4c
  19. 13 2月, 2019 1 次提交
    • R
      driver core: Fix possible supplier PM-usage counter imbalance · 4c06c4e6
      Rafael J. Wysocki 提交于
      If a stateless device link to a certain supplier with
      DL_FLAG_PM_RUNTIME set in the flags is added and then removed by the
      consumer driver's probe callback, the supplier's PM-runtime usage
      counter will be nonzero after that which effectively causes the
      supplier to remain "always on" going forward.
      
      Namely, device_link_add() called to add the link invokes
      device_link_rpm_prepare() which notices that the consumer driver is
      probing, so it increments the supplier's PM-runtime usage counter
      with the assumption that the link will stay around until
      pm_runtime_put_suppliers() is called by driver_probe_device(),
      but if the link goes away before that point, the supplier's
      PM-runtime usage counter will remain nonzero.
      
      To prevent that from happening, first rework pm_runtime_get_suppliers()
      and pm_runtime_put_suppliers() to use the rpm_active refounts of device
      links and make the latter only drop rpm_active and the supplier's
      PM-runtime usage counter for each link by one, unless rpm_active is
      one already for it.  Next, modify device_link_add() to bump up the
      new link's rpm_active refcount and the suppliers PM-runtime usage
      counter by two, to prevent pm_runtime_put_suppliers(), if it is
      called subsequently, from suspending the supplier prematurely (in
      case its PM-runtime usage counter goes down to 0 in there).
      
      Due to the way rpm_put_suppliers() works, this change does not
      affect runtime suspend of the consumer ends of new device links (or,
      generally, device links for which DL_FLAG_PM_RUNTIME has just been
      set).
      
      Fixes: e2f3cd83 ("driver core: Fix handling of runtime PM flags in device_link_add()")
      Reported-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      Tested-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4c06c4e6
  20. 01 2月, 2019 2 次提交
    • R
      driver core: Add device link flag DL_FLAG_AUTOPROBE_CONSUMER · e7dd4010
      Rafael J. Wysocki 提交于
      Add a new device link flag, DL_FLAG_AUTOPROBE_CONSUMER, to request the
      driver core to probe for a consumer driver automatically after binding
      a driver to the supplier device on a persistent managed device link.
      
      As unbinding the supplier driver on a managed device link causes the
      consumer driver to be detached from its device automatically, this
      flag provides a complementary mechanism which is needed to address
      some "composite device" use cases.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e7dd4010
    • R
      driver core: Make driver core own stateful device links · 72175d4e
      Rafael J. Wysocki 提交于
      Even though stateful device links are managed by the driver core in
      principle, their creators are allowed and sometimes even expected
      to drop references to them via device_link_del() or
      device_link_remove(), but that doesn't really play well with the
      "persistent" link concept.
      
      If "persistent" managed device links are created from driver
      probe callbacks, device_link_add() called to do that will take a
      new reference on the link each time the callback runs and those
      references will never be dropped, which kind of isn't nice.
      
      This issues arises because of the link reference counting carried
      out by device_link_add() for existing links, but that is only done to
      avoid deleting device links that may still be necessary, which
      shouldn't be a concern for managed (stateful) links.  These device
      links are managed by the driver core and whoever creates one of them
      will need it at least as long as until the consumer driver is detached
      from its device and deleting it may be left to the driver core just
      fine.
      
      For this reason, rework device_link_add() to apply the reference
      counting to stateless links only and make device_link_del() and
      device_link_remove() drop references to stateless links only too.
      After this change, if called to add a stateful device link for
      a consumer-supplier pair for which a stateful device link is
      present already, device_link_add() will return the existing link
      without incrementing its reference counter.  Accordingly,
      device_link_del() and device_link_remove() will WARN() and do
      nothing when called to drop a reference to a stateful link.  Thus,
      effectively, all stateful device links will be owned by the driver
      core.
      
      In addition, clean up the handling of the link management flags,
      DL_FLAG_AUTOREMOVE_CONSUMER and DL_FLAG_AUTOREMOVE_SUPPLIER, so that
      (a) they are never set at the same time and (b) if device_link_add()
      is called for a consumer-supplier pair with an existing stateful link
      between them, the flags of that link will be combined with the flags
      passed to device_link_add() to ensure that the life time of the link
      is sufficient for all of the callers of device_link_add() for the
      same consumer-supplier pair.
      
      Update the device_link_add() kerneldoc comment to reflect the
      above changes.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      72175d4e