linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning
@ 2016-11-09 16:13 James Hogan
  2016-11-09 16:13 ` James Hogan
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: James Hogan @ 2016-11-09 16:13 UTC (permalink / raw)
  To: stable
  Cc: Paolo Bonzini, Radim Krčmář,
	Ralf Baechle, linux-mips, kvm, James Hogan

From: Nicholas Mc Guire <hofrat@osadl.org>

commit 5f508c43a7648baa892528922402f1e13f258bd4 upstream.

As kvm_mips_complete_mmio_load() did not yet modify PC at this point
as James Hogans <james.hogan@imgtec.com> explained the curr_pc variable
and the comments along with it can be dropped.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Link: http://lkml.org/lkml/2015/5/8/422
Cc: Gleb Natapov <gleb@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: kvm@vger.kernel.org
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/9993/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
[james.hogan@imgtec.com: Backport to 3.10..3.16]
Signed-off-by: James Hogan <james.hogan@imgtec.com>
---
 arch/mips/kvm/kvm_mips_emul.c | 6 ------
 1 file changed, 0 insertions(+), 6 deletions(-)

diff --git a/arch/mips/kvm/kvm_mips_emul.c b/arch/mips/kvm/kvm_mips_emul.c
index 1983678883c9..a32e838d9aeb 100644
--- a/arch/mips/kvm/kvm_mips_emul.c
+++ b/arch/mips/kvm/kvm_mips_emul.c
@@ -2115,7 +2115,6 @@ kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run)
 {
 	unsigned long *gpr = &vcpu->arch.gprs[vcpu->arch.io_gpr];
 	enum emulation_result er = EMULATE_DONE;
-	unsigned long curr_pc;
 
 	if (run->mmio.len > sizeof(*gpr)) {
 		printk("Bad MMIO length: %d", run->mmio.len);
@@ -2123,11 +2122,6 @@ kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run)
 		goto done;
 	}
 
-	/*
-	 * Update PC and hold onto current PC in case there is
-	 * an error and we want to rollback the PC
-	 */
-	curr_pc = vcpu->arch.pc;
 	er = update_pc(vcpu, vcpu->arch.pending_load_cause);
 	if (er == EMULATE_FAIL)
 		return er;
-- 
git-series 0.8.10

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

* [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning
  2016-11-09 16:13 [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning James Hogan
@ 2016-11-09 16:13 ` James Hogan
  2016-11-09 16:13 ` [BACKPORT PATCH 3.10..3.16 2/2] KVM: MIPS: Precalculate MMIO load resume PC James Hogan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: James Hogan @ 2016-11-09 16:13 UTC (permalink / raw)
  To: stable
  Cc: Paolo Bonzini, Radim Krčmář,
	Ralf Baechle, linux-mips, kvm, James Hogan

From: Nicholas Mc Guire <hofrat@osadl.org>

commit 5f508c43a7648baa892528922402f1e13f258bd4 upstream.

As kvm_mips_complete_mmio_load() did not yet modify PC at this point
as James Hogans <james.hogan@imgtec.com> explained the curr_pc variable
and the comments along with it can be dropped.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Link: http://lkml.org/lkml/2015/5/8/422
Cc: Gleb Natapov <gleb@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: James Hogan <james.hogan@imgtec.com>
Cc: kvm@vger.kernel.org
Cc: linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/9993/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
[james.hogan@imgtec.com: Backport to 3.10..3.16]
Signed-off-by: James Hogan <james.hogan@imgtec.com>
---
 arch/mips/kvm/kvm_mips_emul.c | 6 ------
 1 file changed, 0 insertions(+), 6 deletions(-)

diff --git a/arch/mips/kvm/kvm_mips_emul.c b/arch/mips/kvm/kvm_mips_emul.c
index 1983678883c9..a32e838d9aeb 100644
--- a/arch/mips/kvm/kvm_mips_emul.c
+++ b/arch/mips/kvm/kvm_mips_emul.c
@@ -2115,7 +2115,6 @@ kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run)
 {
 	unsigned long *gpr = &vcpu->arch.gprs[vcpu->arch.io_gpr];
 	enum emulation_result er = EMULATE_DONE;
-	unsigned long curr_pc;
 
 	if (run->mmio.len > sizeof(*gpr)) {
 		printk("Bad MMIO length: %d", run->mmio.len);
@@ -2123,11 +2122,6 @@ kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run)
 		goto done;
 	}
 
-	/*
-	 * Update PC and hold onto current PC in case there is
-	 * an error and we want to rollback the PC
-	 */
-	curr_pc = vcpu->arch.pc;
 	er = update_pc(vcpu, vcpu->arch.pending_load_cause);
 	if (er == EMULATE_FAIL)
 		return er;
-- 
git-series 0.8.10

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

* [BACKPORT PATCH 3.10..3.16 2/2] KVM: MIPS: Precalculate MMIO load resume PC
  2016-11-09 16:13 [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning James Hogan
  2016-11-09 16:13 ` James Hogan
@ 2016-11-09 16:13 ` James Hogan
  2016-11-09 16:13   ` James Hogan
  2016-11-09 17:28 ` [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning Willy Tarreau
  2016-11-09 21:28 ` Jiri Slaby
  3 siblings, 1 reply; 7+ messages in thread
From: James Hogan @ 2016-11-09 16:13 UTC (permalink / raw)
  To: stable
  Cc: Paolo Bonzini, Radim Krčmář,
	Ralf Baechle, linux-mips, kvm, James Hogan

commit e1e575f6b026734be3b1f075e780e91ab08ca541 upstream.

The advancing of the PC when completing an MMIO load is done before
re-entering the guest, i.e. before restoring the guest ASID. However if
the load is in a branch delay slot it may need to access guest code to
read the prior branch instruction. This isn't safe in TLB mapped code at
the moment, nor in the future when we'll access unmapped guest segments
using direct user accessors too, as it could read the branch from host
user memory instead.

Therefore calculate the resume PC in advance while we're still in the
right context and save it in the new vcpu->arch.io_pc (replacing the no
longer needed vcpu->arch.pending_load_cause), and restore it on MMIO
completion.

Fixes: e685c689f3a8 ("KVM/MIPS32: Privileged instruction/target branch emulation.")
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Cc: <stable@vger.kernel.org> # 3.10.x-3.16.x: 5f508c43a764: MIPS: KVM: Fix unused variable build warning
Cc: <stable@vger.kernel.org> # 3.10.x-3.16.x
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
[james.hogan@imgtec.com: Backport to 3.10..3.16]
Signed-off-by: James Hogan <james.hogan@imgtec.com>
---
 arch/mips/include/asm/kvm_host.h |  7 ++++---
 arch/mips/kvm/kvm_mips_emul.c    | 25 +++++++++++++++----------
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index 5bddbc63fc3b..f8cdc274173a 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -403,7 +403,10 @@ struct kvm_vcpu_arch {
 	/* Host KSEG0 address of the EI/DI offset */
 	void *kseg0_commpage;
 
-	u32 io_gpr;		/* GPR used as IO source/target */
+	/* Resume PC after MMIO completion */
+	unsigned long io_pc;
+	/* GPR used as IO source/target */
+	u32 io_gpr;
 
 	struct hrtimer comparecount_timer;
 	/* Count timer control KVM register */
@@ -425,8 +428,6 @@ struct kvm_vcpu_arch {
 	/* Bitmask of pending exceptions to be cleared */
 	unsigned long pending_exceptions_clr;
 
-	unsigned long pending_load_cause;
-
 	/* Save/Restore the entryhi register when are are preempted/scheduled back in */
 	unsigned long preempt_entryhi;
 
diff --git a/arch/mips/kvm/kvm_mips_emul.c b/arch/mips/kvm/kvm_mips_emul.c
index a32e838d9aeb..4feffc82f39a 100644
--- a/arch/mips/kvm/kvm_mips_emul.c
+++ b/arch/mips/kvm/kvm_mips_emul.c
@@ -1283,6 +1283,7 @@ kvm_mips_emulate_load(uint32_t inst, uint32_t cause,
 		      struct kvm_run *run, struct kvm_vcpu *vcpu)
 {
 	enum emulation_result er = EMULATE_DO_MMIO;
+	unsigned long curr_pc;
 	int32_t op, base, rt, offset;
 	uint32_t bytes;
 
@@ -1291,7 +1292,18 @@ kvm_mips_emulate_load(uint32_t inst, uint32_t cause,
 	offset = inst & 0xffff;
 	op = (inst >> 26) & 0x3f;
 
-	vcpu->arch.pending_load_cause = cause;
+	/*
+	 * Find the resume PC now while we have safe and easy access to the
+	 * prior branch instruction, and save it for
+	 * kvm_mips_complete_mmio_load() to restore later.
+	 */
+	curr_pc = vcpu->arch.pc;
+	er = update_pc(vcpu, cause);
+	if (er == EMULATE_FAIL)
+		return er;
+	vcpu->arch.io_pc = vcpu->arch.pc;
+	vcpu->arch.pc = curr_pc;
+
 	vcpu->arch.io_gpr = rt;
 
 	switch (op) {
@@ -2122,9 +2134,8 @@ kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run)
 		goto done;
 	}
 
-	er = update_pc(vcpu, vcpu->arch.pending_load_cause);
-	if (er == EMULATE_FAIL)
-		return er;
+	/* Restore saved resume PC */
+	vcpu->arch.pc = vcpu->arch.io_pc;
 
 	switch (run->mmio.len) {
 	case 4:
@@ -2146,12 +2157,6 @@ kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run)
 		break;
 	}
 
-	if (vcpu->arch.pending_load_cause & CAUSEF_BD)
-		kvm_debug
-		    ("[%#lx] Completing %d byte BD Load to gpr %d (0x%08lx) type %d\n",
-		     vcpu->arch.pc, run->mmio.len, vcpu->arch.io_gpr, *gpr,
-		     vcpu->mmio_needed);
-
 done:
 	return er;
 }
-- 
git-series 0.8.10

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

* [BACKPORT PATCH 3.10..3.16 2/2] KVM: MIPS: Precalculate MMIO load resume PC
  2016-11-09 16:13 ` [BACKPORT PATCH 3.10..3.16 2/2] KVM: MIPS: Precalculate MMIO load resume PC James Hogan
@ 2016-11-09 16:13   ` James Hogan
  0 siblings, 0 replies; 7+ messages in thread
From: James Hogan @ 2016-11-09 16:13 UTC (permalink / raw)
  To: stable
  Cc: Paolo Bonzini, Radim Krčmář,
	Ralf Baechle, linux-mips, kvm, James Hogan

commit e1e575f6b026734be3b1f075e780e91ab08ca541 upstream.

The advancing of the PC when completing an MMIO load is done before
re-entering the guest, i.e. before restoring the guest ASID. However if
the load is in a branch delay slot it may need to access guest code to
read the prior branch instruction. This isn't safe in TLB mapped code at
the moment, nor in the future when we'll access unmapped guest segments
using direct user accessors too, as it could read the branch from host
user memory instead.

Therefore calculate the resume PC in advance while we're still in the
right context and save it in the new vcpu->arch.io_pc (replacing the no
longer needed vcpu->arch.pending_load_cause), and restore it on MMIO
completion.

Fixes: e685c689f3a8 ("KVM/MIPS32: Privileged instruction/target branch emulation.")
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Cc: <stable@vger.kernel.org> # 3.10.x-3.16.x: 5f508c43a764: MIPS: KVM: Fix unused variable build warning
Cc: <stable@vger.kernel.org> # 3.10.x-3.16.x
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
[james.hogan@imgtec.com: Backport to 3.10..3.16]
Signed-off-by: James Hogan <james.hogan@imgtec.com>
---
 arch/mips/include/asm/kvm_host.h |  7 ++++---
 arch/mips/kvm/kvm_mips_emul.c    | 25 +++++++++++++++----------
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index 5bddbc63fc3b..f8cdc274173a 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -403,7 +403,10 @@ struct kvm_vcpu_arch {
 	/* Host KSEG0 address of the EI/DI offset */
 	void *kseg0_commpage;
 
-	u32 io_gpr;		/* GPR used as IO source/target */
+	/* Resume PC after MMIO completion */
+	unsigned long io_pc;
+	/* GPR used as IO source/target */
+	u32 io_gpr;
 
 	struct hrtimer comparecount_timer;
 	/* Count timer control KVM register */
@@ -425,8 +428,6 @@ struct kvm_vcpu_arch {
 	/* Bitmask of pending exceptions to be cleared */
 	unsigned long pending_exceptions_clr;
 
-	unsigned long pending_load_cause;
-
 	/* Save/Restore the entryhi register when are are preempted/scheduled back in */
 	unsigned long preempt_entryhi;
 
diff --git a/arch/mips/kvm/kvm_mips_emul.c b/arch/mips/kvm/kvm_mips_emul.c
index a32e838d9aeb..4feffc82f39a 100644
--- a/arch/mips/kvm/kvm_mips_emul.c
+++ b/arch/mips/kvm/kvm_mips_emul.c
@@ -1283,6 +1283,7 @@ kvm_mips_emulate_load(uint32_t inst, uint32_t cause,
 		      struct kvm_run *run, struct kvm_vcpu *vcpu)
 {
 	enum emulation_result er = EMULATE_DO_MMIO;
+	unsigned long curr_pc;
 	int32_t op, base, rt, offset;
 	uint32_t bytes;
 
@@ -1291,7 +1292,18 @@ kvm_mips_emulate_load(uint32_t inst, uint32_t cause,
 	offset = inst & 0xffff;
 	op = (inst >> 26) & 0x3f;
 
-	vcpu->arch.pending_load_cause = cause;
+	/*
+	 * Find the resume PC now while we have safe and easy access to the
+	 * prior branch instruction, and save it for
+	 * kvm_mips_complete_mmio_load() to restore later.
+	 */
+	curr_pc = vcpu->arch.pc;
+	er = update_pc(vcpu, cause);
+	if (er == EMULATE_FAIL)
+		return er;
+	vcpu->arch.io_pc = vcpu->arch.pc;
+	vcpu->arch.pc = curr_pc;
+
 	vcpu->arch.io_gpr = rt;
 
 	switch (op) {
@@ -2122,9 +2134,8 @@ kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run)
 		goto done;
 	}
 
-	er = update_pc(vcpu, vcpu->arch.pending_load_cause);
-	if (er == EMULATE_FAIL)
-		return er;
+	/* Restore saved resume PC */
+	vcpu->arch.pc = vcpu->arch.io_pc;
 
 	switch (run->mmio.len) {
 	case 4:
@@ -2146,12 +2157,6 @@ kvm_mips_complete_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run)
 		break;
 	}
 
-	if (vcpu->arch.pending_load_cause & CAUSEF_BD)
-		kvm_debug
-		    ("[%#lx] Completing %d byte BD Load to gpr %d (0x%08lx) type %d\n",
-		     vcpu->arch.pc, run->mmio.len, vcpu->arch.io_gpr, *gpr,
-		     vcpu->mmio_needed);
-
 done:
 	return er;
 }
-- 
git-series 0.8.10

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

* Re: [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning
  2016-11-09 16:13 [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning James Hogan
  2016-11-09 16:13 ` James Hogan
  2016-11-09 16:13 ` [BACKPORT PATCH 3.10..3.16 2/2] KVM: MIPS: Precalculate MMIO load resume PC James Hogan
@ 2016-11-09 17:28 ` Willy Tarreau
  2016-11-09 21:28 ` Jiri Slaby
  3 siblings, 0 replies; 7+ messages in thread
From: Willy Tarreau @ 2016-11-09 17:28 UTC (permalink / raw)
  To: James Hogan
  Cc: stable, Paolo Bonzini, Radim Kr??má??,
	Ralf Baechle, linux-mips, kvm

Both patches queued for 3.10.y, thanks James!

Willy

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

* Re: [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning
  2016-11-09 16:13 [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning James Hogan
                   ` (2 preceding siblings ...)
  2016-11-09 17:28 ` [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning Willy Tarreau
@ 2016-11-09 21:28 ` Jiri Slaby
  2016-11-09 22:11   ` James Hogan
  3 siblings, 1 reply; 7+ messages in thread
From: Jiri Slaby @ 2016-11-09 21:28 UTC (permalink / raw)
  To: James Hogan, stable
  Cc: Paolo Bonzini, Radim Krčmář,
	Ralf Baechle, linux-mips, kvm

On 11/09/2016, 05:13 PM, James Hogan wrote:
> From: Nicholas Mc Guire <hofrat@osadl.org>
> 
> commit 5f508c43a7648baa892528922402f1e13f258bd4 upstream.

Both applied now to 3.12, albeit the latter didn't apply cleanly.

thanks,
-- 
js
suse labs

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

* Re: [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning
  2016-11-09 21:28 ` Jiri Slaby
@ 2016-11-09 22:11   ` James Hogan
  0 siblings, 0 replies; 7+ messages in thread
From: James Hogan @ 2016-11-09 22:11 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: stable, Paolo Bonzini, Radim Krčmář,
	Ralf Baechle, linux-mips, kvm

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

On Wed, Nov 09, 2016 at 10:28:58PM +0100, Jiri Slaby wrote:
> On 11/09/2016, 05:13 PM, James Hogan wrote:
> > From: Nicholas Mc Guire <hofrat@osadl.org>
> > 
> > commit 5f508c43a7648baa892528922402f1e13f258bd4 upstream.
> 
> Both applied now to 3.12, albeit the latter didn't apply cleanly.

/me digs in terminal log

Sorry, I used patch -p1 intentionally when testing 3.12 to try to spot
unclean stable patches, expecting it to reject it, but didn't spot the
fuzz:

$ git show 4.9/kvm/fixes_rc3/stable/3.16 | patch -p1                                                                                 
patching file arch/mips/include/asm/kvm_host.h
Hunk #1 succeeded at 375 with fuzz 2 (offset -28 lines).
...

Thanks
James

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

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

end of thread, other threads:[~2016-11-09 22:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-09 16:13 [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning James Hogan
2016-11-09 16:13 ` James Hogan
2016-11-09 16:13 ` [BACKPORT PATCH 3.10..3.16 2/2] KVM: MIPS: Precalculate MMIO load resume PC James Hogan
2016-11-09 16:13   ` James Hogan
2016-11-09 17:28 ` [BACKPORT PATCH 3.10..3.16 1/2] MIPS: KVM: Fix unused variable build warning Willy Tarreau
2016-11-09 21:28 ` Jiri Slaby
2016-11-09 22:11   ` James Hogan

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