Implements MMIO emulation for lvx/stvx instructions
Subsystems (2)
v2 cover Implements MMIO emulation for lvx/stvx instructions
v2:
- kvmppc_get_vsr_word_offset() moved back to its original place
- EA AND ~0xF, following ISA.
- fixed BE/LE cases
TESTS:
For testing purposes I wrote a small program that performs stvx/lvx using the program's virtual memory and using MMIO. Load/Store into virtual memory is the model I use to check if MMIO results are correct (because only MMIO is emulated by KVM).
Results:
HOST LE - GUEST BE
address: 0x100348500100x21436587bbbbaaaa4444555578563412io_address: 0x3fff89a200000x21436587bbbbaaaa4444555578563412
HOST LE - GUEST LE
address: 0x10033a200100x1234567855554444aaaabbbb87654321io_address: 0x3fffb53800000x1234567855554444aaaabbbb87654321
HOST BE - GUEST BE
address: 0x1002c4a00100x21436587bbbbaaaa4444555578563412io_address: 0x3ffface400000x21436587bbbbaaaa4444555578563412
HOST BR - GUEST LE
address: 0x100225e00100x1234567855554444aaaabbbb87654321io_address: 0x3fff7fcb00000x1234567855554444aaaabbbb87654321
This patch implements MMIO emulation for two instructions: lvx and stvx.
Jose Ricardo Ziviani (1):
KVM: PPC: Book3S: Add MMIO emulation for VMX instructions
arch/powerpc/include/asm/kvm_host.h | 2 + arch/powerpc/include/asm/kvm_ppc.h | 4 + arch/powerpc/include/asm/ppc-opcode.h | 6 ++ arch/powerpc/kvm/emulate_loadstore.c | 34 ++++++++ arch/powerpc/kvm/powerpc.c | 153 +++++++++++++++++++++++++++++++++- 5 files changed, 198 insertions(+), 1 deletion(-)
Signature · 1 line
2.14.3
PATCH v2 1/1 KVM: PPC: Book3S: Add MMIO emulation for VMX instructions
This patch provides the MMIO load/store vector indexed X-Form emulation.
Instructions implemented:
lvx: the quadword in storage addressed by the result of EA & 0xffff_ffff_ffff_fff0 is loaded into VRT.
stvx: the contents of VRS are stored into the quadword in storage addressed by the result of EA & 0xffff_ffff_ffff_fff0.
--- arch/powerpc/include/asm/kvm_host.h | 2 + arch/powerpc/include/asm/kvm_ppc.h | 4 + arch/powerpc/include/asm/ppc-opcode.h | 6 ++ arch/powerpc/kvm/emulate_loadstore.c | 34 ++++++++ arch/powerpc/kvm/powerpc.c | 153 +++++++++++++++++++++++++++++++++- 5 files changed, 198 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/kvm_host.h +2 -0
@@ -690,6 +690,7 @@ struct kvm_vcpu_arch {u8 mmio_vsx_offset;u8 mmio_vsx_copy_type;u8 mmio_vsx_tx_sx_enabled; +u8 mmio_vmx_copy_nums;u8 osi_needed;u8 osi_enabled;u8 papr_enabled;
@@ -800,6 +801,7 @@ struct kvm_vcpu_arch {#define KVM_MMIO_REG_QPR 0x0040#define KVM_MMIO_REG_FQPR 0x0060#define KVM_MMIO_REG_VSX 0x0080 +#define KVM_MMIO_REG_VMX 0x00a0#define __KVM_HAVE_ARCH_WQP#define __KVM_HAVE_CREATE_DEVICE
arch/powerpc/include/asm/kvm_ppc.h +4 -0
@@ -81,6 +81,10 @@ extern int kvmppc_handle_loads(struct kvm_run *run, struct kvm_vcpu *vcpu,extern int kvmppc_handle_vsx_load (struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int rt,unsigned int bytes,int is_default_endian,int mmio_sign_extend); +extern int kvmppc_handle_load128_by2x64 (struct kvm_run *run, +struct kvm_vcpu *vcpu,unsigned int rt,int is_default_endian); +extern int kvmppc_handle_store128_by2x64 (struct kvm_run *run, +struct kvm_vcpu *vcpu,unsigned int rs,int is_default_endian);extern int kvmppc_handle_store (struct kvm_run *run,struct kvm_vcpu *vcpu,u64 val,unsigned int bytes,int is_default_endian);
arch/powerpc/include/asm/ppc-opcode.h +6 -0
@@ -156,6 +156,12 @@#define OP_31_XOP_LFDX 599#define OP_31_XOP_LFDUX 631 +/* VMX Vector Load Instructions */ +#define OP_31_XOP_LVX 103 + +/* VMX Vector Store Instructions */ +#define OP_31_XOP_STVX 231 +#define OP_LWZ 32#define OP_STFS 52#define OP_STFSU 53
arch/powerpc/kvm/emulate_loadstore.c +34 -0
@@ -58,6 +58,18 @@ static bool kvmppc_check_vsx_disabled(struct kvm_vcpu *vcpu) }#endif /* CONFIG_VSX */ +#ifdef CONFIG_ALTIVEC +static bool kvmppc_check_altivec_disabled (struct kvm_vcpu *vcpu) +{ +if (!(kvmppc_get_msr (vcpu) &MSR_VEC )) { +kvmppc_core_queue_vec_unavail (vcpu); +return true; + } + +return false; +} +#endif /* CONFIG_ALTIVEC */ +/* * XXX to do: * lfiwax, lfiwzx
@@ -98,6 +110,7 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) vcpu->arch.mmio_vsx_copy_type =KVMPPC_VSX_COPY_NONE ; vcpu->arch.mmio_sp64_extend =0 ; vcpu->arch.mmio_sign_extend =0 ; + vcpu->arch.mmio_vmx_copy_nums =0 ;switch (get_op (inst)) {case 31 :
@@ -459,6 +472,27 @@ int kvmppc_emulate_loadstore(struct kvm_vcpu *vcpu) rs, 4, 1);break ;#endif /* CONFIG_VSX */ + +#ifdef CONFIG_ALTIVEC +case OP_31_XOP_LVX : +if (kvmppc_check_altivec_disabled (vcpu)) +return EMULATE_DONE ; + vcpu->arch.vaddr_accessed = ~0xFULL ; + vcpu->arch.mmio_vmx_copy_nums =2 ; + emulated =kvmppc_handle_load128_by2x64 (run, vcpu, +KVM_MMIO_REG_VMX |rt,1 ); +break ; + +case OP_31_XOP_STVX : +if (kvmppc_check_altivec_disabled (vcpu)) +return EMULATE_DONE ; + vcpu->arch.vaddr_accessed = ~0xFULL ; + vcpu->arch.mmio_vmx_copy_nums =2 ; + emulated =kvmppc_handle_store128_by2x64 (run, vcpu, + rs,1 ); +break ; +#endif /* CONFIG_ALTIVEC */ +default : emulated =EMULATE_FAIL ;break ;
arch/powerpc/kvm/powerpc.c +152 -1
190 lines not on this page · raw message
Signature · 1 line
2.14.3