From patchwork Mon Jun 2 16:50:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Low X-Patchwork-Id: 4283261 Return-Path: X-Original-To: patchwork-linux-parisc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 325C3BEEA7 for ; Mon, 2 Jun 2014 16:50:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 63A9E20253 for ; Mon, 2 Jun 2014 16:50:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8CF3C2024D for ; Mon, 2 Jun 2014 16:50:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753868AbaFBQuo (ORCPT ); Mon, 2 Jun 2014 12:50:44 -0400 Received: from g2t1383g.austin.hp.com ([15.217.136.92]:13146 "EHLO g2t1383g.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755896AbaFBQu3 (ORCPT ); Mon, 2 Jun 2014 12:50:29 -0400 Received: from g6t1526.atlanta.hp.com (g6t1526.atlanta.hp.com [15.193.200.69]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by g2t1383g.austin.hp.com (Postfix) with ESMTPS id 5D50C18B6 for ; Mon, 2 Jun 2014 16:31:11 +0000 (UTC) Received: from g5t1633.atlanta.hp.com (g5t1633.atlanta.hp.com [16.201.144.132]) by g6t1526.atlanta.hp.com (Postfix) with ESMTP id 61B00CC; Mon, 2 Jun 2014 16:50:16 +0000 (UTC) Received: from [10.0.2.15] (lowjas2.americas.hpqcorp.net [16.212.74.111]) by g5t1633.atlanta.hp.com (Postfix) with ESMTP id 5703460; Mon, 2 Jun 2014 16:50:11 +0000 (UTC) Message-ID: <1401727810.7440.34.camel@j-VirtualBox> Subject: Re: [PATCH v2] introduce atomic_pointer to fix a race condition in cancelable mcs spinlocks From: Jason Low To: Mikulas Patocka Cc: Linus Torvalds , Peter Zijlstra , jejb@parisc-linux.org, deller@gmx.de, John David Anglin , linux-parisc@vger.kernel.org, linux-kernel@vger.kernel.org, paulmck@linux.vnet.ibm.com, chegu_vinod@hp.com, Waiman.Long@hp.com, tglx@linutronix.de, riel@redhat.com, akpm@linux-foundation.org, davidlohr@hp.com, hpa@zytor.com, andi@firstfloor.org, aswin@hp.com, scott.norton@hp.com Date: Mon, 02 Jun 2014 09:50:10 -0700 In-Reply-To: References: X-Mailer: Evolution 3.2.3-0ubuntu6 Mime-Version: 1.0 Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, 2014-06-02 at 12:00 -0400, Mikulas Patocka wrote: > If you write to some variable with ACCESS_ONCE and use cmpxchg or xchg at > the same time, you break it. ACCESS_ONCE doesn't take the hashed spinlock, > so, in this case, cmpxchg or xchg isn't really atomic at all. So if the problem is using ACCESS_ONCE writes with cmpxchg and xchg at the same time, would the below change address this problem? ----- --- To unsubscribe from this list: send the line "unsubscribe linux-parisc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c index 838dc9e..8396721 100644 --- a/kernel/locking/mcs_spinlock.c +++ b/kernel/locking/mcs_spinlock.c @@ -71,7 +71,7 @@ bool osq_lock(struct optimistic_spin_queue **lock) if (likely(prev == NULL)) return true; - ACCESS_ONCE(prev->next) = node; + xchg(&prev->next, node); /* * Normally @prev is untouchable after the above store; because at that @@ -144,7 +144,7 @@ unqueue: */ ACCESS_ONCE(next->prev) = prev; - ACCESS_ONCE(prev->next) = next; + xchg(&prev->next, next); return false; }