aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390/kvm/kvm-s390.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/s390/kvm/kvm-s390.c')
-rw-r--r--arch/s390/kvm/kvm-s390.c69
1 files changed, 31 insertions, 38 deletions
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 0c3623927563..19e17bd7aec0 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -165,7 +165,6 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
165 case KVM_CAP_ONE_REG: 165 case KVM_CAP_ONE_REG:
166 case KVM_CAP_ENABLE_CAP: 166 case KVM_CAP_ENABLE_CAP:
167 case KVM_CAP_S390_CSS_SUPPORT: 167 case KVM_CAP_S390_CSS_SUPPORT:
168 case KVM_CAP_IRQFD:
169 case KVM_CAP_IOEVENTFD: 168 case KVM_CAP_IOEVENTFD:
170 case KVM_CAP_DEVICE_CTRL: 169 case KVM_CAP_DEVICE_CTRL:
171 case KVM_CAP_ENABLE_CAP_VM: 170 case KVM_CAP_ENABLE_CAP_VM:
@@ -522,7 +521,7 @@ static int kvm_s390_set_processor(struct kvm *kvm, struct kvm_device_attr *attr)
522 memcpy(&kvm->arch.model.cpu_id, &proc->cpuid, 521 memcpy(&kvm->arch.model.cpu_id, &proc->cpuid,
523 sizeof(struct cpuid)); 522 sizeof(struct cpuid));
524 kvm->arch.model.ibc = proc->ibc; 523 kvm->arch.model.ibc = proc->ibc;
525 memcpy(kvm->arch.model.fac->kvm, proc->fac_list, 524 memcpy(kvm->arch.model.fac->list, proc->fac_list,
526 S390_ARCH_FAC_LIST_SIZE_BYTE); 525 S390_ARCH_FAC_LIST_SIZE_BYTE);
527 } else 526 } else
528 ret = -EFAULT; 527 ret = -EFAULT;
@@ -556,7 +555,7 @@ static int kvm_s390_get_processor(struct kvm *kvm, struct kvm_device_attr *attr)
556 } 555 }
557 memcpy(&proc->cpuid, &kvm->arch.model.cpu_id, sizeof(struct cpuid)); 556 memcpy(&proc->cpuid, &kvm->arch.model.cpu_id, sizeof(struct cpuid));
558 proc->ibc = kvm->arch.model.ibc; 557 proc->ibc = kvm->arch.model.ibc;
559 memcpy(&proc->fac_list, kvm->arch.model.fac->kvm, S390_ARCH_FAC_LIST_SIZE_BYTE); 558 memcpy(&proc->fac_list, kvm->arch.model.fac->list, S390_ARCH_FAC_LIST_SIZE_BYTE);
560 if (copy_to_user((void __user *)attr->addr, proc, sizeof(*proc))) 559 if (copy_to_user((void __user *)attr->addr, proc, sizeof(*proc)))
561 ret = -EFAULT; 560 ret = -EFAULT;
562 kfree(proc); 561 kfree(proc);
@@ -576,10 +575,10 @@ static int kvm_s390_get_machine(struct kvm *kvm, struct kvm_device_attr *attr)
576 } 575 }
577 get_cpu_id((struct cpuid *) &mach->cpuid); 576 get_cpu_id((struct cpuid *) &mach->cpuid);
578 mach->ibc = sclp_get_ibc(); 577 mach->ibc = sclp_get_ibc();
579 memcpy(&mach->fac_mask, kvm_s390_fac_list_mask, 578 memcpy(&mach->fac_mask, kvm->arch.model.fac->mask,
580 kvm_s390_fac_list_mask_size() * sizeof(u64)); 579 S390_ARCH_FAC_LIST_SIZE_BYTE);
581 memcpy((unsigned long *)&mach->fac_list, S390_lowcore.stfle_fac_list, 580 memcpy((unsigned long *)&mach->fac_list, S390_lowcore.stfle_fac_list,
582 S390_ARCH_FAC_LIST_SIZE_U64); 581 S390_ARCH_FAC_LIST_SIZE_BYTE);
583 if (copy_to_user((void __user *)attr->addr, mach, sizeof(*mach))) 582 if (copy_to_user((void __user *)attr->addr, mach, sizeof(*mach)))
584 ret = -EFAULT; 583 ret = -EFAULT;
585 kfree(mach); 584 kfree(mach);
@@ -778,15 +777,18 @@ long kvm_arch_vm_ioctl(struct file *filp,
778static int kvm_s390_query_ap_config(u8 *config) 777static int kvm_s390_query_ap_config(u8 *config)
779{ 778{
780 u32 fcn_code = 0x04000000UL; 779 u32 fcn_code = 0x04000000UL;
781 u32 cc; 780 u32 cc = 0;
782 781
782 memset(config, 0, 128);
783 asm volatile( 783 asm volatile(
784 "lgr 0,%1\n" 784 "lgr 0,%1\n"
785 "lgr 2,%2\n" 785 "lgr 2,%2\n"
786 ".long 0xb2af0000\n" /* PQAP(QCI) */ 786 ".long 0xb2af0000\n" /* PQAP(QCI) */
787 "ipm %0\n" 787 "0: ipm %0\n"
788 "srl %0,28\n" 788 "srl %0,28\n"
789 : "=r" (cc) 789 "1:\n"
790 EX_TABLE(0b, 1b)
791 : "+r" (cc)
790 : "r" (fcn_code), "r" (config) 792 : "r" (fcn_code), "r" (config)
791 : "cc", "0", "2", "memory" 793 : "cc", "0", "2", "memory"
792 ); 794 );
@@ -839,9 +841,13 @@ static int kvm_s390_crypto_init(struct kvm *kvm)
839 841
840 kvm_s390_set_crycb_format(kvm); 842 kvm_s390_set_crycb_format(kvm);
841 843
842 /* Disable AES/DEA protected key functions by default */ 844 /* Enable AES/DEA protected key functions by default */
843 kvm->arch.crypto.aes_kw = 0; 845 kvm->arch.crypto.aes_kw = 1;
844 kvm->arch.crypto.dea_kw = 0; 846 kvm->arch.crypto.dea_kw = 1;
847 get_random_bytes(kvm->arch.crypto.crycb->aes_wrapping_key_mask,
848 sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask));
849 get_random_bytes(kvm->arch.crypto.crycb->dea_wrapping_key_mask,
850 sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask));
845 851
846 return 0; 852 return 0;
847} 853}
@@ -886,40 +892,29 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
886 /* 892 /*
887 * The architectural maximum amount of facilities is 16 kbit. To store 893 * The architectural maximum amount of facilities is 16 kbit. To store
888 * this amount, 2 kbyte of memory is required. Thus we need a full 894 * this amount, 2 kbyte of memory is required. Thus we need a full
889 * page to hold the active copy (arch.model.fac->sie) and the current 895 * page to hold the guest facility list (arch.model.fac->list) and the
890 * facilities set (arch.model.fac->kvm). Its address size has to be 896 * facility mask (arch.model.fac->mask). Its address size has to be
891 * 31 bits and word aligned. 897 * 31 bits and word aligned.
892 */ 898 */
893 kvm->arch.model.fac = 899 kvm->arch.model.fac =
894 (struct s390_model_fac *) get_zeroed_page(GFP_KERNEL | GFP_DMA); 900 (struct kvm_s390_fac *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
895 if (!kvm->arch.model.fac) 901 if (!kvm->arch.model.fac)
896 goto out_nofac; 902 goto out_nofac;
897 903
898 memcpy(kvm->arch.model.fac->kvm, S390_lowcore.stfle_fac_list, 904 /* Populate the facility mask initially. */
899 S390_ARCH_FAC_LIST_SIZE_U64); 905 memcpy(kvm->arch.model.fac->mask, S390_lowcore.stfle_fac_list,
900 906 S390_ARCH_FAC_LIST_SIZE_BYTE);
901 /*
902 * If this KVM host runs *not* in a LPAR, relax the facility bits
903 * of the kvm facility mask by all missing facilities. This will allow
904 * to determine the right CPU model by means of the remaining facilities.
905 * Live guest migration must prohibit the migration of KVMs running in
906 * a LPAR to non LPAR hosts.
907 */
908 if (!MACHINE_IS_LPAR)
909 for (i = 0; i < kvm_s390_fac_list_mask_size(); i++)
910 kvm_s390_fac_list_mask[i] &= kvm->arch.model.fac->kvm[i];
911
912 /*
913 * Apply the kvm facility mask to limit the kvm supported/tolerated
914 * facility list.
915 */
916 for (i = 0; i < S390_ARCH_FAC_LIST_SIZE_U64; i++) { 907 for (i = 0; i < S390_ARCH_FAC_LIST_SIZE_U64; i++) {
917 if (i < kvm_s390_fac_list_mask_size()) 908 if (i < kvm_s390_fac_list_mask_size())
918 kvm->arch.model.fac->kvm[i] &= kvm_s390_fac_list_mask[i]; 909 kvm->arch.model.fac->mask[i] &= kvm_s390_fac_list_mask[i];
919 else 910 else
920 kvm->arch.model.fac->kvm[i] = 0UL; 911 kvm->arch.model.fac->mask[i] = 0UL;
921 } 912 }
922 913
914 /* Populate the facility list initially. */
915 memcpy(kvm->arch.model.fac->list, kvm->arch.model.fac->mask,
916 S390_ARCH_FAC_LIST_SIZE_BYTE);
917
923 kvm_s390_get_cpu_id(&kvm->arch.model.cpu_id); 918 kvm_s390_get_cpu_id(&kvm->arch.model.cpu_id);
924 kvm->arch.model.ibc = sclp_get_ibc() & 0x0fff; 919 kvm->arch.model.ibc = sclp_get_ibc() & 0x0fff;
925 920
@@ -1165,8 +1160,6 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
1165 1160
1166 mutex_lock(&vcpu->kvm->lock); 1161 mutex_lock(&vcpu->kvm->lock);
1167 vcpu->arch.cpu_id = vcpu->kvm->arch.model.cpu_id; 1162 vcpu->arch.cpu_id = vcpu->kvm->arch.model.cpu_id;
1168 memcpy(vcpu->kvm->arch.model.fac->sie, vcpu->kvm->arch.model.fac->kvm,
1169 S390_ARCH_FAC_LIST_SIZE_BYTE);
1170 vcpu->arch.sie_block->ibc = vcpu->kvm->arch.model.ibc; 1163 vcpu->arch.sie_block->ibc = vcpu->kvm->arch.model.ibc;
1171 mutex_unlock(&vcpu->kvm->lock); 1164 mutex_unlock(&vcpu->kvm->lock);
1172 1165
@@ -1212,7 +1205,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
1212 vcpu->arch.sie_block->scaol = (__u32)(__u64)kvm->arch.sca; 1205 vcpu->arch.sie_block->scaol = (__u32)(__u64)kvm->arch.sca;
1213 set_bit(63 - id, (unsigned long *) &kvm->arch.sca->mcn); 1206 set_bit(63 - id, (unsigned long *) &kvm->arch.sca->mcn);
1214 } 1207 }
1215 vcpu->arch.sie_block->fac = (int) (long) kvm->arch.model.fac->sie; 1208 vcpu->arch.sie_block->fac = (int) (long) kvm->arch.model.fac->list;
1216 1209
1217 spin_lock_init(&vcpu->arch.local_int.lock); 1210 spin_lock_init(&vcpu->arch.local_int.lock);
1218 vcpu->arch.local_int.float_int = &kvm->arch.float_int; 1211 vcpu->arch.local_int.float_int = &kvm->arch.float_int;