From patchwork Tue Jan 15 16:48:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot for Dave Martin X-Patchwork-Id: 1979631 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 1D7493FE1F for ; Tue, 15 Jan 2013 16:52:25 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tv9hG-0004sy-QI; Tue, 15 Jan 2013 16:49:10 +0000 Received: from mail-bk0-f41.google.com ([209.85.214.41]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Tv9gp-0004o4-EH for linux-arm-kernel@lists.infradead.org; Tue, 15 Jan 2013 16:48:44 +0000 Received: by mail-bk0-f41.google.com with SMTP id jg9so201282bkc.14 for ; Tue, 15 Jan 2013 08:48:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=DIUPm/+ydp6nWaVbENU67BKX/o4tp/EBSh4ZWEFFeGE=; b=HZgY8dGLdRW67LbdNJNN+chQA1k1tsKnu0lMAH9p667l+Pv6AIX8UiWq1X1NXL3PLj Xs2z6f9muI6njUTY9qUBuYNOI61b+VCoZTER2jG3zrNNLg8RnltSXynfeH2k32g/+9py U/ZwpJbL6IDbQW0Eh20cPg1hfIOcem1oIyoiWg5RX9isYKB53Sj0unLxBOCBthJbMS31 9Z9AMfWz6FA41fs7/q7xRaV7nRg3lHBS/3PuMhOSr05IpCdxd19PGvO1swhci5hNTIsw QQ8jESth9NEa3wOAx5KDR7zEqF7tbfJi6cx3v9bN4WdvJp7CDM3JF9PBVOkJnr3hwbWA ryew== X-Received: by 10.204.12.220 with SMTP id y28mr42424538bky.112.1358268522090; Tue, 15 Jan 2013 08:48:42 -0800 (PST) Received: from e103592.peterhouse.linaro.org (fw-lnat.cambridge.arm.com. [217.140.96.63]) by mx.google.com with ESMTPS id 18sm13338796bkv.0.2013.01.15.08.48.40 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 15 Jan 2013 08:48:41 -0800 (PST) From: Dave Martin To: Nicolas Pitre Subject: [RFC PATCH 2/4] ARM: b.L: vlocks: Add architecturally required memory barriers Date: Tue, 15 Jan 2013 16:48:16 +0000 Message-Id: <1358268498-8086-3-git-send-email-dave.martin@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1358268498-8086-1-git-send-email-dave.martin@linaro.org> References: <1358268498-8086-1-git-send-email-dave.martin@linaro.org> X-Gm-Message-State: ALoCoQmquijdl/wOFRKcPNERKO8cY1a/wYEHH2dKJGFwVtlHfJQbqOUISwT/SR7lSGtOBm7QdEx0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130115_114843_629890_59793BFF X-CRM114-Status: GOOD ( 15.87 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.214.41 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Achin Gupta , Will Deacon , Dave Martin , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org For architectural correctness even Strongly-Ordered memory accesses require barriers in order to guarantee that multiple CPUs have a coherent view of the ordering of memory accesses. Whether or not this matters depends on hardware implementation details of the memory system. Since the purpose of this code is to provide a clean, generic locking mechanism with no platform-specific dependencies the barriers should be present to avoid unpleasant surprises on future platforms. This patch adds the required barriers. Note: * When taking the lock, we don't care about implicit background memory operations and other signalling which may be pending, because those are not part of the critical section anyway. A DMB is sufficient to ensure correctly observed ordering if the explicit memory accesses in vlock_trylock. * No barrier is required after checking the election result, because the result is determined by the store st VLOCK_OWNER_OFFSET and is already globally observed due to the barriers in voting_end. This means that global agreement on the winner is guaranteed, even before the winner is known locally. * The magic to guarantee correct barrierless access to the vlocks by aligning them in memory now makes no sense and is removed. However, we must still ensure that these don't share a cacheline with anything else. Signed-off-by: Dave Martin --- arch/arm/common/bL_head.S | 19 ------------------- arch/arm/common/vlock.S | 7 +++++-- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/arch/arm/common/bL_head.S b/arch/arm/common/bL_head.S index 314d4ae..fd71ff6 100644 --- a/arch/arm/common/bL_head.S +++ b/arch/arm/common/bL_head.S @@ -187,26 +187,7 @@ ENDPROC(bL_entry_point) .bss - @ Magic to size and align the first-man vlock structures - @ so that each does not cross a 1KB boundary. - @ We also must ensure that none of these shares a cacheline with - @ any data which might be accessed through the cache. - - .equ .Log2, 0 - .rept 11 - .if (1 << .Log2) < VLOCK_SIZE - .equ .Log2, .Log2 + 1 - .endif - .endr - .if .Log2 > 10 - .error "vlock struct is too large for guaranteed barrierless access ordering" - .endif - .equ .Lvlock_size, 1 << .Log2 - - @ The presence of two .align directives here is deliberate: we must - @ align to whichever of the two boundaries is larger: .align __CACHE_WRITEBACK_ORDER - .align .Log2 first_man_locks: .rept BL_NR_CLUSTERS .space .Lvlock_size diff --git a/arch/arm/common/vlock.S b/arch/arm/common/vlock.S index 0a1ee3a..f55744f 100644 --- a/arch/arm/common/vlock.S +++ b/arch/arm/common/vlock.S @@ -39,10 +39,11 @@ .macro voting_begin rbase:req, rcpu:req, rscratch:req mov \rscratch, #1 strb \rscratch, [\rbase, \rcpu] - dsb + dmb .endm .macro voting_end rbase:req, rcpu:req, rscratch:req + dmb mov \rscratch, #0 strb \rscratch, [\rbase, \rcpu] dsb @@ -68,6 +69,7 @@ ENTRY(vlock_trylock) cmp r2, #VLOCK_OWNER_NONE bne trylock_fail @ fail if so + dmb strb r1, [r0, #VLOCK_OWNER_OFFSET] @ submit my vote voting_end r0, r1, r2 @@ -87,6 +89,7 @@ ENTRY(vlock_trylock) @ Check who won: + dmb ldrb r2, [r0, #VLOCK_OWNER_OFFSET] eor r0, r1, r2 @ zero if I won, else nonzero bx lr @@ -99,8 +102,8 @@ ENDPROC(vlock_trylock) @ r0: lock structure base ENTRY(vlock_unlock) + dmb mov r1, #VLOCK_OWNER_NONE - dsb strb r1, [r0, #VLOCK_OWNER_OFFSET] dsb sev