dma-buf/dma-fence: Add dma_fence_check_and_signal()

The overwhelming majority of users of dma_fence signaling functions
don't care about whether the fence had already been signaled by someone
else. Therefore, the return code shall be removed from those functions.

For the few users who rely on the check, a new, specialized function
shall be provided.

Add dma_fence_check_and_signal(), which signals a fence if it had not
yet been signaled, and informs the user about that.

Add a counter part, dma_fence_check_and_signal_locked(), which doesn't
take the spinlock.

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Philipp Stanner <phasta@kernel.org>
Link: https://patch.msgid.link/20251201105011.19386-4-phasta@kernel.org
This commit is contained in:
Philipp Stanner 2025-12-01 11:50:06 +01:00
parent e58b4dea90
commit c891b99d25
2 changed files with 46 additions and 0 deletions

View File

@ -443,6 +443,50 @@ int dma_fence_signal_locked(struct dma_fence *fence)
}
EXPORT_SYMBOL(dma_fence_signal_locked);
/**
* dma_fence_check_and_signal_locked - signal the fence if it's not yet signaled
* @fence: the fence to check and signal
*
* Checks whether a fence was signaled and signals it if it was not yet signaled.
*
* Unlike dma_fence_check_and_signal(), this function must be called with
* &struct dma_fence.lock being held.
*
* Return: true if fence has been signaled already, false otherwise.
*/
bool dma_fence_check_and_signal_locked(struct dma_fence *fence)
{
bool ret;
ret = dma_fence_test_signaled_flag(fence);
dma_fence_signal_locked(fence);
return ret;
}
EXPORT_SYMBOL(dma_fence_check_and_signal_locked);
/**
* dma_fence_check_and_signal - signal the fence if it's not yet signaled
* @fence: the fence to check and signal
*
* Checks whether a fence was signaled and signals it if it was not yet signaled.
* All this is done in a race-free manner.
*
* Return: true if fence has been signaled already, false otherwise.
*/
bool dma_fence_check_and_signal(struct dma_fence *fence)
{
unsigned long flags;
bool ret;
spin_lock_irqsave(fence->lock, flags);
ret = dma_fence_check_and_signal_locked(fence);
spin_unlock_irqrestore(fence->lock, flags);
return ret;
}
EXPORT_SYMBOL(dma_fence_check_and_signal);
/**
* dma_fence_signal - signal completion of a fence
* @fence: the fence to signal

View File

@ -365,6 +365,8 @@ static inline void __dma_fence_might_wait(void) {}
#endif
int dma_fence_signal(struct dma_fence *fence);
bool dma_fence_check_and_signal(struct dma_fence *fence);
bool dma_fence_check_and_signal_locked(struct dma_fence *fence);
int dma_fence_signal_locked(struct dma_fence *fence);
int dma_fence_signal_timestamp(struct dma_fence *fence, ktime_t timestamp);
int dma_fence_signal_timestamp_locked(struct dma_fence *fence,