From: "Christian König" <christian.koenig@amd.com>
To: Tvrtko Ursulin <tursulin@ursulin.net>,
phasta@mailbox.org, matthew.brost@intel.com,
sumit.semwal@linaro.org
Cc: dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org
Subject: Re: [PATCH 5/9] dma-buf: inline spinlock for fence protection v4
Date: Wed, 21 Jan 2026 09:48:29 +0100 [thread overview]
Message-ID: <4e5c0b99-bbc1-4785-bee8-52b82d696d59@amd.com> (raw)
In-Reply-To: <5de308d9-9ed9-4ae7-8b0e-1ec53282c5e9@ursulin.net>
On 1/20/26 12:41, Tvrtko Ursulin wrote:
>
> On 20/01/2026 10:54, Christian König wrote:
>> Implement per-fence spinlocks, allowing implementations to not give an
>> external spinlock to protect the fence internal statei. Instead a spinlock
>> embedded into the fence structure itself is used in this case.
>>
>> Shared spinlocks have the problem that implementations need to guarantee
>> that the lock live at least as long all fences referencing them.
>>
>> Using a per-fence spinlock allows completely decoupling spinlock producer
>> and consumer life times, simplifying the handling in most use cases.
>>
>> v2: improve naming, coverage and function documentation
>> v3: fix one additional locking in the selftests
>> v4: separate out some changes to make the patch smaller,
>> fix one amdgpu crash found by CI systems
>>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> ---
>> drivers/dma-buf/dma-fence.c | 25 +++++++++++++++++-------
>> drivers/dma-buf/sync_debug.h | 2 +-
>> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +-
>> drivers/gpu/drm/drm_crtc.c | 2 +-
>> drivers/gpu/drm/drm_writeback.c | 2 +-
>> drivers/gpu/drm/nouveau/nouveau_fence.c | 3 ++-
>> drivers/gpu/drm/qxl/qxl_release.c | 3 ++-
>> drivers/gpu/drm/vmwgfx/vmwgfx_fence.c | 3 ++-
>> drivers/gpu/drm/xe/xe_hw_fence.c | 3 ++-
>
> i915 needed changes too, based on the kbuild report.
Going to take a look now.
> Have you seen my note about the RCU sparse warning as well?
Nope, I must have missed that mail.
...
>> +/**
>> + * dma_fence_spinlock - return pointer to the spinlock protecting the fence
>> + * @fence: the fence to get the lock from
>> + *
>> + * Return either the pointer to the embedded or the external spin lock.
>> + */
>> +static inline spinlock_t *dma_fence_spinlock(struct dma_fence *fence)
>> +{
>> + return test_bit(DMA_FENCE_FLAG_INLINE_LOCK_BIT, &fence->flags) ?
>> + &fence->inline_lock : fence->extern_lock;
>> +}
>
> You did not want to move this helper into "dma-buf: abstract fence locking" ?
I was avoiding that to keep the pre-requisite patch smaller, cause this change here seemed independent to that.
But thinking about it I could make a third patch which introduces dma_fence_spinlock() and changes all the container_of uses.
> I think that would have been better to keep everything mechanical in one patch, and then this patch which changes behaviour does not touch any drivers but only dma-fence core.
>
> Also, what about adding something like dma_fence_container_of() in that patch as well?
I would rather like to avoid that. Using the spinlock pointer with container_of seemed to be a bit of a hack to me in the first place and I don't want to encourage people to do that in new code as well.
Regards,
Christian.
>
> Regards,
>
> Tvrtko
>
>> +
>> /**
>> * dma_fence_lock_irqsave - irqsave lock the fence
>> * @fence: the fence to lock
>> @@ -385,7 +403,7 @@ dma_fence_get_rcu_safe(struct dma_fence __rcu **fencep)
>> * Lock the fence, preventing it from changing to the signaled state.
>> */
>> #define dma_fence_lock_irqsave(fence, flags) \
>> - spin_lock_irqsave(fence->lock, flags)
>> + spin_lock_irqsave(dma_fence_spinlock(fence), flags)
>> /**
>> * dma_fence_unlock_irqrestore - unlock the fence and irqrestore
>> @@ -395,7 +413,7 @@ dma_fence_get_rcu_safe(struct dma_fence __rcu **fencep)
>> * Unlock the fence, allowing it to change it's state to signaled again.
>> */
>> #define dma_fence_unlock_irqrestore(fence, flags) \
>> - spin_unlock_irqrestore(fence->lock, flags)
>> + spin_unlock_irqrestore(dma_fence_spinlock(fence), flags)
>> #ifdef CONFIG_LOCKDEP
>> bool dma_fence_begin_signalling(void);
>
next prev parent reply other threads:[~2026-01-21 8:48 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 10:54 Independence for dma_fences! v6 Christian König
2026-01-20 10:54 ` [PATCH 1/9] dma-buf: add dma_fence_was_initialized function v2 Christian König
2026-01-20 11:33 ` Tvrtko Ursulin
2026-07-13 8:58 ` Jiri Slaby
2026-07-14 7:53 ` Philipp Stanner
2026-07-14 8:43 ` Philipp Stanner
2026-08-19 8:59 ` Jiri Slaby
2026-08-19 12:33 ` Philipp Stanner
2026-08-19 12:51 ` Philipp Stanner
2026-08-28 7:29 ` Jiri Slaby
2026-08-28 7:46 ` Jiri Slaby
2026-08-28 8:32 ` Jiri Slaby
2026-09-02 6:52 ` Philipp Stanner
2026-09-02 6:56 ` Jiri Slaby
2026-09-02 7:03 ` Philipp Stanner
2026-09-02 10:47 ` Jiri Slaby
2026-01-20 10:54 ` [PATCH 2/9] dma-buf: protected fence ops by RCU v5 Christian König
2026-01-20 10:54 ` [PATCH 3/9] dma-buf: detach fence ops on signal v2 Christian König
2026-01-20 10:54 ` [PATCH 4/9] dma-buf: abstract fence locking Christian König
2026-01-20 10:54 ` [PATCH 5/9] dma-buf: inline spinlock for fence protection v4 Christian König
2026-01-20 11:41 ` Tvrtko Ursulin
2026-01-21 8:48 ` Christian König [this message]
2026-01-21 9:03 ` Tvrtko Ursulin
2026-01-27 4:56 ` kernel test robot
2026-01-20 10:54 ` [PATCH 6/9] dma-buf/selftests: test RCU ops and inline lock v2 Christian König
2026-01-20 10:54 ` [PATCH 7/9] dma-buf: use inline lock for the stub fence v2 Christian König
2026-01-21 9:29 ` Philipp Stanner
2026-01-20 10:54 ` [PATCH 8/9] dma-buf: use inline lock for the dma-fence-array Christian König
2026-01-20 10:54 ` [PATCH 9/9] dma-buf: use inline lock for the dma-fence-chain Christian König
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=4e5c0b99-bbc1-4785-bee8-52b82d696d59@amd.com \
--to=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=matthew.brost@intel.com \
--cc=phasta@mailbox.org \
--cc=sumit.semwal@linaro.org \
--cc=tursulin@ursulin.net \
/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