All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Mackerras <paulus@samba.org>
To: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org
Cc: kvm-ppc@vger.kernel.org, Scott Wood <scottwood@freescale.com>,
	agraf@suse.de
Subject: [PATCH 2/2] KVM: PPC: Book3S HV: Fix register usage when loading/saving VRSAVE
Date: Thu, 13 Mar 2014 09:02:48 +0000	[thread overview]
Message-ID: <20140313090248.GC32257@iris.ozlabs.ibm.com> (raw)
In-Reply-To: <20140313090107.GA32257@iris.ozlabs.ibm.com>

Commit 595e4f7e697e ("KVM: PPC: Book3S HV: Use load/store_fp_state
functions in HV guest entry/exit") changed the register usage in
kvmppc_save_fp() and kvmppc_load_fp() but omitted changing the
instructions that load and save VRSAVE.  The result is that the
VRSAVE value was loaded from a constant address, and saved to a
location past the end of the vcpu struct, causing host kernel
memory corruption and various kinds of host kernel crashes.

This fixes the problem by using register r31, which contains the
vcpu pointer, instead of r3 and r4.

Signed-off-by: Paul Mackerras <paulus@samba.org>
---
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 781e6bf..818dce3 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -2136,7 +2136,7 @@ BEGIN_FTR_SECTION
 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
 #endif
 	mfspr	r6,SPRN_VRSAVE
-	stw	r6,VCPU_VRSAVE(r3)
+	stw	r6,VCPU_VRSAVE(r31)
 	mtlr	r30
 	mtmsrd	r5
 	isync
@@ -2173,7 +2173,7 @@ BEGIN_FTR_SECTION
 	bl	.load_vr_state
 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
 #endif
-	lwz	r7,VCPU_VRSAVE(r4)
+	lwz	r7,VCPU_VRSAVE(r31)
 	mtspr	SPRN_VRSAVE,r7
 	mtlr	r30
 	mr	r4,r31
-- 
1.9.rc1


WARNING: multiple messages have this Message-ID (diff)
From: Paul Mackerras <paulus@samba.org>
To: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org
Cc: kvm-ppc@vger.kernel.org, Scott Wood <scottwood@freescale.com>,
	agraf@suse.de
Subject: [PATCH 2/2] KVM: PPC: Book3S HV: Fix register usage when loading/saving VRSAVE
Date: Thu, 13 Mar 2014 20:02:48 +1100	[thread overview]
Message-ID: <20140313090248.GC32257@iris.ozlabs.ibm.com> (raw)
In-Reply-To: <20140313090107.GA32257@iris.ozlabs.ibm.com>

Commit 595e4f7e697e ("KVM: PPC: Book3S HV: Use load/store_fp_state
functions in HV guest entry/exit") changed the register usage in
kvmppc_save_fp() and kvmppc_load_fp() but omitted changing the
instructions that load and save VRSAVE.  The result is that the
VRSAVE value was loaded from a constant address, and saved to a
location past the end of the vcpu struct, causing host kernel
memory corruption and various kinds of host kernel crashes.

This fixes the problem by using register r31, which contains the
vcpu pointer, instead of r3 and r4.

Signed-off-by: Paul Mackerras <paulus@samba.org>
---
 arch/powerpc/kvm/book3s_hv_rmhandlers.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
index 781e6bf..818dce3 100644
--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
+++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
@@ -2136,7 +2136,7 @@ BEGIN_FTR_SECTION
 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
 #endif
 	mfspr	r6,SPRN_VRSAVE
-	stw	r6,VCPU_VRSAVE(r3)
+	stw	r6,VCPU_VRSAVE(r31)
 	mtlr	r30
 	mtmsrd	r5
 	isync
@@ -2173,7 +2173,7 @@ BEGIN_FTR_SECTION
 	bl	.load_vr_state
 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
 #endif
-	lwz	r7,VCPU_VRSAVE(r4)
+	lwz	r7,VCPU_VRSAVE(r31)
 	mtspr	SPRN_VRSAVE,r7
 	mtlr	r30
 	mr	r4,r31
-- 
1.9.rc1


  parent reply	other threads:[~2014-03-13  9:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-13  9:01 [PATCH 0/2] Fixes for HV KVM on PPC for 3.14 Paul Mackerras
2014-03-13  9:01 ` Paul Mackerras
2014-03-13  9:02 ` [PATCH 1/2] KVM: PPC: Book3S HV: Remove bogus duplicate code Paul Mackerras
2014-03-13  9:02   ` Paul Mackerras
2014-03-13  9:02 ` Paul Mackerras [this message]
2014-03-13  9:02   ` [PATCH 2/2] KVM: PPC: Book3S HV: Fix register usage when loading/saving VRSAVE Paul Mackerras
2014-03-13  9:50 ` [PATCH 0/2] Fixes for HV KVM on PPC for 3.14 Paolo Bonzini
2014-03-13  9:50   ` Paolo Bonzini
2014-03-13 10:29   ` Paul Mackerras
2014-03-13 10:29     ` Paul Mackerras
2014-03-13 15:43 ` Scott Wood
2014-03-13 15:43   ` Scott Wood
  -- strict thread matches above, loose matches on Subject: below --
2014-03-06 10:48 [PATCH 1/2] Revert "KVM: PPC: Book3S HV: Add new state for transactional memory" Aneesh Kumar K.V
2014-03-06 10:36 ` [PATCH 2/2] KVM: PPC: Book3S HV: Fix register usage when loading/saving VRSAVE Aneesh Kumar K.V
2014-03-06 10:48   ` Aneesh Kumar K.V
2014-03-06 10:36   ` Aneesh Kumar K.V

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=20140313090248.GC32257@iris.ozlabs.ibm.com \
    --to=paulus@samba.org \
    --cc=agraf@suse.de \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=scottwood@freescale.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.