We hit dma_resv_assert_held warnings, reserve the TTM buffer object when
it's being used to avoid them. Also reserve the backing guest_memory_bo
to avoid race conditions when vmw_bo_free() is cleaning up the bo.

Signed-off-by: Maaz Mombasawala <[email protected]>
Fixes: 7b0062036c3b ("drm/vmwgfx: Implement virtual crc generation")
Cc: Zack Rusin <[email protected]>
Cc: Broadcom internal kernel review list <[email protected]>
Cc: [email protected]
---
 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c | 29 +++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
index 8ce10cf9c19e..91afa8a0bd9f 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
@@ -114,6 +114,7 @@ crc_generate_worker(struct work_struct *work)
        u64 frame_start, frame_end;
        u32 crc32 = 0;
        struct vmw_surface *surf = 0;
+       bool valid_crc = false;
 
        spin_lock_irq(&du->vkms.crc_state_lock);
        crc_pending = du->vkms.crc_pending;
@@ -131,6 +132,7 @@ crc_generate_worker(struct work_struct *work)
        spin_unlock_irq(&du->vkms.crc_state_lock);
 
        if (surf) {
+               int ret;
                if (vmw_surface_sync(vmw, surf)) {
                        drm_warn(
                                crtc->dev,
@@ -138,10 +140,35 @@ crc_generate_worker(struct work_struct *work)
                        return;
                }
 
-               compute_crc(crtc, surf, &crc32);
+               if (surf->res.guest_memory_bo) {
+                       struct vmw_resource *res = &surf->res;
+
+                       mutex_lock(&res->dev_priv->cmdbuf_mutex);
+                       ret = vmw_resource_reserve(res, false, true);
+                       if (ret != 0)
+                               goto no_res_reserve;
+                       ret = ttm_bo_reserve(&res->guest_memory_bo->tbo, false,
+                                            false, NULL);
+                       if (ret != 0) {
+                               drm_warn(&vmw->drm, "%s: failed reserve\n",
+                                        __func__);
+                               goto no_tbo_reserve;
+                       }
+                       compute_crc(crtc, surf, &crc32);
+                       valid_crc = true;
+                       ttm_bo_unreserve(&res->guest_memory_bo->tbo);
+no_tbo_reserve:
+                       vmw_resource_unreserve(res, true, false, false, NULL,
+                                              0);
+no_res_reserve:
+                       mutex_unlock(&res->dev_priv->cmdbuf_mutex);
+               }
                vmw_surface_unreference(&surf);
        }
 
+       if (!valid_crc)
+               return;
+
        spin_lock_irq(&du->vkms.crc_state_lock);
        frame_start = du->vkms.frame_start;
        frame_end = du->vkms.frame_end;
-- 
2.56.1

Reply via email to