Received: by 10.223.164.221 with SMTP id h29csp607504wrb; Wed, 11 Oct 2017 06:13:36 -0700 (PDT) X-Received: by 10.84.224.195 with SMTP id k3mr15260053pln.403.1507727616572; Wed, 11 Oct 2017 06:13:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507727616; cv=none; d=google.com; s=arc-20160816; b=hM9yzJ50NWRW86gtvWyVBQXIgUsbei350KetfEKrSMaI6HqNqSZwq+30QEvrEWS2ah Hp/IbKCWegXUmpiuXquGWugbshh8yELh3hTs2njyVklCx6Eq2cPfDRbBEpGpVdoCvQwO VEnCl+BtCqY7Dc7SyrQhk4zHAssipWfQpFa/MA0Wkw+b5vXIJ1+F1BAc3IirAEYeD69U faLjLFIkp0JWwW8qEt92lyOTJkSMwr57g7eI6fU+vqNDa6jKQrfVdHWRaurLK2NTeJIG WeiV7TTlEwM8ud7pzqxF5BLFLQr67ihyYCzl/iyl6/GoGZtFbDTUeqJYlZwR7YoUFDun o5vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=bS6xHxg8G3EOzH270zeitjI6DK0+HySrXFS5i4cdEzE=; b=cBJkJMlsoqxnmw0SkvA64tR+RWct1VDJyXX0P1jGLKcQ44B/Aop88oiMkFlJbeQCYf Q9BgrP4yA5lGsojlpiBmW3FeRhiRb3C22xQiYwgI6Wx7v46hIBn4nOvHgvPT3cLLnqbL +3QlWmS1QLN3YxUnF5oM55Bu1eOCOSty2mFh7a7L8LQBQkmFUkaz8eHDR5/wGZpR2zlo XoGKjLPLkAXvZxRNUM5CKHwldRBVdaPTPqPbAjw5rSM/4HKrZ05M7zRiz0jvhvYCfmys gOR0EovREBN9ItU0hEaSBzjcqqCrMFT2PpNIEI5m+7XevSQsnyni1v9XXXnZyVQoKjy9 rgMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mvista-com.20150623.gappssmtp.com header.s=20150623 header.b=Ln7dMaQH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f73si10925479pfj.125.2017.10.11.06.13.22; Wed, 11 Oct 2017 06:13:36 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@mvista-com.20150623.gappssmtp.com header.s=20150623 header.b=Ln7dMaQH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757393AbdJKNMg (ORCPT + 99 others); Wed, 11 Oct 2017 09:12:36 -0400 Received: from mail-pg0-f43.google.com ([74.125.83.43]:54119 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752066AbdJKNMe (ORCPT ); Wed, 11 Oct 2017 09:12:34 -0400 Received: by mail-pg0-f43.google.com with SMTP id s2so963949pge.10 for ; Wed, 11 Oct 2017 06:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mvista-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=bS6xHxg8G3EOzH270zeitjI6DK0+HySrXFS5i4cdEzE=; b=Ln7dMaQHTqHKhDv1QVMN3CdElNeLMxWlb3qBjkjBDz9V7YfZy6UCW8xAJuxH8IVWKw XhCBQ1eVD7Pbl4wRNpHcKQ/nt29qL22/bXNrJiPD1Bz/85SRc60Oeoq1RDAljzK8S1Af CXOeoosEAkbkZm2DZavTalf3E4vHYk+zcRoAm4q5frHqs0qBDkQ6ZCMCf9v5so0JuybW /gbmlXvY7rk29lOxnmXAk+SxX5jKcZgfyVnNHht7MFoIB42X7WkANof0RhwE2P3Bfhx9 /bPhp92IsFyuM7GrZy3EfmB0P6bDI6SZQdyJmtZiev4nwVkzPek9RQCy7XZi6nHtOuRe rmeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=bS6xHxg8G3EOzH270zeitjI6DK0+HySrXFS5i4cdEzE=; b=kmoF1aO14A0UO/KhP4XUUjCmDlG8W+hOc5v/ab1dv+KGhCKBWke34n8ry48Sp8qEk3 2s9fIvnAvVbk4d1j4GopNX2d/9hlozJO16bZyt0cwHrGfN/EImPtcH0PG+31ghJOldlr jwPJkjEW0E0mmBRzQOU2MU3u/OmrYd/eXcMajb9KTWN4YwXqqLJu8vzPm8G1CCtR7BYe yHQHuJKLEYVnDU3jVE1cR8/BGgYck/2OL4SLEamq+bDGzCx8qW9b3/rX+8bnwU4qFi47 Th8kDXRaAi89zNS/ZkpD5gBtPhBPrPW0ZmgJkhet4hV+/du6nlvkzFpxGVKpW7OH3O6i hWxQ== X-Gm-Message-State: AMCzsaVKyp02xBCqjE/q2GyhDQMEGahr5i4kVoO4pTFni0hTeiPfr6xe Hdh+uh2TapxdUih6bHjCfh4uag== X-Google-Smtp-Source: AOwi7QC+qOHhDDo6PP+T8adhrM89wmoMPfQrPfrR+mnM+3xlJg47roBAyjFhlnQ7IdwmdVdOJVj8MA== X-Received: by 10.98.78.202 with SMTP id c193mr10260764pfb.295.1507727553972; Wed, 11 Oct 2017 06:12:33 -0700 (PDT) Received: from [192.168.27.3] ([47.184.168.85]) by smtp.gmail.com with ESMTPSA id u85sm26449063pfi.132.2017.10.11.06.12.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Oct 2017 06:12:33 -0700 (PDT) Subject: Re: [PATCH] MIPS: Fix exception entry when CONFIG_EVA enabled To: Matt Redfearn , Ralf Baechle , James Hogan Cc: Matthew Fortune , linux-mips@linux-mips.org, linux-kernel@vger.kernel.org, "Jason A. Donenfeld" , Paul Burton References: <1507712360-20657-1-git-send-email-matt.redfearn@mips.com> From: Corey Minyard Message-ID: <605f6a96-a843-085c-efc6-a2c0f2afd84a@mvista.com> Date: Wed, 11 Oct 2017 08:12:31 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1507712360-20657-1-git-send-email-matt.redfearn@mips.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/11/2017 03:59 AM, Matt Redfearn wrote: > Commit 9fef68686317b ("MIPS: Make SAVE_SOME more standard") made several > changes to the order in which registers are saved in the SAVE_SOME > macro, used by exception handlers to save the processor state. In > particular, it removed the > move k1, sp > in the delay slot of the branch testing if the processor is already in > kernel mode. This is replaced later in the macro by a > move k0, sp > When CONFIG_EVA is disabled, this instruction actually appears in the > delay slot of the branch. However, when CONFIG_EVA is enabled, instead > the RPS workaround of > MFC0 k0, CP0_ENTRYHI > appears in the delay slot. This results in k0 not containing the stack > pointer, but some unrelated value, which is then saved to the kernel > stack. On exit from the exception, this bogus value is restored to the > stack pointer, resulting in an OOPS. > > Fix this by moving the save of SP in k0 explicitly in the delay slot of > the branch, outside of the CONFIG_EVA section, restoring the expected > instruction ordering when CONFIG_EVA is active. > > Fixes: 9fef68686317b ("MIPS: Make SAVE_SOME more standard") > Signed-off-by: Matt Redfearn > Reported-by: Vladimir Kondratiev I looked this over pretty carefully and it looks correct to me.  It makes no difference in the instructions generated by the non-EVA case.  I shouldn't have missed this :(. Reviewed-by: Corey Minyard > > --- > > Note that some of our compiler people are dubious about putting frame > related instructions in conditionally executed blocks of code. In this > case, presuming that we only care about unwinding the kernel stack, then > we only care about the case in which the branch is taken, and k0 always > contains the SP to be saved. There is also a question about putting > frame related instructions in branch delay slots. Again, in this case, > we think it's OK to use them since the only path that ought to be > unwound will be the "branch taken" route where we are already on the > kernel stack. Since the compiler can put frame-related instructions in delay slots (see aee16625b19 MIPS: Fix issues in backtraces), it's probably ok.  I have tested this before with kernel dumps and gdb, and gdb had no issues with this. That said, this is a tricky case.  But looking at the generated unwinding info, it seems to do the right thing. > Not having access to a CFI based kernel stack unwinder makes this change > difficult to verify, but since the same construct already existed when > CONFIG_EVA is disabled, I don't think this change is likely to break the > unwinder, and fixes exception entry when CONFIG_EVA is enabled. Agreed.  Thanks for fixing this. -corey > Thanks, > Matt > > --- > arch/mips/include/asm/stackframe.h | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/mips/include/asm/stackframe.h b/arch/mips/include/asm/stackframe.h > index 5d3563c55e0c..2161357cc68f 100644 > --- a/arch/mips/include/asm/stackframe.h > +++ b/arch/mips/include/asm/stackframe.h > @@ -199,6 +199,10 @@ > sll k0, 3 /* extract cu0 bit */ > .set noreorder > bltz k0, 8f > + move k0, sp > + .if \docfi > + .cfi_register sp, k0 > + .endif > #ifdef CONFIG_EVA > /* > * Flush interAptiv's Return Prediction Stack (RPS) by writing > @@ -225,10 +229,6 @@ > MTC0 k0, CP0_ENTRYHI > #endif > .set reorder > - move k0, sp > - .if \docfi > - .cfi_register sp, k0 > - .endif > /* Called from user mode, new stack. */ > get_saved_sp docfi=\docfi tosp=1 > 8: From 1580951206118155742@xxx Wed Oct 11 09:02:40 +0000 2017 X-GM-THRID: 1580951206118155742 X-Gmail-Labels: Inbox,Category Forums