public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/9] MIPS: KVM: MIPS r6 support
@ 2016-07-04 18:35 James Hogan
  2016-07-04 18:35 ` [PATCH 3/9] MIPS: KVM: Fix fpu.S misassembly with r6 James Hogan
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: James Hogan @ 2016-07-04 18:35 UTC (permalink / raw)
  To: Paolo Bonzini, Ralf Baechle
  Cc: Radim Krčmář, Paul Burton, James Hogan, linux-mips,
	kvm

Add basic MIPS KVM support for MIPS32r6, primarily to prepare for VZ
support on r6 processors. This patchset is based on my recent uasm
conversion patchset.

Patches 1-2 from Paul are general MIPS changes which make a couple of
tweaks to the naming of opcode definitions. They aren't expected to
conflict with MIPS changes in v4.8.

Patches 3-9 make fairly simple changes to support r6, and are self
explanatory.

James Hogan (7):
  MIPS: KVM: Fix fpu.S misassembly with r6
  MIPS: KVM: Fix pre-r6 ll/sc instructions on r6
  MIPS: KVM: Don't save/restore lo/hi for r6
  MIPS: KVM: Support r6 compact branch emulation
  MIPS: KVM: Recognise r6 CACHE encoding
  MIPS: KVM: Decode RDHWR more strictly
  MIPS: KVM: Emulate generic QEMU machine on r6 T&E

Paul Burton (2):
  MIPS: inst.h: Rename b{eq,ne}zcji[al]c_op to pop{6,7}6_op
  MIPS: inst.h: Rename cbcond{0,1}_op to pop{1,3}0_op

 arch/mips/include/asm/kvm_host.h  |  6 +--
 arch/mips/include/uapi/asm/inst.h |  8 ++--
 arch/mips/kernel/branch.c         |  8 ++--
 arch/mips/kvm/dyntrans.c          |  5 ++-
 arch/mips/kvm/emulate.c           | 77 +++++++++++++++++++++++++++++++++++----
 arch/mips/kvm/entry.c             | 16 ++------
 arch/mips/kvm/fpu.S               |  7 +++-
 arch/mips/kvm/mips.c              |  6 +++
 arch/mips/kvm/trap_emul.c         |  8 +++-
 arch/mips/math-emu/cp1emu.c       |  8 ++--
 10 files changed, 110 insertions(+), 39 deletions(-)

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
-- 
2.4.10


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

* [PATCH 3/9] MIPS: KVM: Fix fpu.S misassembly with r6
  2016-07-04 18:35 [PATCH 0/9] MIPS: KVM: MIPS r6 support James Hogan
@ 2016-07-04 18:35 ` James Hogan
  2016-07-04 18:35 ` [PATCH 4/9] MIPS: KVM: Fix pre-r6 ll/sc instructions on r6 James Hogan
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: James Hogan @ 2016-07-04 18:35 UTC (permalink / raw)
  To: Paolo Bonzini, Ralf Baechle
  Cc: Radim Krčmář, Paul Burton, James Hogan, linux-mips,
	kvm

__kvm_save_fpu and __kvm_restore_fpu use .set mips64r2 so that they can
access the odd FPU registers as well as the even, however this causes
misassembly of the return instruction on MIPSr6.

Fix by replacing .set mips64r2 with .set fp=64, which doesn't change the
architecture revision.

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
---
 arch/mips/kvm/fpu.S | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kvm/fpu.S b/arch/mips/kvm/fpu.S
index 531fbf5131c0..16f17c6390dd 100644
--- a/arch/mips/kvm/fpu.S
+++ b/arch/mips/kvm/fpu.S
@@ -14,13 +14,16 @@
 #include <asm/mipsregs.h>
 #include <asm/regdef.h>
 
+/* preprocessor replaces the fp in ".set fp=64" with $30 otherwise */
+#undef fp
+
 	.set	noreorder
 	.set	noat
 
 LEAF(__kvm_save_fpu)
 	.set	push
-	.set	mips64r2
 	SET_HARDFLOAT
+	.set	fp=64
 	mfc0	t0, CP0_STATUS
 	sll     t0, t0, 5			# is Status.FR set?
 	bgez    t0, 1f				# no: skip odd doubles
@@ -63,8 +66,8 @@ LEAF(__kvm_save_fpu)
 
 LEAF(__kvm_restore_fpu)
 	.set	push
-	.set	mips64r2
 	SET_HARDFLOAT
+	.set	fp=64
 	mfc0	t0, CP0_STATUS
 	sll     t0, t0, 5			# is Status.FR set?
 	bgez    t0, 1f				# no: skip odd doubles
-- 
2.4.10


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

* [PATCH 4/9] MIPS: KVM: Fix pre-r6 ll/sc instructions on r6
  2016-07-04 18:35 [PATCH 0/9] MIPS: KVM: MIPS r6 support James Hogan
  2016-07-04 18:35 ` [PATCH 3/9] MIPS: KVM: Fix fpu.S misassembly with r6 James Hogan
@ 2016-07-04 18:35 ` James Hogan
  2016-07-04 18:35 ` [PATCH 5/9] MIPS: KVM: Don't save/restore lo/hi for r6 James Hogan
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: James Hogan @ 2016-07-04 18:35 UTC (permalink / raw)
  To: Paolo Bonzini, Ralf Baechle
  Cc: Radim Krčmář, Paul Burton, James Hogan, linux-mips,
	kvm

The atomic KVM register access macros in kvm_host.h (for the guest Cause
register with KVM in trap & emulate mode) use ll/sc instructions,
however they still .set mips3, which causes pre-MIPSr6 instruction
encodings to be emitted, even for a MIPSr6 build.

Fix it to use MIPS_ISA_ARCH_LEVEL as other parts of arch/mips already
do.

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
---
 arch/mips/include/asm/kvm_host.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index b32785543787..b54bcadd8aec 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -400,7 +400,7 @@ static inline void _kvm_atomic_set_c0_guest_reg(unsigned long *reg,
 	unsigned long temp;
 	do {
 		__asm__ __volatile__(
-		"	.set	mips3				\n"
+		"	.set	"MIPS_ISA_ARCH_LEVEL"		\n"
 		"	" __LL "%0, %1				\n"
 		"	or	%0, %2				\n"
 		"	" __SC	"%0, %1				\n"
@@ -416,7 +416,7 @@ static inline void _kvm_atomic_clear_c0_guest_reg(unsigned long *reg,
 	unsigned long temp;
 	do {
 		__asm__ __volatile__(
-		"	.set	mips3				\n"
+		"	.set	"MIPS_ISA_ARCH_LEVEL"		\n"
 		"	" __LL "%0, %1				\n"
 		"	and	%0, %2				\n"
 		"	" __SC	"%0, %1				\n"
@@ -433,7 +433,7 @@ static inline void _kvm_atomic_change_c0_guest_reg(unsigned long *reg,
 	unsigned long temp;
 	do {
 		__asm__ __volatile__(
-		"	.set	mips3				\n"
+		"	.set	"MIPS_ISA_ARCH_LEVEL"		\n"
 		"	" __LL "%0, %1				\n"
 		"	and	%0, %2				\n"
 		"	or	%0, %3				\n"
-- 
2.4.10


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

* [PATCH 5/9] MIPS: KVM: Don't save/restore lo/hi for r6
  2016-07-04 18:35 [PATCH 0/9] MIPS: KVM: MIPS r6 support James Hogan
  2016-07-04 18:35 ` [PATCH 3/9] MIPS: KVM: Fix fpu.S misassembly with r6 James Hogan
  2016-07-04 18:35 ` [PATCH 4/9] MIPS: KVM: Fix pre-r6 ll/sc instructions on r6 James Hogan
@ 2016-07-04 18:35 ` James Hogan
  2016-07-04 18:35 ` [PATCH 6/9] MIPS: KVM: Support r6 compact branch emulation James Hogan
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: James Hogan @ 2016-07-04 18:35 UTC (permalink / raw)
  To: Paolo Bonzini, Ralf Baechle
  Cc: Radim Krčmář, Paul Burton, James Hogan, linux-mips,
	kvm

MIPSr6 doesn't have lo/hi registers, so don't bother saving or
restoring them, and don't expose them to userland with the KVM ioctl
interface either.

In fact the lo/hi registers aren't callee saved in the MIPS ABIs anyway,
so there is no need to preserve the host lo/hi values at all when
transitioning to and from the guest (which happens via a function call).

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
---
 arch/mips/kvm/entry.c | 16 ++++------------
 arch/mips/kvm/mips.c  |  6 ++++++
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/arch/mips/kvm/entry.c b/arch/mips/kvm/entry.c
index de8b6ec5573f..75ba7c2ecb3d 100644
--- a/arch/mips/kvm/entry.c
+++ b/arch/mips/kvm/entry.c
@@ -178,12 +178,6 @@ void *kvm_mips_build_vcpu_run(void *addr)
 		UASM_i_SW(&p, i, offsetof(struct pt_regs, regs[i]), K1);
 	}
 
-	/* Save hi/lo */
-	uasm_i_mflo(&p, V0);
-	UASM_i_SW(&p, V0, offsetof(struct pt_regs, lo), K1);
-	uasm_i_mfhi(&p, V1);
-	UASM_i_SW(&p, V1, offsetof(struct pt_regs, hi), K1);
-
 	/* Save host status */
 	uasm_i_mfc0(&p, V0, C0_STATUS);
 	UASM_i_SW(&p, V0, offsetof(struct pt_regs, cp0_status), K1);
@@ -307,12 +301,14 @@ static void *kvm_mips_build_enter_guest(void *addr)
 		UASM_i_LW(&p, i, offsetof(struct kvm_vcpu_arch, gprs[i]), K1);
 	}
 
+#ifndef CONFIG_CPU_MIPSR6
 	/* Restore hi/lo */
 	UASM_i_LW(&p, K0, offsetof(struct kvm_vcpu_arch, hi), K1);
 	uasm_i_mthi(&p, K0);
 
 	UASM_i_LW(&p, K0, offsetof(struct kvm_vcpu_arch, lo), K1);
 	uasm_i_mtlo(&p, K0);
+#endif
 
 	/* Restore the guest's k0/k1 registers */
 	UASM_i_LW(&p, K0, offsetof(struct kvm_vcpu_arch, gprs[K0]), K1);
@@ -408,12 +404,14 @@ void *kvm_mips_build_exit(void *addr)
 		UASM_i_SW(&p, i, offsetof(struct kvm_vcpu_arch, gprs[i]), K1);
 	}
 
+#ifndef CONFIG_CPU_MIPSR6
 	/* We need to save hi/lo and restore them on the way out */
 	uasm_i_mfhi(&p, T0);
 	UASM_i_SW(&p, T0, offsetof(struct kvm_vcpu_arch, hi), K1);
 
 	uasm_i_mflo(&p, T0);
 	UASM_i_SW(&p, T0, offsetof(struct kvm_vcpu_arch, lo), K1);
+#endif
 
 	/* Finally save guest k1 to VCPU */
 	uasm_i_ehb(&p);
@@ -663,12 +661,6 @@ static void *kvm_mips_build_ret_to_host(void *addr)
 		UASM_i_LW(&p, i, offsetof(struct pt_regs, regs[i]), K1);
 	}
 
-	UASM_i_LW(&p, K0, offsetof(struct pt_regs, hi), K1);
-	uasm_i_mthi(&p, K0);
-
-	UASM_i_LW(&p, K0, offsetof(struct pt_regs, lo), K1);
-	uasm_i_mtlo(&p, K0);
-
 	/* Restore RDHWR access */
 	UASM_i_LA_mostly(&p, K0, (long)&hwrena);
 	uasm_i_lw(&p, K0, uasm_rel_lo((long)&hwrena), K0);
diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
index a62267f6fb07..0d11d9595600 100644
--- a/arch/mips/kvm/mips.c
+++ b/arch/mips/kvm/mips.c
@@ -521,8 +521,10 @@ static u64 kvm_mips_get_one_regs[] = {
 	KVM_REG_MIPS_R30,
 	KVM_REG_MIPS_R31,
 
+#ifndef CONFIG_CPU_MIPSR6
 	KVM_REG_MIPS_HI,
 	KVM_REG_MIPS_LO,
+#endif
 	KVM_REG_MIPS_PC,
 
 	KVM_REG_MIPS_CP0_INDEX,
@@ -666,12 +668,14 @@ static int kvm_mips_get_reg(struct kvm_vcpu *vcpu,
 	case KVM_REG_MIPS_R0 ... KVM_REG_MIPS_R31:
 		v = (long)vcpu->arch.gprs[reg->id - KVM_REG_MIPS_R0];
 		break;
+#ifndef CONFIG_CPU_MIPSR6
 	case KVM_REG_MIPS_HI:
 		v = (long)vcpu->arch.hi;
 		break;
 	case KVM_REG_MIPS_LO:
 		v = (long)vcpu->arch.lo;
 		break;
+#endif
 	case KVM_REG_MIPS_PC:
 		v = (long)vcpu->arch.pc;
 		break;
@@ -887,12 +891,14 @@ static int kvm_mips_set_reg(struct kvm_vcpu *vcpu,
 	case KVM_REG_MIPS_R1 ... KVM_REG_MIPS_R31:
 		vcpu->arch.gprs[reg->id - KVM_REG_MIPS_R0] = v;
 		break;
+#ifndef CONFIG_CPU_MIPSR6
 	case KVM_REG_MIPS_HI:
 		vcpu->arch.hi = v;
 		break;
 	case KVM_REG_MIPS_LO:
 		vcpu->arch.lo = v;
 		break;
+#endif
 	case KVM_REG_MIPS_PC:
 		vcpu->arch.pc = v;
 		break;
-- 
2.4.10


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

* [PATCH 6/9] MIPS: KVM: Support r6 compact branch emulation
  2016-07-04 18:35 [PATCH 0/9] MIPS: KVM: MIPS r6 support James Hogan
                   ` (2 preceding siblings ...)
  2016-07-04 18:35 ` [PATCH 5/9] MIPS: KVM: Don't save/restore lo/hi for r6 James Hogan
@ 2016-07-04 18:35 ` James Hogan
  2016-07-04 18:35 ` [PATCH 7/9] MIPS: KVM: Recognise r6 CACHE encoding James Hogan
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: James Hogan @ 2016-07-04 18:35 UTC (permalink / raw)
  To: Paolo Bonzini, Ralf Baechle
  Cc: Radim Krčmář, Paul Burton, James Hogan, linux-mips,
	kvm

Add support in KVM for emulation of instructions in the forbidden slot
of MIPSr6 compact branches. If we hit an exception on the forbidden
slot, then the branch must not have been taken, which makes calculation
of the resume PC trivial.

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
---
 arch/mips/kvm/emulate.c | 52 +++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 46 insertions(+), 6 deletions(-)

diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index 5f0354c80c8e..f0fa9e956056 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -161,9 +161,12 @@ unsigned long kvm_compute_return_epc(struct kvm_vcpu *vcpu,
 		nextpc = epc;
 		break;
 
-	case blez_op:		/* not really i_format */
-	case blezl_op:
-		/* rt field assumed to be zero */
+	case blez_op:	/* POP06 */
+#ifndef CONFIG_CPU_MIPSR6
+	case blezl_op:	/* removed in R6 */
+#endif
+		if (insn.i_format.rt != 0)
+			goto compact_branch;
 		if ((long)arch->gprs[insn.i_format.rs] <= 0)
 			epc = epc + 4 + (insn.i_format.simmediate << 2);
 		else
@@ -171,9 +174,12 @@ unsigned long kvm_compute_return_epc(struct kvm_vcpu *vcpu,
 		nextpc = epc;
 		break;
 
-	case bgtz_op:
-	case bgtzl_op:
-		/* rt field assumed to be zero */
+	case bgtz_op:	/* POP07 */
+#ifndef CONFIG_CPU_MIPSR6
+	case bgtzl_op:	/* removed in R6 */
+#endif
+		if (insn.i_format.rt != 0)
+			goto compact_branch;
 		if ((long)arch->gprs[insn.i_format.rs] > 0)
 			epc = epc + 4 + (insn.i_format.simmediate << 2);
 		else
@@ -185,6 +191,40 @@ unsigned long kvm_compute_return_epc(struct kvm_vcpu *vcpu,
 	case cop1_op:
 		kvm_err("%s: unsupported cop1_op\n", __func__);
 		break;
+
+#ifdef CONFIG_CPU_MIPSR6
+	/* R6 added the following compact branches with forbidden slots */
+	case blezl_op:	/* POP26 */
+	case bgtzl_op:	/* POP27 */
+		/* only rt == 0 isn't compact branch */
+		if (insn.i_format.rt != 0)
+			goto compact_branch;
+		break;
+	case pop10_op:
+	case pop30_op:
+		/* only rs == rt == 0 is reserved, rest are compact branches */
+		if (insn.i_format.rs != 0 || insn.i_format.rt != 0)
+			goto compact_branch;
+		break;
+	case pop66_op:
+	case pop76_op:
+		/* only rs == 0 isn't compact branch */
+		if (insn.i_format.rs != 0)
+			goto compact_branch;
+		break;
+compact_branch:
+		/*
+		 * If we've hit an exception on the forbidden slot, then
+		 * the branch must not have been taken.
+		 */
+		epc += 8;
+		nextpc = epc;
+		break;
+#else
+compact_branch:
+		/* Compact branches not supported before R6 */
+		break;
+#endif
 	}
 
 	return nextpc;
-- 
2.4.10


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

* [PATCH 7/9] MIPS: KVM: Recognise r6 CACHE encoding
  2016-07-04 18:35 [PATCH 0/9] MIPS: KVM: MIPS r6 support James Hogan
                   ` (3 preceding siblings ...)
  2016-07-04 18:35 ` [PATCH 6/9] MIPS: KVM: Support r6 compact branch emulation James Hogan
@ 2016-07-04 18:35 ` James Hogan
  2016-07-04 18:35 ` [PATCH 8/9] MIPS: KVM: Decode RDHWR more strictly James Hogan
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: James Hogan @ 2016-07-04 18:35 UTC (permalink / raw)
  To: Paolo Bonzini, Ralf Baechle
  Cc: Radim Krčmář, Paul Burton, James Hogan, linux-mips,
	kvm

Recognise the new MIPSr6 CACHE instruction encoding rather than the
pre-r6 one when an r6 kernel is being built. A SPECIAL3 opcode is used
and the immediate field is reduced to 9 bits wide since MIPSr6.

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
---
 arch/mips/kvm/dyntrans.c |  5 ++++-
 arch/mips/kvm/emulate.c  | 21 ++++++++++++++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/arch/mips/kvm/dyntrans.c b/arch/mips/kvm/dyntrans.c
index 8a1833b9eb38..91ebd2b6034f 100644
--- a/arch/mips/kvm/dyntrans.c
+++ b/arch/mips/kvm/dyntrans.c
@@ -72,7 +72,10 @@ int kvm_mips_trans_cache_va(union mips_instruction inst, u32 *opc,
 	synci_inst.i_format.opcode = bcond_op;
 	synci_inst.i_format.rs = inst.i_format.rs;
 	synci_inst.i_format.rt = synci_op;
-	synci_inst.i_format.simmediate = inst.i_format.simmediate;
+	if (cpu_has_mips_r6)
+		synci_inst.i_format.simmediate = inst.spec3_format.simmediate;
+	else
+		synci_inst.i_format.simmediate = inst.i_format.simmediate;
 
 	return kvm_mips_trans_replace(vcpu, opc, synci_inst);
 }
diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index f0fa9e956056..62e6a7b313ae 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -1601,7 +1601,10 @@ enum emulation_result kvm_mips_emulate_cache(union mips_instruction inst,
 
 	base = inst.i_format.rs;
 	op_inst = inst.i_format.rt;
-	offset = inst.i_format.simmediate;
+	if (cpu_has_mips_r6)
+		offset = inst.spec3_format.simmediate;
+	else
+		offset = inst.i_format.simmediate;
 	cache = op_inst & CacheOp_Cache;
 	op = op_inst & CacheOp_Op;
 
@@ -1764,11 +1767,27 @@ enum emulation_result kvm_mips_emulate_inst(u32 cause, u32 *opc,
 		er = kvm_mips_emulate_load(inst, cause, run, vcpu);
 		break;
 
+#ifndef CONFIG_CPU_MIPSR6
 	case cache_op:
 		++vcpu->stat.cache_exits;
 		trace_kvm_exit(vcpu, KVM_TRACE_EXIT_CACHE);
 		er = kvm_mips_emulate_cache(inst, opc, cause, run, vcpu);
 		break;
+#else
+	case spec3_op:
+		switch (inst.spec3_format.func) {
+		case cache6_op:
+			++vcpu->stat.cache_exits;
+			trace_kvm_exit(vcpu, KVM_TRACE_EXIT_CACHE);
+			er = kvm_mips_emulate_cache(inst, opc, cause, run,
+						    vcpu);
+			break;
+		default:
+			goto unknown;
+		};
+		break;
+unknown:
+#endif
 
 	default:
 		kvm_err("Instruction emulation not supported (%p/%#x)\n", opc,
-- 
2.4.10


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

* [PATCH 8/9] MIPS: KVM: Decode RDHWR more strictly
  2016-07-04 18:35 [PATCH 0/9] MIPS: KVM: MIPS r6 support James Hogan
                   ` (4 preceding siblings ...)
  2016-07-04 18:35 ` [PATCH 7/9] MIPS: KVM: Recognise r6 CACHE encoding James Hogan
@ 2016-07-04 18:35 ` James Hogan
  2016-07-05 11:16   ` Sergei Shtylyov
  2016-07-04 18:35 ` [PATCH 9/9] MIPS: KVM: Emulate generic QEMU machine on r6 T&E James Hogan
  2016-07-05 13:58 ` [PATCH 0/9] MIPS: KVM: MIPS r6 support Ralf Baechle
  7 siblings, 1 reply; 13+ messages in thread
From: James Hogan @ 2016-07-04 18:35 UTC (permalink / raw)
  To: Paolo Bonzini, Ralf Baechle
  Cc: Radim Krčmář, Paul Burton, James Hogan, linux-mips,
	kvm

When KVM emulates the RDHWR instruction, decode the instruction more
strictly. The rs field (bits 25:21) should be zero, as should bits 10:9.
Bits 8:6 is the register select field in MIPSr6, so we aren't strict
about those bits (no other operations should use that encoding space).

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
---
 arch/mips/kvm/emulate.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
index 62e6a7b313ae..be18dfe9ecaa 100644
--- a/arch/mips/kvm/emulate.c
+++ b/arch/mips/kvm/emulate.c
@@ -2357,7 +2357,9 @@ enum emulation_result kvm_mips_handle_ri(u32 cause, u32 *opc,
 	}
 
 	if (inst.r_format.opcode == spec3_op &&
-	    inst.r_format.func == rdhwr_op) {
+	    inst.r_format.func == rdhwr_op &&
+	    inst.r_format.rs == 0 &&
+	    (inst.r_format.re >> 3) == 0) {
 		int usermode = !KVM_GUEST_KERNEL_MODE(vcpu);
 		int rd = inst.r_format.rd;
 		int rt = inst.r_format.rt;
-- 
2.4.10


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

* [PATCH 9/9] MIPS: KVM: Emulate generic QEMU machine on r6 T&E
  2016-07-04 18:35 [PATCH 0/9] MIPS: KVM: MIPS r6 support James Hogan
                   ` (5 preceding siblings ...)
  2016-07-04 18:35 ` [PATCH 8/9] MIPS: KVM: Decode RDHWR more strictly James Hogan
@ 2016-07-04 18:35 ` James Hogan
  2016-07-05 13:58 ` [PATCH 0/9] MIPS: KVM: MIPS r6 support Ralf Baechle
  7 siblings, 0 replies; 13+ messages in thread
From: James Hogan @ 2016-07-04 18:35 UTC (permalink / raw)
  To: Paolo Bonzini, Ralf Baechle
  Cc: Radim Krčmář, Paul Burton, James Hogan, linux-mips,
	kvm

Default the guest PRId register to represent a generic QEMU machine
instead of a 24kc on MIPSr6. 24kc isn't supported by r6 Linux kernels.

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
---
 arch/mips/kvm/trap_emul.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/mips/kvm/trap_emul.c b/arch/mips/kvm/trap_emul.c
index 00e8dc3d36cb..091553942bcb 100644
--- a/arch/mips/kvm/trap_emul.c
+++ b/arch/mips/kvm/trap_emul.c
@@ -431,9 +431,15 @@ static int kvm_trap_emul_vcpu_setup(struct kvm_vcpu *vcpu)
 
 	/*
 	 * Arch specific stuff, set up config registers properly so that the
-	 * guest will come up as expected, for now we simulate a MIPS 24kc
+	 * guest will come up as expected
 	 */
+#ifndef CONFIG_CPU_MIPSR6
+	/* r2-r5, simulate a MIPS 24kc */
 	kvm_write_c0_guest_prid(cop0, 0x00019300);
+#else
+	/* r6+, simulate a generic QEMU machine */
+	kvm_write_c0_guest_prid(cop0, 0x00010000);
+#endif
 	/*
 	 * Have config1, Cacheable, noncoherent, write-back, write allocate.
 	 * Endianness, arch revision & virtually tagged icache should match
-- 
2.4.10


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

* Re: [PATCH 8/9] MIPS: KVM: Decode RDHWR more strictly
  2016-07-04 18:35 ` [PATCH 8/9] MIPS: KVM: Decode RDHWR more strictly James Hogan
@ 2016-07-05 11:16   ` Sergei Shtylyov
  2016-07-05 12:39     ` Paolo Bonzini
  2016-07-05 12:51     ` Ralf Baechle
  0 siblings, 2 replies; 13+ messages in thread
From: Sergei Shtylyov @ 2016-07-05 11:16 UTC (permalink / raw)
  To: James Hogan, Paolo Bonzini, Ralf Baechle
  Cc: Radim Krčmář, Paul Burton, linux-mips, kvm

Hello.

On 7/4/2016 9:35 PM, James Hogan wrote:

> When KVM emulates the RDHWR instruction, decode the instruction more
> strictly. The rs field (bits 25:21) should be zero, as should bits 10:9.
> Bits 8:6 is the register select field in MIPSr6, so we aren't strict
> about those bits (no other operations should use that encoding space).
>
> 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
> ---
>  arch/mips/kvm/emulate.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
> index 62e6a7b313ae..be18dfe9ecaa 100644
> --- a/arch/mips/kvm/emulate.c
> +++ b/arch/mips/kvm/emulate.c
> @@ -2357,7 +2357,9 @@ enum emulation_result kvm_mips_handle_ri(u32 cause, u32 *opc,
>  	}
>
>  	if (inst.r_format.opcode == spec3_op &&
> -	    inst.r_format.func == rdhwr_op) {
> +	    inst.r_format.func == rdhwr_op &&
> +	    inst.r_format.rs == 0 &&
> +	    (inst.r_format.re >> 3) == 0) {

    Inner parens not necessary here.

[...]

MBR, Sergei


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

* Re: [PATCH 8/9] MIPS: KVM: Decode RDHWR more strictly
  2016-07-05 11:16   ` Sergei Shtylyov
@ 2016-07-05 12:39     ` Paolo Bonzini
  2016-07-05 14:34       ` Sergei Shtylyov
  2016-07-05 12:51     ` Ralf Baechle
  1 sibling, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2016-07-05 12:39 UTC (permalink / raw)
  To: Sergei Shtylyov, James Hogan, Ralf Baechle
  Cc: Radim Krčmář, Paul Burton, linux-mips, kvm



On 05/07/2016 13:16, Sergei Shtylyov wrote:
>>      if (inst.r_format.opcode == spec3_op &&
>> -        inst.r_format.func == rdhwr_op) {
>> +        inst.r_format.func == rdhwr_op &&
>> +        inst.r_format.rs == 0 &&
>> +        (inst.r_format.re >> 3) == 0) {
> 
>    Inner parens not necessary here.

They are nicer though.

Paolo

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

* Re: [PATCH 8/9] MIPS: KVM: Decode RDHWR more strictly
  2016-07-05 11:16   ` Sergei Shtylyov
  2016-07-05 12:39     ` Paolo Bonzini
@ 2016-07-05 12:51     ` Ralf Baechle
  1 sibling, 0 replies; 13+ messages in thread
From: Ralf Baechle @ 2016-07-05 12:51 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: James Hogan, Paolo Bonzini, Radim Krčmář,
	Paul Burton, linux-mips, kvm

On Tue, Jul 05, 2016 at 02:16:48PM +0300, Sergei Shtylyov wrote:

> > When KVM emulates the RDHWR instruction, decode the instruction more
> > strictly. The rs field (bits 25:21) should be zero, as should bits 10:9.
> > Bits 8:6 is the register select field in MIPSr6, so we aren't strict
> > about those bits (no other operations should use that encoding space).
> > 
> > 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
> > ---
> >  arch/mips/kvm/emulate.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/mips/kvm/emulate.c b/arch/mips/kvm/emulate.c
> > index 62e6a7b313ae..be18dfe9ecaa 100644
> > --- a/arch/mips/kvm/emulate.c
> > +++ b/arch/mips/kvm/emulate.c
> > @@ -2357,7 +2357,9 @@ enum emulation_result kvm_mips_handle_ri(u32 cause, u32 *opc,
> >  	}
> > 
> >  	if (inst.r_format.opcode == spec3_op &&
> > -	    inst.r_format.func == rdhwr_op) {
> > +	    inst.r_format.func == rdhwr_op &&
> > +	    inst.r_format.rs == 0 &&
> > +	    (inst.r_format.re >> 3) == 0) {
> 
>    Inner parens not necessary here.

While I often strip unnecessary parens from patches I apply my guideline for
leaving them in is that nobody should need to know all C operator priorities
by heart.

  Ralf

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

* Re: [PATCH 0/9] MIPS: KVM: MIPS r6 support
  2016-07-04 18:35 [PATCH 0/9] MIPS: KVM: MIPS r6 support James Hogan
                   ` (6 preceding siblings ...)
  2016-07-04 18:35 ` [PATCH 9/9] MIPS: KVM: Emulate generic QEMU machine on r6 T&E James Hogan
@ 2016-07-05 13:58 ` Ralf Baechle
  7 siblings, 0 replies; 13+ messages in thread
From: Ralf Baechle @ 2016-07-05 13:58 UTC (permalink / raw)
  To: James Hogan
  Cc: Paolo Bonzini, Radim Krčmář, Paul Burton,
	linux-mips, kvm

On Mon, Jul 04, 2016 at 07:35:06PM +0100, James Hogan wrote:


Ack for the whole thing as well:

Acked-by: Ralf Baechle <ralf@linux-mips.org>

  Ralf

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

* Re: [PATCH 8/9] MIPS: KVM: Decode RDHWR more strictly
  2016-07-05 12:39     ` Paolo Bonzini
@ 2016-07-05 14:34       ` Sergei Shtylyov
  0 siblings, 0 replies; 13+ messages in thread
From: Sergei Shtylyov @ 2016-07-05 14:34 UTC (permalink / raw)
  To: Paolo Bonzini, James Hogan, Ralf Baechle
  Cc: Radim Krčmář, Paul Burton, linux-mips, kvm

On 07/05/2016 03:39 PM, Paolo Bonzini wrote:

>>>      if (inst.r_format.opcode == spec3_op &&
>>> -        inst.r_format.func == rdhwr_op) {
>>> +        inst.r_format.func == rdhwr_op &&
>>> +        inst.r_format.rs == 0 &&
>>> +        (inst.r_format.re >> 3) == 0) {
>>
>>    Inner parens not necessary here.
>
> They are nicer though.

    I wouldn't say so...

> Paolo

MBR, Sergei


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

end of thread, other threads:[~2016-07-05 14:34 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-04 18:35 [PATCH 0/9] MIPS: KVM: MIPS r6 support James Hogan
2016-07-04 18:35 ` [PATCH 3/9] MIPS: KVM: Fix fpu.S misassembly with r6 James Hogan
2016-07-04 18:35 ` [PATCH 4/9] MIPS: KVM: Fix pre-r6 ll/sc instructions on r6 James Hogan
2016-07-04 18:35 ` [PATCH 5/9] MIPS: KVM: Don't save/restore lo/hi for r6 James Hogan
2016-07-04 18:35 ` [PATCH 6/9] MIPS: KVM: Support r6 compact branch emulation James Hogan
2016-07-04 18:35 ` [PATCH 7/9] MIPS: KVM: Recognise r6 CACHE encoding James Hogan
2016-07-04 18:35 ` [PATCH 8/9] MIPS: KVM: Decode RDHWR more strictly James Hogan
2016-07-05 11:16   ` Sergei Shtylyov
2016-07-05 12:39     ` Paolo Bonzini
2016-07-05 14:34       ` Sergei Shtylyov
2016-07-05 12:51     ` Ralf Baechle
2016-07-04 18:35 ` [PATCH 9/9] MIPS: KVM: Emulate generic QEMU machine on r6 T&E James Hogan
2016-07-05 13:58 ` [PATCH 0/9] MIPS: KVM: MIPS r6 support Ralf Baechle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox