Skip to content

Commit 5808844

Browse files
James Hoganbonzini
authored andcommitted
MIPS: KVM: Fix 64-bit big endian dynamic translation
The MFC0 and MTC0 instructions in the guest which cause traps can be replaced with 32-bit loads and stores to the commpage, however on big endian 64-bit builds the offset needs to have 4 added so as to load/store the least significant half of the long instead of the most significant half. 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 2a06dab commit 5808844

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/mips/kvm/dyntrans.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ int kvm_mips_trans_mfc0(union mips_instruction inst, u32 *opc,
103103
mfc0_inst.i_format.rt = inst.c0r_format.rt;
104104
mfc0_inst.i_format.simmediate = KVM_GUEST_COMMPAGE_ADDR |
105105
offsetof(struct kvm_mips_commpage, cop0.reg[rd][sel]);
106+
#ifdef CONFIG_CPU_BIG_ENDIAN
107+
if (sizeof(vcpu->arch.cop0->reg[0][0]) == 8)
108+
mfc0_inst.i_format.simmediate |= 4;
109+
#endif
106110
}
107111

108112
return kvm_mips_trans_replace(vcpu, opc, mfc0_inst);
@@ -121,6 +125,10 @@ int kvm_mips_trans_mtc0(union mips_instruction inst, u32 *opc,
121125
mtc0_inst.i_format.rt = inst.c0r_format.rt;
122126
mtc0_inst.i_format.simmediate = KVM_GUEST_COMMPAGE_ADDR |
123127
offsetof(struct kvm_mips_commpage, cop0.reg[rd][sel]);
128+
#ifdef CONFIG_CPU_BIG_ENDIAN
129+
if (sizeof(vcpu->arch.cop0->reg[0][0]) == 8)
130+
mtc0_inst.i_format.simmediate |= 4;
131+
#endif
124132

125133
return kvm_mips_trans_replace(vcpu, opc, mtc0_inst);
126134
}

0 commit comments

Comments
 (0)