From patchwork Fri Mar 1 00:43:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 15178 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 A79AA23E1A for ; Fri, 1 Mar 2013 00:44:16 +0000 (UTC) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by fiordland.canonical.com (Postfix) with ESMTP id 57F4FA1935F for ; Fri, 1 Mar 2013 00:44:16 +0000 (UTC) Received: by mail-ve0-f171.google.com with SMTP id b10so2424879vea.2 for ; Thu, 28 Feb 2013 16:44:15 -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:x-gm-message-state; bh=AKJpewKqRlXsluGeUDvHREnV+P6+3utlU22lbADNYI4=; b=V/dXzy1AeTc4tJ+fPUuDDiQ7L+zKiuebyk8VXEaeHtO2BGEyoYjS95dinHYGKjA/v1 3EaiSXak6PUY3lGt4dmdB/zUwtKRKWp67glCjerCOomGO//dgngNg5p/ewTgqeZyEsx7 +/uu9QDLRZVuSZs5icnL5JqgkM2AnB868kKImhvc6hgTZygrdgmRUz6zt6asqplDb+So /5hfGVMji6iGvS7uXOQjaV66Foj3QtP0y6K1I4GJVmwAx1uso3MQDETvmwpN1/XVHdQY lP4aPAYuT9HCMDsqLoiXtLGeKqMlHUVY646t2EuDTLXJNbYafdVgTE7c0pYQnVudnYZe KZWw== X-Received: by 10.52.177.163 with SMTP id cr3mr2914473vdc.94.1362098655904; Thu, 28 Feb 2013 16:44:15 -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 st5csp666veb; Thu, 28 Feb 2013 16:44:15 -0800 (PST) X-Received: by 10.67.5.193 with SMTP id co1mr16133090pad.6.1362098654999; Thu, 28 Feb 2013 16:44:14 -0800 (PST) Received: from mail-pb0-f45.google.com (mail-pb0-f45.google.com [209.85.160.45]) by mx.google.com with ESMTPS id tm6si10280180pbc.145.2013.02.28.16.44.14 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Feb 2013 16:44:14 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.45 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.160.45; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.45 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-pb0-f45.google.com with SMTP id ro8so1387804pbb.32 for ; Thu, 28 Feb 2013 16:44:14 -0800 (PST) X-Received: by 10.68.129.135 with SMTP id nw7mr11900341pbb.58.1362098654634; Thu, 28 Feb 2013 16:44:14 -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.13 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 28 Feb 2013 16:44:13 -0800 (PST) From: John Stultz To: lkml Cc: Erik Gilling , Maarten Lankhorst , Daniel Vetter , Rob Clark , Sumit Semwal , Greg KH , dri-devel@lists.freedesktop.org, Android Kernel Team , John Stultz Subject: [PATCH 22/30] staging: sync: Protect unlocked access to fence status Date: Thu, 28 Feb 2013 16:43:18 -0800 Message-Id: <1362098606-26469-23-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> X-Gm-Message-State: ALoCoQlOnvlI5kvvN+9EdOx1xEffmAoMq0mbnUr4q2ZpIlleapXwQzMFiQw74u+H47ltghOd7ux7 From: Erik Gilling Fence status is checked outside of locks in both sync_fence_wait and sync_fence_poll. This patch adds propper barrier protection in these cases to avoid seeing stale status. 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 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 36ffa20..2394189 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -556,6 +556,16 @@ int sync_fence_cancel_async(struct sync_fence *fence, } EXPORT_SYMBOL(sync_fence_cancel_async); +static bool sync_fence_check(struct sync_fence *fence) +{ + /* + * Make sure that reads to fence->status are ordered with the + * wait queue event triggering + */ + smp_rmb(); + return fence->status != 0; +} + int sync_fence_wait(struct sync_fence *fence, long timeout) { int err = 0; @@ -563,7 +573,7 @@ int sync_fence_wait(struct sync_fence *fence, long timeout) if (timeout > 0) { timeout = msecs_to_jiffies(timeout); err = wait_event_interruptible_timeout(fence->wq, - fence->status != 0, + sync_fence_check(fence), timeout); } else if (timeout < 0) { err = wait_event_interruptible(fence->wq, fence->status != 0); @@ -630,6 +640,12 @@ static unsigned int sync_fence_poll(struct file *file, poll_table *wait) poll_wait(file, &fence->wq, wait); + /* + * Make sure that reads to fence->status are ordered with the + * wait queue event triggering + */ + smp_rmb(); + if (fence->status == 1) return POLLIN; else if (fence->status < 0)