From: Matthew Brost <matthew.brost@intel.com>
To: Zack Rusin <zack.rusin@broadcom.com>
Cc: <dri-devel@lists.freedesktop.org>, <ian.forbes@broadcom.com>,
<maaz.mombasawala@broadcom.com>, <stable@vger.kernel.org>
Subject: Re: [PATCH 04/12] drm/vmwgfx: take fman->lock around fence list mutation in fifo_down
Date: Tue, 5 May 2026 20:59:01 -0700 [thread overview]
Message-ID: <afq8hfDELz9DfDyK@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <20260505222728.519626-5-zack.rusin@broadcom.com>
On Tue, May 05, 2026 at 06:22:25PM -0400, Zack Rusin wrote:
> vmw_fence_fifo_down() drops fman->lock to wait on a fence and, on
> timeout, mutates fman->fence_list via list_del_init() and signals
> the fence without re-acquiring the lock. __vmw_fences_update() walks
> and removes entries from the same list under fman->lock from any
> other waiter, the fence-IRQ thread, or vmw_fences_update(), so the
> unlocked list_del_init() can corrupt the list head.
>
> Re-take fman->lock before manipulating fence->head and use
> dma_fence_signal_locked(). Wrap the locked signalling in
> dma_fence_begin_signalling() / dma_fence_end_signalling() so the
> lockdep annotation that dma_fence_signal() previously provided is
> preserved (the same pattern as __vmw_fences_update()).
>
> dma_fence_put() is moved outside the lock to avoid a recursive
> acquire from vmw_fence_obj_destroy(), which also takes fman->lock.
>
Just looking as someone who is curious about AI - not my driver but this
almost certainly looks like a good fix from quick look at vmwgfx code.
> Fixes: ae2a104058e2 ("vmwgfx: Implement fence objects")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-4.7
> Signed-off-by: Zack Rusin <zack.rusin@broadcom.com>
> ---
> drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
> index 4ef84ff9b638..384c6736cf6b 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fence.c
> @@ -367,13 +367,24 @@ void vmw_fence_fifo_down(struct vmw_fence_manager *fman)
> ret = vmw_fence_obj_wait(fence, false, false,
> VMW_FENCE_WAIT_TIMEOUT);
>
> + spin_lock(&fman->lock);
> if (unlikely(ret != 0)) {
> + bool cookie = dma_fence_begin_signalling();
> +
> list_del_init(&fence->head);
> - dma_fence_signal(&fence->base);
> + if (fence->waiter_added) {
> + vmw_seqno_waiter_remove(fman->dev_priv);
> + fence->waiter_added = false;
> + }
> + dma_fence_signal_locked(&fence->base);
> + dma_fence_end_signalling(cookie);
> }
>
> BUG_ON(!list_empty(&fence->head));
> + spin_unlock(&fman->lock);
> +
You likely can drop spin_unlock/spin_lock dance around the put here as a
put is just ref count move or vmw_fence_obj_destroy on final which seems
to resolve to kfree_rcu in any case. ofc, if you want to be parnoid it
is perfectly fine to drop the reacquire the lock.
Matt
> dma_fence_put(&fence->base);
> +
> spin_lock(&fman->lock);
> }
> spin_unlock(&fman->lock);
> --
> 2.51.0
>
next prev parent reply other threads:[~2026-05-06 3:59 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260505222728.519626-1-zack.rusin@broadcom.com>
2026-05-05 22:22 ` [PATCH 01/12] drm/vmwgfx: fix guest_memory_dirty bitfield clobbered as size Zack Rusin
2026-05-05 22:22 ` [PATCH 02/12] drm/vmwgfx: reject DX_BIND_QUERY without a DX context Zack Rusin
2026-05-05 22:22 ` [PATCH 03/12] drm/vmwgfx: clamp dirty-page range with min, not max Zack Rusin
2026-05-05 22:22 ` [PATCH 04/12] drm/vmwgfx: take fman->lock around fence list mutation in fifo_down Zack Rusin
2026-05-06 3:59 ` Matthew Brost [this message]
2026-05-05 22:22 ` [PATCH 05/12] drm/vmwgfx: drop dma_buf reference on foreign-fd prime import Zack Rusin
2026-05-05 22:22 ` [PATCH 06/12] drm/vmwgfx: validate DRAW_PRIMITIVES header size before division Zack Rusin
2026-05-05 22:22 ` [PATCH 07/12] drm/vmwgfx: bound DMA command body size against suffix pointer Zack Rusin
2026-05-05 22:22 ` [PATCH 08/12] drm/vmwgfx: avoid destroy_workqueue(NULL) on vkms init failure Zack Rusin
2026-05-05 22:22 ` [PATCH 09/12] drm/vmwgfx: enforce cursor size limits for MOB cursors Zack Rusin
2026-05-05 22:22 ` [PATCH 10/12] drm/vmwgfx: skip hash_del_rcu when validation context has no hash table Zack Rusin
2026-05-05 22:22 ` [PATCH 11/12] drm/vmwgfx: use check_add_overflow for shader size+offset bound Zack Rusin
2026-05-05 22:22 ` [PATCH 12/12] drm/vmwgfx: validate external BO copy bounds for both stride paths Zack Rusin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=afq8hfDELz9DfDyK@gsse-cloud1.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ian.forbes@broadcom.com \
--cc=maaz.mombasawala@broadcom.com \
--cc=stable@vger.kernel.org \
--cc=zack.rusin@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox