1. 10 8月, 2021 1 次提交
  2. 20 7月, 2021 1 次提交
  3. 24 6月, 2021 2 次提交
    • D
      dma-buf: Document dma-buf implicit fencing/resv fencing rules · 05459351
      Daniel Vetter 提交于
      Docs for struct dma_resv are fairly clear:
      
      "A reservation object can have attached one exclusive fence (normally
      associated with write operations) or N shared fences (read
      operations)."
      
      https://dri.freedesktop.org/docs/drm/driver-api/dma-buf.html#reservation-objects
      
      Furthermore a review across all of upstream.
      
      First of render drivers and how they set implicit fences:
      
      - nouveau follows this contract, see in validate_fini_no_ticket()
      
      			nouveau_bo_fence(nvbo, fence, !!b->write_domains);
      
        and that last boolean controls whether the exclusive or shared fence
        slot is used.
      
      - radeon follows this contract by setting
      
      		p->relocs[i].tv.num_shared = !r->write_domain;
      
        in radeon_cs_parser_relocs(), which ensures that the call to
        ttm_eu_fence_buffer_objects() in radeon_cs_parser_fini() will do the
        right thing.
      
      - vmwgfx seems to follow this contract with the shotgun approach of
        always setting ttm_val_buf->num_shared = 0, which means
        ttm_eu_fence_buffer_objects() will only use the exclusive slot.
      
      - etnaviv follows this contract, as can be trivially seen by looking
        at submit_attach_object_fences()
      
      - i915 is a bit a convoluted maze with multiple paths leading to
        i915_vma_move_to_active(). Which sets the exclusive flag if
        EXEC_OBJECT_WRITE is set. This can either come as a buffer flag for
        softpin mode, or through the write_domain when using relocations. It
        follows this contract.
      
      - lima follows this contract, see lima_gem_submit() which sets the
        exclusive fence when the LIMA_SUBMIT_BO_WRITE flag is set for that
        bo
      
      - msm follows this contract, see msm_gpu_submit() which sets the
        exclusive flag when the MSM_SUBMIT_BO_WRITE is set for that buffer
      
      - panfrost follows this contract with the shotgun approach of just
        always setting the exclusive fence, see
        panfrost_attach_object_fences(). Benefits of a single engine I guess
      
      - v3d follows this contract with the same shotgun approach in
        v3d_attach_fences_and_unlock_reservation(), but it has at least an
        XXX comment that maybe this should be improved
      
      - v4c uses the same shotgun approach of always setting an exclusive
        fence, see vc4_update_bo_seqnos()
      
      - vgem also follows this contract, see vgem_fence_attach_ioctl() and
        the VGEM_FENCE_WRITE. This is used in some igts to validate prime
        sharing with i915.ko without the need of a 2nd gpu
      
      - vritio follows this contract again with the shotgun approach of
        always setting an exclusive fence, see virtio_gpu_array_add_fence()
      
      This covers the setting of the exclusive fences when writing.
      
      Synchronizing against the exclusive fence is a lot more tricky, and I
      only spot checked a few:
      
      - i915 does it, with the optional EXEC_OBJECT_ASYNC to skip all
        implicit dependencies (which is used by vulkan)
      
      - etnaviv does this. Implicit dependencies are collected in
        submit_fence_sync(), again with an opt-out flag
        ETNA_SUBMIT_NO_IMPLICIT. These are then picked up in
        etnaviv_sched_dependency which is the
        drm_sched_backend_ops->dependency callback.
      
      - v4c seems to not do much here, maybe gets away with it by not having
        a scheduler and only a single engine. Since all newer broadcom chips than
        the OG vc4 use v3d for rendering, which follows this contract, the
        impact of this issue is fairly small.
      
      - v3d does this using the drm_gem_fence_array_add_implicit() helper,
        which then it's drm_sched_backend_ops->dependency callback
        v3d_job_dependency() picks up.
      
      - panfrost is nice here and tracks the implicit fences in
        panfrost_job->implicit_fences, which again the
        drm_sched_backend_ops->dependency callback panfrost_job_dependency()
        picks up. It is mildly questionable though since it only picks up
        exclusive fences in panfrost_acquire_object_fences(), but not buggy
        in practice because it also always sets the exclusive fence. It
        should pick up both sets of fences, just in case there's ever going
        to be a 2nd gpu in a SoC with a mali gpu. Or maybe a mali SoC with a
        pcie port and a real gpu, which might actually happen eventually. A
        bug, but easy to fix. Should probably use the
        drm_gem_fence_array_add_implicit() helper.
      
      - lima is nice an easy, uses drm_gem_fence_array_add_implicit() and
        the same schema as v3d.
      
      - msm is mildly entertaining. It also supports MSM_SUBMIT_NO_IMPLICIT,
        but because it doesn't use the drm/scheduler it handles fences from
        the wrong context with a synchronous dma_fence_wait. See
        submit_fence_sync() leading to msm_gem_sync_object(). Investing into
        a scheduler might be a good idea.
      
      - all the remaining drivers are ttm based, where I hope they do
        appropriately obey implicit fences already. I didn't do the full
        audit there because a) not follow the contract would confuse ttm
        quite well and b) reading non-standard scheduler and submit code
        which isn't based on drm/scheduler is a pain.
      
      Onwards to the display side.
      
      - Any driver using the drm_gem_plane_helper_prepare_fb() helper will
        correctly. Overwhelmingly most drivers get this right, except a few
        totally dont. I'll follow up with a patch to make this the default
        and avoid a bunch of bugs.
      
      - I didn't audit the ttm drivers, but given that dma_resv started
        there I hope they get this right.
      
      In conclusion this IS the contract, both as documented and
      overwhelmingly implemented, specically as implemented by all render
      drivers except amdgpu.
      
      Amdgpu tried to fix this already in
      
      commit 049aca43
      Author: Christian König <christian.koenig@amd.com>
      Date:   Wed Sep 19 16:54:35 2018 +0200
      
          drm/amdgpu: fix using shared fence for exported BOs v2
      
      but this fix falls short on a number of areas:
      
      - It's racy, by the time the buffer is shared it might be too late. To
        make sure there's definitely never a problem we need to set the
        fences correctly for any buffer that's potentially exportable.
      
      - It's breaking uapi, dma-buf fds support poll() and differentitiate
        between, which was introduced in
      
      	commit 9b495a58
      	Author: Maarten Lankhorst <maarten.lankhorst@canonical.com>
      	Date:   Tue Jul 1 12:57:43 2014 +0200
      
      	    dma-buf: add poll support, v3
      
      - Christian König wants to nack new uapi building further on this
        dma_resv contract because it breaks amdgpu, quoting
      
        "Yeah, and that is exactly the reason why I will NAK this uAPI change.
      
        "This doesn't works for amdgpu at all for the reasons outlined above."
      
        https://lore.kernel.org/dri-devel/f2eb6751-2f82-9b23-f57e-548de5b729de@gmail.com/
      
        Rejecting new development because your own driver is broken and
        violates established cross driver contracts and uapi is really not
        how upstream works.
      
      Now this patch will have a severe performance impact on anything that
      runs on multiple engines. So we can't just merge it outright, but need
      a bit a plan:
      
      - amdgpu needs a proper uapi for handling implicit fencing. The funny
        thing is that to do it correctly, implicit fencing must be treated
        as a very strange IPC mechanism for transporting fences, where both
        setting the fence and dependency intercepts must be handled
        explicitly. Current best practices is a per-bo flag to indicate
        writes, and a per-bo flag to to skip implicit fencing in the CS
        ioctl as a new chunk.
      
      - Since amdgpu has been shipping with broken behaviour we need an
        opt-out flag from the butchered implicit fencing model to enable the
        proper explicit implicit fencing model.
      
      - for kernel memory fences due to bo moves at least the i915 idea is
        to use ttm_bo->moving. amdgpu probably needs the same.
      
      - since the current p2p dma-buf interface assumes the kernel memory
        fence is in the exclusive dma_resv fence slot we need to add a new
        fence slot for kernel fences, which must never be ignored. Since
        currently only amdgpu supports this there's no real problem here
        yet, until amdgpu gains a NO_IMPLICIT CS flag.
      
      - New userspace needs to ship in enough desktop distros so that users
        wont notice the perf impact. I think we can ignore LTS distros who
        upgrade their kernels but not their mesa3d snapshot.
      
      - Then when this is all in place we can merge this patch here.
      
      What is not a solution to this problem here is trying to make the
      dma_resv rules in the kernel more clever. The fundamental issue here
      is that the amdgpu CS uapi is the least expressive one across all
      drivers (only equalled by panfrost, which has an actual excuse) by not
      allowing any userspace control over how implicit sync is conducted.
      
      Until this is fixed it's completely pointless to make the kernel more
      clever to improve amdgpu, because all we're doing is papering over
      this uapi design issue. amdgpu needs to attain the status quo
      established by other drivers first, once that's achieved we can tackle
      the remaining issues in a consistent way across drivers.
      
      v2: Bas pointed me at AMDGPU_GEM_CREATE_EXPLICIT_SYNC, which I
      entirely missed.
      
      This is great because it means the amdgpu specific piece for proper
      implicit fence handling exists already, and that since a while. The
      only thing that's now missing is
      - fishing the implicit fences out of a shared object at the right time
      - setting the exclusive implicit fence slot at the right time.
      
      Jason has a patch series to fill that gap with a bunch of generic
      ioctl on the dma-buf fd:
      
      https://lore.kernel.org/dri-devel/20210520190007.534046-1-jason@jlekstrand.net/
      
      v3: Since Christian has fixed amdgpu now in
      
      commit 8c505bdc (drm-misc/drm-misc-next)
      Author: Christian König <christian.koenig@amd.com>
      Date:   Wed Jun 9 13:51:36 2021 +0200
      
          drm/amdgpu: rework dma_resv handling v3
      
      Use the audit covered in this commit message as the excuse to update
      the dma-buf docs around dma_buf.resv usage across drivers.
      
      Since dynamic importers have different rules also hammer these in
      again while we're at it.
      
      v4:
      - Add the missing "through the device" in the dynamic section that I
        overlooked.
      - Fix a kerneldoc markup mistake, the link didn't connect
      
      v5:
      - A few s/should/must/ to make clear what must be done (if the driver
        does implicit sync) and what's more a maybe (Daniel Stone)
      - drop all the example api discussion, that needs to be expanded,
        clarified and put into a new chapter in drm-uapi.rst (Daniel Stone)
      
      Cc: Daniel Stone <daniel@fooishbar.org>
      Acked-by: NDaniel Stone <daniel@fooishbar.org>
      Reviewed-by: Dave Airlie <airlied@redhat.com> (v4)
      Reviewed-by: Christian König <christian.koenig@amd.com> (v3)
      Cc: mesa-dev@lists.freedesktop.org
      Cc: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
      Cc: Dave Airlie <airlied@gmail.com>
      Cc: Rob Clark <robdclark@chromium.org>
      Cc: Kristian H. Kristensen <hoegsberg@google.com>
      Cc: Michel Dänzer <michel@daenzer.net>
      Cc: Daniel Stone <daniels@collabora.com>
      Cc: Sumit Semwal <sumit.semwal@linaro.org>
      Cc: "Christian König" <christian.koenig@amd.com>
      Cc: Alex Deucher <alexander.deucher@amd.com>
      Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
      Cc: Deepak R Varma <mh12gx2825@gmail.com>
      Cc: Chen Li <chenli@uniontech.com>
      Cc: Kevin Wang <kevin1.wang@amd.com>
      Cc: Dennis Li <Dennis.Li@amd.com>
      Cc: Luben Tuikov <luben.tuikov@amd.com>
      Cc: linaro-mm-sig@lists.linaro.org
      Signed-off-by: NDaniel Vetter <daniel.vetter@intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210624125246.166721-1-daniel.vetter@ffwll.ch
      05459351
    • D
      dma-buf: Switch to inline kerneldoc · d6abed2a
      Daniel Vetter 提交于
      Also review & update everything while we're at it.
      
      This is prep work to smash a ton of stuff into the kerneldoc for
      @resv.
      
      v2: Move the doc for sysfs_entry.attachment_uid to the right place too
      (Sam)
      Reviewed-by: NSam Ravnborg <sam@ravnborg.org>
      Acked-by: NChristian König <christian.koenig@amd.com>
      Cc: Sam Ravnborg <sam@ravnborg.org>
      Reviewed-by: NAlex Deucher <alexander.deucher@amd.com>
      Signed-off-by: NDaniel Vetter <daniel.vetter@intel.com>
      Cc: Sumit Semwal <sumit.semwal@linaro.org>
      Cc: "Christian König" <christian.koenig@amd.com>
      Cc: Alex Deucher <alexander.deucher@amd.com>
      Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
      Cc: Dave Airlie <airlied@redhat.com>
      Cc: Nirmoy Das <nirmoy.das@amd.com>
      Cc: Deepak R Varma <mh12gx2825@gmail.com>
      Cc: Chen Li <chenli@uniontech.com>
      Cc: Kevin Wang <kevin1.wang@amd.com>
      Cc: linux-media@vger.kernel.org
      Cc: linaro-mm-sig@lists.linaro.org
      Link: https://patchwork.freedesktop.org/patch/msgid/20210623161712.3370885-1-daniel.vetter@ffwll.ch
      d6abed2a
  4. 23 6月, 2021 1 次提交
    • D
      dma-buf: Document non-dynamic exporter expectations better · 89bcadc8
      Daniel Vetter 提交于
      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: NChristian König <christian.koenig@amd.com>
      Cc: Christian König <ckoenig.leichtzumerken@gmail.com>
      Signed-off-by: NDaniel Vetter <daniel.vetter@intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210621151758.2347474-1-daniel.vetter@ffwll.ch
      89bcadc8
  5. 15 6月, 2021 1 次提交
    • H
      dmabuf: Add the capability to expose DMA-BUF stats in sysfs · bdb8d06d
      Hridya Valsaraju 提交于
      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/+/1549734Reviewed-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NHridya Valsaraju <hridya@google.com>
      Reported-by: Nkernel test robot <lkp@intel.com>
      Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://patchwork.freedesktop.org/patch/msgid/20210603214758.2955251-1-hridya@google.com
      bdb8d06d
  6. 18 1月, 2021 1 次提交
    • D
      dma-buf: Add debug option · 84335675
      Daniel Vetter 提交于
      We have too many people abusing the struct page they can get at but
      really shouldn't in importers. Aside from that the backing page might
      simply not exist (for dynamic p2p mappings) looking at it and using it
      e.g. for mmap can also wreak the page handling of the exporter
      completely. Importers really must go through the proper interface like
      dma_buf_mmap for everything.
      
      I'm semi-tempted to enforce this for dynamic importers since those
      really have no excuse at all to break the rules.
      
      Unfortuantely we can't store the right pointers somewhere safe to make
      sure we oops on something recognizable, so best is to just wrangle
      them a bit by flipping all the bits. At least on x86 kernel addresses
      have all their high bits sets and the struct page array is fairly low
      in the kernel mapping, so flipping all the bits gives us a very high
      pointer in userspace and hence excellent chances for an invalid
      dereference.
      
      v2: Add a note to the @map_dma_buf hook that exporters shouldn't do
      fancy caching tricks, which would blow up with this address scrambling
      trick here (Chris)
      
      Enable by default when CONFIG_DMA_API_DEBUG is enabled.
      
      v3: Only one copy of the mangle/unmangle code (Christian)
      
      v4: #ifdef, not #if (0day)
      
      v5: sg_table can also be an ERR_PTR (Chris, Christian)
      Reviewed-by: NChris Wilson <chris@chris-wilson.co.uk>
      Reviewed-by: NChristian König <christian.koenig@amd.com>
      Signed-off-by: NDaniel Vetter <daniel.vetter@intel.com>
      Cc: Chris Wilson <chris@chris-wilson.co.uk>
      Cc: Sumit Semwal <sumit.semwal@linaro.org>
      Cc: "Christian König" <christian.koenig@amd.com>
      Cc: David Stevens <stevensd@chromium.org>
      Cc: linux-media@vger.kernel.org
      Cc: linaro-mm-sig@lists.linaro.org
      Link: https://patchwork.freedesktop.org/patch/msgid/20210115164739.3958206-1-daniel.vetter@ffwll.ch
      84335675
  7. 16 12月, 2020 3 次提交
  8. 12 11月, 2020 1 次提交
  9. 16 10月, 2020 1 次提交
  10. 29 9月, 2020 3 次提交
  11. 02 9月, 2020 1 次提交
  12. 10 7月, 2020 1 次提交
    • C
      dmabuf: use spinlock to access dmabuf->name · 6348dd29
      Charan Teja Kalla 提交于
      There exists a sleep-while-atomic bug while accessing the dmabuf->name
      under mutex in the dmabuffs_dname(). This is caused from the SELinux
      permissions checks on a process where it tries to validate the inherited
      files from fork() by traversing them through iterate_fd() (which
      traverse files under spin_lock) and call
      match_file(security/selinux/hooks.c) where the permission checks happen.
      This audit information is logged using dump_common_audit_data() where it
      calls d_path() to get the file path name. If the file check happen on
      the dmabuf's fd, then it ends up in ->dmabuffs_dname() and use mutex to
      access dmabuf->name. The flow will be like below:
      flush_unauthorized_files()
        iterate_fd()
          spin_lock() --> Start of the atomic section.
            match_file()
              file_has_perm()
                avc_has_perm()
                  avc_audit()
                    slow_avc_audit()
      	        common_lsm_audit()
      		  dump_common_audit_data()
      		    audit_log_d_path()
      		      d_path()
                              dmabuffs_dname()
                                mutex_lock()--> Sleep while atomic.
      
      Call trace captured (on 4.19 kernels) is below:
      ___might_sleep+0x204/0x208
      __might_sleep+0x50/0x88
      __mutex_lock_common+0x5c/0x1068
      __mutex_lock_common+0x5c/0x1068
      mutex_lock_nested+0x40/0x50
      dmabuffs_dname+0xa0/0x170
      d_path+0x84/0x290
      audit_log_d_path+0x74/0x130
      common_lsm_audit+0x334/0x6e8
      slow_avc_audit+0xb8/0xf8
      avc_has_perm+0x154/0x218
      file_has_perm+0x70/0x180
      match_file+0x60/0x78
      iterate_fd+0x128/0x168
      selinux_bprm_committing_creds+0x178/0x248
      security_bprm_committing_creds+0x30/0x48
      install_exec_creds+0x1c/0x68
      load_elf_binary+0x3a4/0x14e0
      search_binary_handler+0xb0/0x1e0
      
      So, use spinlock to access dmabuf->name to avoid sleep-while-atomic.
      
      Cc: <stable@vger.kernel.org> [5.3+]
      Signed-off-by: NCharan Teja Kalla <charante@codeaurora.org>
      Reviewed-by: NMichael J. Ruhl <michael.j.ruhl@intel.com>
      Acked-by: NChristian König <christian.koenig@amd.com>
       [sumits: added comment to spinlock_t definition to avoid warning]
      Signed-off-by: NSumit Semwal <sumit.semwal@linaro.org>
      Link: https://patchwork.freedesktop.org/patch/msgid/a83e7f0d-4e54-9848-4b58-e1acdbe06735@codeaurora.org
      6348dd29
  13. 30 4月, 2020 1 次提交
  14. 01 4月, 2020 1 次提交
  15. 27 2月, 2020 2 次提交
    • C
      dma-buf: drop dynamic_mapping flag · bd2275ee
      Christian König 提交于
      Instead use the pin() callback to detect dynamic DMA-buf handling.
      Since amdgpu is now migrated it doesn't make much sense to keep
      the extra flag.
      Signed-off-by: NChristian König <christian.koenig@amd.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://patchwork.freedesktop.org/patch/353997/?series=73646&rev=1
      bd2275ee
    • C
      dma-buf: add dynamic DMA-buf handling v15 · bb42df46
      Christian König 提交于
      On the exporter side we add optional explicit pinning callbacks. Which are
      called when the importer doesn't implement dynamic handling, move notification
      or need the DMA-buf locked in place for its use case.
      
      On the importer side we add an optional move_notify callback. This callback is
      used by the exporter to inform the importers that their mappings should be
      destroyed as soon as possible.
      
      This allows the exporter to provide the mappings without the need to pin
      the backing store.
      
      v2: don't try to invalidate mappings when the callback is NULL,
          lock the reservation obj while using the attachments,
          add helper to set the callback
      v3: move flag for invalidation support into the DMA-buf,
          use new attach_info structure to set the callback
      v4: use importer_priv field instead of mangling exporter priv.
      v5: drop invalidation_supported flag
      v6: squash together with pin/unpin changes
      v7: pin/unpin takes an attachment now
      v8: nuke dma_buf_attachment_(map|unmap)_locked,
          everything is now handled backward compatible
      v9: always cache when export/importer don't agree on dynamic handling
      v10: minimal style cleanup
      v11: drop automatically re-entry avoidance
      v12: rename callback to move_notify
      v13: add might_lock in appropriate places
      v14: rebase on separated locking change
      v15: add EXPERIMENTAL flag, some more code comments
      Signed-off-by: NChristian König <christian.koenig@amd.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://patchwork.freedesktop.org/patch/353993/?series=73646&rev=1
      bb42df46
  16. 26 11月, 2019 2 次提交
  17. 24 10月, 2019 1 次提交
    • C
      dma-buf: change DMA-buf locking convention v3 · 15fd552d
      Christian König 提交于
      This patch is a stripped down version of the locking changes
      necessary to support dynamic DMA-buf handling.
      
      It adds a dynamic flag for both importers as well as exporters
      so that drivers can choose if they want the reservation object
      locked or unlocked during mapping of attachments.
      
      For compatibility between drivers we cache the DMA-buf mapping
      during attaching an importer as soon as exporter/importer
      disagree on the dynamic handling.
      
      Issues and solutions we considered:
      
      - We can't change all existing drivers, and existing improters have
        strong opinions about which locks they're holding while calling
        dma_buf_attachment_map/unmap. Exporters also have strong opinions about
        which locks they can acquire in their ->map/unmap callbacks, levaing no
        room for change. The solution to avoid this was to move the
        actual map/unmap out from this call, into the attach/detach callbacks,
        and cache the mapping. This works because drivers don't call
        attach/detach from deep within their code callchains (like deep in
        memory management code called from cs/execbuf ioctl), but directly from
        the fd2handle implementation.
      
      - The caching has some troubles on some soc drivers, which set other modes
        than DMA_BIDIRECTIONAL. We can't have 2 incompatible mappings, and we
        can't re-create the mapping at _map time due to the above locking fun.
        We very carefuly step around that by only caching at attach time if the
        dynamic mode between importer/expoert mismatches.
      
      - There's been quite some discussion on dma-buf mappings which need active
        cache management, which would all break down when caching, plus we don't
        have explicit flush operations on the attachment side. The solution to
        this was to shrug and keep the current discrepancy between what the
        dma-buf docs claim and what implementations do, with the hope that the
        begin/end_cpu_access hooks are good enough and that all necessary
        flushing to keep device mappings consistent will be done there.
      
      v2: cleanup set_name merge, improve kerneldoc
      v3: update commit message, kerneldoc and cleanup _debug_show()
      Signed-off-by: NChristian König <christian.koenig@amd.com>
      Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: https://patchwork.freedesktop.org/patch/336788/
      15fd552d
  18. 13 8月, 2019 1 次提交
  19. 19 6月, 2019 1 次提交
  20. 14 6月, 2019 1 次提交
  21. 22 5月, 2019 1 次提交
  22. 24 4月, 2019 2 次提交
  23. 20 6月, 2018 2 次提交
  24. 01 6月, 2018 1 次提交
  25. 28 11月, 2017 1 次提交
  26. 20 4月, 2017 1 次提交
  27. 30 12月, 2016 2 次提交
  28. 13 12月, 2016 2 次提交
  29. 25 10月, 2016 1 次提交
    • C
      dma-buf: Rename struct fence to dma_fence · f54d1867
      Chris Wilson 提交于
      I plan to usurp the short name of struct fence for a core kernel struct,
      and so I need to rename the specialised fence/timeline for DMA
      operations to make room.
      
      A consensus was reached in
      https://lists.freedesktop.org/archives/dri-devel/2016-July/113083.html
      that making clear this fence applies to DMA operations was a good thing.
      Since then the patch has grown a bit as usage increases, so hopefully it
      remains a good thing!
      
      (v2...: rebase, rerun spatch)
      v3: Compile on msm, spotted a manual fixup that I broke.
      v4: Try again for msm, sorry Daniel
      
      coccinelle script:
      @@
      
      @@
      - struct fence
      + struct dma_fence
      @@
      
      @@
      - struct fence_ops
      + struct dma_fence_ops
      @@
      
      @@
      - struct fence_cb
      + struct dma_fence_cb
      @@
      
      @@
      - struct fence_array
      + struct dma_fence_array
      @@
      
      @@
      - enum fence_flag_bits
      + enum dma_fence_flag_bits
      @@
      
      @@
      (
      - fence_init
      + dma_fence_init
      |
      - fence_release
      + dma_fence_release
      |
      - fence_free
      + dma_fence_free
      |
      - fence_get
      + dma_fence_get
      |
      - fence_get_rcu
      + dma_fence_get_rcu
      |
      - fence_put
      + dma_fence_put
      |
      - fence_signal
      + dma_fence_signal
      |
      - fence_signal_locked
      + dma_fence_signal_locked
      |
      - fence_default_wait
      + dma_fence_default_wait
      |
      - fence_add_callback
      + dma_fence_add_callback
      |
      - fence_remove_callback
      + dma_fence_remove_callback
      |
      - fence_enable_sw_signaling
      + dma_fence_enable_sw_signaling
      |
      - fence_is_signaled_locked
      + dma_fence_is_signaled_locked
      |
      - fence_is_signaled
      + dma_fence_is_signaled
      |
      - fence_is_later
      + dma_fence_is_later
      |
      - fence_later
      + dma_fence_later
      |
      - fence_wait_timeout
      + dma_fence_wait_timeout
      |
      - fence_wait_any_timeout
      + dma_fence_wait_any_timeout
      |
      - fence_wait
      + dma_fence_wait
      |
      - fence_context_alloc
      + dma_fence_context_alloc
      |
      - fence_array_create
      + dma_fence_array_create
      |
      - to_fence_array
      + to_dma_fence_array
      |
      - fence_is_array
      + dma_fence_is_array
      |
      - trace_fence_emit
      + trace_dma_fence_emit
      |
      - FENCE_TRACE
      + DMA_FENCE_TRACE
      |
      - FENCE_WARN
      + DMA_FENCE_WARN
      |
      - FENCE_ERR
      + DMA_FENCE_ERR
      )
       (
       ...
       )
      Signed-off-by: NChris Wilson <chris@chris-wilson.co.uk>
      Reviewed-by: NGustavo Padovan <gustavo.padovan@collabora.co.uk>
      Acked-by: NSumit Semwal <sumit.semwal@linaro.org>
      Acked-by: NChristian König <christian.koenig@amd.com>
      Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Link: http://patchwork.freedesktop.org/patch/msgid/20161025120045.28839-1-chris@chris-wilson.co.uk
      f54d1867