All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v7] drm/vmwgfx: Reserve ttm object before resv usage
@ 2026-11-17  0:59 Maaz Mombasawala
  2026-11-17  1:24 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Maaz Mombasawala @ 2026-11-17  0:59 UTC (permalink / raw)
  To: dri-devel
  Cc: bcm-kernel-feedback-list, ian.forbes, zack.rusin,
	Maaz Mombasawala

We hit dma_resv_assert_held warnings, reserve the ttm base object when it's
being used to avoid them.

Signed-off-by: Maaz Mombasawala <maaz.mombasawala@broadcom.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
index 3d0d5dfa869f..ef163d4b64d1 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
@@ -131,6 +131,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,7 +139,14 @@ crc_generate_worker(struct work_struct *work)
 			return;
 		}
 
+		ret = ttm_bo_reserve(&surf->res.guest_memory_bo->tbo, false, false, NULL);
+		if (ret != 0) {
+			drm_warn(&vmw->drm, "%s: failed reserve\n", __func__);
+			goto done;
+		}
 		compute_crc(crtc, surf, &crc32);
+		ttm_bo_unreserve(&surf->res.guest_memory_bo->tbo);
+done:
 		vmw_surface_unreference(&surf);
 	}
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v7] drm/vmwgfx: Reserve ttm object before resv usage
  2026-11-17  0:59 [PATCH v7] drm/vmwgfx: Reserve ttm object before resv usage Maaz Mombasawala
@ 2026-11-17  1:24 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-17  1:24 UTC (permalink / raw)
  To: Maaz Mombasawala, dri-devel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/vmwgfx: UAF and NULL deref on guest_memory_bo in
  crc_generate_worker()
- [Low] drm/vmwgfx: missing Fixes trailer and inaccurate TTM type in
  commit message
--

commit 9ec8429beccaa97a3b1b9ddc00c56d85a9cbdb38
Author: Maaz Mombasawala <maaz.mombasawala@broadcom.com>

> drm/vmwgfx: Reserve ttm object before resv usage
> 
> We hit dma_resv_assert_held warnings, reserve the ttm base object when it's
> being used to avoid them.
> 
> Signed-off-by: Maaz Mombasawala <maaz.mombasawala@broadcom.com>

[Severity: Low]
This fixes the unreserved BO map in compute_crc().  Should it include:

  Fixes: 7b0062036c3b ("drm/vmwgfx: Implement virtual crc generation")

Also, surf->res.guest_memory_bo->tbo is a struct ttm_buffer_object rather
than a struct ttm_base_object.

> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
> index 3d0d5dfa869f9..ef163d4b64d1f 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_vkms.c
> @@ -131,6 +131,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,7 +139,14 @@ crc_generate_worker(struct work_struct *work)
>  			return;
>  		}
>  
> +		ret = ttm_bo_reserve(&surf->res.guest_memory_bo->tbo, false, false, NULL);
> +		if (ret != 0) {
> +			drm_warn(&vmw->drm, "%s: failed reserve\n", __func__);
> +			goto done;
> +		}
>  		compute_crc(crtc, surf, &crc32);
> +		ttm_bo_unreserve(&surf->res.guest_memory_bo->tbo);

[Severity: High]
Can surf->res.guest_memory_bo become NULL or be freed while
crc_generate_worker() accesses it?

crc_generate_worker() holds a reference on surf, but res->guest_memory_bo
is only stabilized while surf->res is reserved or pinned.  During an
atomic commit, drm_atomic_helper_commit_tail() cleans up and unpins the
old plane state's surface before vmw_atomic_commit_tail() flushes
du->vkms.crc_generator_work.  For a dumb scanout buffer, vmw_dumb_create()
drops the surface's GEM reference on the BO, so once the FB and dumb BO
are destroyed, vmw_bo_free() clears surf->res.guest_memory_bo and frees
the BO even while crc_generate_worker() still holds surf:

CPU0                                  kworker (crc_generate_worker)
----                                  -----------------------------
vmw_atomic_commit_tail()
  drm_atomic_helper_commit_tail()
    ...
      vmw_stdu_primary_plane_cleanup_fb()
        vmw_resource_unpin(&surf->res)
                                      surf = vmw_surface_reference(...)
                                      vmw_surface_sync(vmw, surf)
vmw_bo_free()
  res->guest_memory_bo = NULL
  ...
  kfree(vbo)
                                      ttm_bo_reserve(
                                        &surf->res.guest_memory_bo->tbo, ...)
                                        <-- NULL pointer dereference / UAF

If vmw_bo_free() or vmw_cmd_bind_gb_surface() changes
surf->res.guest_memory_bo between ttm_bo_reserve() and
ttm_bo_unreserve(), re-reading surf->res.guest_memory_bo in
ttm_bo_unreserve() also unlocks the wrong reservation object or
dereferences NULL.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117005945.806941-2-maaz.mombasawala@broadcom.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-17  1:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  0:59 [PATCH v7] drm/vmwgfx: Reserve ttm object before resv usage Maaz Mombasawala
2026-11-17  1:24 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.