From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752137AbbJOIYb (ORCPT ); Thu, 15 Oct 2015 04:24:31 -0400 Received: from pandora.arm.linux.org.uk ([78.32.30.218]:37126 "EHLO pandora.arm.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751452AbbJOIY1 (ORCPT ); Thu, 15 Oct 2015 04:24:27 -0400 Date: Thu, 15 Oct 2015 09:24:17 +0100 From: Russell King - ARM Linux To: Shengjiu Wang Cc: nico@linaro.org, ard.biesheuvel@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ARM: SWP emulation: Restore original *data when failed Message-ID: <20151015082417.GX32532@n2100.arm.linux.org.uk> References: <1444791077-26020-1-git-send-email-shengjiu.wang@freescale.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1444791077-26020-1-git-send-email-shengjiu.wang@freescale.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 14, 2015 at 10:51:17AM +0800, Shengjiu Wang wrote: > __user_swpX_asm maybe failed in first STREX operation, emulate_swpX > will try again, but the *data has been changed in first time. which > cause the result is wrong. So need to recover the *data when failed. > > Signed-off-by: Shengjiu Wang > --- > arch/arm/kernel/swp_emulate.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/arm/kernel/swp_emulate.c b/arch/arm/kernel/swp_emulate.c > index 5b26e7e..c61fbf92 100644 > --- a/arch/arm/kernel/swp_emulate.c > +++ b/arch/arm/kernel/swp_emulate.c > @@ -41,6 +41,7 @@ > "1: strex"B" %0, %2, [%3]\n" \ > " cmp %0, #0\n" \ > " movne %0, %4\n" \ > + " movne %1, %2\n" \ > "2:\n" \ > " .section .text.fixup,\"ax\"\n" \ > " .align 2\n" \ I think I'd prefer this to be: __asm__ __volatile__( \ "0: ldrex"B" %2, [%3]\n" \ "1: strex"B" %0, %1, [%3]\n" \ " cmp %0, #0\n" \ " moveq %1, %2\n" \ " movne %0, %4\n" \ so that we're not loading into %1 (an in-out non-temporary) but rather loading it into a temporary - and only overwriting the saved register value if the swap succeeds. Thanks. -- FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.