Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

James Hogan and committed by
Ralf Baechle
088ec208 cb1b447f

+3 -7
+3 -7
arch/mips/kvm/dyntrans.c
··· 86 86 } else { 87 87 mfc0_inst = LW_TEMPLATE; 88 88 mfc0_inst |= ((rt & 0x1f) << 16); 89 - mfc0_inst |= 90 - offsetof(struct mips_coproc, 91 - reg[rd][sel]) + offsetof(struct kvm_mips_commpage, 92 - cop0); 89 + mfc0_inst |= offsetof(struct kvm_mips_commpage, 90 + cop0.reg[rd][sel]); 93 91 } 94 92 95 93 if (KVM_GUEST_KSEGX(opc) == KVM_GUEST_KSEG0) { ··· 121 123 sel = inst & 0x7; 122 124 123 125 mtc0_inst |= ((rt & 0x1f) << 16); 124 - mtc0_inst |= 125 - offsetof(struct mips_coproc, 126 - reg[rd][sel]) + offsetof(struct kvm_mips_commpage, cop0); 126 + mtc0_inst |= offsetof(struct kvm_mips_commpage, cop0.reg[rd][sel]); 127 127 128 128 if (KVM_GUEST_KSEGX(opc) == KVM_GUEST_KSEG0) { 129 129 kseg0_opc =