From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>,
chris@chris-wilson.co.uk, daniel.vetter@ffwll.ch,
sumit.semwal@linaro.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org
Subject: Re: [PATCH] dma-fence: fix dma_fence_get_rcu_safe v2
Date: Thu, 21 Sep 2017 09:28:41 +0200 [thread overview]
Message-ID: <0297e4f4-e3fa-8a50-09c2-acfeedc7d834@linux.intel.com> (raw)
In-Reply-To: <1505469187-3565-1-git-send-email-deathsimple@vodafone.de>
Op 15-09-17 om 11:53 schreef Christian König:
> From: Christian König <christian.koenig@amd.com>
>
> When dma_fence_get_rcu() fails to acquire a reference it doesn't necessary
> mean that there is no fence at all.
>
> It usually mean that the fence was replaced by a new one and in this situation
> we certainly want to have the new one as result and *NOT* NULL.
>
> v2: Keep extra check after dma_fence_get_rcu().
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Sumit Semwal <sumit.semwal@linaro.org>
> Cc: linux-media@vger.kernel.org
> Cc: dri-devel@lists.freedesktop.org
> Cc: linaro-mm-sig@lists.linaro.org
> ---
> include/linux/dma-fence.h | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
> index 0a186c4..f4f23cb 100644
> --- a/include/linux/dma-fence.h
> +++ b/include/linux/dma-fence.h
> @@ -248,9 +248,12 @@ dma_fence_get_rcu_safe(struct dma_fence * __rcu *fencep)
> struct dma_fence *fence;
>
> fence = rcu_dereference(*fencep);
> - if (!fence || !dma_fence_get_rcu(fence))
> + if (!fence)
> return NULL;
>
> + if (!dma_fence_get_rcu(fence))
> + continue;
> +
> /* The atomic_inc_not_zero() inside dma_fence_get_rcu()
> * provides a full memory barrier upon success (such as now).
> * This is paired with the write barrier from assigning
Should be safe from an infinite loop since the old fence is only unreffed after the new pointer is written, so we'll always make progress. :)
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
prev parent reply other threads:[~2017-09-21 7:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-15 9:53 [PATCH] dma-fence: fix dma_fence_get_rcu_safe v2 Christian König
2017-09-21 7:28 ` Maarten Lankhorst [this message]
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=0297e4f4-e3fa-8a50-09c2-acfeedc7d834@linux.intel.com \
--to=maarten.lankhorst@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-media@vger.kernel.org \
--cc=sumit.semwal@linaro.org \
/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