MIPS: KVM: Refactor added offsetof()s

When calculating the offsets into the commpage for dynamically
translated mtc0/mfc0 guest instructions, multiple offsetof()s are added
together to find the offset of the specific register in the mips_coproc,
within the commpage.

Simplify each of these cases to a single offsetof() to find the offset
of the specific register within the commpage.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/11888/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
This commit is contained in:
James Hogan 2015-12-16 23:49:31 +00:00 committed by Ralf Baechle
parent cb1b447f0c
commit 088ec208d6
1 changed files with 3 additions and 7 deletions

View File

@ -86,10 +86,8 @@ int kvm_mips_trans_mfc0(uint32_t inst, uint32_t *opc, struct kvm_vcpu *vcpu)
} else { } else {
mfc0_inst = LW_TEMPLATE; mfc0_inst = LW_TEMPLATE;
mfc0_inst |= ((rt & 0x1f) << 16); mfc0_inst |= ((rt & 0x1f) << 16);
mfc0_inst |= mfc0_inst |= offsetof(struct kvm_mips_commpage,
offsetof(struct mips_coproc, cop0.reg[rd][sel]);
reg[rd][sel]) + offsetof(struct kvm_mips_commpage,
cop0);
} }
if (KVM_GUEST_KSEGX(opc) == KVM_GUEST_KSEG0) { if (KVM_GUEST_KSEGX(opc) == KVM_GUEST_KSEG0) {
@ -123,9 +121,7 @@ int kvm_mips_trans_mtc0(uint32_t inst, uint32_t *opc, struct kvm_vcpu *vcpu)
sel = inst & 0x7; sel = inst & 0x7;
mtc0_inst |= ((rt & 0x1f) << 16); mtc0_inst |= ((rt & 0x1f) << 16);
mtc0_inst |= mtc0_inst |= offsetof(struct kvm_mips_commpage, cop0.reg[rd][sel]);
offsetof(struct mips_coproc,
reg[rd][sel]) + offsetof(struct kvm_mips_commpage, cop0);
if (KVM_GUEST_KSEGX(opc) == KVM_GUEST_KSEG0) { if (KVM_GUEST_KSEGX(opc) == KVM_GUEST_KSEG0) {
kseg0_opc = kseg0_opc =