You need to sign in or sign up before continuing.
  1. 25 6月, 2021 1 次提交
  2. 22 6月, 2021 1 次提交
  3. 09 6月, 2021 1 次提交
  4. 11 5月, 2021 1 次提交
  5. 08 4月, 2021 1 次提交
    • W
      spi: Fix use-after-free with devm_spi_alloc_* · 794aaf01
      William A. Kennington III 提交于
      We can't rely on the contents of the devres list during
      spi_unregister_controller(), as the list is already torn down at the
      time we perform devres_find() for devm_spi_release_controller. This
      causes devices registered with devm_spi_alloc_{master,slave}() to be
      mistakenly identified as legacy, non-devm managed devices and have their
      reference counters decremented below 0.
      
      ------------[ cut here ]------------
      WARNING: CPU: 1 PID: 660 at lib/refcount.c:28 refcount_warn_saturate+0x108/0x174
      [<b0396f04>] (refcount_warn_saturate) from [<b03c56a4>] (kobject_put+0x90/0x98)
      [<b03c5614>] (kobject_put) from [<b0447b4c>] (put_device+0x20/0x24)
       r4:b6700140
      [<b0447b2c>] (put_device) from [<b07515e8>] (devm_spi_release_controller+0x3c/0x40)
      [<b07515ac>] (devm_spi_release_controller) from [<b045343c>] (release_nodes+0x84/0xc4)
       r5:b6700180 r4:b6700100
      [<b04533b8>] (release_nodes) from [<b0454160>] (devres_release_all+0x5c/0x60)
       r8:b1638c54 r7:b117ad94 r6:b1638c10 r5:b117ad94 r4:b163dc10
      [<b0454104>] (devres_release_all) from [<b044e41c>] (__device_release_driver+0x144/0x1ec)
       r5:b117ad94 r4:b163dc10
      [<b044e2d8>] (__device_release_driver) from [<b044f70c>] (device_driver_detach+0x84/0xa0)
       r9:00000000 r8:00000000 r7:b117ad94 r6:b163dc54 r5:b1638c10 r4:b163dc10
      [<b044f688>] (device_driver_detach) from [<b044d274>] (unbind_store+0xe4/0xf8)
      
      Instead, determine the devm allocation state as a flag on the
      controller which is guaranteed to be stable during cleanup.
      
      Fixes: 5e844cc3 ("spi: Introduce device-managed SPI controller allocation")
      Signed-off-by: NWilliam A. Kennington III <wak@google.com>
      Link: https://lore.kernel.org/r/20210407095527.2771582-1-wak@google.comSigned-off-by: NMark Brown <broonie@kernel.org>
      794aaf01
  6. 01 4月, 2021 1 次提交
  7. 16 3月, 2021 2 次提交
  8. 12 3月, 2021 1 次提交
  9. 08 2月, 2021 1 次提交
  10. 06 1月, 2021 1 次提交
  11. 28 12月, 2020 2 次提交
  12. 12 11月, 2020 1 次提交
    • L
      spi: Introduce device-managed SPI controller allocation · 5e844cc3
      Lukas Wunner 提交于
      SPI driver probing currently comprises two steps, whereas removal
      comprises only one step:
      
          spi_alloc_master()
          spi_register_controller()
      
          spi_unregister_controller()
      
      That's because spi_unregister_controller() calls device_unregister()
      instead of device_del(), thereby releasing the reference on the
      spi_controller which was obtained by spi_alloc_master().
      
      An SPI driver's private data is contained in the same memory allocation
      as the spi_controller struct.  Thus, once spi_unregister_controller()
      has been called, the private data is inaccessible.  But some drivers
      need to access it after spi_unregister_controller() to perform further
      teardown steps.
      
      Introduce devm_spi_alloc_master() and devm_spi_alloc_slave(), which
      release a reference on the spi_controller struct only after the driver
      has unbound, thereby keeping the memory allocation accessible.  Change
      spi_unregister_controller() to not release a reference if the
      spi_controller was allocated by one of these new devm functions.
      
      The present commit is small enough to be backportable to stable.
      It allows fixing drivers which use the private data in their ->remove()
      hook after it's been freed.  It also allows fixing drivers which neglect
      to release a reference on the spi_controller in the probe error path.
      
      Long-term, most SPI drivers shall be moved over to the devm functions
      introduced herein.  The few that can't shall be changed in a treewide
      commit to explicitly release the last reference on the controller.
      That commit shall amend spi_unregister_controller() to no longer release
      a reference, thereby completing the migration.
      
      As a result, the behaviour will be less surprising and more consistent
      with subsystems such as IIO, which also includes the private data in the
      allocation of the generic iio_dev struct, but calls device_del() in
      iio_device_unregister().
      Signed-off-by: NLukas Wunner <lukas@wunner.de>
      Link: https://lore.kernel.org/r/272bae2ef08abd21388c98e23729886663d19192.1605121038.git.lukas@wunner.deSigned-off-by: NMark Brown <broonie@kernel.org>
      5e844cc3
  13. 11 11月, 2020 1 次提交
  14. 27 7月, 2020 1 次提交
  15. 17 7月, 2020 1 次提交
  16. 10 7月, 2020 1 次提交
  17. 02 7月, 2020 1 次提交
    • D
      spi: Avoid setting the chip select if we don't need to · d40f0b6f
      Douglas Anderson 提交于
      On some SPI controllers (like spi-geni-qcom) setting the chip select
      is a heavy operation.  For instance on spi-geni-qcom, with the current
      code, is was measured as taking upwards of 20 us.  Even on SPI
      controllers that aren't as heavy, setting the chip select is at least
      something like a MMIO operation over some peripheral bus which isn't
      as fast as a RAM access.
      
      While it would be good to find ways to mitigate problems like this in
      the drivers for those SPI controllers, it can also be noted that the
      SPI framework could also help out.  Specifically, in some situations,
      we can see the SPI framework calling the driver's set_cs() with the
      same parameter several times in a row.  This is specifically observed
      when looking at the way the Chrome OS EC SPI driver (cros_ec_spi)
      works but other drivers likely trip it to some extent.
      
      Let's solve this by caching the chip select state in the core and only
      calling into the controller if there was a change.  We check not only
      the "enable" state but also the chip select mode (active high or
      active low) since controllers may care about both the mode and the
      enable flag in their callback.
      Signed-off-by: NDouglas Anderson <dianders@chromium.org>
      Link: https://lore.kernel.org/r/20200629164103.1.Ied8e8ad8bbb2df7f947e3bc5ea1c315e041785a2@changeidSigned-off-by: NMark Brown <broonie@kernel.org>
      d40f0b6f
  18. 23 6月, 2020 1 次提交
  19. 21 4月, 2020 1 次提交
  20. 10 3月, 2020 1 次提交
  21. 05 3月, 2020 1 次提交
    • V
      spi: Do spi_take_timestamp_pre for as many times as necessary · 6a726824
      Vladimir Oltean 提交于
      When dealing with a SPI controller driver that is sending more than 1
      byte at once (or the entire buffer at once), and the SPI peripheral
      driver has requested timestamping for a byte in the middle of the
      buffer, we find that spi_take_timestamp_pre never records a "pre"
      timestamp.
      
      This happens because the function currently expects to be called with
      the "progress" argument >= to what the peripheral has requested to be
      timestamped. But clearly there are cases when that isn't going to fly.
      
      And since we can't change the past when we realize that the opportunity
      to take a "pre" timestamp has just passed and there isn't going to be
      another one, the approach taken is to keep recording the "pre" timestamp
      on each call, overwriting the previously recorded one until the "post"
      timestamp is also taken.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Link: https://lore.kernel.org/r/20200304220044.11193-8-olteanv@gmail.comSigned-off-by: NMark Brown <broonie@kernel.org>
      6a726824
  22. 29 2月, 2020 1 次提交
  23. 08 1月, 2020 1 次提交
    • G
      spi: Add generic support for unused native cs with cs-gpios · 7d93aecd
      Geert Uytterhoeven 提交于
      Some SPI master controllers always drive a native chip select when
      performing a transfer.  Hence when using both native and GPIO chip
      selects, at least one native chip select must be left unused, to be
      driven when performing transfers with slave devices using GPIO chip
      selects.
      
      Currently, to find an unused native chip select, SPI controller drivers
      need to parse and process cs-gpios theirselves.  This is not only
      duplicated in each driver that needs it, but also duplicates part of the
      work done later at SPI controller registration time.  Note that this
      cannot be done after spi_register_controller() returns, as at that time,
      slave devices may have been probed already.
      
      Hence add generic support to the SPI subsystem for finding an unused
      native chip select.  Optionally, this unused native chip select, and all
      other in-use native chip selects, can be validated against the maximum
      number of native chip selects available on the controller hardware.
      Signed-off-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Link: https://lore.kernel.org/r/20200102133822.29346-2-geert+renesas@glider.beSigned-off-by: NMark Brown <broonie@kernel.org>
      7d93aecd
  24. 28 12月, 2019 1 次提交
  25. 24 10月, 2019 1 次提交
  26. 15 10月, 2019 8 次提交
  27. 09 10月, 2019 1 次提交
    • V
      spi: Add a PTP system timestamp to the transfer structure · 79591b7d
      Vladimir Oltean 提交于
      SPI is one of the interfaces used to access devices which have a POSIX
      clock driver (real time clocks, 1588 timers etc). The fact that the SPI
      bus is slow is not what the main problem is, but rather the fact that
      drivers don't take a constant amount of time in transferring data over
      SPI. When there is a high delay in the readout of time, there will be
      uncertainty in the value that has been read out of the peripheral.
      When that delay is constant, the uncertainty can at least be
      approximated with a certain accuracy which is fine more often than not.
      
      Timing jitter occurs all over in the kernel code, and is mainly caused
      by having to let go of the CPU for various reasons such as preemption,
      servicing interrupts, going to sleep, etc. Another major reason is CPU
      dynamic frequency scaling.
      
      It turns out that the problem of retrieving time from a SPI peripheral
      with high accuracy can be solved by the use of "PTP system
      timestamping" - a mechanism to correlate the time when the device has
      snapshotted its internal time counter with the Linux system time at that
      same moment. This is sufficient for having a precise time measurement -
      it is not necessary for the whole SPI transfer to be transmitted "as
      fast as possible", or "as low-jitter as possible". The system has to be
      low-jitter for a very short amount of time to be effective.
      
      This patch introduces a PTP system timestamping mechanism in struct
      spi_transfer. This is to be used by SPI device drivers when they need to
      know the exact time at which the underlying device's time was
      snapshotted. More often than not, SPI peripherals have a very exact
      timing for when their SPI-to-interconnect bridge issues a transaction
      for snapshotting and reading the time register, and that will be
      dependent on when the SPI-to-interconnect bridge figures out that this
      is what it should do, aka as soon as it sees byte N of the SPI transfer.
      Since spi_device drivers are the ones who'd know best how the peripheral
      behaves in this regard, expose a mechanism in spi_transfer which allows
      them to specify which word (or word range) from the transfer should be
      timestamped.
      
      Add a default implementation of the PTP system timestamping in the SPI
      core. This is not going to be satisfactory performance-wise, but should
      at least increase the likelihood that SPI device drivers will use PTP
      system timestamping in the future.
      There are 3 entry points from the core towards the SPI controller
      drivers:
      
      - transfer_one: The driver is passed individual spi_transfers to
        execute. This is the easiest to timestamp.
      
      - transfer_one_message: The core passes the driver an entire spi_message
        (a potential batch of spi_transfers). The core puts the same pre and
        post timestamp to all transfers within a message. This is not ideal,
        but nothing better can be done by default anyway, since the core has
        no insight into how the driver batches the transfers.
      
      - transfer: Like transfer_one_message, but for unqueued drivers (i.e.
        the driver implements its own queue scheduling).
      Signed-off-by: NVladimir Oltean <olteanv@gmail.com>
      Link: https://lore.kernel.org/r/20190905010114.26718-3-olteanv@gmail.comSigned-off-by: NMark Brown <broonie@kernel.org>
      79591b7d
  28. 08 10月, 2019 1 次提交
    • V
      spi: Add a PTP system timestamp to the transfer structure · b42faeee
      Vladimir Oltean 提交于
      SPI is one of the interfaces used to access devices which have a POSIX
      clock driver (real time clocks, 1588 timers etc). The fact that the SPI
      bus is slow is not what the main problem is, but rather the fact that
      drivers don't take a constant amount of time in transferring data over
      SPI. When there is a high delay in the readout of time, there will be
      uncertainty in the value that has been read out of the peripheral.
      When that delay is constant, the uncertainty can at least be
      approximated with a certain accuracy which is fine more often than not.
      
      Timing jitter occurs all over in the kernel code, and is mainly caused
      by having to let go of the CPU for various reasons such as preemption,
      servicing interrupts, going to sleep, etc. Another major reason is CPU
      dynamic frequency scaling.
      
      It turns out that the problem of retrieving time from a SPI peripheral
      with high accuracy can be solved by the use of "PTP system
      timestamping" - a mechanism to correlate the time when the device has
      snapshotted its internal time counter with the Linux system time at that
      same moment. This is sufficient for having a precise time measurement -
      it is not necessary for the whole SPI transfer to be transmitted "as
      fast as possible", or "as low-jitter as possible". The system has to be
      low-jitter for a very short amount of time to be effective.
      
      This patch introduces a PTP system timestamping mechanism in struct
      spi_transfer. This is to be used by SPI device drivers when they need to
      know the exact time at which the underlying device's time was
      snapshotted. More often than not, SPI peripherals have a very exact
      timing for when their SPI-to-interconnect bridge issues a transaction
      for snapshotting and reading the time register, and that will be
      dependent on when the SPI-to-interconnect bridge figures out that this
      is what it should do, aka as soon as it sees byte N of the SPI transfer.
      Since spi_device drivers are the ones who'd know best how the peripheral
      behaves in this regard, expose a mechanism in spi_transfer which allows
      them to specify which word (or word range) from the transfer should be
      timestamped.
      
      Add a default implementation of the PTP system timestamping in the SPI
      core. This is not going to be satisfactory performance-wise, but should
      at least increase the likelihood that SPI device drivers will use PTP
      system timestamping in the future.
      There are 3 entry points from the core towards the SPI controller
      drivers:
      
      - transfer_one: The driver is passed individual spi_transfers to
        execute. This is the easiest to timestamp.
      
      - transfer_one_message: The core passes the driver an entire spi_message
        (a potential batch of spi_transfers). The core puts the same pre and
        post timestamp to all transfers within a message. This is not ideal,
        but nothing better can be done by default anyway, since the core has
        no insight into how the driver batches the transfers.
      
      - transfer: Like transfer_one_message, but for unqueued drivers (i.e.
        the driver implements its own queue scheduling).
      Signed-off-by: NVladimir Oltean <olteanv@gmail.com>
      Link: https://lore.kernel.org/r/20190905010114.26718-3-olteanv@gmail.comSigned-off-by: NMark Brown <broonie@kernel.org>
      b42faeee
  29. 17 6月, 2019 1 次提交
  30. 23 5月, 2019 1 次提交
  31. 13 5月, 2019 1 次提交