Skip to content
  1. Nov 05, 2021
    • Maxime Ripard's avatar
      drm/vc4: kms: Don't duplicate pending commit · c51fbd41
      Maxime Ripard authored
      
      
      Our HVS global state, when duplicated, will also copy the pointer to the
      drm_crtc_commit (and increase the reference count) for each FIFO if the
      pointer is not NULL.
      
      However, our atomic_setup function will overwrite that pointer without
      putting the reference back leading to a memory leak.
      
      Since the commit is only relevant during the atomic commit process, it
      doesn't make sense to duplicate the reference to the commit anyway.
      Let's remove it.
      
      Fixes: 9ec03d7f ("drm/vc4: kms: Wait on previous FIFO users before a commit")
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      c51fbd41
    • Maxime Ripard's avatar
      drm/vc4: kms: Clear the HVS FIFO commit pointer once done · cda23575
      Maxime Ripard authored
      
      
      Commit 9ec03d7f ("drm/vc4: kms: Wait on previous FIFO users before a
      commit") introduced a wait on the previous commit done on a given HVS
      FIFO.
      
      However, we never cleared that pointer once done. Since
      drm_crtc_commit_put can free the drm_crtc_commit structure directly if
      we were the last user, this means that it can lead to a use-after free
      if we were to duplicate the state, and that stale pointer would even be
      copied to the new state.
      
      Set the pointer to NULL once we're done with the wait so that we don't
      carry over a pointer to a free'd structure.
      
      Fixes: 9ec03d7f ("drm/vc4: kms: Wait on previous FIFO users before a commit")
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      cda23575
    • Maxime Ripard's avatar
      drm/vc4: kms: Fix return code check · 16f2bdd9
      Maxime Ripard authored
      
      
      The HVS global state functions return an error pointer, but in most
      cases we check if it's NULL, possibly resulting in an invalid pointer
      dereference.
      
      Fixes: 9ec03d7f ("drm/vc4: kms: Wait on previous FIFO users before a commit")
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      16f2bdd9
    • Maxime Ripard's avatar
      drm/vc4: Wait for the commit before starting our clock request · 10151fdf
      Maxime Ripard authored
      
      
      Several DRM/KMS atomic commits can run in parallel if they affect
      different CRTC. These commits share the global HVS state, so we have
      some code to make sure we run commits in sequence. This synchronization
      code is one of the first thing that runs in vc4_atomic_commit_tail().
      
      Another constraints we have is that we need to make sure the HVS clock
      gets a boost during the commit. That code relies on clk_requests and
      will remove the old requests and start a new one. We also need another,
      temporary, request for the duration of the commit.
      
      The algorithm is thus to start a temporary request, drop the previous
      one, do the commit, start a new request for the current mode, and
      finally drop the temporary request.
      
      However, the part that takes a temporary request and drops the older one
      runs before the commit synchronization code.
      
      Thus, under the proper conditions, we can end up dropping twice the old
      request, resulting in an use-after-free.
      
      To avoid it, let's move the clock setup in the protected section.
      
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      10151fdf
    • Maxime Ripard's avatar
      drm/vc4: kms: Add missing drm_crtc_commit_put · 2d01bc8f
      Maxime Ripard authored
      
      
      Commit 9ec03d7f ("drm/vc4: kms: Wait on previous FIFO users before a
      commit") introduced a global state for the HVS, with each FIFO storing
      the current CRTC commit so that we can properly synchronize commits.
      
      However, the refcounting was off and we thus ended up leaking the
      drm_crtc_commit structure every commit. Add a drm_crtc_commit_put to
      prevent the leakage.
      
      Fixes: 9ec03d7f ("drm/vc4: kms: Wait on previous FIFO users before a commit")
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      2d01bc8f
    • Maxime Ripard's avatar
      drm/vc4: crtc: Make sure the HDMI controller is powered at boot · 2c513b51
      Maxime Ripard authored
      
      
      If vc4_crtc_disable_at_boot runs, we call into the HDMI controller hooks
      to disable it but we never made sure it was running and the core clock
      was running either.
      
      This doesn't fix any known bugs, but it's still something we should make
      sure of.
      
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      2c513b51
    • Maxime Ripard's avatar
      drm/vc4: hdmi: Unregister codec device on unbind · c30f96c1
      Maxime Ripard authored
      
      
      On bind we will register the HDMI codec device but we don't unregister
      it on unbind, leading to a device leakage. Unregister our device at
      unbind.
      
      Signed-off-by: default avatarMaxime Ripard <maxime@cerno.tech>
      c30f96c1
  2. Oct 01, 2021