Skip to content

Commit 172e02d

Browse files
James Hoganbonzini
authored andcommitted
MIPS: KVM: Sign extend MFC0/RDHWR results
When emulating MFC0 instructions to load 32-bit values from guest COP0 registers and the RDHWR instruction to read the CC (Count) register, sign extend the result to comply with the MIPS64 architecture. The result must be in canonical 32-bit form or the guest may malfunction. 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 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 5808844 commit 172e02d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

arch/mips/kvm/emulate.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,14 +1072,15 @@ enum emulation_result kvm_mips_emulate_CP0(union mips_instruction inst,
10721072
#endif
10731073
/* Get reg */
10741074
if ((rd == MIPS_CP0_COUNT) && (sel == 0)) {
1075-
vcpu->arch.gprs[rt] = kvm_mips_read_count(vcpu);
1075+
vcpu->arch.gprs[rt] =
1076+
(s32)kvm_mips_read_count(vcpu);
10761077
} else if ((rd == MIPS_CP0_ERRCTL) && (sel == 0)) {
10771078
vcpu->arch.gprs[rt] = 0x0;
10781079
#ifdef CONFIG_KVM_MIPS_DYN_TRANS
10791080
kvm_mips_trans_mfc0(inst, opc, vcpu);
10801081
#endif
10811082
} else {
1082-
vcpu->arch.gprs[rt] = cop0->reg[rd][sel];
1083+
vcpu->arch.gprs[rt] = (s32)cop0->reg[rd][sel];
10831084

10841085
#ifdef CONFIG_KVM_MIPS_DYN_TRANS
10851086
kvm_mips_trans_mfc0(inst, opc, vcpu);
@@ -2380,7 +2381,7 @@ enum emulation_result kvm_mips_handle_ri(u32 cause, u32 *opc,
23802381
current_cpu_data.icache.linesz);
23812382
break;
23822383
case MIPS_HWR_CC: /* Read count register */
2383-
arch->gprs[rt] = kvm_mips_read_count(vcpu);
2384+
arch->gprs[rt] = (s32)kvm_mips_read_count(vcpu);
23842385
break;
23852386
case MIPS_HWR_CCRES: /* Count register resolution */
23862387
switch (current_cpu_data.cputype) {

0 commit comments

Comments
 (0)