1. 01 12月, 2022 1 次提交
    • R
      regulator: core: fix use_count leakage when handling boot-on · 0591b14c
      Rui Zhang 提交于
      I found a use_count leakage towards supply regulator of rdev with
      boot-on option.
      
      ┌───────────────────┐           ┌───────────────────┐
      │  regulator_dev A  │           │  regulator_dev B  │
      │     (boot-on)     │           │     (boot-on)     │
      │    use_count=0    │──supply──│    use_count=1    │
      │                   │           │                   │
      └───────────────────┘           └───────────────────┘
      
      In case of rdev(A) configured with `regulator-boot-on', the use_count
      of supplying regulator(B) will increment inside
      regulator_enable(rdev->supply).
      
      Thus, B will acts like always-on, and further balanced
      regulator_enable/disable cannot actually disable it anymore.
      
      However, B was also configured with `regulator-boot-on', we wish it
      could be disabled afterwards.
      Signed-off-by: NRui Zhang <zr.zhang@vivo.com>
      Link: https://lore.kernel.org/r/20221201033806.2567812-1-zr.zhang@vivo.comSigned-off-by: NMark Brown <broonie@kernel.org>
      0591b14c
  2. 23 11月, 2022 1 次提交
  3. 15 11月, 2022 1 次提交
  4. 03 11月, 2022 1 次提交
  5. 10 9月, 2022 1 次提交
  6. 30 8月, 2022 1 次提交
  7. 26 8月, 2022 2 次提交
    • D
      regulator: core: Don't err if allow-set-load but no allowed-modes · 57919f4a
      Douglas Anderson 提交于
      Apparently the device trees of some boards have the property
      "regulator-allow-set-load" for some of their regulators but then they
      don't specify anything for "regulator-allowed-modes". That's not
      really legit, but...
      
      ...before commit efb0cb50 ("regulator: qcom-rpmh: Implement
      get_optimum_mode(), not set_load()") they used to get away with it, at
      least on boards using RPMH regulators. That's because when a regulator
      driver implements set_load() then the core doesn't look at
      "regulator-allowed-modes" when trying to automatically adjust things
      in response to the regulator's load. The core doesn't know what mode
      we'll end up in, so how could it validate it?
      
      Said another way: before commit efb0cb50 ("regulator: qcom-rpmh:
      Implement get_optimum_mode(), not set_load()") some boards _were_
      having the regulator mode adjusted despite listing no allowed
      modes. After commit efb0cb50 ("regulator: qcom-rpmh: Implement
      get_optimum_mode(), not set_load()") these same boards were now
      getting an error returned when trying to use their regulators, since
      simply enabling a regulator tries to update its load and that was
      failing.
      
      We don't really want to go back to the behavior from before commit
      efb0cb50 ("regulator: qcom-rpmh: Implement get_optimum_mode(), not
      set_load()"). Boards shouldn't have been changing modes if no allowed
      modes were listed. However, the behavior after commit efb0cb50
      ("regulator: qcom-rpmh: Implement get_optimum_mode(), not set_load()")
      isn't the best because now boards can't even turn their regulators on.
      
      Let's choose to detect this case and return "no error" from
      drms_uA_update(). The net-result will be _different_ behavior than we
      had before commit efb0cb50 ("regulator: qcom-rpmh: Implement
      get_optimum_mode(), not set_load()"), but this new behavior seems more
      correct. If a board truly needed the mode switched then its device
      tree should be updated to list the allowed modes.
      Reported-by: NAndrew Halaney <ahalaney@redhat.com>
      Fixes: efb0cb50 ("regulator: qcom-rpmh: Implement get_optimum_mode(), not set_load()")
      Signed-off-by: NDouglas Anderson <dianders@chromium.org>
      Tested-by: NAndrew Halaney <ahalaney@redhat.com>
      Link: https://lore.kernel.org/r/20220824142229.RFT.v2.2.I6f77860e5cd98bf5c67208fa9edda4a08847c304@changeidSigned-off-by: NMark Brown <broonie@kernel.org>
      57919f4a
    • D
      regulator: core: Require regulator drivers to check uV for get_optimum_mode() · 55841199
      Douglas Anderson 提交于
      The get_optimum_mode() for regulator drivers is passed the input
      voltage and output voltage as well as the current. This is because, in
      theory, the optimum mode can depend on all three things.
      
      It turns out that for all regulator drivers in mainline only the
      current is looked at when implementing get_optimum_mode(). None of the
      drivers take the input or output voltage into account. Despite the
      fact that none of the drivers take the input or output voltage into
      account, though, the regulator framework will error out before calling
      into get_optimum_mode() if it doesn't know the input or output
      voltage.
      
      The above behavior turned out to be a probelm for some boards when we
      landed commit efb0cb50 ("regulator: qcom-rpmh: Implement
      get_optimum_mode(), not set_load()"). Before that change we'd have no
      problems running drms_uA_update() for RPMH regulators even if a
      regulator's input or output voltage was unknown. After that change
      drms_uA_update() started to fail. This is because typically boards
      using RPMH regulators don't model the input supplies of RPMH
      regulators. Input supplies for RPMH regulators nearly always come from
      the output of other RPMH regulators (or always-on regulators) and RPMH
      firmware is initialized with this knowledge and handles enabling (and
      adjusting the voltage of) input supplies. While we could model the
      parent/child relationship of the regulators in Linux, many boards
      don't bother since it adds extra overhead.
      
      Let's change the regulator core to make things work again. Now if we
      fail to get the input or output voltage we'll still call into
      get_optimum_mode() and we'll just pass error codes in for input_uV
      and/or output_uV parameters.
      
      Since no existing regulator drivers even look at input_uV and
      output_uV we don't need to add this error handling anywhere right
      now. We'll add some comments in the core so that it's obvious that (if
      regulator drivers care) it's up to them to add the checks.
      Reported-by: NAndrew Halaney <ahalaney@redhat.com>
      Fixes: efb0cb50 ("regulator: qcom-rpmh: Implement get_optimum_mode(), not set_load()")
      Signed-off-by: NDouglas Anderson <dianders@chromium.org>
      Tested-by: NAndrew Halaney <ahalaney@redhat.com>
      Link: https://lore.kernel.org/r/20220824142229.RFT.v2.1.I137e6bef4f6d517be7b081be926059321102fd3d@changeidSigned-off-by: NMark Brown <broonie@kernel.org>
      55841199
  8. 22 8月, 2022 2 次提交
  9. 18 8月, 2022 1 次提交
  10. 10 8月, 2022 1 次提交
  11. 27 7月, 2022 1 次提交
  12. 20 7月, 2022 1 次提交
  13. 05 5月, 2022 1 次提交
  14. 04 5月, 2022 1 次提交
  15. 21 4月, 2022 2 次提交
  16. 04 4月, 2022 1 次提交
  17. 08 2月, 2022 1 次提交
    • O
      regulator: core: fix false positive in regulator_late_cleanup() · 4e2a354e
      Oliver Barta 提交于
      The check done by regulator_late_cleanup() to detect whether a regulator
      is on was inconsistent with the check done by _regulator_is_enabled().
      While _regulator_is_enabled() takes the enable GPIO into account,
      regulator_late_cleanup() was not doing that.
      
      This resulted in a false positive, e.g. when a GPIO-controlled fixed
      regulator was used, which was not enabled at boot time, e.g.
      
      reg_disp_1v2: reg_disp_1v2 {
      	compatible = "regulator-fixed";
      	regulator-name = "display_1v2";
      	regulator-min-microvolt = <1200000>;
      	regulator-max-microvolt = <1200000>;
      	gpio = <&tlmm 148 0>;
      	enable-active-high;
      };
      
      Such regulator doesn't have an is_enabled() operation. Nevertheless
      it's state can be determined based on the enable GPIO. The check in
      regulator_late_cleanup() wrongly assumed that the regulator is on and
      tried to disable it.
      Signed-off-by: NOliver Barta <oliver.barta@aptiv.com>
      Link: https://lore.kernel.org/r/20220208084645.8686-1-oliver.barta@aptiv.comSigned-off-by: NMark Brown <broonie@kernel.org>
      4e2a354e
  18. 23 10月, 2021 1 次提交
  19. 30 9月, 2021 1 次提交
  20. 17 9月, 2021 1 次提交
    • M
      kernel/locking: Add context to ww_mutex_trylock() · 12235da8
      Maarten Lankhorst 提交于
      i915 will soon gain an eviction path that trylock a whole lot of locks
      for eviction, getting dmesg failures like below:
      
        BUG: MAX_LOCK_DEPTH too low!
        turning off the locking correctness validator.
        depth: 48  max: 48!
        48 locks held by i915_selftest/5776:
         #0: ffff888101a79240 (&dev->mutex){....}-{3:3}, at: __driver_attach+0x88/0x160
         #1: ffffc900009778c0 (reservation_ww_class_acquire){+.+.}-{0:0}, at: i915_vma_pin.constprop.63+0x39/0x1b0 [i915]
         #2: ffff88800cf74de8 (reservation_ww_class_mutex){+.+.}-{3:3}, at: i915_vma_pin.constprop.63+0x5f/0x1b0 [i915]
         #3: ffff88810c7f9e38 (&vm->mutex/1){+.+.}-{3:3}, at: i915_vma_pin_ww+0x1c4/0x9d0 [i915]
         #4: ffff88810bad5768 (reservation_ww_class_mutex){+.+.}-{3:3}, at: i915_gem_evict_something+0x110/0x860 [i915]
         #5: ffff88810bad60e8 (reservation_ww_class_mutex){+.+.}-{3:3}, at: i915_gem_evict_something+0x110/0x860 [i915]
        ...
         #46: ffff88811964d768 (reservation_ww_class_mutex){+.+.}-{3:3}, at: i915_gem_evict_something+0x110/0x860 [i915]
         #47: ffff88811964e0e8 (reservation_ww_class_mutex){+.+.}-{3:3}, at: i915_gem_evict_something+0x110/0x860 [i915]
        INFO: lockdep is turned off.
      
      Fixing eviction to nest into ww_class_acquire is a high priority, but
      it requires a rework of the entire driver, which can only be done one
      step at a time.
      
      As an intermediate solution, add an acquire context to
      ww_mutex_trylock, which allows us to do proper nesting annotations on
      the trylocks, making the above lockdep splat disappear.
      
      This is also useful in regulator_lock_nested, which may avoid dropping
      regulator_nesting_mutex in the uncontended path, so use it there.
      
      TTM may be another user for this, where we could lock a buffer in a
      fastpath with list locks held, without dropping all locks we hold.
      
      [peterz: rework actual ww_mutex_trylock() implementations]
      Signed-off-by: NMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
      Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
      Link: https://lkml.kernel.org/r/YUBGPdDDjKlxAuXJ@hirez.programming.kicks-ass.net
      12235da8
  21. 13 9月, 2021 1 次提交
  22. 21 6月, 2021 3 次提交
  23. 02 6月, 2021 1 次提交
  24. 01 6月, 2021 1 次提交
  25. 21 5月, 2021 1 次提交
  26. 23 4月, 2021 1 次提交
    • V
      regulator: core: Fix off_on_delay handling · a8ce7bd8
      Vincent Whitchurch 提交于
      The jiffies-based off_on_delay implementation has a couple of problems
      that cause it to sometimes not actually delay for the required time:
      
       (1) If, for example, the off_on_delay time is equivalent to one jiffy,
           and the ->last_off_jiffy is set just before a new jiffy starts,
           then _regulator_do_enable() does not wait at all since it checks
           using time_before().
      
       (2) When jiffies overflows, the value of "remaining" becomes higher
           than "max_delay" and the code simply proceeds without waiting.
      
      Fix these problems by changing it to use ktime_t instead.
      
      [Note that since jiffies doesn't start at zero but at INITIAL_JIFFIES
       ("-5 minutes"), (2) above also led to the code not delaying if
       the first regulator_enable() is called when the ->last_off_jiffy is not
       initialised, such as for regulators with ->constraints->boot_on set.
       It's not clear to me if this was intended or not, but I've preserved
       this behaviour explicitly with the check for a non-zero ->last_off.]
      Signed-off-by: NVincent Whitchurch <vincent.whitchurch@axis.com>
      Link: https://lore.kernel.org/r/20210423114524.26414-1-vincent.whitchurch@axis.comSigned-off-by: NMark Brown <broonie@kernel.org>
      a8ce7bd8
  27. 22 4月, 2021 1 次提交
  28. 21 4月, 2021 2 次提交
  29. 25 1月, 2021 1 次提交
    • H
      regulator: core: Avoid debugfs: Directory ... already present! error · dbe954d8
      Hans de Goede 提交于
      Sometimes regulator_get() gets called twice for the same supply on the
      same device. This may happen e.g. when a framework / library is used
      which uses the regulator; and the driver itself also needs to enable
      the regulator in some cases where the framework will not enable it.
      
      Commit ff268b56 ("regulator: core: Don't spew backtraces on
      duplicate sysfs") already takes care of the backtrace which would
      trigger when creating a duplicate consumer symlink under
      /sys/class/regulator/regulator.%d in this scenario.
      
      Commit c33d4423 ("debugfs: make error message a bit more verbose")
      causes a new error to get logged in this scenario:
      
      [   26.938425] debugfs: Directory 'wm5102-codec-MICVDD' with parent 'spi-WM510204:00-MICVDD' already present!
      
      There is no _nowarn variant of debugfs_create_dir(), but we can detect
      and avoid this problem by checking the return value of the earlier
      sysfs_create_link_nowarn() call.
      
      Add a check for the earlier sysfs_create_link_nowarn() failing with
      -EEXIST and skip the debugfs_create_dir() call in that case, avoiding
      this error getting logged.
      
      Fixes: c33d4423 ("debugfs: make error message a bit more verbose")
      Cc: Charles Keepax <ckeepax@opensource.cirrus.com>
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Reviewed-by: NCharles Keepax <ckeepax@opensource.cirrus.com>
      Link: https://lore.kernel.org/r/20210122183250.370571-1-hdegoede@redhat.comSigned-off-by: NMark Brown <broonie@kernel.org>
      dbe954d8
  30. 23 1月, 2021 1 次提交
  31. 22 1月, 2021 1 次提交
  32. 09 1月, 2021 1 次提交
    • D
      regulator: core: avoid regulator_resolve_supply() race condition · eaa7995c
      David Collins 提交于
      The final step in regulator_register() is to call
      regulator_resolve_supply() for each registered regulator
      (including the one in the process of being registered).  The
      regulator_resolve_supply() function first checks if rdev->supply
      is NULL, then it performs various steps to try to find the supply.
      If successful, rdev->supply is set inside of set_supply().
      
      This procedure can encounter a race condition if two concurrent
      tasks call regulator_register() near to each other on separate CPUs
      and one of the regulators has rdev->supply_name specified.  There
      is currently nothing guaranteeing atomicity between the rdev->supply
      check and set steps.  Thus, both tasks can observe rdev->supply==NULL
      in their regulator_resolve_supply() calls.  This then results in
      both creating a struct regulator for the supply.  One ends up
      actually stored in rdev->supply and the other is lost (though still
      present in the supply's consumer_list).
      
      Here is a kernel log snippet showing the issue:
      
      [   12.421768] gpu_cc_gx_gdsc: supplied by pm8350_s5_level
      [   12.425854] gpu_cc_gx_gdsc: supplied by pm8350_s5_level
      [   12.429064] debugfs: Directory 'regulator.4-SUPPLY' with parent
                     '17a00000.rsc:rpmh-regulator-gfxlvl-pm8350_s5_level'
                     already present!
      
      Avoid this race condition by holding the rdev->mutex lock inside
      of regulator_resolve_supply() while checking and setting
      rdev->supply.
      Signed-off-by: NDavid Collins <collinsd@codeaurora.org>
      Link: https://lore.kernel.org/r/1610068562-4410-1-git-send-email-collinsd@codeaurora.orgSigned-off-by: NMark Brown <broonie@kernel.org>
      eaa7995c
  33. 04 1月, 2021 1 次提交
  34. 26 11月, 2020 1 次提交