From patchwork Mon Jun 24 15:13:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 2771891 Return-Path: X-Original-To: patchwork-linux-arm@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 A77EBC0AB1 for ; Mon, 24 Jun 2013 15:14:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 789942027D for ; Mon, 24 Jun 2013 15:14:12 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2B8752027B for ; Mon, 24 Jun 2013 15:14:11 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ur8T0-0004MK-K3; Mon, 24 Jun 2013 15:14:06 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ur8Sx-0004Yx-TK; Mon, 24 Jun 2013 15:14:03 +0000 Received: from mail-vb0-x236.google.com ([2607:f8b0:400c:c02::236]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ur8Su-0004YO-L4 for linux-arm-kernel@lists.infradead.org; Mon, 24 Jun 2013 15:14:01 +0000 Received: by mail-vb0-f54.google.com with SMTP id q12so8149356vbe.41 for ; Mon, 24 Jun 2013 08:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=JNKxEzd9HnytP/q+fglgpONAylat5OP/Sv0rnZWTcSQ=; b=E+ydH8AOaKw5ZXYautLI3J0gJxZCSDNJwaaPEBmPCd5s0WuDrmn+wAFnbOJofAEWIY gYngHx3P8NHIOhKlH3ELNFHDs1K/vnRY0d4uLMdub9p6pwc+BmWpyZS55xlmPE631+9C 6wVKzxz7oF9FvOgre/IgrtnDzyuLYALHCL7qrYM3D1VI9/8pTA2dgLEBKsWPxl+xuYzt myaUl+oEfs5p1CuZAJIaRHedXJlxas2W5gpJ/azQ9xwJodlsBjrG5txKfCtmak0HrAfE 3TRummXk4SeQ6xLzTB+cWjwUdYh5e8xrDxmETfmkVnxQ8Ew2PapD91RjSGGTcZ9Zeu5x YOdg== MIME-Version: 1.0 X-Received: by 10.58.90.5 with SMTP id bs5mr11921398veb.60.1372086818324; Mon, 24 Jun 2013 08:13:38 -0700 (PDT) Received: by 10.220.223.202 with HTTP; Mon, 24 Jun 2013 08:13:38 -0700 (PDT) Date: Mon, 24 Jun 2013 23:13:38 +0800 Message-ID: Subject: [Question] race between spin_lock and spin_unlock From: Ming Lei To: Will Deacon X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130624_111400_781211_08189BAE X-CRM114-Status: UNSURE ( 8.76 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.0 (--) Cc: Nicolas Pitre , Russell King , linux-arm-kernel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Hi, When reading the code of arch_spin_lock(), I think there might be a race between arch_spin_lock() and arch_spin_unlock(): - arch_spin_unlock() happened just between StoreExcl(lock->next) and comparing lockval.tickets.next with lockval.tickets.owner inside arch_spin_lock() - arch_spin_lock() can't notice the change on lock->owner, so call wfe(), then just waiting for being waken up, but there isn't corresponding unlock to send wake event any more. Maybe the below change may make the race to happen difficultly, but it still can't avoid it completely. Any comments on the problem? Thanks, diff --git a/arch/arm/include/asm/spinlock.h b/arch/arm/include/asm/spinlock.h index 6220e9f..e1b239c 100644 --- a/arch/arm/include/asm/spinlock.h +++ b/arch/arm/include/asm/spinlock.h @@ -87,10 +87,8 @@ static inline void arch_spin_lock(arch_spinlock_t *lock) : "r" (&lock->slock), "I" (1 << TICKET_SHIFT) : "cc"); - while (lockval.tickets.next != lockval.tickets.owner) { + while (lockval.tickets.next != ACCESS_ONCE(lock->tickets.owner)) wfe(); - lockval.tickets.owner = ACCESS_ONCE(lock->tickets.owner); - } smp_mb(); }