From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Stultz Subject: [PATCH 28/30] staging: sync: Fix race condition between merge and signal Date: Thu, 28 Feb 2013 16:43:24 -0800 Message-ID: <1362098606-26469-29-git-send-email-john.stultz@linaro.org> References: <1362098606-26469-1-git-send-email-john.stultz@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: <1362098606-26469-1-git-send-email-john.stultz@linaro.org> Sender: linux-kernel-owner@vger.kernel.org To: lkml Cc: =?UTF-8?q?=C3=98rjan=20Eide?= , Maarten Lankhorst , Erik Gilling , Daniel Vetter , Rob Clark , Sumit Semwal , Greg KH , dri-devel@lists.freedesktop.org, Android Kernel Team , John Stultz List-Id: dri-devel@lists.freedesktop.org =46rom: =C3=98rjan Eide The copied sync_pt was activated immediately. If the sync_pt was signaled before the entire merge was completed, the new fence's pt_list could be iterated over while it is still in the process of being created. Moving the the sync_pt_activate call for all new sync_pts to after both the sync_fence_copy_pts and the sync_fence_merge_pts calls ensure that the pt_list is complete and immutable before it can be reached from the timeline's active list. Cc: Maarten Lankhorst Cc: Erik Gilling Cc: Daniel Vetter Cc: Rob Clark Cc: Sumit Semwal Cc: Greg KH Cc: dri-devel@lists.freedesktop.org Cc: Android Kernel Team Signed-off-by: Erik Gilling Signed-off-by: John Stultz --- drivers/staging/android/sync.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/s= ync.c index 1ddc404..bd18c75 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -324,7 +324,6 @@ static int sync_fence_copy_pts(struct sync_fence *d= st, struct sync_fence *src) =20 new_pt->fence =3D dst; list_add(&new_pt->pt_list, &dst->pt_list_head); - sync_pt_activate(new_pt); } =20 return 0; @@ -357,7 +356,6 @@ static int sync_fence_merge_pts(struct sync_fence *= dst, struct sync_fence *src) new_pt->fence =3D dst; list_replace(&dst_pt->pt_list, &new_pt->pt_list); - sync_pt_activate(new_pt); sync_pt_free(dst_pt); } collapsed =3D true; @@ -373,7 +371,6 @@ static int sync_fence_merge_pts(struct sync_fence *= dst, struct sync_fence *src) =20 new_pt->fence =3D dst; list_add(&new_pt->pt_list, &dst->pt_list_head); - sync_pt_activate(new_pt); } } =20 @@ -454,6 +451,7 @@ struct sync_fence *sync_fence_merge(const char *nam= e, struct sync_fence *a, struct sync_fence *b) { struct sync_fence *fence; + struct list_head *pos; int err; =20 fence =3D sync_fence_alloc(name); @@ -468,6 +466,12 @@ struct sync_fence *sync_fence_merge(const char *na= me, if (err < 0) goto err; =20 + list_for_each(pos, &fence->pt_list_head) { + struct sync_pt *pt =3D + container_of(pos, struct sync_pt, pt_list); + sync_pt_activate(pt); + } + /* * signal the fence in case one of it's pts were activated before * they were activated --=20 1.7.10.4