From patchwork Fri Oct 16 10:37:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 55090 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lf0-f69.google.com (mail-lf0-f69.google.com [209.85.215.69]) by patches.linaro.org (Postfix) with ESMTPS id 6024822FFA for ; Fri, 16 Oct 2015 10:37:41 +0000 (UTC) Received: by lffy185 with SMTP id y185sf16303424lff.2 for ; Fri, 16 Oct 2015 03:37:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=YC8qEXHMy2GNdv1PwWg5jjsJZPeKfo1pZIFI9QzYFO8=; b=fzVt9Xe2smLRDbfukWDC39mpUAD0k0qWTOd0EP1xBm2eCWt+7PyT73MUEKxBKuZzsD yEARDljH6rQx6jQcVv9NqVFG5Uzu8qC2zil7jrst+q+Kt13rOF6iSkq/VmYDKDIM+20h 5Ejs1cMApPKDadG+sqHPM0jC8cm2QH1hA51a1VI4nJpAe5nx7FATtKKac+aD1bHaBHAT bVPH4n8K4v+ZEVOARL82CZwmr+Ky9uMsgKbmboRCO1DIxn6V6sVuiyn6tbPY4l54kmOW dqVB2wQ6NYfBIztnFlhVzk5Mw8ZerqMyZ86c5zb3yUyrQKoIKBRem+/4NmXpAdt629Me MJmQ== X-Gm-Message-State: ALoCoQmmrNgZBTjLqCuqDlDfqhvjdMxpP6SAlHF43dOKsBbOrvEiZ2e2x7hrdwk3+/+i31XnFAKA X-Received: by 10.194.71.107 with SMTP id t11mr105330wju.6.1444991860295; Fri, 16 Oct 2015 03:37:40 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.43.135 with SMTP id r129ls315737lfr.93.gmail; Fri, 16 Oct 2015 03:37:40 -0700 (PDT) X-Received: by 10.25.159.79 with SMTP id i76mr5241613lfe.0.1444991860096; Fri, 16 Oct 2015 03:37:40 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id ue7si12458404lbb.33.2015.10.16.03.37.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Oct 2015 03:37:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbbes7 with SMTP id es7so7662532lbb.2 for ; Fri, 16 Oct 2015 03:37:40 -0700 (PDT) X-Received: by 10.112.161.168 with SMTP id xt8mr6865559lbb.88.1444991859885; Fri, 16 Oct 2015 03:37:39 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1182447lbq; Fri, 16 Oct 2015 03:37:38 -0700 (PDT) X-Received: by 10.68.253.42 with SMTP id zx10mr12793895pbc.99.1444991858545; Fri, 16 Oct 2015 03:37:38 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id kh6si28797023pad.102.2015.10.16.03.37.38; Fri, 16 Oct 2015 03:37:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753998AbbJPKhf (ORCPT + 30 others); Fri, 16 Oct 2015 06:37:35 -0400 Received: from foss.arm.com ([217.140.101.70]:40602 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751968AbbJPKhe (ORCPT ); Fri, 16 Oct 2015 06:37:34 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BAB6B3C; Fri, 16 Oct 2015 03:37:30 -0700 (PDT) Received: from e104818-lin.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 62A6D3F49B; Fri, 16 Oct 2015 03:37:32 -0700 (PDT) Date: Fri, 16 Oct 2015 11:37:29 +0100 From: Catalin Marinas To: Vladimir Murzin Cc: Will Deacon , Shengjiu Wang , Russell King - ARM Linux , "ard.biesheuvel@linaro.org" , Punit Agrawal , "linux-kernel@vger.kernel.org" , "nico@linaro.org" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [PATCH] ARM: SWP emulation: Restore original *data when failed Message-ID: <20151016103729.GA6613@e104818-lin.cambridge.arm.com> References: <1444791077-26020-1-git-send-email-shengjiu.wang@freescale.com> <20151015082417.GX32532@n2100.arm.linux.org.uk> <20151015083629.GA32630@shlinux2> <20151015085700.GY32532@n2100.arm.linux.org.uk> <561F6F3B.6030607@arm.com> <20151015130247.GB29301@arm.com> <561FA948.5080505@arm.com> <5620ACB8.20908@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5620ACB8.20908@arm.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: catalin.marinas@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On Fri, Oct 16, 2015 at 08:52:24AM +0100, Vladimir Murzin wrote: > > On 15/10/15 14:02, Will Deacon wrote: > >> diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c > >> index bcee7abac68e..6039d1eb5912 100644 > >> --- a/arch/arm64/kernel/armv8_deprecated.c > >> +++ b/arch/arm64/kernel/armv8_deprecated.c > >> @@ -284,12 +284,12 @@ static void register_insn_emulation_sysctl(struct ctl_table *table) > >> __asm__ __volatile__( \ > >> ALTERNATIVE("nop", SET_PSTATE_PAN(0), ARM64_HAS_PAN, \ > >> CONFIG_ARM64_PAN) \ > >> - " mov %w2, %w1\n" \ > >> - "0: ldxr"B" %w1, [%3]\n" \ > >> - "1: stxr"B" %w0, %w2, [%3]\n" \ > >> + "0: ldxr"B" %w2, [%3]\n" \ > >> + "1: stxr"B" %w0, %w1, [%3]\n" \ > >> " cbz %w0, 2f\n" \ > >> " mov %w0, %w4\n" \ > >> "2:\n" \ > >> + " mov %w1, %w2\n" \ > >> " .pushsection .fixup,\"ax\"\n" \ > >> " .align 2\n" \ > >> "3: mov %w0, %w5\n" \ > > On the second thought looks like we still update *data in case stxr > fails (or I need more coffee). I'm on the second cup and I see the same problem. Even if stxr fails, we fall back through "mov %w1, %w2", so *data is always updated with the loaded value. Maybe something like below on top of Will's patch: Since Will is away for a week, I'll wait until he's back to push this patch. diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c index 6039d1eb5912..3fab37b3bc95 100644 --- a/arch/arm64/kernel/armv8_deprecated.c +++ b/arch/arm64/kernel/armv8_deprecated.c @@ -286,10 +286,10 @@ static void register_insn_emulation_sysctl(struct ctl_table *table) CONFIG_ARM64_PAN) \ "0: ldxr"B" %w2, [%3]\n" \ "1: stxr"B" %w0, %w1, [%3]\n" \ - " cbz %w0, 2f\n" \ - " mov %w0, %w4\n" \ + " cmp %w0, #0\n" \ + " csel %w0, %w4, wzr, ne\n" \ + " csel %w1, %w2, %w1, eq\n" \ "2:\n" \ - " mov %w1, %w2\n" \ " .pushsection .fixup,\"ax\"\n" \ " .align 2\n" \ "3: mov %w0, %w5\n" \ @@ -303,7 +303,7 @@ static void register_insn_emulation_sysctl(struct ctl_table *table) ALTERNATIVE("nop", SET_PSTATE_PAN(1), ARM64_HAS_PAN, \ CONFIG_ARM64_PAN) \ : "=&r" (res), "+r" (data), "=&r" (temp) \ - : "r" (addr), "i" (-EAGAIN), "i" (-EFAULT) \ + : "r" (addr), "r" (-EAGAIN), "i" (-EFAULT) \ : "memory") #define __user_swp_asm(data, addr, res, temp) \ @@ -342,7 +342,7 @@ static void set_segfault(struct pt_regs *regs, unsigned long addr) static int emulate_swpX(unsigned int address, unsigned int *data, unsigned int type) { - unsigned int res = 0; + unsigned int res; if ((type != TYPE_SWPB) && (address & 0x3)) { /* SWP to unaligned address not permitted */