From patchwork Mon Feb 3 18:16:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 24048 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f70.google.com (mail-vb0-f70.google.com [209.85.212.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4C93D202B2 for ; Mon, 3 Feb 2014 18:16:43 +0000 (UTC) Received: by mail-vb0-f70.google.com with SMTP id w17sf18988914vbj.5 for ; Mon, 03 Feb 2014 10:16:42 -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=M2D64PkG6ODHMGumbl7rNb7tmSefLLxM8K1r+7Ks1Pv7WOqzZ8OvY4BiEtwZBP0FU2 8FezdhvRgP4KFXZ9Cer47K1657NkoHHxYl7mT+OhTgW58fiiNelJwWnaOJGCSnkGcB7R XEVoQMx9tIoSx2fOV0xpPZ67/09CPJJrTWWp+UQvTm9mXTre3lgH06FrIbDw9QyWtdBE uNxr0Frft6RIBw4TbK5OcUx0k9i3rrP6npDilQ0+Ff5ir6jzu8+GldmDrjoysyHaSkx6 Iow4zR9qAmEAzBjh5+7FKgPjuxKTlPndKvW8w4MMhMxfDAF9iIbrEAKETHd/19guI6EB 2Wqg== X-Gm-Message-State: ALoCoQn0w+Go7eQoBUJfGpPSIDsYtatbQNS1Q4dGSA1yd7rdGmc35ip8P8CNO1flkJpu92HVXiEj X-Received: by 10.58.32.131 with SMTP id j3mr13448568vei.13.1391451402486; Mon, 03 Feb 2014 10:16:42 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.81.16 with SMTP id e16ls2048275qgd.63.gmail; Mon, 03 Feb 2014 10:16:42 -0800 (PST) X-Received: by 10.52.100.135 with SMTP id ey7mr147928vdb.58.1391451402356; Mon, 03 Feb 2014 10:16:42 -0800 (PST) Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by mx.google.com with ESMTPS id b7si7029027vej.108.2014.02.03.10.16.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Feb 2014 10:16:42 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.176; Received: by mail-vc0-f176.google.com with SMTP id la4so4938717vcb.7 for ; Mon, 03 Feb 2014 10:16:42 -0800 (PST) X-Received: by 10.58.86.230 with SMTP id s6mr29334640vez.16.1391451402281; Mon, 03 Feb 2014 10:16:42 -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 u4csp174163vcz; Mon, 3 Feb 2014 10:16:41 -0800 (PST) X-Received: by 10.68.143.196 with SMTP id sg4mr4656131pbb.155.1391451401178; Mon, 03 Feb 2014 10:16:41 -0800 (PST) Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by mx.google.com with ESMTPS id r7si21457537pbk.267.2014.02.03.10.16.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Feb 2014 10:16:41 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.54 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.220.54; Received: by mail-pa0-f54.google.com with SMTP id fa1so7401288pad.13 for ; Mon, 03 Feb 2014 10:16:40 -0800 (PST) X-Received: by 10.66.191.42 with SMTP id gv10mr38617491pac.125.1391451400686; Mon, 03 Feb 2014 10:16:40 -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 y9sm150496099pas.10.2014.02.03.10.16.39 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Feb 2014 10:16:40 -0800 (PST) From: John Stultz To: LKML Cc: Prakash Kamliya , Colin Cross , Android Kernel Team , John Stultz Subject: [PATCH 06/16] staging: sync: Signal pt before sync_timeline object gets destroyed Date: Mon, 3 Feb 2014 10:16:18 -0800 Message-Id: <1391451388-23906-7-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1391451388-23906-1-git-send-email-john.stultz@linaro.org> References: <1391451388-23906-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.220.176 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);