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

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.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Gleb Natapov <gleb@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Cc: linux-api@vger.kernel.org
Cc: linux-doc@vger.kernel.org

+51
+13
Documentation/virtual/kvm/api.txt
··· 3312 3312 This capability enables the in-kernel irqchip for s390. Please refer to 3313 3313 "4.24 KVM_CREATE_IRQCHIP" for details. 3314 3314 3315 + 6.9 KVM_CAP_MIPS_FPU 3316 + 3317 + Architectures: mips 3318 + Target: vcpu 3319 + Parameters: args[0] is reserved for future use (should be 0). 3320 + 3321 + This capability allows the use of the host Floating Point Unit by the guest. It 3322 + allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is 3323 + done the KVM_REG_MIPS_FPR_* and KVM_REG_MIPS_FCR_* registers can be accessed 3324 + (depending on the current guest FPU register mode), and the Status.FR, 3325 + Config5.FRE bits are accessible via the KVM API and also from the guest, 3326 + depending on them being supported by the FPU. 3327 + 3315 3328 7. Capabilities that can be enabled on VMs 3316 3329 ------------------------------------------ 3317 3330
+37
arch/mips/kvm/mips.c
··· 797 797 return 0; 798 798 } 799 799 800 + static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, 801 + struct kvm_enable_cap *cap) 802 + { 803 + int r = 0; 804 + 805 + if (!kvm_vm_ioctl_check_extension(vcpu->kvm, cap->cap)) 806 + return -EINVAL; 807 + if (cap->flags) 808 + return -EINVAL; 809 + if (cap->args[0]) 810 + return -EINVAL; 811 + 812 + switch (cap->cap) { 813 + case KVM_CAP_MIPS_FPU: 814 + vcpu->arch.fpu_enabled = true; 815 + break; 816 + default: 817 + r = -EINVAL; 818 + break; 819 + } 820 + 821 + return r; 822 + } 823 + 800 824 long kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, 801 825 unsigned long arg) 802 826 { ··· 878 854 r = kvm_vcpu_ioctl_interrupt(vcpu, &irq); 879 855 break; 880 856 } 857 + case KVM_ENABLE_CAP: { 858 + struct kvm_enable_cap cap; 859 + 860 + r = -EFAULT; 861 + if (copy_from_user(&cap, argp, sizeof(cap))) 862 + goto out; 863 + r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap); 864 + break; 865 + } 881 866 default: 882 867 r = -ENOIOCTLCMD; 883 868 } ··· 995 962 996 963 switch (ext) { 997 964 case KVM_CAP_ONE_REG: 965 + case KVM_CAP_ENABLE_CAP: 998 966 r = 1; 999 967 break; 1000 968 case KVM_CAP_COALESCED_MMIO: 1001 969 r = KVM_COALESCED_MMIO_PAGE_OFFSET; 970 + break; 971 + case KVM_CAP_MIPS_FPU: 972 + r = !!cpu_has_fpu; 1002 973 break; 1003 974 default: 1004 975 r = 0;
+1
include/uapi/linux/kvm.h
··· 802 802 #define KVM_CAP_S390_MEM_OP 108 803 803 #define KVM_CAP_S390_USER_STSI 109 804 804 #define KVM_CAP_S390_SKEYS 110 805 + #define KVM_CAP_MIPS_FPU 111 805 806 806 807 #ifdef KVM_CAP_IRQ_ROUTING 807 808