linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Russell Currey <ruscur@russell.cc>
To: kvm-ppc@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org, stable@vger.kernel.org,
	Russell Currey <ruscur@russell.cc>
Subject: [PATCH] powerpc/kvm: Save and restore AMR instead of zeroing
Date: Wed, 20 Feb 2019 15:59:58 +1100	[thread overview]
Message-ID: <20190220045958.14966-1-ruscur@russell.cc> (raw)

Using the hash MMU on P7+, the AMR is used for pkeys.  It's important
that the host and guest never end up with each other's AMR value, since
this could disrupt operations and break things.

The AMR gets correctly restored on context switch, however before this
happens (i.e. in a program like qemu) having the host value of the AMR
be zero would interfere with that program using pkeys.

In addition, the AMR on Radix can control kernel access to userspace
data, which you wouldn't want to be zeroed.

So, just save and restore it like the other registers that get saved and
restored.

Fixes: cf43d3b26452 ("powerpc: Enable pkey subsystem")
Cc: <stable@vger.kernel.org> # v4.16+
Signed-off-by: Russell Currey <ruscur@russell.cc>
---
I'm not entirely sure the stack frame numbers are correct, I've tested it
and it works but it'd be good if someone could double check this.

 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 9b8d50a7cbaf..6291751c4ad9 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -47,7 +47,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
 #define NAPPING_NOVCPU	2
 
 /* Stack frame offsets for kvmppc_hv_entry */
-#define SFS			208
+#define SFS			224		/* must be divisible by 16 */
 #define STACK_SLOT_TRAP		(SFS-4)
 #define STACK_SLOT_SHORT_PATH	(SFS-8)
 #define STACK_SLOT_TID		(SFS-16)
@@ -58,8 +58,9 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
 #define STACK_SLOT_DAWR		(SFS-56)
 #define STACK_SLOT_DAWRX	(SFS-64)
 #define STACK_SLOT_HFSCR	(SFS-72)
+#define STACK_SLOT_AMR		(SFS-80)
 /* the following is used by the P9 short path */
-#define STACK_SLOT_NVGPRS	(SFS-152)	/* 18 gprs */
+#define STACK_SLOT_NVGPRS	(SFS-160)	/* 18 gprs */
 
 /*
  * Call kvmppc_hv_entry in real mode.
@@ -743,6 +744,9 @@ BEGIN_FTR_SECTION
 	std	r7, STACK_SLOT_DAWRX(r1)
 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
 
+	mfspr	r5, SPRN_AMR
+	std	r5, STACK_SLOT_AMR(r1)
+
 BEGIN_FTR_SECTION
 	/* Set partition DABR */
 	/* Do this before re-enabling PMU to avoid P7 DABR corruption bug */
@@ -1640,13 +1644,14 @@ BEGIN_FTR_SECTION
 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
 8:
 
-	/* Save and reset AMR and UAMOR before turning on the MMU */
+	/* Save and restore/reset AMR and UAMOR before turning on the MMU */
 	mfspr	r5,SPRN_AMR
 	mfspr	r6,SPRN_UAMOR
 	std	r5,VCPU_AMR(r9)
 	std	r6,VCPU_UAMOR(r9)
+	ld	r5,STACK_SLOT_AMR(r1)
 	li	r6,0
-	mtspr	SPRN_AMR,r6
+	mtspr	SPRN_AMR, r5
 	mtspr	SPRN_UAMOR, r6
 
 	/* Switch DSCR back to host value */
-- 
2.20.1


             reply	other threads:[~2019-02-20  5:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20  4:59 Russell Currey [this message]
2019-02-20 23:55 ` [PATCH] powerpc/kvm: Save and restore AMR instead of zeroing Paul Mackerras
2019-02-21  4:00   ` Russell Currey
2019-02-22 15:24 ` Sasha Levin
2019-02-23  3:16   ` Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190220045958.14966-1-ruscur@russell.cc \
    --to=ruscur@russell.cc \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).