Skip to content
Snippets Groups Projects
  1. Jan 13, 2022
  2. Dec 01, 2021
  3. Nov 30, 2021
  4. Nov 11, 2021
  5. Nov 04, 2021
  6. Oct 29, 2021
  7. Oct 28, 2021
  8. Oct 26, 2021
    • Arnd Bergmann's avatar
      dma-buf: st: fix error handling in test_get_fences() · 55d5e4f9
      Arnd Bergmann authored and Christian König's avatar Christian König committed
      
      The new driver incorrectly unwinds after errors, as clang points out:
      
      drivers/dma-buf/st-dma-resv.c:295:7: error: variable 'i' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
                      if (r) {
                          ^
      drivers/dma-buf/st-dma-resv.c:336:9: note: uninitialized use occurs here
              while (i--)
                     ^
      drivers/dma-buf/st-dma-resv.c:295:3: note: remove the 'if' if its condition is always false
                      if (r) {
                      ^~~~~~~~
      drivers/dma-buf/st-dma-resv.c:288:6: error: variable 'i' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
              if (r) {
                  ^
      drivers/dma-buf/st-dma-resv.c:336:9: note: uninitialized use occurs here
              while (i--)
                     ^
      drivers/dma-buf/st-dma-resv.c:288:2: note: remove the 'if' if its condition is always false
              if (r) {
              ^~~~~~~~
      drivers/dma-buf/st-dma-resv.c:280:10: note: initialize the variable 'i' to silence this warning
              int r, i;
                      ^
                       = 0
      
      Skip cleaning up the bits that have not been allocated at this point.
      
      Fixes: 1d51775c ("dma-buf: add dma_resv selftest v4")
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
      Link: https://patchwork.freedesktop.org/patch/msgid/20211026083448.3471055-1-arnd@kernel.org
      
      
      Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
      55d5e4f9
  9. Oct 25, 2021
  10. Oct 22, 2021
  11. Oct 18, 2021
  12. Oct 11, 2021
    • Tvrtko Ursulin's avatar
      dma-resv: Fix dma_resv_get_fences and dma_resv_copy_fences after conversion · 5e51cc00
      Tvrtko Ursulin authored and Christian König's avatar Christian König committed
      
      Cache the count of shared fences in the iterator to avoid dereferencing
      the dma_resv_object outside the RCU protection. Otherwise iterator and its
      users can observe an incosistent state which makes it impossible to use
      safely. Such as:
      
      <6> [187.517041] [IGT] gem_sync: executing
      <7> [187.536343] i915 0000:00:02.0: [drm:i915_gem_context_create_ioctl [i915]] HW context 1 created
      <7> [187.536793] i915 0000:00:02.0: [drm:i915_gem_context_create_ioctl [i915]] HW context 1 created
      <6> [187.551235] [IGT] gem_sync: starting subtest basic-many-each
      <1> [188.935462] BUG: kernel NULL pointer dereference, address: 0000000000000010
      <1> [188.935485] #PF: supervisor write access in kernel mode
      <1> [188.935495] #PF: error_code(0x0002) - not-present page
      <6> [188.935504] PGD 0 P4D 0
      <4> [188.935512] Oops: 0002 [#1] PREEMPT SMP NOPTI
      <4> [188.935521] CPU: 2 PID: 1467 Comm: gem_sync Not tainted 5.15.0-rc4-CI-Patchwork_21264+ #1
      <4> [188.935535] Hardware name:  /NUC6CAYB, BIOS AYAPLCEL.86A.0049.2018.0508.1356 05/08/2018
      <4> [188.935546] RIP: 0010:dma_resv_get_fences+0x116/0x2d0
      <4> [188.935560] Code: 10 85 c0 7f c9 be 03 00 00 00 e8 15 8b df ff eb bd e8 8e c6 ff ff eb b6 41 8b 04 24 49 8b 55 00 48 89 e7 8d 48 01 41 89 0c 24 <4c> 89 34 c2 e8 41 f2 ff ff 49 89 c6 48 85 c0 75 8c 48 8b 44 24 10
      <4> [188.935583] RSP: 0018:ffffc900011dbcc8 EFLAGS: 00010202
      <4> [188.935593] RAX: 0000000000000000 RBX: 00000000ffffffff RCX: 0000000000000001
      <4> [188.935603] RDX: 0000000000000010 RSI: ffffffff822e343c RDI: ffffc900011dbcc8
      <4> [188.935613] RBP: ffffc900011dbd48 R08: ffff88812d255bb8 R09: 00000000fffffffe
      <4> [188.935623] R10: 0000000000000001 R11: 0000000000000000 R12: ffffc900011dbd44
      <4> [188.935633] R13: ffffc900011dbd50 R14: ffff888113d29cc0 R15: 0000000000000000
      <4> [188.935643] FS:  00007f68d17e9700(0000) GS:ffff888277900000(0000) knlGS:0000000000000000
      <4> [188.935655] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      <4> [188.935665] CR2: 0000000000000010 CR3: 000000012d0a4000 CR4: 00000000003506e0
      <4> [188.935676] Call Trace:
      <4> [188.935685]  i915_gem_object_wait+0x1ff/0x410 [i915]
      <4> [188.935988]  i915_gem_wait_ioctl+0xf2/0x2a0 [i915]
      <4> [188.936272]  ? i915_gem_object_wait+0x410/0x410 [i915]
      <4> [188.936533]  drm_ioctl_kernel+0xae/0x140
      <4> [188.936546]  drm_ioctl+0x201/0x3d0
      <4> [188.936555]  ? i915_gem_object_wait+0x410/0x410 [i915]
      <4> [188.936820]  ? __fget_files+0xc2/0x1c0
      <4> [188.936830]  ? __fget_files+0xda/0x1c0
      <4> [188.936839]  __x64_sys_ioctl+0x6d/0xa0
      <4> [188.936848]  do_syscall_64+0x3a/0xb0
      <4> [188.936859]  entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      If the shared object has changed during the RCU unlocked period
      callers will correctly handle the restart on the next iteration.
      
      Signed-off-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
      Fixes: 96601e8a ("dma-buf: use new iterator in dma_resv_copy_fences")
      Fixes: d3c80698 ("dma-buf: use new iterator in dma_resv_get_fences v3")
      Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/4274
      Cc: Christian König <christian.koenig@amd.com>
      Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
      Cc: Sumit Semwal <sumit.semwal@linaro.org>
      Cc: linux-media@vger.kernel.org
      Cc: dri-devel@lists.freedesktop.org
      Cc: linaro-mm-sig@lists.linaro.org
      Link: https://patchwork.freedesktop.org/patch/msgid/20211008095007.972693-1-tvrtko.ursulin@linux.intel.com
      
      
      Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
      Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
      5e51cc00
  13. Oct 07, 2021
  14. Oct 06, 2021
  15. Oct 01, 2021
    • Christian König's avatar
      dma-buf: fix and rework dma_buf_poll v7 · 6b51b02a
      Christian König authored
      
      Daniel pointed me towards this function and there are multiple obvious problems
      in the implementation.
      
      First of all the retry loop is not working as intended. In general the retry
      makes only sense if you grab the reference first and then check the sequence
      values.
      
      Then we should always also wait for the exclusive fence.
      
      It's also good practice to keep the reference around when installing callbacks
      to fences you don't own.
      
      And last the whole implementation was unnecessary complex and rather hard to
      understand which could lead to probably unexpected behavior of the IOCTL.
      
      Fix all this by reworking the implementation from scratch. Dropping the
      whole RCU approach and taking the lock instead.
      
      Only mildly tested and needs a thoughtful review of the code.
      
      Pushing through drm-misc-next to avoid merge conflicts and give the code
      another round of testing.
      
      v2: fix the reference counting as well
      v3: keep the excl fence handling as is for stable
      v4: back to testing all fences, drop RCU
      v5: handle in and out separately
      v6: add missing clear of events
      v7: change coding style as suggested by Michel, drop unused variables
      
      Signed-off-by: default avatarChristian König <christian.koenig@amd.com>
      Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Tested-by: default avatarMichel Dänzer <mdaenzer@redhat.com>
      CC: stable@vger.kernel.org
      Link: https://patchwork.freedesktop.org/patch/msgid/20210720131110.88512-1-christian.koenig@amd.com
      6b51b02a
  16. Sep 14, 2021
  17. Sep 07, 2021
  18. Sep 03, 2021
  19. Sep 02, 2021
  20. Aug 30, 2021
    • Simona Vetter's avatar
      dma-resv: Give the docs a do-over · d9edf92d
      Simona Vetter authored
      
      Specifically document the new/clarified rules around how the shared
      fences do not have any ordering requirements against the exclusive
      fence.
      
      But also document all the things a bit better, given how central
      struct dma_resv to dynamic buffer management the docs have been very
      inadequat.
      
      - Lots more links to other pieces of the puzzle. Unfortunately
        ttm_buffer_object has no docs, so no links :-(
      
      - Explain/complain a bit about dma_resv_locking_ctx(). I still don't
        like that one, but fixing the ttm call chains is going to be
        horrible. Plus we want to plug in real slowpath locking when we do
        that anyway.
      
      - Main part of the patch is some actual docs for struct dma_resv.
      
      Overall I think we still have a lot of bad naming in this area (e.g.
      dma_resv.fence is singular, but contains the multiple shared fences),
      but I think that's more indicative of how the semantics and rules are
      just not great.
      
      Another thing that's real awkard is how chaining exclusive fences
      right now means direct dma_resv.exclusive_fence pointer access with an
      rcu_assign_pointer. Not so great either.
      
      v2:
      - Fix a pile of typos (Matt, Jason)
      - Hammer it in that breaking the rules leads to use-after-free issues
        around dma-buf sharing (Christian)
      
      Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
      Cc: Jason Ekstrand <jason@jlekstrand.net>
      Cc: Matthew Auld <matthew.auld@intel.com>
      Reviewed-by: default avatarMatthew Auld <matthew.auld@intel.com>
      Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
      Cc: Sumit Semwal <sumit.semwal@linaro.org>
      Cc: "Christian König" <christian.koenig@amd.com>
      Cc: linux-media@vger.kernel.org
      Cc: linaro-mm-sig@lists.linaro.org
      Link: https://patchwork.freedesktop.org/patch/msgid/20210805104705.862416-21-daniel.vetter@ffwll.ch
      d9edf92d
  21. Aug 16, 2021
  22. Aug 12, 2021
  23. Jul 20, 2021
  24. Jul 12, 2021
  25. Jul 08, 2021
  26. Jun 23, 2021
  27. Jun 22, 2021
    • Simona Vetter's avatar
      dma-buf: Document non-dynamic exporter expectations better · 89bcadc8
      Simona Vetter authored
      
      Christian and me realized we have a pretty massive disconnect about
      different interpretations of what dma_resv is used for by different
      drivers. The discussion is much, much bigger than this change here,
      but this is an important one:
      
      Non-dynamic exporters must guarantee that the memory they return is
      ready for use. They cannot expect importers to wait for the exclusive
      fence. Only dynamic importers are required to obey the dma_resv fences
      strictly (and more patches are needed to define exactly what this
      means).
      
      Christian has patches to update nouvea, radeon and amdgpu. The only
      other driver using both ttm and supporting dma-buf export is qxl,
      which only uses synchronous ttm_bo_move.
      
      v2: To hammer this in document that dynamic importers _must_ wait for
      the exclusive fence after having called dma_buf_map_attachment.
      
      Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
      Cc: Christian König <ckoenig.leichtzumerken@gmail.com>
      Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210621151758.2347474-1-daniel.vetter@ffwll.ch
      89bcadc8
  28. Jun 15, 2021
    • Hridya Valsaraju's avatar
      dmabuf: Add the capability to expose DMA-BUF stats in sysfs · bdb8d06d
      Hridya Valsaraju authored and Simona Vetter's avatar Simona Vetter committed
      Overview
      ========
      The patch adds DMA-BUF statistics to /sys/kernel/dmabuf/buffers. It
      allows statistics to be enabled for each DMA-BUF in sysfs by enabling
      the config CONFIG_DMABUF_SYSFS_STATS.
      
      The following stats will be exposed by the interface:
      
      /sys/kernel/dmabuf/buffers/<inode_number>/exporter_name
      /sys/kernel/dmabuf/buffers/<inode_number>/size
      /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/device
      /sys/kernel/dmabuf/buffers/<inode_number>/attachments/<attach_uid>/map_counter
      
      The inode_number is unique for each DMA-BUF and was added earlier [1]
      in order to allow userspace to track DMA-BUF usage across different
      processes.
      
      Use Cases
      =========
      The interface provides a way to gather DMA-BUF per-buffer statistics
      from production devices. These statistics will be used to derive DMA-BUF
      per-exporter stats and per-device usage stats for Android Bug reports.
      The corresponding userspace changes can be found at [2].
      Telemetry tools will also capture this information(along with other
      memory metrics) periodically as well as on important events like a
      foreground app kill (which might have been triggered by Low Memory
      Killer). It will also contribute to provide a snapshot of the system
      memory usage on other events such as OOM kills and Application Not
      Responding events.
      
      Background
      ==========
      Currently, there are two existing interfaces that provide information
      about DMA-BUFs.
      1) /sys/kernel/debug/dma_buf/bufinfo
      debugfs is however unsuitable to be mounted in production systems and
      cannot be considered as an alternative to the sysfs interface being
      proposed.
      2) proc/<pid>/fdinfo/<fd>
      The proc/<pid>/fdinfo/<fd> files expose information about DMA-BUF fds.
      However, the existing procfs interfaces can only provide information
      about the buffers for which processes hold fds or have the buffers
      mmapped into their address space. Since the procfs interfaces alone
      cannot provide a full picture of all DMA-BUFs in the system, there is
      the need for an alternate interface to provide this information on
      production systems.
      
      The patch contains the following major improvements over v1:
      1) Each attachment is represented by its own directory to allow creating
      a symlink to the importing device and to also provide room for future
      expansion.
      2) The number of distinct mappings of each attachment is exposed in a
      separate file.
      3) The per-buffer statistics are now in /sys/kernel/dmabuf/buffers
      inorder to make the interface expandable in future.
      
      All of the improvements above are based on suggestions/feedback from
      Daniel Vetter and Christian König.
      
      A shell script that can be run on a classic Linux environment to read
      out the DMA-BUF statistics can be found at [3](suggested by John
      Stultz).
      
      [1]: https://lore.kernel.org/patchwork/patch/1088791/
      [2]: https://android-review.googlesource.com/q/topic:%22dmabuf-sysfs%22+(status:open%20OR%20status:merged)
      [3]: https://android-review.googlesource.com/c/platform/system/memory/libmeminfo/+/1549734
      
      
      
      Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarHridya Valsaraju <hridya@google.com>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210603214758.2955251-1-hridya@google.com
      bdb8d06d
  29. Jun 14, 2021
Loading