dma-fence: Serialise signal enabling (dma_fence_enable_sw_signaling)
[ Upstream commit 9c98f021e4e717ffd9948fa65340ea3ef12b7935 ] Make dma_fence_enable_sw_signaling() behave like its dma_fence_add_callback() and dma_fence_default_wait() counterparts and perform the test to enable signaling under the fence->lock, along with the action to do so. This ensure that should an implementation be trying to flush the cb_list (by signaling) on retirement before freeing the fence, it can do so in a race-free manner. See also 0fc89b6802ba ("dma-fence: Simply wrap dma_fence_signal_locked with dma_fence_signal"). v2: Refactor all 3 enable_signaling paths to use a common function. v3: Don't argue, just keep the tracepoint in the existing spot. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20191004101140.32713-1-chris@chris-wilson.co.uk Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
3e4afbb188
commit
8e634b7b19
@ -244,6 +244,30 @@ void dma_fence_free(struct dma_fence *fence)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL(dma_fence_free);
|
EXPORT_SYMBOL(dma_fence_free);
|
||||||
|
|
||||||
|
static bool __dma_fence_enable_signaling(struct dma_fence *fence)
|
||||||
|
{
|
||||||
|
bool was_set;
|
||||||
|
|
||||||
|
lockdep_assert_held(fence->lock);
|
||||||
|
|
||||||
|
was_set = test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
|
||||||
|
&fence->flags);
|
||||||
|
|
||||||
|
if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!was_set && fence->ops->enable_signaling) {
|
||||||
|
trace_dma_fence_enable_signal(fence);
|
||||||
|
|
||||||
|
if (!fence->ops->enable_signaling(fence)) {
|
||||||
|
dma_fence_signal_locked(fence);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dma_fence_enable_sw_signaling - enable signaling on fence
|
* dma_fence_enable_sw_signaling - enable signaling on fence
|
||||||
* @fence: the fence to enable
|
* @fence: the fence to enable
|
||||||
@ -256,19 +280,12 @@ void dma_fence_enable_sw_signaling(struct dma_fence *fence)
|
|||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
if (!test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
|
if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
|
||||||
&fence->flags) &&
|
return;
|
||||||
!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags) &&
|
|
||||||
fence->ops->enable_signaling) {
|
|
||||||
trace_dma_fence_enable_signal(fence);
|
|
||||||
|
|
||||||
spin_lock_irqsave(fence->lock, flags);
|
spin_lock_irqsave(fence->lock, flags);
|
||||||
|
__dma_fence_enable_signaling(fence);
|
||||||
if (!fence->ops->enable_signaling(fence))
|
spin_unlock_irqrestore(fence->lock, flags);
|
||||||
dma_fence_signal_locked(fence);
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(fence->lock, flags);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(dma_fence_enable_sw_signaling);
|
EXPORT_SYMBOL(dma_fence_enable_sw_signaling);
|
||||||
|
|
||||||
@ -302,7 +319,6 @@ int dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb,
|
|||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
bool was_set;
|
|
||||||
|
|
||||||
if (WARN_ON(!fence || !func))
|
if (WARN_ON(!fence || !func))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -314,25 +330,14 @@ int dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb,
|
|||||||
|
|
||||||
spin_lock_irqsave(fence->lock, flags);
|
spin_lock_irqsave(fence->lock, flags);
|
||||||
|
|
||||||
was_set = test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
|
if (__dma_fence_enable_signaling(fence)) {
|
||||||
&fence->flags);
|
|
||||||
|
|
||||||
if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
|
|
||||||
ret = -ENOENT;
|
|
||||||
else if (!was_set && fence->ops->enable_signaling) {
|
|
||||||
trace_dma_fence_enable_signal(fence);
|
|
||||||
|
|
||||||
if (!fence->ops->enable_signaling(fence)) {
|
|
||||||
dma_fence_signal_locked(fence);
|
|
||||||
ret = -ENOENT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ret) {
|
|
||||||
cb->func = func;
|
cb->func = func;
|
||||||
list_add_tail(&cb->node, &fence->cb_list);
|
list_add_tail(&cb->node, &fence->cb_list);
|
||||||
} else
|
} else {
|
||||||
INIT_LIST_HEAD(&cb->node);
|
INIT_LIST_HEAD(&cb->node);
|
||||||
|
ret = -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
spin_unlock_irqrestore(fence->lock, flags);
|
spin_unlock_irqrestore(fence->lock, flags);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -432,7 +437,6 @@ dma_fence_default_wait(struct dma_fence *fence, bool intr, signed long timeout)
|
|||||||
struct default_wait_cb cb;
|
struct default_wait_cb cb;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
signed long ret = timeout ? timeout : 1;
|
signed long ret = timeout ? timeout : 1;
|
||||||
bool was_set;
|
|
||||||
|
|
||||||
if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
|
if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
|
||||||
return ret;
|
return ret;
|
||||||
@ -444,21 +448,9 @@ dma_fence_default_wait(struct dma_fence *fence, bool intr, signed long timeout)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
was_set = test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
|
if (!__dma_fence_enable_signaling(fence))
|
||||||
&fence->flags);
|
|
||||||
|
|
||||||
if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!was_set && fence->ops->enable_signaling) {
|
|
||||||
trace_dma_fence_enable_signal(fence);
|
|
||||||
|
|
||||||
if (!fence->ops->enable_signaling(fence)) {
|
|
||||||
dma_fence_signal_locked(fence);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!timeout) {
|
if (!timeout) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto out;
|
goto out;
|
||||||
|
Loading…
Reference in New Issue
Block a user