MIPS: KVM: Guest FPU & SIMD (MSA) support
Subsystems (5)
v2 cover MIPS: KVM: Guest FPU & SIMD (MSA) support
This patchset primarily adds guest Floating Point Unit (FPU) and MIPS SIMD Architecture (MSA) support to MIPS KVM, by enabling the host FPU/MSA while in guest mode.
This patchset depends on Paul Burton's FP/MSA fixes patchset, which will make it into 4.0. I've only included the 3 patches (15, 19, 20) that have changed since v1, which can be found here:
http://thread.gmane.org/gmane.linux.kernel.api/8984
The corresponding QEMU patchset can be found here:
http://thread.gmane.org/gmane.comp.emulators.kvm.devel/134314
Assuming there are no further review comments I'll submit a pull request once Ralf has applied the FP/MSA fixes for me to merge.
Changes in v2:
- Add missing MSA vector and control register id bit patterns to API documentation.
- Rebased on KVM queue (KVM_CAP_MIPS_FPU & KVM_CAP_MIPS_MSA increased to 108 & 109 after KVM_CAP_S390_VECTOR_REGISTERS took 107).
- Just call kvm_vm_ioctl_check_extension() from kvm_vcpu_ioctl_enable_cap() rather than duplicating the extension presence conditions (Paolo).
Original description:
- Adds KVM_CAP_MIPS_FPU and KVM_CAP_MIPS_MSA capabilities which must be enabled to add FPU/MSA to the guest.
- Supports FR=0, FR=1, FRE=1 floating point register modes and 128-bit vector registers.
- Does not support UFR/UFE (guest user control of FR/FRE bits), or MSA vector partitioning.
- Context restore is lazy: done on first actual use.
- Context save is lazy: once restored, host FPU/MSA gets enabled/disabled when guest enables/disables it, with registers left loaded as long as possible.
- So the state that can be loaded at any one time is:
- No FPRs/vector state
- FR=0 FPRs (change of FR discards FP state)
- FR=1 FPRs
- Vector state (includes FR=1 FPRs)
- Vector state only (when guest CU1=0, FR=0)
- FCSR/MSACSR status registers are saved/restored around guest execution, since care must be taken to handle FP exceptions when writing these registers.
The patches are arranged roughly in groups:
- Patch 1 is a related minimal stable fix which can be applied in advance of the others (patch 18 fills it out a bit).
- Patch 2 is a generic MIPS change required to be able to restore FCSR/MSACSR registers with exceptions pending.
- Patches 3..10 add various misc KVM improvements and cleanups, most of which the later patches depend on.
- Patches 11..15 add the main guest FPU support.
- Patches 16..20 add the main guest MSA support (structured like 11.15).
James Hogan (20):
MIPS: KVM: Handle MSA Disabled exceptions from guest
MIPS: Clear [MSA]FPE CSR.Cause after notify_die()
MIPS: KVM: Handle TRAP exceptions from guest kernel
MIPS: KVM: Implement PRid CP0 register access
MIPS: KVM: Sort kvm_mips_get_reg() registers
MIPS: KVM: Drop pr_info messages on init/exit
MIPS: KVM: Clean up register definitions a little
MIPS: KVM: Simplify default guest Config registers
MIPS: KVM: Add Config4/5 and writing of Config registers
MIPS: KVM: Add vcpu_get_regs/vcpu_set_regs callback
MIPS: KVM: Add base guest FPU support
MIPS: KVM: Emulate FPU bits in COP0 interface
MIPS: KVM: Add FP exception handling
MIPS: KVM: Expose FPU registers
MIPS: KVM: Wire up FPU capability
MIPS: KVM: Add base guest MSA support
MIPS: KVM: Emulate MSA bits in COP0 interface
MIPS: KVM: Add MSA exception handling
MIPS: KVM: Expose MSA registers
MIPS: KVM: Wire up MSA capability
Documentation/virtual/kvm/api.txt | 54 +++++ arch/mips/include/asm/kdebug.h | 3 +- arch/mips/include/asm/kvm_host.h | 125 +++++++--- arch/mips/include/uapi/asm/kvm.h | 160 ++++++++----- arch/mips/kernel/asm-offsets.c | 39 ++++ arch/mips/kernel/genex.S | 14 +- arch/mips/kernel/traps.c | 16 +- arch/mips/kvm/Makefile | 8 +- arch/mips/kvm/emulate.c | 332 ++++++++++++++++++++++++++- arch/mips/kvm/fpu.S | 122 ++++++++++ arch/mips/kvm/locore.S | 38 +++ arch/mips/kvm/mips.c | 472 +++++++++++++++++++++++++++++++++++++- arch/mips/kvm/msa.S | 161 +++++++++++++ arch/mips/kvm/stats.c | 4 + arch/mips/kvm/tlb.c | 6 + arch/mips/kvm/trap_emul.c | 199 +++++++++++++++- include/uapi/linux/kvm.h | 2 + 17 files changed, 1631 insertions(+), 124 deletions(-) create mode 100644 arch/mips/kvm/fpu.S create mode 100644 arch/mips/kvm/msa.S
Signature · 1 line
2.0.5
PATCH v2 15/20 MIPS: KVM: Wire up FPU capability
Now that the code is in place for KVM to support FPU in MIPS KVM guests, wire up the new KVM_CAP_MIPS_FPU capability.
For backwards compatibility, the capability must be explicitly enabled in order to detect or make use of the FPU from the guest.
---
Changes in v2:
- Rebased on KVM queue (KVM_CAP_MIPS_FPU increased to 108 after KVM_CAP_S390_VECTOR_REGISTERS took 107).
- Just call kvm_vm_ioctl_check_extension() from kvm_vcpu_ioctl_enable_cap() rather than duplicating the extension presence condition (Paolo).
--- Documentation/virtual/kvm/api.txt | 13 +++++++++++++ arch/mips/kvm/mips.c | 37 +++++++++++++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 1 + 3 files changed, 51 insertions(+)
Documentation/virtual/kvm/api.txt +13 -0
@@ -3208,6 +3208,19 @@ Parameters: none This capability enables the in-kernel irqchip for s390. Please refer to "4.24 KVM_CREATE_IRQCHIP" for details. +6.9 KVM_CAP_MIPS_FPU + +Architectures: mips +Target: vcpu +Parameters: args[0] is reserved for future use (should be 0). + +This capability allows the use of the host Floating Point Unit by the guest. It +allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is +done the KVM_REG_MIPS_FPR_* and KVM_REG_MIPS_FCR_* registers can be accessed +(depending on the current guest FPU register mode), and the Status.FR, +Config5.FRE bits are accessible via the KVM API and also from the guest, +depending on them being supported by the FPU. + 7. Capabilities that can be enabled on VMs ------------------------------------------
arch/mips/kvm/mips.c +37 -0
@@ -797,6 +797,30 @@ static int kvm_mips_set_reg(struct kvm_vcpu *vcpu,return 0 ; } +static int kvm_vcpu_ioctl_enable_cap (struct kvm_vcpu *vcpu, +struct kvm_enable_cap *cap) +{ +int r =0 ; + +if (!kvm_vm_ioctl_check_extension (vcpu->kvm, cap->cap)) +return -EINVAL ; +if (cap->flags) +return -EINVAL ; +if (cap->args[0 ]) +return -EINVAL ; + +switch (cap->cap) { +case KVM_CAP_MIPS_FPU : + vcpu->arch.fpu_enabled = true; +break ; +default : + r = -EINVAL ; +break ; + } + +return r; +} +long kvm_arch_vcpu_ioctl (struct file *filp,unsigned int ioctl,unsigned long arg) {
@@ -854,6 +878,15 @@ long kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, r =kvm_vcpu_ioctl_interrupt (vcpu, &irq);break ; } +case KVM_ENABLE_CAP : { +struct kvm_enable_cap cap; + + r = -EFAULT ; +if (copy_from_user (&cap, argp,sizeof (cap))) + goto out; + r =kvm_vcpu_ioctl_enable_cap (vcpu, &cap); +break ; + }default : r = -ENOIOCTLCMD ; }
@@ -962,11 +995,15 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)switch (ext) {case KVM_CAP_ONE_REG : +case KVM_CAP_ENABLE_CAP : r =1 ;break ;case KVM_CAP_COALESCED_MMIO : r =KVM_COALESCED_MMIO_PAGE_OFFSET ;break ; +case KVM_CAP_MIPS_FPU : + r = !!cpu_has_fpu; +break ;default : r =0 ;break ;
include/uapi/linux/kvm.h +1 -0
@@ -761,6 +761,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_CHECK_EXTENSION_VM 105#define KVM_CAP_S390_USER_SIGP 106#define KVM_CAP_S390_VECTOR_REGISTERS 107 +#define KVM_CAP_MIPS_FPU 108#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
2.0.5
A message that is not in the archive (sent off-list or not yet received): 1427386113-30515-1-git-send-email-james.hogan-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org
PATCH v2 19/20 MIPS: KVM: Expose MSA registers
Add KVM register numbers for the MIPS SIMD Architecture (MSA) registers, and implement access to them with the KVM_GET_ONE_REG / KVM_SET_ONE_REG ioctls when the MSA capability is enabled (exposed in a later patch) and present in the guest according to its Config3.MSAP bit.
The MSA vector registers use the same register numbers as the FPU registers except with a different size (128bits). Since MSA depends on Status.FR=1, these registers are inaccessible when Status.FR=0. These registers are returned as a single native endian 128bit value, rather than least significant half first with each 64-bit half native endian as the kernel uses internally.
---
Changes in v2:
- Add missing MSA vector and control register id bit patterns to API documentation.
--- Documentation/virtual/kvm/api.txt | 12 +++++++- arch/mips/include/uapi/asm/kvm.h | 12 ++++++-- arch/mips/kvm/mips.c | 65 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 3 deletions(-)
Documentation/virtual/kvm/api.txt +11 -1
@@ -1981,8 +1981,11 @@ registers, find a list below: MIPS | KVM_REG_MIPS_COUNT_HZ | 64 MIPS | KVM_REG_MIPS_FPR_32(0..31) | 32 MIPS | KVM_REG_MIPS_FPR_64(0..31) | 64 + MIPS | KVM_REG_MIPS_VEC_128(0..31) | 128 MIPS | KVM_REG_MIPS_FCR_IR | 32 MIPS | KVM_REG_MIPS_FCR_CSR | 32 + MIPS | KVM_REG_MIPS_MSA_IR | 32 + MIPS | KVM_REG_MIPS_MSA_CSR | 32 ARM registers are mapped using the lower 32 bits. The upper 16 of that is the register group type, or coprocessor number:
@@ -2040,14 +2043,21 @@ MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following id bit patterns depending on the size of the register being accessed. They are always accessed according to the current guest FPU mode (Status.FR and Config5.FRE), i.e. as the guest would see them, and they become unpredictable -if the guest FPU mode is changed: +if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector +registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they +overlap the FPU registers: 0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers) 0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers) + 0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers) MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the following id bit patterns: 0x7020 0000 0003 01 <0:3> <reg:5> +MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the +following id bit patterns: + 0x7020 0000 0003 02 <0:3> <reg:5> + 4.69 KVM_GET_ONE_REG
arch/mips/include/uapi/asm/kvm.h +10 -2
@@ -58,7 +58,7 @@ struct kvm_fpu {* * Register set = 2: KVM specific registers (see definitions below). * -* Register set = 3: FPU registers (see definitions below). +* Register set = 3: FPU / MSA registers (see definitions below). * * Other sets registers may be added in the future. Each set would * have its own identifier in bits[31..16].
@@ -148,7 +148,7 @@ struct kvm_fpu {/* -* KVM_REG_MIPS_FPU - Floating Point registers. +* KVM_REG_MIPS_FPU - Floating Point and MIPS SIMD Architecture (MSA) registers. * * bits[15..8] - Register subset (see definitions below). * bits[7..5] - Must be zero.
@@ -157,12 +157,14 @@ struct kvm_fpu {#define KVM_REG_MIPS_FPR (KVM_REG_MIPS_FPU | 0x0000000000000000ULL)#define KVM_REG_MIPS_FCR (KVM_REG_MIPS_FPU | 0x0000000000000100ULL) +#define KVM_REG_MIPS_MSACR (KVM_REG_MIPS_FPU | 0x0000000000000200ULL)/* * KVM_REG_MIPS_FPR - Floating point / Vector registers. */ #define KVM_REG_MIPS_FPR_32 (n) (KVM_REG_MIPS_FPR | KVM_REG_SIZE_U32 | (n))#define KVM_REG_MIPS_FPR_64 (n) (KVM_REG_MIPS_FPR | KVM_REG_SIZE_U64 | (n)) +#define KVM_REG_MIPS_VEC_128 (n) (KVM_REG_MIPS_FPR | KVM_REG_SIZE_U128 | (n))/* * KVM_REG_MIPS_FCR - Floating point control registers.
@@ -170,6 +172,12 @@ struct kvm_fpu {#define KVM_REG_MIPS_FCR_IR (KVM_REG_MIPS_FCR | KVM_REG_SIZE_U32 | 0)#define KVM_REG_MIPS_FCR_CSR (KVM_REG_MIPS_FCR | KVM_REG_SIZE_U32 | 31) +/* +* KVM_REG_MIPS_MSACR - MIPS SIMD Architecture (MSA) control registers. +*/ +#define KVM_REG_MIPS_MSA_IR (KVM_REG_MIPS_MSACR | KVM_REG_SIZE_U32 | 0) +#define KVM_REG_MIPS_MSA_CSR (KVM_REG_MIPS_MSACR | KVM_REG_SIZE_U32 | 1) +/* * KVM MIPS specific structures and definitions
arch/mips/kvm/mips.c +65 -0
101 lines not on this page · raw message
Signature · 1 line
2.0.5
PATCH v2 20/20 MIPS: KVM: Wire up MSA capability
In reply to James HoganNow that the code is in place for KVM to support MIPS SIMD Architecutre (MSA) in MIPS guests, wire up the new KVM_CAP_MIPS_MSA capability.
For backwards compatibility, the capability must be explicitly enabled in order to detect or make use of MSA from the guest.
The capability is not supported if the hardware supports MSA vector partitioning, since the extra support cannot be tested yet and it extends the state that the userland program would have to save.
---
Changes in v2:
- Rebased on KVM queue (KVM_CAP_MIPS_MSA increased to 109 after KVM_CAP_S390_VECTOR_REGISTERS took 107).
- Drop the MSA capability presence check from kvm_vcpu_ioctl_enable_cap() now that it already calls kvm_vm_ioctl_check_extension() (Paolo).
--- Documentation/virtual/kvm/api.txt | 12 ++++++++++++ arch/mips/kvm/mips.c | 18 ++++++++++++++++++ include/uapi/linux/kvm.h | 1 + 3 files changed, 31 insertions(+)
Documentation/virtual/kvm/api.txt +12 -0
@@ -3231,6 +3231,18 @@ done the KVM_REG_MIPS_FPR_* and KVM_REG_MIPS_FCR_* registers can be accessed Config5.FRE bits are accessible via the KVM API and also from the guest, depending on them being supported by the FPU. +6.10 KVM_CAP_MIPS_MSA + +Architectures: mips +Target: vcpu +Parameters: args[0] is reserved for future use (should be 0). + +This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest. +It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest. +Once this is done the KVM_REG_MIPS_VEC_* and KVM_REG_MIPS_MSA_* registers can be +accessed, and the Config5.MSAEn bit is accessible via the KVM API and also from +the guest. + 7. Capabilities that can be enabled on VMs ------------------------------------------
arch/mips/kvm/mips.c +18 -0
@@ -880,6 +880,9 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,case KVM_CAP_MIPS_FPU : vcpu->arch.fpu_enabled = true;break ; +case KVM_CAP_MIPS_MSA : + vcpu->arch.msa_enabled = true; +break ;default : r = -EINVAL ;break ;
@@ -1071,6 +1074,21 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)case KVM_CAP_MIPS_FPU : r = !!cpu_has_fpu;break ; +case KVM_CAP_MIPS_MSA : +/* +* We don't support MSA vector partitioning yet: +* 1) It would require explicit support which can't be tested +* yet due to lack of support in current hardware. +* 2) It extends the state that would need to be saved/restored +* by e.g. QEMU for migration. +* +* When vector partitioning hardware becomes available, support +* could be added by requiring a flag when enabling +* KVM_CAP_MIPS_MSA capability to indicate that userland knows +* to save/restore the appropriate extra state. +*/ + r = cpu_has_msa && !(boot_cpu_data.msa_id &MSA_IR_WRPF ); +break ;default : r =0 ;break ;
include/uapi/linux/kvm.h +1 -0
@@ -762,6 +762,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_S390_USER_SIGP 106#define KVM_CAP_S390_VECTOR_REGISTERS 107#define KVM_CAP_MIPS_FPU 108 +#define KVM_CAP_MIPS_MSA 109#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
2.0.5
Paolo Bonzini
maintainerQuoted 8 lines · James Hogan
This patchset primarily adds guest Floating Point Unit (FPU) and MIPS SIMD Architecture (MSA) support to MIPS KVM, by enabling the host FPU/MSA while in guest mode.
This patchset depends on Paul Burton's FP/MSA fixes patchset, which will make it into 4.0. I've only included the 3 patches (15, 19, 20) that have changed since v1, which can be found here:
http://thread.gmane.org/gmane.linux.kernel.api/8984
Thanks, the fixes look good.
Paolo