From patchwork Wed Feb 5 00:08:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 24150 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AD26D202FA for ; Wed, 5 Feb 2014 00:09:17 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id e9sf22687751qcy.7 for ; Tue, 04 Feb 2014 16:09:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=5HljR7yijltVWcR9cMJixvEn16bV/sF949EGZss5OVI=; b=CW2GGMoO1mHvBotLCS5LzopUrI3wfdi0Ri1vhfsDT/4OVb/4yMGpY5TRGPyNQa7N2A M4d14UQvbVTh1M+M1LpkmVfLneFIdhSRJqq4E5Ym9dye3ohQ0xrUqbV5wg+q94QSesRN x2XVogQMdtU0OptaPiAu20Wt3kNP6wIAIwJMNjBp8EuUGAZzB0T2dvMPIapXWJE2C6bJ ott8tHQs/Xw6RnbbHw8wuNrWTtVnmeZ6fgPYtp33RQzvzcu/trVOyu+EOlnM+qflZW4U lB1zweLznK/ACx/vaZErjY6Kgxw5bkUkXNWHQPe4BB2OvOJTmvWgw/exFW6OwazYpnU5 Iwmw== X-Gm-Message-State: ALoCoQkzypazvReM2YLLy3GDqVVkdQEVpLHffqbwQ2/laKNAdShyA1ZTpgzUi+irO8Yaadp0LezJ X-Received: by 10.236.94.202 with SMTP id n50mr1053673yhf.31.1391558956714; Tue, 04 Feb 2014 16:09:16 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.98.161 with SMTP id o30ls2586528qge.98.gmail; Tue, 04 Feb 2014 16:09:16 -0800 (PST) X-Received: by 10.58.161.46 with SMTP id xp14mr67510veb.37.1391558956641; Tue, 04 Feb 2014 16:09:16 -0800 (PST) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id yj2si2968366veb.123.2014.02.04.16.09.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 16:09:16 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id jz11so6545579veb.36 for ; Tue, 04 Feb 2014 16:09:16 -0800 (PST) X-Received: by 10.58.161.46 with SMTP id xp14mr67503veb.37.1391558956557; Tue, 04 Feb 2014 16:09:16 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp4078vcz; Tue, 4 Feb 2014 16:09:16 -0800 (PST) X-Received: by 10.67.15.70 with SMTP id fm6mr47442107pad.32.1391558955617; Tue, 04 Feb 2014 16:09:15 -0800 (PST) Received: from mail-pd0-f171.google.com (mail-pd0-f171.google.com [209.85.192.171]) by mx.google.com with ESMTPS id yg10si20273209pbc.122.2014.02.04.16.09.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 16:09:15 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.171 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.171; Received: by mail-pd0-f171.google.com with SMTP id g10so8896602pdj.30 for ; Tue, 04 Feb 2014 16:09:15 -0800 (PST) X-Received: by 10.68.238.201 with SMTP id vm9mr46815926pbc.18.1391558955145; Tue, 04 Feb 2014 16:09:15 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id g6sm181483447pat.2.2014.02.04.16.09.13 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 16:09:14 -0800 (PST) From: John Stultz To: LKML Cc: Prakash Kamliya , Colin Cross , Android Kernel Team , John Stultz Subject: [PATCH 2/7] staging: sync: Signal pt before sync_timeline object gets destroyed Date: Tue, 4 Feb 2014 16:08:35 -0800 Message-Id: <1391558920-31590-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1391558920-31590-1-git-send-email-john.stultz@linaro.org> References: <1391558920-31590-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Prakash Kamliya There is a race condition Assume we have *one* sync_fence object, with *one* sync_pt which belongs to *one* sync_timeline, given this condition, sync_timeline->kref will have two counts, one for sync_timeline (implicit) and another for sync_pt. Assume following is the situation on CPU Theead-1 : (Thread which calls sync_timeline_destroy()) -> (some function calls) -> sync_timeline_destory() -> sync_timeline_signal() (CPU is inside this function after putting reference to sync_timeline) At this time Thread-2 comes and does following Thread-2 : (fclose on fence fd) > sync_fence_release() -> because of fclose() on fence object -> sync_fence_free() -> sync_pt_free() -> kref_put(&pt->parent->kref, sync_timeline_free); -> sync_timeline_free() (CPU is inside this because this time kref will be zero after _put) Thread-2 will free sync_timeline object before Thread-1 has finished its work inside sync_timeline_signal. With this change we signals all sync_pt before putting reference to sync_timeline object. c: Greg KH Cc: Colin Cross Cc: Android Kernel Team Signed-off-by: Prakash Kamliya [jstultz: minor commit subject tweak] Signed-off-by: John Stultz --- drivers/staging/android/sync.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 38e5d3b..fec2d1c 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -92,14 +92,14 @@ static void sync_timeline_free(struct kref *kref) void sync_timeline_destroy(struct sync_timeline *obj) { obj->destroyed = true; + smp_wmb(); /* - * If this is not the last reference, signal any children - * that their parent is going away. + * signal any children that their parent is going away. */ + sync_timeline_signal(obj); - if (!kref_put(&obj->kref, sync_timeline_free)) - sync_timeline_signal(obj); + kref_put(&obj->kref, sync_timeline_free); } EXPORT_SYMBOL(sync_timeline_destroy);