stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] MIPS: KVM: Misc fixes
@ 2015-11-11 14:21 James Hogan
  2015-11-11 14:21 ` [PATCH 1/3] MIPS: KVM: Fix ASID restoration logic James Hogan
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: James Hogan @ 2015-11-11 14:21 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Ralf Baechle, Gleb Natapov, linux-mips, kvm, stable

A few misc MIPS KVM fixes for issues that have been around since the
code was merged in v3.10.

James Hogan (3):
  MIPS: KVM: Fix ASID restoration logic
  MIPS: KVM: Fix CACHE immediate offset sign extension
  MIPS: KVM: Uninit VCPU in vcpu_create error path

 arch/mips/kvm/emulate.c |  2 +-
 arch/mips/kvm/locore.S  | 16 ++++++++++------
 arch/mips/kvm/mips.c    |  5 ++++-
 3 files changed, 15 insertions(+), 8 deletions(-)

Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Cc: <stable@vger.kernel.org>
-- 
2.4.10


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] MIPS: KVM: Fix ASID restoration logic
  2015-11-11 14:21 [PATCH 0/3] MIPS: KVM: Misc fixes James Hogan
@ 2015-11-11 14:21 ` James Hogan
  2015-11-11 14:21 ` [PATCH 2/3] MIPS: KVM: Fix CACHE immediate offset sign extension James Hogan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: James Hogan @ 2015-11-11 14:21 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Ralf Baechle, Gleb Natapov, linux-mips, kvm, stable

ASID restoration on guest resume should determine the guest execution
mode based on the guest Status register rather than bit 30 of the guest
PC.

Fix the two places in locore.S that do this, loading the guest status
from the cop0 area. Note, this assembly is specific to the trap &
emulate implementation of KVM, so it doesn't need to check the
supervisor bit as that mode is not implemented in the guest.

Fixes: b680f70fc111 ("KVM/MIPS32: Entry point for trampolining to...")
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Cc: <stable@vger.kernel.org> # 3.10.x-
---
 arch/mips/kvm/locore.S | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/mips/kvm/locore.S b/arch/mips/kvm/locore.S
index c567240386a0..d1ee95a7f7dd 100644
--- a/arch/mips/kvm/locore.S
+++ b/arch/mips/kvm/locore.S
@@ -165,9 +165,11 @@ FEXPORT(__kvm_mips_vcpu_run)
 
 FEXPORT(__kvm_mips_load_asid)
 	/* Set the ASID for the Guest Kernel */
-	INT_SLL	t0, t0, 1	/* with kseg0 @ 0x40000000, kernel */
-			        /* addresses shift to 0x80000000 */
-	bltz	t0, 1f		/* If kernel */
+	PTR_L	t0, VCPU_COP0(k1)
+	LONG_L	t0, COP0_STATUS(t0)
+	andi	t0, KSU_USER | ST0_ERL | ST0_EXL
+	xori	t0, KSU_USER
+	bnez	t0, 1f		/* If kernel */
 	 INT_ADDIU t1, k1, VCPU_GUEST_KERNEL_ASID  /* (BD)  */
 	INT_ADDIU t1, k1, VCPU_GUEST_USER_ASID    /* else user */
 1:
@@ -482,9 +484,11 @@ __kvm_mips_return_to_guest:
 	mtc0	t0, CP0_EPC
 
 	/* Set the ASID for the Guest Kernel */
-	INT_SLL	t0, t0, 1	/* with kseg0 @ 0x40000000, kernel */
-				/* addresses shift to 0x80000000 */
-	bltz	t0, 1f		/* If kernel */
+	PTR_L	t0, VCPU_COP0(k1)
+	LONG_L	t0, COP0_STATUS(t0)
+	andi	t0, KSU_USER | ST0_ERL | ST0_EXL
+	xori	t0, KSU_USER
+	bnez	t0, 1f		/* If kernel */
 	 INT_ADDIU t1, k1, VCPU_GUEST_KERNEL_ASID  /* (BD)  */
 	INT_ADDIU t1, k1, VCPU_GUEST_USER_ASID    /* else user */
 1:
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] MIPS: KVM: Fix CACHE immediate offset sign extension
  2015-11-11 14:21 [PATCH 0/3] MIPS: KVM: Misc fixes James Hogan
  2015-11-11 14:21 ` [PATCH 1/3] MIPS: KVM: Fix ASID restoration logic James Hogan
@ 2015-11-11 14:21 ` James Hogan
  2015-11-11 14:21 ` [PATCH 3/3] MIPS: KVM: Uninit VCPU in vcpu_create error path James Hogan
  2015-11-11 14:43 ` [PATCH 0/3] MIPS: KVM: Misc fixes Paolo Bonzini
  3 siblings, 0 replies; 7+ messages in thread
From: James Hogan @ 2015-11-11 14:21 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Ralf Baechle, Gleb Natapov, linux-mips, kvm, stable

The immediate field of the CACHE instruction is signed, so ensure that
it gets sign extended by casting it to an int16_t rather than just
masking the low 16 bits.

Fixes: e685c689f3a8 ("KVM/MIPS32: Privileged instruction/target branch emulation.")
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Cc: <stable@vger.kernel.org> # 3.10.x-
---
 arch/mips/kvm/emulate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index d5fa3eaf39a1..41b1b090f56f 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -1581,7 +1581,7 @@ enum emulation_result kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc,
 
 	base = (inst >> 21) & 0x1f;
 	op_inst = (inst >> 16) & 0x1f;
-	offset = inst & 0xffff;
+	offset = (int16_t)inst;
 	cache = (inst >> 16) & 0x3;
 	op = (inst >> 18) & 0x7;
 
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] MIPS: KVM: Uninit VCPU in vcpu_create error path
  2015-11-11 14:21 [PATCH 0/3] MIPS: KVM: Misc fixes James Hogan
  2015-11-11 14:21 ` [PATCH 1/3] MIPS: KVM: Fix ASID restoration logic James Hogan
  2015-11-11 14:21 ` [PATCH 2/3] MIPS: KVM: Fix CACHE immediate offset sign extension James Hogan
@ 2015-11-11 14:21 ` James Hogan
  2015-11-11 14:43 ` [PATCH 0/3] MIPS: KVM: Misc fixes Paolo Bonzini
  3 siblings, 0 replies; 7+ messages in thread
From: James Hogan @ 2015-11-11 14:21 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: James Hogan, Ralf Baechle, Gleb Natapov, linux-mips, kvm, stable

If either of the memory allocations in kvm_arch_vcpu_create() fail, the
vcpu which has been allocated and kvm_vcpu_init'd doesn't get uninit'd
in the error handling path. Add a call to kvm_vcpu_uninit() to fix this.

Fixes: 669e846e6c4e ("KVM/MIPS32: MIPS arch specific APIs for KVM")
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Cc: <stable@vger.kernel.org> # 3.10.x-
---
 arch/mips/kvm/mips.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index 49ff3bfc007e..b9b803facdbf 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -279,7 +279,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
 
 	if (!gebase) {
 		err = -ENOMEM;
-		goto out_free_cpu;
+		goto out_uninit_cpu;
 	}
 	kvm_debug("Allocated %d bytes for KVM Exception Handlers @ %p\n",
 		  ALIGN(size, PAGE_SIZE), gebase);
@@ -343,6 +343,9 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
 out_free_gebase:
 	kfree(gebase);
 
+out_uninit_cpu:
+	kvm_vcpu_uninit(vcpu);
+
 out_free_cpu:
 	kfree(vcpu);
 
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/3] MIPS: KVM: Misc fixes
  2015-11-11 14:21 [PATCH 0/3] MIPS: KVM: Misc fixes James Hogan
                   ` (2 preceding siblings ...)
  2015-11-11 14:21 ` [PATCH 3/3] MIPS: KVM: Uninit VCPU in vcpu_create error path James Hogan
@ 2015-11-11 14:43 ` Paolo Bonzini
  2015-11-11 14:57   ` James Hogan
  3 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2015-11-11 14:43 UTC (permalink / raw)
  To: James Hogan; +Cc: Ralf Baechle, Gleb Natapov, linux-mips, kvm, stable



On 11/11/2015 15:21, James Hogan wrote:
> A few misc MIPS KVM fixes for issues that have been around since the
> code was merged in v3.10.
> 
> James Hogan (3):
>   MIPS: KVM: Fix ASID restoration logic
>   MIPS: KVM: Fix CACHE immediate offset sign extension
>   MIPS: KVM: Uninit VCPU in vcpu_create error path
> 
>  arch/mips/kvm/emulate.c |  2 +-
>  arch/mips/kvm/locore.S  | 16 ++++++++++------
>  arch/mips/kvm/mips.c    |  5 ++++-
>  3 files changed, 15 insertions(+), 8 deletions(-)
> 
> Cc: Ralf Baechle <ralf@linux-mips.org>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Gleb Natapov <gleb@kernel.org>
> Cc: linux-mips@linux-mips.org
> Cc: kvm@vger.kernel.org
> Cc: <stable@vger.kernel.org>
> 

Thanks, these will have to wait after the end of the merge window.

Paolo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/3] MIPS: KVM: Misc fixes
  2015-11-11 14:43 ` [PATCH 0/3] MIPS: KVM: Misc fixes Paolo Bonzini
@ 2015-11-11 14:57   ` James Hogan
  2015-11-11 14:59     ` Paolo Bonzini
  0 siblings, 1 reply; 7+ messages in thread
From: James Hogan @ 2015-11-11 14:57 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Ralf Baechle, Gleb Natapov, linux-mips, kvm, stable

[-- Attachment #1: Type: text/plain, Size: 1065 bytes --]

Hi Paolo,

On Wed, Nov 11, 2015 at 03:43:14PM +0100, Paolo Bonzini wrote:
> On 11/11/2015 15:21, James Hogan wrote:
> > A few misc MIPS KVM fixes for issues that have been around since the
> > code was merged in v3.10.
> > 
> > James Hogan (3):
> >   MIPS: KVM: Fix ASID restoration logic
> >   MIPS: KVM: Fix CACHE immediate offset sign extension
> >   MIPS: KVM: Uninit VCPU in vcpu_create error path
> > 
> >  arch/mips/kvm/emulate.c |  2 +-
> >  arch/mips/kvm/locore.S  | 16 ++++++++++------
> >  arch/mips/kvm/mips.c    |  5 ++++-
> >  3 files changed, 15 insertions(+), 8 deletions(-)
> > 
> > Cc: Ralf Baechle <ralf@linux-mips.org>
> > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > Cc: Gleb Natapov <gleb@kernel.org>
> > Cc: linux-mips@linux-mips.org
> > Cc: kvm@vger.kernel.org
> > Cc: <stable@vger.kernel.org>
> > 
> 
> Thanks, these will have to wait after the end of the merge window.

Okay, no problem. As long as they can make v4.4.

For the record do you prefer not to receive patches during merge window?

Thanks
James

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/3] MIPS: KVM: Misc fixes
  2015-11-11 14:57   ` James Hogan
@ 2015-11-11 14:59     ` Paolo Bonzini
  0 siblings, 0 replies; 7+ messages in thread
From: Paolo Bonzini @ 2015-11-11 14:59 UTC (permalink / raw)
  To: James Hogan; +Cc: Ralf Baechle, Gleb Natapov, linux-mips, kvm, stable

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256



On 11/11/2015 15:57, James Hogan wrote:
> Okay, no problem. As long as they can make v4.4.
> 
> For the record do you prefer not to receive patches during merge 
> window?

It's okay, at worst I won't process them for a few days or weeks.

Paolo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJWQ1fWAAoJEL/70l94x66D5mEIAJbKuP0oRsfMVhZGDlonqzOp
+ugEDNWAzC8tQas2joei0tBtmsFMKY+9NXbFUUthcE0Tn4TbfBi5rRpOfE7B+ekV
Y6sec+vp0AsplpQtNI3OdU8jrZqMYkWUK6ZBdOJrpdPzBzfmFkXuMdimLomhdlVl
8r6Vh6la7RohEJWxXBAaGEzgGqIQ25H+Xw/FNHo3Pk2ZPhI2EgusSlMby6w087kQ
nht5LSVn92Jvx7CNCsqAEhccO/a6XYiRXfW+nFCa/Z1DUvYoezgyXl7jWvyGwKj5
9y73jwIYop63B+KcEDTWZ6gKu2GDrT+TQod+IlWoWDk58PdQjxI1BNcqS+QMFlc=
=VHcV
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-11-11 14:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-11 14:21 [PATCH 0/3] MIPS: KVM: Misc fixes James Hogan
2015-11-11 14:21 ` [PATCH 1/3] MIPS: KVM: Fix ASID restoration logic James Hogan
2015-11-11 14:21 ` [PATCH 2/3] MIPS: KVM: Fix CACHE immediate offset sign extension James Hogan
2015-11-11 14:21 ` [PATCH 3/3] MIPS: KVM: Uninit VCPU in vcpu_create error path James Hogan
2015-11-11 14:43 ` [PATCH 0/3] MIPS: KVM: Misc fixes Paolo Bonzini
2015-11-11 14:57   ` James Hogan
2015-11-11 14:59     ` Paolo Bonzini

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).