From patchwork Mon Aug 15 11:09:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Pettersson X-Patchwork-Id: 110024 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 18E2EB6F77 for ; Mon, 15 Aug 2011 21:27:24 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751900Ab1HOL1L (ORCPT ); Mon, 15 Aug 2011 07:27:11 -0400 Received: from fanny.its.uu.se ([130.238.4.241]:10912 "EHLO fanny.its.uu.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751634Ab1HOL1K (ORCPT ); Mon, 15 Aug 2011 07:27:10 -0400 X-Greylist: delayed 1078 seconds by postgrey-1.27 at vger.kernel.org; Mon, 15 Aug 2011 07:27:10 EDT Received: from fanny.its.uu.se (localhost [127.0.0.1]) by fanny.its.uu.se (Postfix) with ESMTP id A311662DE; Mon, 15 Aug 2011 13:09:10 +0200 (MSZ) Received: from pilspetsen.it.uu.se (pilspetsen.it.uu.se [130.238.18.39]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by fanny.its.uu.se (Postfix) with ESMTP id 5099261F9; Mon, 15 Aug 2011 13:09:10 +0200 (MSZ) Received: (from mikpe@localhost) by pilspetsen.it.uu.se (8.14.4+Sun/8.14.4) id p7FB99ab020558; Mon, 15 Aug 2011 13:09:09 +0200 (MEST) X-Authentication-Warning: pilspetsen.it.uu.se: mikpe set sender to mikpe@it.uu.se using -f MIME-Version: 1.0 Message-ID: <20040.65109.439941.444670@pilspetsen.it.uu.se> Date: Mon, 15 Aug 2011 13:09:09 +0200 From: Mikael Pettersson To: sparclinux@vger.kernel.org Subject: [PATCH, SPARC] make sparc32 arch_write_unlock() match the sparc64 version Cc: linux-kernel@vger.kernel.org X-Mailer: VM 7.17 under Emacs 20.7.1 X-Virus-Scanned: ClamAV using ClamSMTP Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org The sparc32 version of arch_write_unlock() is just a plain assignment. Unfortunately this allows the compiler to schedule side-effects in a protected region to occur after the HW-level unlock, which is broken. E.g., the following trivial test case gets miscompiled: #include rwlock_t lock; int counter; void foo(void) { write_lock(&lock); ++counter; write_unlock(&lock); } Fixed by adding a compiler memory barrier to arch_write_unlock(). The sparc64 version combines the barrier and assignment into a single asm(), so that's what I did here as well. Compiled-tested with a sparc32 SMP kernel. Signed-off-by: Mikael Pettersson --- -- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- linux-3.1-rc2/arch/sparc/include/asm/spinlock_32.h.~1~ 2011-07-22 12:01:08.000000000 +0200 +++ linux-3.1-rc2/arch/sparc/include/asm/spinlock_32.h 2011-08-15 11:43:49.000000000 +0200 @@ -131,6 +131,15 @@ static inline void arch_write_lock(arch_ *(volatile __u32 *)&lp->lock = ~0U; } +static void inline arch_write_unlock(arch_rwlock_t *lock) +{ + __asm__ __volatile__( +" st %%g0, [%0]" + : /* no outputs */ + : "r" (lock) + : "memory"); +} + static inline int arch_write_trylock(arch_rwlock_t *rw) { unsigned int val; @@ -175,7 +184,7 @@ static inline int __arch_read_trylock(ar res; \ }) -#define arch_write_unlock(rw) do { (rw)->lock = 0; } while(0) +#define arch_write_unlock(rw) arch_write_unlock(rw) #define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock) #define arch_read_lock_flags(rw, flags) arch_read_lock(rw)