From patchwork Fri Oct 17 16:38:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 38896 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D1505202DB for ; Fri, 17 Oct 2014 16:39:05 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id gi9sf681444lab.6 for ; Fri, 17 Oct 2014 09:39:04 -0700 (PDT) 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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=p2G2n6a3xq3IcuSabKSke7Ek9MRw/YAG4cQgafcmq18=; b=Xv+00PXkRYrwEyQVdxixZsOweJDvuC/r95asNNgG5axb6r5uA12PMnV/ZssJwJkPk+ JaooZ2eaBwMNUPnFtwLJX/NhzLhQfe8N31X4LjzwbWVBx7uqA2jQSy0L49ApwNck1SQj AiKe/Foe7T4Sj7dvAjuP8bMKa+MsAt4Kho7dfzED4qgZKxM8YKPKus+BYu90BVJ0Y5/I 6Sm+StavqIxpaqMRBPRLNe94KAIGQUF9Y6vFTOu7fpCeF2Iqd8FHgGtghVqFRomE9an0 HnLR50uLyUegHJ1pjoMcrzblrdkWZF+pqt3eStOWyeBq6N8g3yB2jsTcnKeyoZWVSMOD RQuA== X-Gm-Message-State: ALoCoQmxEAL2Ntw+ggGw299zhhpIDfvUU3zsQmKDpzHGygWpI4fvoIt1xGYfeco5SfUD6tgRZkrT X-Received: by 10.180.90.115 with SMTP id bv19mr22115wib.1.1413563944399; Fri, 17 Oct 2014 09:39:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.45.101 with SMTP id l5ls253699lam.103.gmail; Fri, 17 Oct 2014 09:39:04 -0700 (PDT) X-Received: by 10.152.243.39 with SMTP id wv7mr9844350lac.48.1413563943967; Fri, 17 Oct 2014 09:39:03 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id lm5si2822522lac.87.2014.10.17.09.39.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Oct 2014 09:39:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id l4so993672lbv.12 for ; Fri, 17 Oct 2014 09:39:03 -0700 (PDT) X-Received: by 10.152.29.8 with SMTP id f8mr10059233lah.56.1413563943709; Fri, 17 Oct 2014 09:39:03 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp261015lbz; Fri, 17 Oct 2014 09:39:03 -0700 (PDT) X-Received: by 10.66.97.39 with SMTP id dx7mr9659911pab.65.1413563942238; Fri, 17 Oct 2014 09:39:02 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fk4si1468712pbb.236.2014.10.17.09.39.01 for ; Fri, 17 Oct 2014 09:39:02 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753388AbaJQQi6 (ORCPT + 27 others); Fri, 17 Oct 2014 12:38:58 -0400 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:45520 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752822AbaJQQi5 (ORCPT ); Fri, 17 Oct 2014 12:38:57 -0400 Received: from foss-smtp-na-1.foss.arm.com (unknown [10.80.61.8]) by foss-mx-na.foss.arm.com (Postfix) with ESMTP id 416ECAF; Fri, 17 Oct 2014 11:38:53 -0500 (CDT) Received: from collaborate-mta1.arm.com (highbank-bc01-b06.austin.arm.com [10.112.81.134]) by foss-smtp-na-1.foss.arm.com (Postfix) with ESMTP id 295695FAD7; Fri, 17 Oct 2014 11:38:52 -0500 (CDT) Received: from e104818-lin.cambridge.arm.com (e104818-lin.cambridge.arm.com [10.1.203.148]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 88C2A13F899; Fri, 17 Oct 2014 11:38:50 -0500 (CDT) From: Catalin Marinas To: linux-kernel@vger.kernel.org Cc: Matteo Franchin , Davidlohr Bueso , Linus Torvalds , Darren Hart , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , "Paul E. McKenney" Subject: [PATCH] futex: Ensure get_futex_key_refs() always implies a barrier Date: Fri, 17 Oct 2014 17:38:49 +0100 Message-Id: <1413563929-2664-1-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 2.1.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: catalin.marinas@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Commit b0c29f79ecea (futexes: Avoid taking the hb->lock if there's nothing to wake up) changes the futex code to avoid taking a lock when there are no waiters. This code has been subsequently fixed in commit 11d4616bd07f (futex: revert back to the explicit waiter counting code). Both the original commit and the fix-up rely on get_futex_key_refs() to always imply a barrier. However, for private futexes, none of the cases in the switch statement of get_futex_key_refs() would be hit and the function completes without a memory barrier as required before checking the "waiters" in futex_wake() -> hb_waiters_pending(). The consequence is a race with a thread waiting on a futex on another CPU, allowing the waker thread to read "waiters == 0" while the waiter thread to have read "futex_val == locked" (in kernel). Without this fix, the problem (user space deadlocks) can be seen with Android bionic's mutex implementation on an arm64 multi-cluster system. Signed-off-by: Catalin Marinas Reported-by: Matteo Franchin Fixes: b0c29f79ecea (futexes: Avoid taking the hb->lock if there's nothing to wake up) Cc: Cc: Davidlohr Bueso Cc: Linus Torvalds Cc: Darren Hart Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Paul E. McKenney Acked-by: Davidlohr Bueso Acked-by: Catalin Marinas --- kernel/futex.c | 2 ++ 1 file changed, 2 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/kernel/futex.c b/kernel/futex.c index 815d7af2ffe8..f3a3a071283c 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -343,6 +343,8 @@ static void get_futex_key_refs(union futex_key *key) case FUT_OFF_MMSHARED: futex_get_mm(key); /* implies MB (B) */ break; + default: + smp_mb(); /* explicit MB (B) */ } }