From patchwork Fri Mar 1 00:43:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 15184 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 089FA23E1A for ; Fri, 1 Mar 2013 00:44:26 +0000 (UTC) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by fiordland.canonical.com (Postfix) with ESMTP id 9AD94A19700 for ; Fri, 1 Mar 2013 00:44:25 +0000 (UTC) Received: by mail-vc0-f178.google.com with SMTP id m8so1612440vcd.23 for ; Thu, 28 Feb 2013 16:44:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=ocrBv/NIUx5HXF++UMkFSCm514zJCeeb9VyfHmTffWw=; b=BMmCGAnuoxxgDNOYhIN6BZqFSVbO+1vQ5hBYZbHn2YKr+oHlgYqA2HfYWS9zlTAisS 2edwsPqp4PZiT5rd90BprgGrDdb9LQkCYzCV7nsCicBkDiPiH3AUD4DztQL3DoPn/iV0 ohQFGUj907ccxas6Q4aTPpi7eZW/ChgENPpwF6vqp6M4bPrApcPKlTChsV0iZwRJbgQ1 SwPROTxoq9oVZMNcja2Y/It/YPslUWnLjHVd7FZAPK4pTQYsutPAqKZpbk4jm5sLYERv 1X/uKHE/x5Lvt1eGyTggkWRD1Q0QOKwRQep8/XWNY+xbFbeuxvlwPvYlhjVtkEF7cYx+ a5FA== X-Received: by 10.52.93.235 with SMTP id cx11mr2825287vdb.51.1362098665159; Thu, 28 Feb 2013 16:44:25 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.145.101 with SMTP id st5csp675veb; Thu, 28 Feb 2013 16:44:24 -0800 (PST) X-Received: by 10.66.149.133 with SMTP id ua5mr15831724pab.122.1362098664370; Thu, 28 Feb 2013 16:44:24 -0800 (PST) Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) by mx.google.com with ESMTPS id ot10si10306062pbb.7.2013.02.28.16.44.24 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Feb 2013 16:44:24 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.49 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.220.49; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.49 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) smtp.mail=john.stultz@linaro.org Received: by mail-pa0-f49.google.com with SMTP id kp6so1456731pab.36 for ; Thu, 28 Feb 2013 16:44:24 -0800 (PST) X-Received: by 10.66.76.37 with SMTP id h5mr16380129paw.33.1362098663946; Thu, 28 Feb 2013 16:44:23 -0800 (PST) Received: from localhost.localdomain (c-24-21-54-107.hsd1.or.comcast.net. [24.21.54.107]) by mx.google.com with ESMTPS id dx17sm10914892pac.17.2013.02.28.16.44.22 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Feb 2013 16:44:23 -0800 (PST) From: John Stultz 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 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> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1362098606-26469-1-git-send-email-john.stultz@linaro.org> References: <1362098606-26469-1-git-send-email-john.stultz@linaro.org> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkWOPaCywLyWleYccZbPZYubwMzDI9ykCy2TmxHDMBLuyNa75LS9o0e2S/Ux7xZu2wpo1gF From: Ørjan 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/sync.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 *dst, struct sync_fence *src) new_pt->fence = dst; list_add(&new_pt->pt_list, &dst->pt_list_head); - sync_pt_activate(new_pt); } return 0; @@ -357,7 +356,6 @@ static int sync_fence_merge_pts(struct sync_fence *dst, struct sync_fence *src) new_pt->fence = dst; list_replace(&dst_pt->pt_list, &new_pt->pt_list); - sync_pt_activate(new_pt); sync_pt_free(dst_pt); } collapsed = true; @@ -373,7 +371,6 @@ static int sync_fence_merge_pts(struct sync_fence *dst, struct sync_fence *src) new_pt->fence = dst; list_add(&new_pt->pt_list, &dst->pt_list_head); - sync_pt_activate(new_pt); } } @@ -454,6 +451,7 @@ struct sync_fence *sync_fence_merge(const char *name, struct sync_fence *a, struct sync_fence *b) { struct sync_fence *fence; + struct list_head *pos; int err; fence = sync_fence_alloc(name); @@ -468,6 +466,12 @@ struct sync_fence *sync_fence_merge(const char *name, if (err < 0) goto err; + list_for_each(pos, &fence->pt_list_head) { + struct sync_pt *pt = + 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