mips/kvm: Fix ABI for compatibility with 64-bit guests.
PATCH v2 1/1 mips/kvm: Fix ABI for compatibility with 64-bit guests.
From: David Daney <[email protected]>
There are several parts to this:
o All registers are 64-bits wide, 32-bit guests use the least significant portion of the register storage fields.
o FPU register formats are defined.
o CP0 Registers are manipulated via the KVM_GET_MSRS/KVM_SET_MSRS mechanism.
The vcpu_ioctl_get_regs and vcpu_ioctl_set_regs function pointers become unused so they were removed.
Some IOCTL functions were moved to kvm_trap_emul because the implementations are only for that flavor of KVM host. In the future, if hardware based virtualization is added, they can be hidden behind function pointers as appropriate.
---
Difference from v1: Don't make unrelated change of s/gprs/gpr/
arch/mips/include/asm/kvm.h | 106 ++++++++++--- arch/mips/include/asm/kvm_host.h | 4 - arch/mips/kvm/kvm_mips.c | 102 +----------- arch/mips/kvm/kvm_trap_emul.c | 330 ++++++++++++++++++++++++++++++++++----- 4 files changed, 382 insertions(+), 160 deletions(-)
arch/mips/include/asm/kvm.h +82 -24
@@ -1,55 +1,113 @@/* -* This file is subject to the terms and conditions of the GNU General Public -* License. See the file "COPYING" in the main directory of this archive -* for more details. -* -* Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. -* Authors: Sanjay Lal <[email protected]> -*/ +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file "COPYING" in the main directory of this archive +* for more details. +* +* Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. +* Copyright (C) 2013 Cavium, Inc. +* Authors: Sanjay Lal <[email protected]> +*/ #ifndef __LINUX_KVM_MIPS_H#define __LINUX_KVM_MIPS_H#include <linux/types.h> -#define __KVM_MIPS - -#define N_MIPS_COPROC_REGS 32 -#define N_MIPS_COPROC_SEL 8 +/* +* KVM MIPS specific structures and definitions. +* +* Some parts derived from the x86 version of this file. +*/ /* for KVM_GET_REGS and KVM_SET_REGS */ +/* +* If Config[AT] is zero (32-bit CPU), the register contents are +* stored in the lower 32-bits of the struct kvm_regs fields and sign +* extended to 64-bits. +*/ struct kvm_regs { -__u32 gprs[32 ]; -__u32 hi; -__u32 lo; -__u32 pc; +/* out (KVM_GET_REGS) / in (KVM_SET_REGS) */ +__u64 gpr[32 ]; +__u64 hi, lo; +__u64 pc; +}; -__u32 cp0reg[N_MIPS_COPROC_REGS ][N_MIPS_COPROC_SEL ]; +/* for KVM_GET_FPU and KVM_SET_FPU */ +/* +* If Status[FR] is zero (32-bit FPU), the upper 32-bits of the FPRs +* are zero filled. +*/ +struct kvm_fpu { +__u64 fpr[32 ]; +__u32 fir; +__u32 fccr; +__u32 fexr; +__u32 fenr; +__u32 fcsr; +__u32 pad; }; -/* for KVM_GET_SREGS and KVM_SET_SREGS */ -struct kvm_sregs { + +/* +* For MIPS, we use the same APIs as x86, where 'msr' corresponds to a +* CP0 register. The index field is broken down as follows: +* +* bits[2..0] - Register 'sel' index. +* bits[7..3] - Register 'rd' index. +* bits[15..8] - Must be zero. +* bits[31..16] - 0 -> CP0 registers. +* +* Other sets registers may be added in the future. Each set would +* have its own identifier in bits[31..16]. +* +* For MSRs that are narrower than 64-bits, the value is stored in the +* low order bits of the data field, and sign extended to 64-bits. +*/ +#define KVM_MIPS_MSR_CP0 0 +struct kvm_msr_entry { +__u32 index; +__u32 reserved; +__u64 data; }; -/* for KVM_GET_FPU and KVM_SET_FPU */ -struct kvm_fpu { +/* for KVM_GET_MSRS and KVM_SET_MSRS */ +struct kvm_msrs { +__u32 nmsrs;/* number of msrs in entries */ +__u32 pad; + +struct kvm_msr_entry entries[0 ]; }; +/* for KVM_GET_MSR_INDEX_LIST */ +struct kvm_msr_list { +__u32 nmsrs;/* number of msrs in entries */ +__u32 indices[0 ]; +}; + +/* +* KVM MIPS specific structures and definitions +* +*/ struct kvm_debug_exit_arch { +__u64 epc; };/* for KVM_SET_GUEST_DEBUG */ struct kvm_guest_debug_arch { }; +/* definition of registers in kvm_run */ +struct kvm_sync_regs { +}; + +/* dummy definition */ +struct kvm_sregs { +}; +struct kvm_mips_interrupt {/* in */ __u32 cpu;__u32 irq; }; -/* definition of registers in kvm_run */ -struct kvm_sync_regs { -}; -#endif /* __LINUX_KVM_MIPS_H */
arch/mips/include/asm/kvm_host.h +0 -4
@@ -496,10 +496,6 @@ struct kvm_mips_callbacks { uint32_t cause);int (*irq_clear) (struct kvm_vcpu *vcpu,unsigned int priority,uint32_t cause); -int (*vcpu_ioctl_get_regs) (struct kvm_vcpu *vcpu, -struct kvm_regs *regs); -int (*vcpu_ioctl_set_regs) (struct kvm_vcpu *vcpu, -struct kvm_regs *regs); };extern struct kvm_mips_callbacks *kvm_mips_callbacks;int kvm_mips_emulation_init (struct kvm_mips_callbacks **install_callbacks);
arch/mips/kvm/kvm_mips.c +7 -95
147 lines not on this page · raw message
arch/mips/kvm/kvm_trap_emul.c +293 -37
362 lines not on this page · raw message
Signature · 1 line
1.7.11.7