Lines Matching refs:kvm

270 static int sca_switch_to_extended(struct kvm *kvm);
303 struct kvm *kvm; in kvm_clock_sync() local
308 list_for_each_entry(kvm, &vm_list, vm_list) { in kvm_clock_sync()
309 kvm_for_each_vcpu(i, vcpu, kvm) { in kvm_clock_sync()
312 kvm->arch.epoch = vcpu->arch.sie_block->epoch; in kvm_clock_sync()
313 kvm->arch.epdx = vcpu->arch.sie_block->epdx; in kvm_clock_sync()
559 int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) in kvm_vm_ioctl_check_extension() argument
600 if (hpage && !(kvm && kvm_is_ucontrol(kvm))) in kvm_vm_ioctl_check_extension()
679 void kvm_arch_sync_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot) in kvm_arch_sync_dirty_log() argument
684 struct gmap *gmap = kvm->arch.gmap; in kvm_arch_sync_dirty_log()
700 mark_page_dirty(kvm, cur_gfn + i); in kvm_arch_sync_dirty_log()
715 int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, in kvm_vm_ioctl_get_dirty_log() argument
723 if (kvm_is_ucontrol(kvm)) in kvm_vm_ioctl_get_dirty_log()
726 mutex_lock(&kvm->slots_lock); in kvm_vm_ioctl_get_dirty_log()
732 r = kvm_get_dirty_log(kvm, log, &is_dirty, &memslot); in kvm_vm_ioctl_get_dirty_log()
743 mutex_unlock(&kvm->slots_lock); in kvm_vm_ioctl_get_dirty_log()
747 static void icpt_operexc_on_all_vcpus(struct kvm *kvm) in icpt_operexc_on_all_vcpus() argument
752 kvm_for_each_vcpu(i, vcpu, kvm) { in icpt_operexc_on_all_vcpus()
757 int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap) in kvm_vm_ioctl_enable_cap() argument
766 VM_EVENT(kvm, 3, "%s", "ENABLE: CAP_S390_IRQCHIP"); in kvm_vm_ioctl_enable_cap()
767 kvm->arch.use_irqchip = 1; in kvm_vm_ioctl_enable_cap()
771 VM_EVENT(kvm, 3, "%s", "ENABLE: CAP_S390_USER_SIGP"); in kvm_vm_ioctl_enable_cap()
772 kvm->arch.user_sigp = 1; in kvm_vm_ioctl_enable_cap()
776 mutex_lock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
777 if (kvm->created_vcpus) { in kvm_vm_ioctl_enable_cap()
780 set_kvm_facility(kvm->arch.model.fac_mask, 129); in kvm_vm_ioctl_enable_cap()
781 set_kvm_facility(kvm->arch.model.fac_list, 129); in kvm_vm_ioctl_enable_cap()
783 set_kvm_facility(kvm->arch.model.fac_mask, 134); in kvm_vm_ioctl_enable_cap()
784 set_kvm_facility(kvm->arch.model.fac_list, 134); in kvm_vm_ioctl_enable_cap()
787 set_kvm_facility(kvm->arch.model.fac_mask, 135); in kvm_vm_ioctl_enable_cap()
788 set_kvm_facility(kvm->arch.model.fac_list, 135); in kvm_vm_ioctl_enable_cap()
791 set_kvm_facility(kvm->arch.model.fac_mask, 148); in kvm_vm_ioctl_enable_cap()
792 set_kvm_facility(kvm->arch.model.fac_list, 148); in kvm_vm_ioctl_enable_cap()
795 set_kvm_facility(kvm->arch.model.fac_mask, 152); in kvm_vm_ioctl_enable_cap()
796 set_kvm_facility(kvm->arch.model.fac_list, 152); in kvm_vm_ioctl_enable_cap()
799 set_kvm_facility(kvm->arch.model.fac_mask, 192); in kvm_vm_ioctl_enable_cap()
800 set_kvm_facility(kvm->arch.model.fac_list, 192); in kvm_vm_ioctl_enable_cap()
805 mutex_unlock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
806 VM_EVENT(kvm, 3, "ENABLE: CAP_S390_VECTOR_REGISTERS %s", in kvm_vm_ioctl_enable_cap()
811 mutex_lock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
812 if (kvm->created_vcpus) { in kvm_vm_ioctl_enable_cap()
815 set_kvm_facility(kvm->arch.model.fac_mask, 64); in kvm_vm_ioctl_enable_cap()
816 set_kvm_facility(kvm->arch.model.fac_list, 64); in kvm_vm_ioctl_enable_cap()
819 mutex_unlock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
820 VM_EVENT(kvm, 3, "ENABLE: CAP_S390_RI %s", in kvm_vm_ioctl_enable_cap()
824 mutex_lock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
825 if (kvm->created_vcpus) { in kvm_vm_ioctl_enable_cap()
828 set_kvm_facility(kvm->arch.model.fac_mask, 72); in kvm_vm_ioctl_enable_cap()
829 set_kvm_facility(kvm->arch.model.fac_list, 72); in kvm_vm_ioctl_enable_cap()
832 mutex_unlock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
833 VM_EVENT(kvm, 3, "ENABLE: AIS %s", in kvm_vm_ioctl_enable_cap()
838 mutex_lock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
839 if (kvm->created_vcpus) { in kvm_vm_ioctl_enable_cap()
842 set_kvm_facility(kvm->arch.model.fac_mask, 133); in kvm_vm_ioctl_enable_cap()
843 set_kvm_facility(kvm->arch.model.fac_list, 133); in kvm_vm_ioctl_enable_cap()
846 mutex_unlock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
847 VM_EVENT(kvm, 3, "ENABLE: CAP_S390_GS %s", in kvm_vm_ioctl_enable_cap()
851 mutex_lock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
852 if (kvm->created_vcpus) in kvm_vm_ioctl_enable_cap()
854 else if (!hpage || kvm->arch.use_cmma || kvm_is_ucontrol(kvm)) in kvm_vm_ioctl_enable_cap()
858 mmap_write_lock(kvm->mm); in kvm_vm_ioctl_enable_cap()
859 kvm->mm->context.allow_gmap_hpage_1m = 1; in kvm_vm_ioctl_enable_cap()
860 mmap_write_unlock(kvm->mm); in kvm_vm_ioctl_enable_cap()
866 kvm->arch.use_skf = 0; in kvm_vm_ioctl_enable_cap()
867 kvm->arch.use_pfmfi = 0; in kvm_vm_ioctl_enable_cap()
869 mutex_unlock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
870 VM_EVENT(kvm, 3, "ENABLE: CAP_S390_HPAGE %s", in kvm_vm_ioctl_enable_cap()
874 VM_EVENT(kvm, 3, "%s", "ENABLE: CAP_S390_USER_STSI"); in kvm_vm_ioctl_enable_cap()
875 kvm->arch.user_stsi = 1; in kvm_vm_ioctl_enable_cap()
879 VM_EVENT(kvm, 3, "%s", "ENABLE: CAP_S390_USER_INSTR0"); in kvm_vm_ioctl_enable_cap()
880 kvm->arch.user_instr0 = 1; in kvm_vm_ioctl_enable_cap()
881 icpt_operexc_on_all_vcpus(kvm); in kvm_vm_ioctl_enable_cap()
886 mutex_lock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
887 if (kvm->created_vcpus) { in kvm_vm_ioctl_enable_cap()
890 set_kvm_facility(kvm->arch.model.fac_mask, 11); in kvm_vm_ioctl_enable_cap()
891 set_kvm_facility(kvm->arch.model.fac_list, 11); in kvm_vm_ioctl_enable_cap()
894 mutex_unlock(&kvm->lock); in kvm_vm_ioctl_enable_cap()
895 VM_EVENT(kvm, 3, "ENABLE: CAP_S390_CPU_TOPOLOGY %s", in kvm_vm_ioctl_enable_cap()
905 static int kvm_s390_get_mem_control(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_get_mem_control() argument
912 VM_EVENT(kvm, 3, "QUERY: max guest memory: %lu bytes", in kvm_s390_get_mem_control()
913 kvm->arch.mem_limit); in kvm_s390_get_mem_control()
914 if (put_user(kvm->arch.mem_limit, (u64 __user *)attr->addr)) in kvm_s390_get_mem_control()
924 static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_set_mem_control() argument
934 VM_EVENT(kvm, 3, "%s", "ENABLE: CMMA support"); in kvm_s390_set_mem_control()
935 mutex_lock(&kvm->lock); in kvm_s390_set_mem_control()
936 if (kvm->created_vcpus) in kvm_s390_set_mem_control()
938 else if (kvm->mm->context.allow_gmap_hpage_1m) in kvm_s390_set_mem_control()
941 kvm->arch.use_cmma = 1; in kvm_s390_set_mem_control()
943 kvm->arch.use_pfmfi = 0; in kvm_s390_set_mem_control()
946 mutex_unlock(&kvm->lock); in kvm_s390_set_mem_control()
953 if (!kvm->arch.use_cmma) in kvm_s390_set_mem_control()
956 VM_EVENT(kvm, 3, "%s", "RESET: CMMA states"); in kvm_s390_set_mem_control()
957 mutex_lock(&kvm->lock); in kvm_s390_set_mem_control()
958 idx = srcu_read_lock(&kvm->srcu); in kvm_s390_set_mem_control()
959 s390_reset_cmma(kvm->arch.gmap->mm); in kvm_s390_set_mem_control()
960 srcu_read_unlock(&kvm->srcu, idx); in kvm_s390_set_mem_control()
961 mutex_unlock(&kvm->lock); in kvm_s390_set_mem_control()
967 if (kvm_is_ucontrol(kvm)) in kvm_s390_set_mem_control()
973 if (kvm->arch.mem_limit != KVM_S390_NO_MEM_LIMIT && in kvm_s390_set_mem_control()
974 new_limit > kvm->arch.mem_limit) in kvm_s390_set_mem_control()
985 mutex_lock(&kvm->lock); in kvm_s390_set_mem_control()
986 if (!kvm->created_vcpus) { in kvm_s390_set_mem_control()
993 gmap_remove(kvm->arch.gmap); in kvm_s390_set_mem_control()
994 new->private = kvm; in kvm_s390_set_mem_control()
995 kvm->arch.gmap = new; in kvm_s390_set_mem_control()
999 mutex_unlock(&kvm->lock); in kvm_s390_set_mem_control()
1000 VM_EVENT(kvm, 3, "SET: max guest address: %lu", new_limit); in kvm_s390_set_mem_control()
1001 VM_EVENT(kvm, 3, "New guest asce: 0x%pK", in kvm_s390_set_mem_control()
1002 (void *) kvm->arch.gmap->asce); in kvm_s390_set_mem_control()
1014 void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm) in kvm_s390_vcpu_crypto_reset_all() argument
1019 kvm_s390_vcpu_block_all(kvm); in kvm_s390_vcpu_crypto_reset_all()
1021 kvm_for_each_vcpu(i, vcpu, kvm) { in kvm_s390_vcpu_crypto_reset_all()
1027 kvm_s390_vcpu_unblock_all(kvm); in kvm_s390_vcpu_crypto_reset_all()
1030 static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_vm_set_crypto() argument
1032 mutex_lock(&kvm->lock); in kvm_s390_vm_set_crypto()
1035 if (!test_kvm_facility(kvm, 76)) { in kvm_s390_vm_set_crypto()
1036 mutex_unlock(&kvm->lock); in kvm_s390_vm_set_crypto()
1040 kvm->arch.crypto.crycb->aes_wrapping_key_mask, in kvm_s390_vm_set_crypto()
1041 sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask)); in kvm_s390_vm_set_crypto()
1042 kvm->arch.crypto.aes_kw = 1; in kvm_s390_vm_set_crypto()
1043 VM_EVENT(kvm, 3, "%s", "ENABLE: AES keywrapping support"); in kvm_s390_vm_set_crypto()
1046 if (!test_kvm_facility(kvm, 76)) { in kvm_s390_vm_set_crypto()
1047 mutex_unlock(&kvm->lock); in kvm_s390_vm_set_crypto()
1051 kvm->arch.crypto.crycb->dea_wrapping_key_mask, in kvm_s390_vm_set_crypto()
1052 sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask)); in kvm_s390_vm_set_crypto()
1053 kvm->arch.crypto.dea_kw = 1; in kvm_s390_vm_set_crypto()
1054 VM_EVENT(kvm, 3, "%s", "ENABLE: DEA keywrapping support"); in kvm_s390_vm_set_crypto()
1057 if (!test_kvm_facility(kvm, 76)) { in kvm_s390_vm_set_crypto()
1058 mutex_unlock(&kvm->lock); in kvm_s390_vm_set_crypto()
1061 kvm->arch.crypto.aes_kw = 0; in kvm_s390_vm_set_crypto()
1062 memset(kvm->arch.crypto.crycb->aes_wrapping_key_mask, 0, in kvm_s390_vm_set_crypto()
1063 sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask)); in kvm_s390_vm_set_crypto()
1064 VM_EVENT(kvm, 3, "%s", "DISABLE: AES keywrapping support"); in kvm_s390_vm_set_crypto()
1067 if (!test_kvm_facility(kvm, 76)) { in kvm_s390_vm_set_crypto()
1068 mutex_unlock(&kvm->lock); in kvm_s390_vm_set_crypto()
1071 kvm->arch.crypto.dea_kw = 0; in kvm_s390_vm_set_crypto()
1072 memset(kvm->arch.crypto.crycb->dea_wrapping_key_mask, 0, in kvm_s390_vm_set_crypto()
1073 sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask)); in kvm_s390_vm_set_crypto()
1074 VM_EVENT(kvm, 3, "%s", "DISABLE: DEA keywrapping support"); in kvm_s390_vm_set_crypto()
1078 mutex_unlock(&kvm->lock); in kvm_s390_vm_set_crypto()
1081 kvm->arch.crypto.apie = 1; in kvm_s390_vm_set_crypto()
1085 mutex_unlock(&kvm->lock); in kvm_s390_vm_set_crypto()
1088 kvm->arch.crypto.apie = 0; in kvm_s390_vm_set_crypto()
1091 mutex_unlock(&kvm->lock); in kvm_s390_vm_set_crypto()
1095 kvm_s390_vcpu_crypto_reset_all(kvm); in kvm_s390_vm_set_crypto()
1096 mutex_unlock(&kvm->lock); in kvm_s390_vm_set_crypto()
1103 if (!vcpu->kvm->arch.use_zpci_interp) in kvm_s390_vcpu_pci_setup()
1110 void kvm_s390_vcpu_pci_enable_interp(struct kvm *kvm) in kvm_s390_vcpu_pci_enable_interp() argument
1115 lockdep_assert_held(&kvm->lock); in kvm_s390_vcpu_pci_enable_interp()
1124 kvm->arch.use_zpci_interp = 1; in kvm_s390_vcpu_pci_enable_interp()
1126 kvm_s390_vcpu_block_all(kvm); in kvm_s390_vcpu_pci_enable_interp()
1128 kvm_for_each_vcpu(i, vcpu, kvm) { in kvm_s390_vcpu_pci_enable_interp()
1133 kvm_s390_vcpu_unblock_all(kvm); in kvm_s390_vcpu_pci_enable_interp()
1136 static void kvm_s390_sync_request_broadcast(struct kvm *kvm, int req) in kvm_s390_sync_request_broadcast() argument
1141 kvm_for_each_vcpu(cx, vcpu, kvm) in kvm_s390_sync_request_broadcast()
1149 static int kvm_s390_vm_start_migration(struct kvm *kvm) in kvm_s390_vm_start_migration() argument
1157 if (kvm->arch.migration_mode) in kvm_s390_vm_start_migration()
1159 slots = kvm_memslots(kvm); in kvm_s390_vm_start_migration()
1163 if (!kvm->arch.use_cmma) { in kvm_s390_vm_start_migration()
1164 kvm->arch.migration_mode = 1; in kvm_s390_vm_start_migration()
1180 atomic64_set(&kvm->arch.cmma_dirty_pages, ram_pages); in kvm_s390_vm_start_migration()
1181 kvm->arch.migration_mode = 1; in kvm_s390_vm_start_migration()
1182 kvm_s390_sync_request_broadcast(kvm, KVM_REQ_START_MIGRATION); in kvm_s390_vm_start_migration()
1190 static int kvm_s390_vm_stop_migration(struct kvm *kvm) in kvm_s390_vm_stop_migration() argument
1193 if (!kvm->arch.migration_mode) in kvm_s390_vm_stop_migration()
1195 kvm->arch.migration_mode = 0; in kvm_s390_vm_stop_migration()
1196 if (kvm->arch.use_cmma) in kvm_s390_vm_stop_migration()
1197 kvm_s390_sync_request_broadcast(kvm, KVM_REQ_STOP_MIGRATION); in kvm_s390_vm_stop_migration()
1201 static int kvm_s390_vm_set_migration(struct kvm *kvm, in kvm_s390_vm_set_migration() argument
1206 mutex_lock(&kvm->slots_lock); in kvm_s390_vm_set_migration()
1209 res = kvm_s390_vm_start_migration(kvm); in kvm_s390_vm_set_migration()
1212 res = kvm_s390_vm_stop_migration(kvm); in kvm_s390_vm_set_migration()
1217 mutex_unlock(&kvm->slots_lock); in kvm_s390_vm_set_migration()
1222 static int kvm_s390_vm_get_migration(struct kvm *kvm, in kvm_s390_vm_get_migration() argument
1225 u64 mig = kvm->arch.migration_mode; in kvm_s390_vm_get_migration()
1235 static void __kvm_s390_set_tod_clock(struct kvm *kvm, const struct kvm_s390_vm_tod_clock *gtod);
1237 static int kvm_s390_set_tod_ext(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_set_tod_ext() argument
1244 if (!test_kvm_facility(kvm, 139) && gtod.epoch_idx) in kvm_s390_set_tod_ext()
1246 __kvm_s390_set_tod_clock(kvm, &gtod); in kvm_s390_set_tod_ext()
1248 VM_EVENT(kvm, 3, "SET: TOD extension: 0x%x, TOD base: 0x%llx", in kvm_s390_set_tod_ext()
1254 static int kvm_s390_set_tod_high(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_set_tod_high() argument
1264 VM_EVENT(kvm, 3, "SET: TOD extension: 0x%x", gtod_high); in kvm_s390_set_tod_high()
1269 static int kvm_s390_set_tod_low(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_set_tod_low() argument
1277 __kvm_s390_set_tod_clock(kvm, &gtod); in kvm_s390_set_tod_low()
1278 VM_EVENT(kvm, 3, "SET: TOD base: 0x%llx", gtod.tod); in kvm_s390_set_tod_low()
1282 static int kvm_s390_set_tod(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_set_tod() argument
1289 mutex_lock(&kvm->lock); in kvm_s390_set_tod()
1294 if (kvm_s390_pv_is_protected(kvm)) { in kvm_s390_set_tod()
1301 ret = kvm_s390_set_tod_ext(kvm, attr); in kvm_s390_set_tod()
1304 ret = kvm_s390_set_tod_high(kvm, attr); in kvm_s390_set_tod()
1307 ret = kvm_s390_set_tod_low(kvm, attr); in kvm_s390_set_tod()
1315 mutex_unlock(&kvm->lock); in kvm_s390_set_tod()
1319 static void kvm_s390_get_tod_clock(struct kvm *kvm, in kvm_s390_get_tod_clock() argument
1328 gtod->tod = clk.tod + kvm->arch.epoch; in kvm_s390_get_tod_clock()
1330 if (test_kvm_facility(kvm, 139)) { in kvm_s390_get_tod_clock()
1331 gtod->epoch_idx = clk.ei + kvm->arch.epdx; in kvm_s390_get_tod_clock()
1339 static int kvm_s390_get_tod_ext(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_get_tod_ext() argument
1344 kvm_s390_get_tod_clock(kvm, &gtod); in kvm_s390_get_tod_ext()
1348 VM_EVENT(kvm, 3, "QUERY: TOD extension: 0x%x, TOD base: 0x%llx", in kvm_s390_get_tod_ext()
1353 static int kvm_s390_get_tod_high(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_get_tod_high() argument
1360 VM_EVENT(kvm, 3, "QUERY: TOD extension: 0x%x", gtod_high); in kvm_s390_get_tod_high()
1365 static int kvm_s390_get_tod_low(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_get_tod_low() argument
1369 gtod = kvm_s390_get_tod_clock_fast(kvm); in kvm_s390_get_tod_low()
1372 VM_EVENT(kvm, 3, "QUERY: TOD base: 0x%llx", gtod); in kvm_s390_get_tod_low()
1377 static int kvm_s390_get_tod(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_get_tod() argument
1386 ret = kvm_s390_get_tod_ext(kvm, attr); in kvm_s390_get_tod()
1389 ret = kvm_s390_get_tod_high(kvm, attr); in kvm_s390_get_tod()
1392 ret = kvm_s390_get_tod_low(kvm, attr); in kvm_s390_get_tod()
1401 static int kvm_s390_set_processor(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_set_processor() argument
1407 mutex_lock(&kvm->lock); in kvm_s390_set_processor()
1408 if (kvm->created_vcpus) { in kvm_s390_set_processor()
1419 kvm->arch.model.cpuid = proc->cpuid; in kvm_s390_set_processor()
1424 kvm->arch.model.ibc = unblocked_ibc; in kvm_s390_set_processor()
1426 kvm->arch.model.ibc = lowest_ibc; in kvm_s390_set_processor()
1428 kvm->arch.model.ibc = proc->ibc; in kvm_s390_set_processor()
1430 memcpy(kvm->arch.model.fac_list, proc->fac_list, in kvm_s390_set_processor()
1432 VM_EVENT(kvm, 3, "SET: guest ibc: 0x%4.4x, guest cpuid: 0x%16.16llx", in kvm_s390_set_processor()
1433 kvm->arch.model.ibc, in kvm_s390_set_processor()
1434 kvm->arch.model.cpuid); in kvm_s390_set_processor()
1435 VM_EVENT(kvm, 3, "SET: guest faclist: 0x%16.16llx.%16.16llx.%16.16llx", in kvm_s390_set_processor()
1436 kvm->arch.model.fac_list[0], in kvm_s390_set_processor()
1437 kvm->arch.model.fac_list[1], in kvm_s390_set_processor()
1438 kvm->arch.model.fac_list[2]); in kvm_s390_set_processor()
1443 mutex_unlock(&kvm->lock); in kvm_s390_set_processor()
1447 static int kvm_s390_set_processor_feat(struct kvm *kvm, in kvm_s390_set_processor_feat() argument
1459 mutex_lock(&kvm->lock); in kvm_s390_set_processor_feat()
1460 if (kvm->created_vcpus) { in kvm_s390_set_processor_feat()
1461 mutex_unlock(&kvm->lock); in kvm_s390_set_processor_feat()
1464 bitmap_from_arr64(kvm->arch.cpu_feat, data.feat, KVM_S390_VM_CPU_FEAT_NR_BITS); in kvm_s390_set_processor_feat()
1465 mutex_unlock(&kvm->lock); in kvm_s390_set_processor_feat()
1466 VM_EVENT(kvm, 3, "SET: guest feat: 0x%16.16llx.0x%16.16llx.0x%16.16llx", in kvm_s390_set_processor_feat()
1473 static int kvm_s390_set_processor_subfunc(struct kvm *kvm, in kvm_s390_set_processor_subfunc() argument
1476 mutex_lock(&kvm->lock); in kvm_s390_set_processor_subfunc()
1477 if (kvm->created_vcpus) { in kvm_s390_set_processor_subfunc()
1478 mutex_unlock(&kvm->lock); in kvm_s390_set_processor_subfunc()
1482 if (copy_from_user(&kvm->arch.model.subfuncs, (void __user *)attr->addr, in kvm_s390_set_processor_subfunc()
1484 mutex_unlock(&kvm->lock); in kvm_s390_set_processor_subfunc()
1487 mutex_unlock(&kvm->lock); in kvm_s390_set_processor_subfunc()
1489 VM_EVENT(kvm, 3, "SET: guest PLO subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1490 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[0], in kvm_s390_set_processor_subfunc()
1491 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[1], in kvm_s390_set_processor_subfunc()
1492 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[2], in kvm_s390_set_processor_subfunc()
1493 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[3]); in kvm_s390_set_processor_subfunc()
1494 VM_EVENT(kvm, 3, "SET: guest PTFF subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1495 ((unsigned long *) &kvm->arch.model.subfuncs.ptff)[0], in kvm_s390_set_processor_subfunc()
1496 ((unsigned long *) &kvm->arch.model.subfuncs.ptff)[1]); in kvm_s390_set_processor_subfunc()
1497 VM_EVENT(kvm, 3, "SET: guest KMAC subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1498 ((unsigned long *) &kvm->arch.model.subfuncs.kmac)[0], in kvm_s390_set_processor_subfunc()
1499 ((unsigned long *) &kvm->arch.model.subfuncs.kmac)[1]); in kvm_s390_set_processor_subfunc()
1500 VM_EVENT(kvm, 3, "SET: guest KMC subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1501 ((unsigned long *) &kvm->arch.model.subfuncs.kmc)[0], in kvm_s390_set_processor_subfunc()
1502 ((unsigned long *) &kvm->arch.model.subfuncs.kmc)[1]); in kvm_s390_set_processor_subfunc()
1503 VM_EVENT(kvm, 3, "SET: guest KM subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1504 ((unsigned long *) &kvm->arch.model.subfuncs.km)[0], in kvm_s390_set_processor_subfunc()
1505 ((unsigned long *) &kvm->arch.model.subfuncs.km)[1]); in kvm_s390_set_processor_subfunc()
1506 VM_EVENT(kvm, 3, "SET: guest KIMD subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1507 ((unsigned long *) &kvm->arch.model.subfuncs.kimd)[0], in kvm_s390_set_processor_subfunc()
1508 ((unsigned long *) &kvm->arch.model.subfuncs.kimd)[1]); in kvm_s390_set_processor_subfunc()
1509 VM_EVENT(kvm, 3, "SET: guest KLMD subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1510 ((unsigned long *) &kvm->arch.model.subfuncs.klmd)[0], in kvm_s390_set_processor_subfunc()
1511 ((unsigned long *) &kvm->arch.model.subfuncs.klmd)[1]); in kvm_s390_set_processor_subfunc()
1512 VM_EVENT(kvm, 3, "SET: guest PCKMO subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1513 ((unsigned long *) &kvm->arch.model.subfuncs.pckmo)[0], in kvm_s390_set_processor_subfunc()
1514 ((unsigned long *) &kvm->arch.model.subfuncs.pckmo)[1]); in kvm_s390_set_processor_subfunc()
1515 VM_EVENT(kvm, 3, "SET: guest KMCTR subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1516 ((unsigned long *) &kvm->arch.model.subfuncs.kmctr)[0], in kvm_s390_set_processor_subfunc()
1517 ((unsigned long *) &kvm->arch.model.subfuncs.kmctr)[1]); in kvm_s390_set_processor_subfunc()
1518 VM_EVENT(kvm, 3, "SET: guest KMF subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1519 ((unsigned long *) &kvm->arch.model.subfuncs.kmf)[0], in kvm_s390_set_processor_subfunc()
1520 ((unsigned long *) &kvm->arch.model.subfuncs.kmf)[1]); in kvm_s390_set_processor_subfunc()
1521 VM_EVENT(kvm, 3, "SET: guest KMO subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1522 ((unsigned long *) &kvm->arch.model.subfuncs.kmo)[0], in kvm_s390_set_processor_subfunc()
1523 ((unsigned long *) &kvm->arch.model.subfuncs.kmo)[1]); in kvm_s390_set_processor_subfunc()
1524 VM_EVENT(kvm, 3, "SET: guest PCC subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1525 ((unsigned long *) &kvm->arch.model.subfuncs.pcc)[0], in kvm_s390_set_processor_subfunc()
1526 ((unsigned long *) &kvm->arch.model.subfuncs.pcc)[1]); in kvm_s390_set_processor_subfunc()
1527 VM_EVENT(kvm, 3, "SET: guest PPNO subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1528 ((unsigned long *) &kvm->arch.model.subfuncs.ppno)[0], in kvm_s390_set_processor_subfunc()
1529 ((unsigned long *) &kvm->arch.model.subfuncs.ppno)[1]); in kvm_s390_set_processor_subfunc()
1530 VM_EVENT(kvm, 3, "SET: guest KMA subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1531 ((unsigned long *) &kvm->arch.model.subfuncs.kma)[0], in kvm_s390_set_processor_subfunc()
1532 ((unsigned long *) &kvm->arch.model.subfuncs.kma)[1]); in kvm_s390_set_processor_subfunc()
1533 VM_EVENT(kvm, 3, "SET: guest KDSA subfunc 0x%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1534 ((unsigned long *) &kvm->arch.model.subfuncs.kdsa)[0], in kvm_s390_set_processor_subfunc()
1535 ((unsigned long *) &kvm->arch.model.subfuncs.kdsa)[1]); in kvm_s390_set_processor_subfunc()
1536 VM_EVENT(kvm, 3, "SET: guest SORTL subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1537 ((unsigned long *) &kvm->arch.model.subfuncs.sortl)[0], in kvm_s390_set_processor_subfunc()
1538 ((unsigned long *) &kvm->arch.model.subfuncs.sortl)[1], in kvm_s390_set_processor_subfunc()
1539 ((unsigned long *) &kvm->arch.model.subfuncs.sortl)[2], in kvm_s390_set_processor_subfunc()
1540 ((unsigned long *) &kvm->arch.model.subfuncs.sortl)[3]); in kvm_s390_set_processor_subfunc()
1541 VM_EVENT(kvm, 3, "SET: guest DFLTCC subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx", in kvm_s390_set_processor_subfunc()
1542 ((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[0], in kvm_s390_set_processor_subfunc()
1543 ((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[1], in kvm_s390_set_processor_subfunc()
1544 ((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[2], in kvm_s390_set_processor_subfunc()
1545 ((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[3]); in kvm_s390_set_processor_subfunc()
1559 static int kvm_s390_set_uv_feat(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_set_uv_feat() argument
1570 mutex_lock(&kvm->lock); in kvm_s390_set_uv_feat()
1571 if (kvm->created_vcpus) { in kvm_s390_set_uv_feat()
1572 mutex_unlock(&kvm->lock); in kvm_s390_set_uv_feat()
1575 kvm->arch.model.uv_feat_guest.feat = data; in kvm_s390_set_uv_feat()
1576 mutex_unlock(&kvm->lock); in kvm_s390_set_uv_feat()
1578 VM_EVENT(kvm, 3, "SET: guest UV-feat: 0x%16.16lx", data); in kvm_s390_set_uv_feat()
1583 static int kvm_s390_set_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_set_cpu_model() argument
1589 ret = kvm_s390_set_processor(kvm, attr); in kvm_s390_set_cpu_model()
1592 ret = kvm_s390_set_processor_feat(kvm, attr); in kvm_s390_set_cpu_model()
1595 ret = kvm_s390_set_processor_subfunc(kvm, attr); in kvm_s390_set_cpu_model()
1598 ret = kvm_s390_set_uv_feat(kvm, attr); in kvm_s390_set_cpu_model()
1604 static int kvm_s390_get_processor(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_get_processor() argument
1614 proc->cpuid = kvm->arch.model.cpuid; in kvm_s390_get_processor()
1615 proc->ibc = kvm->arch.model.ibc; in kvm_s390_get_processor()
1616 memcpy(&proc->fac_list, kvm->arch.model.fac_list, in kvm_s390_get_processor()
1618 VM_EVENT(kvm, 3, "GET: guest ibc: 0x%4.4x, guest cpuid: 0x%16.16llx", in kvm_s390_get_processor()
1619 kvm->arch.model.ibc, in kvm_s390_get_processor()
1620 kvm->arch.model.cpuid); in kvm_s390_get_processor()
1621 VM_EVENT(kvm, 3, "GET: guest faclist: 0x%16.16llx.%16.16llx.%16.16llx", in kvm_s390_get_processor()
1622 kvm->arch.model.fac_list[0], in kvm_s390_get_processor()
1623 kvm->arch.model.fac_list[1], in kvm_s390_get_processor()
1624 kvm->arch.model.fac_list[2]); in kvm_s390_get_processor()
1632 static int kvm_s390_get_machine(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_get_machine() argument
1644 memcpy(&mach->fac_mask, kvm->arch.model.fac_mask, in kvm_s390_get_machine()
1648 VM_EVENT(kvm, 3, "GET: host ibc: 0x%4.4x, host cpuid: 0x%16.16llx", in kvm_s390_get_machine()
1649 kvm->arch.model.ibc, in kvm_s390_get_machine()
1650 kvm->arch.model.cpuid); in kvm_s390_get_machine()
1651 VM_EVENT(kvm, 3, "GET: host facmask: 0x%16.16llx.%16.16llx.%16.16llx", in kvm_s390_get_machine()
1655 VM_EVENT(kvm, 3, "GET: host faclist: 0x%16.16llx.%16.16llx.%16.16llx", in kvm_s390_get_machine()
1666 static int kvm_s390_get_processor_feat(struct kvm *kvm, in kvm_s390_get_processor_feat() argument
1671 bitmap_to_arr64(data.feat, kvm->arch.cpu_feat, KVM_S390_VM_CPU_FEAT_NR_BITS); in kvm_s390_get_processor_feat()
1674 VM_EVENT(kvm, 3, "GET: guest feat: 0x%16.16llx.0x%16.16llx.0x%16.16llx", in kvm_s390_get_processor_feat()
1681 static int kvm_s390_get_machine_feat(struct kvm *kvm, in kvm_s390_get_machine_feat() argument
1689 VM_EVENT(kvm, 3, "GET: host feat: 0x%16.16llx.0x%16.16llx.0x%16.16llx", in kvm_s390_get_machine_feat()
1696 static int kvm_s390_get_processor_subfunc(struct kvm *kvm, in kvm_s390_get_processor_subfunc() argument
1699 if (copy_to_user((void __user *)attr->addr, &kvm->arch.model.subfuncs, in kvm_s390_get_processor_subfunc()
1703 VM_EVENT(kvm, 3, "GET: guest PLO subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1704 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[0], in kvm_s390_get_processor_subfunc()
1705 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[1], in kvm_s390_get_processor_subfunc()
1706 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[2], in kvm_s390_get_processor_subfunc()
1707 ((unsigned long *) &kvm->arch.model.subfuncs.plo)[3]); in kvm_s390_get_processor_subfunc()
1708 VM_EVENT(kvm, 3, "GET: guest PTFF subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1709 ((unsigned long *) &kvm->arch.model.subfuncs.ptff)[0], in kvm_s390_get_processor_subfunc()
1710 ((unsigned long *) &kvm->arch.model.subfuncs.ptff)[1]); in kvm_s390_get_processor_subfunc()
1711 VM_EVENT(kvm, 3, "GET: guest KMAC subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1712 ((unsigned long *) &kvm->arch.model.subfuncs.kmac)[0], in kvm_s390_get_processor_subfunc()
1713 ((unsigned long *) &kvm->arch.model.subfuncs.kmac)[1]); in kvm_s390_get_processor_subfunc()
1714 VM_EVENT(kvm, 3, "GET: guest KMC subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1715 ((unsigned long *) &kvm->arch.model.subfuncs.kmc)[0], in kvm_s390_get_processor_subfunc()
1716 ((unsigned long *) &kvm->arch.model.subfuncs.kmc)[1]); in kvm_s390_get_processor_subfunc()
1717 VM_EVENT(kvm, 3, "GET: guest KM subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1718 ((unsigned long *) &kvm->arch.model.subfuncs.km)[0], in kvm_s390_get_processor_subfunc()
1719 ((unsigned long *) &kvm->arch.model.subfuncs.km)[1]); in kvm_s390_get_processor_subfunc()
1720 VM_EVENT(kvm, 3, "GET: guest KIMD subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1721 ((unsigned long *) &kvm->arch.model.subfuncs.kimd)[0], in kvm_s390_get_processor_subfunc()
1722 ((unsigned long *) &kvm->arch.model.subfuncs.kimd)[1]); in kvm_s390_get_processor_subfunc()
1723 VM_EVENT(kvm, 3, "GET: guest KLMD subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1724 ((unsigned long *) &kvm->arch.model.subfuncs.klmd)[0], in kvm_s390_get_processor_subfunc()
1725 ((unsigned long *) &kvm->arch.model.subfuncs.klmd)[1]); in kvm_s390_get_processor_subfunc()
1726 VM_EVENT(kvm, 3, "GET: guest PCKMO subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1727 ((unsigned long *) &kvm->arch.model.subfuncs.pckmo)[0], in kvm_s390_get_processor_subfunc()
1728 ((unsigned long *) &kvm->arch.model.subfuncs.pckmo)[1]); in kvm_s390_get_processor_subfunc()
1729 VM_EVENT(kvm, 3, "GET: guest KMCTR subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1730 ((unsigned long *) &kvm->arch.model.subfuncs.kmctr)[0], in kvm_s390_get_processor_subfunc()
1731 ((unsigned long *) &kvm->arch.model.subfuncs.kmctr)[1]); in kvm_s390_get_processor_subfunc()
1732 VM_EVENT(kvm, 3, "GET: guest KMF subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1733 ((unsigned long *) &kvm->arch.model.subfuncs.kmf)[0], in kvm_s390_get_processor_subfunc()
1734 ((unsigned long *) &kvm->arch.model.subfuncs.kmf)[1]); in kvm_s390_get_processor_subfunc()
1735 VM_EVENT(kvm, 3, "GET: guest KMO subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1736 ((unsigned long *) &kvm->arch.model.subfuncs.kmo)[0], in kvm_s390_get_processor_subfunc()
1737 ((unsigned long *) &kvm->arch.model.subfuncs.kmo)[1]); in kvm_s390_get_processor_subfunc()
1738 VM_EVENT(kvm, 3, "GET: guest PCC subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1739 ((unsigned long *) &kvm->arch.model.subfuncs.pcc)[0], in kvm_s390_get_processor_subfunc()
1740 ((unsigned long *) &kvm->arch.model.subfuncs.pcc)[1]); in kvm_s390_get_processor_subfunc()
1741 VM_EVENT(kvm, 3, "GET: guest PPNO subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1742 ((unsigned long *) &kvm->arch.model.subfuncs.ppno)[0], in kvm_s390_get_processor_subfunc()
1743 ((unsigned long *) &kvm->arch.model.subfuncs.ppno)[1]); in kvm_s390_get_processor_subfunc()
1744 VM_EVENT(kvm, 3, "GET: guest KMA subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1745 ((unsigned long *) &kvm->arch.model.subfuncs.kma)[0], in kvm_s390_get_processor_subfunc()
1746 ((unsigned long *) &kvm->arch.model.subfuncs.kma)[1]); in kvm_s390_get_processor_subfunc()
1747 VM_EVENT(kvm, 3, "GET: guest KDSA subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1748 ((unsigned long *) &kvm->arch.model.subfuncs.kdsa)[0], in kvm_s390_get_processor_subfunc()
1749 ((unsigned long *) &kvm->arch.model.subfuncs.kdsa)[1]); in kvm_s390_get_processor_subfunc()
1750 VM_EVENT(kvm, 3, "GET: guest SORTL subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1751 ((unsigned long *) &kvm->arch.model.subfuncs.sortl)[0], in kvm_s390_get_processor_subfunc()
1752 ((unsigned long *) &kvm->arch.model.subfuncs.sortl)[1], in kvm_s390_get_processor_subfunc()
1753 ((unsigned long *) &kvm->arch.model.subfuncs.sortl)[2], in kvm_s390_get_processor_subfunc()
1754 ((unsigned long *) &kvm->arch.model.subfuncs.sortl)[3]); in kvm_s390_get_processor_subfunc()
1755 VM_EVENT(kvm, 3, "GET: guest DFLTCC subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx", in kvm_s390_get_processor_subfunc()
1756 ((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[0], in kvm_s390_get_processor_subfunc()
1757 ((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[1], in kvm_s390_get_processor_subfunc()
1758 ((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[2], in kvm_s390_get_processor_subfunc()
1759 ((unsigned long *) &kvm->arch.model.subfuncs.dfltcc)[3]); in kvm_s390_get_processor_subfunc()
1764 static int kvm_s390_get_machine_subfunc(struct kvm *kvm, in kvm_s390_get_machine_subfunc() argument
1771 VM_EVENT(kvm, 3, "GET: host PLO subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1776 VM_EVENT(kvm, 3, "GET: host PTFF subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1779 VM_EVENT(kvm, 3, "GET: host KMAC subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1782 VM_EVENT(kvm, 3, "GET: host KMC subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1785 VM_EVENT(kvm, 3, "GET: host KM subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1788 VM_EVENT(kvm, 3, "GET: host KIMD subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1791 VM_EVENT(kvm, 3, "GET: host KLMD subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1794 VM_EVENT(kvm, 3, "GET: host PCKMO subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1797 VM_EVENT(kvm, 3, "GET: host KMCTR subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1800 VM_EVENT(kvm, 3, "GET: host KMF subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1803 VM_EVENT(kvm, 3, "GET: host KMO subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1806 VM_EVENT(kvm, 3, "GET: host PCC subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1809 VM_EVENT(kvm, 3, "GET: host PPNO subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1812 VM_EVENT(kvm, 3, "GET: host KMA subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1815 VM_EVENT(kvm, 3, "GET: host KDSA subfunc 0x%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1818 VM_EVENT(kvm, 3, "GET: host SORTL subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1823 VM_EVENT(kvm, 3, "GET: host DFLTCC subfunc 0x%16.16lx.%16.16lx.%16.16lx.%16.16lx", in kvm_s390_get_machine_subfunc()
1832 static int kvm_s390_get_processor_uv_feat(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_get_processor_uv_feat() argument
1835 unsigned long feat = kvm->arch.model.uv_feat_guest.feat; in kvm_s390_get_processor_uv_feat()
1839 VM_EVENT(kvm, 3, "GET: guest UV-feat: 0x%16.16lx", feat); in kvm_s390_get_processor_uv_feat()
1844 static int kvm_s390_get_machine_uv_feat(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_get_machine_uv_feat() argument
1854 VM_EVENT(kvm, 3, "GET: guest UV-feat: 0x%16.16lx", feat); in kvm_s390_get_machine_uv_feat()
1859 static int kvm_s390_get_cpu_model(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_get_cpu_model() argument
1865 ret = kvm_s390_get_processor(kvm, attr); in kvm_s390_get_cpu_model()
1868 ret = kvm_s390_get_machine(kvm, attr); in kvm_s390_get_cpu_model()
1871 ret = kvm_s390_get_processor_feat(kvm, attr); in kvm_s390_get_cpu_model()
1874 ret = kvm_s390_get_machine_feat(kvm, attr); in kvm_s390_get_cpu_model()
1877 ret = kvm_s390_get_processor_subfunc(kvm, attr); in kvm_s390_get_cpu_model()
1880 ret = kvm_s390_get_machine_subfunc(kvm, attr); in kvm_s390_get_cpu_model()
1883 ret = kvm_s390_get_processor_uv_feat(kvm, attr); in kvm_s390_get_cpu_model()
1886 ret = kvm_s390_get_machine_uv_feat(kvm, attr); in kvm_s390_get_cpu_model()
1903 static void kvm_s390_update_topology_change_report(struct kvm *kvm, bool val) in kvm_s390_update_topology_change_report() argument
1908 read_lock(&kvm->arch.sca_lock); in kvm_s390_update_topology_change_report()
1909 sca = kvm->arch.sca; in kvm_s390_update_topology_change_report()
1915 read_unlock(&kvm->arch.sca_lock); in kvm_s390_update_topology_change_report()
1918 static int kvm_s390_set_topo_change_indication(struct kvm *kvm, in kvm_s390_set_topo_change_indication() argument
1921 if (!test_kvm_facility(kvm, 11)) in kvm_s390_set_topo_change_indication()
1924 kvm_s390_update_topology_change_report(kvm, !!attr->attr); in kvm_s390_set_topo_change_indication()
1928 static int kvm_s390_get_topo_change_indication(struct kvm *kvm, in kvm_s390_get_topo_change_indication() argument
1933 if (!test_kvm_facility(kvm, 11)) in kvm_s390_get_topo_change_indication()
1936 read_lock(&kvm->arch.sca_lock); in kvm_s390_get_topo_change_indication()
1937 topo = ((struct bsca_block *)kvm->arch.sca)->utility.mtcr; in kvm_s390_get_topo_change_indication()
1938 read_unlock(&kvm->arch.sca_lock); in kvm_s390_get_topo_change_indication()
1943 static int kvm_s390_vm_set_attr(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_vm_set_attr() argument
1949 ret = kvm_s390_set_mem_control(kvm, attr); in kvm_s390_vm_set_attr()
1952 ret = kvm_s390_set_tod(kvm, attr); in kvm_s390_vm_set_attr()
1955 ret = kvm_s390_set_cpu_model(kvm, attr); in kvm_s390_vm_set_attr()
1958 ret = kvm_s390_vm_set_crypto(kvm, attr); in kvm_s390_vm_set_attr()
1961 ret = kvm_s390_vm_set_migration(kvm, attr); in kvm_s390_vm_set_attr()
1964 ret = kvm_s390_set_topo_change_indication(kvm, attr); in kvm_s390_vm_set_attr()
1974 static int kvm_s390_vm_get_attr(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_vm_get_attr() argument
1980 ret = kvm_s390_get_mem_control(kvm, attr); in kvm_s390_vm_get_attr()
1983 ret = kvm_s390_get_tod(kvm, attr); in kvm_s390_vm_get_attr()
1986 ret = kvm_s390_get_cpu_model(kvm, attr); in kvm_s390_vm_get_attr()
1989 ret = kvm_s390_vm_get_migration(kvm, attr); in kvm_s390_vm_get_attr()
1992 ret = kvm_s390_get_topo_change_indication(kvm, attr); in kvm_s390_vm_get_attr()
2002 static int kvm_s390_vm_has_attr(struct kvm *kvm, struct kvm_device_attr *attr) in kvm_s390_vm_has_attr() argument
2070 ret = test_kvm_facility(kvm, 11) ? 0 : -ENXIO; in kvm_s390_vm_has_attr()
2080 static int kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args) in kvm_s390_get_skeys() argument
2102 srcu_idx = srcu_read_lock(&kvm->srcu); in kvm_s390_get_skeys()
2104 hva = gfn_to_hva(kvm, args->start_gfn + i); in kvm_s390_get_skeys()
2114 srcu_read_unlock(&kvm->srcu, srcu_idx); in kvm_s390_get_skeys()
2128 static int kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args) in kvm_s390_set_skeys() argument
2160 srcu_idx = srcu_read_lock(&kvm->srcu); in kvm_s390_set_skeys()
2163 hva = gfn_to_hva(kvm, args->start_gfn + i); in kvm_s390_set_skeys()
2185 srcu_read_unlock(&kvm->srcu, srcu_idx); in kvm_s390_set_skeys()
2201 static int kvm_s390_peek_cmma(struct kvm *kvm, struct kvm_s390_cmma_log *args, in kvm_s390_peek_cmma() argument
2208 hva = gfn_to_hva(kvm, cur_gfn); in kvm_s390_peek_cmma()
2215 if (get_pgste(kvm->mm, hva, &pgstev) < 0) in kvm_s390_peek_cmma()
2258 static int kvm_s390_get_cmma(struct kvm *kvm, struct kvm_s390_cmma_log *args, in kvm_s390_get_cmma() argument
2262 struct kvm_memslots *slots = kvm_memslots(kvm); in kvm_s390_get_cmma()
2269 ms = gfn_to_memslot(kvm, cur_gfn); in kvm_s390_get_cmma()
2278 hva = gfn_to_hva(kvm, cur_gfn); in kvm_s390_get_cmma()
2283 atomic64_dec(&kvm->arch.cmma_dirty_pages); in kvm_s390_get_cmma()
2284 if (get_pgste(kvm->mm, hva, &pgstev) < 0) in kvm_s390_get_cmma()
2301 ms = gfn_to_memslot(kvm, cur_gfn); in kvm_s390_get_cmma()
2317 static int kvm_s390_get_cmma_bits(struct kvm *kvm, in kvm_s390_get_cmma_bits() argument
2324 if (!kvm->arch.use_cmma) in kvm_s390_get_cmma_bits()
2331 if (!peek && !kvm->arch.migration_mode) in kvm_s390_get_cmma_bits()
2335 if (!bufsize || !kvm->mm->context.uses_cmm) { in kvm_s390_get_cmma_bits()
2340 if (!peek && !atomic64_read(&kvm->arch.cmma_dirty_pages)) { in kvm_s390_get_cmma_bits()
2349 mmap_read_lock(kvm->mm); in kvm_s390_get_cmma_bits()
2350 srcu_idx = srcu_read_lock(&kvm->srcu); in kvm_s390_get_cmma_bits()
2352 ret = kvm_s390_peek_cmma(kvm, args, values, bufsize); in kvm_s390_get_cmma_bits()
2354 ret = kvm_s390_get_cmma(kvm, args, values, bufsize); in kvm_s390_get_cmma_bits()
2355 srcu_read_unlock(&kvm->srcu, srcu_idx); in kvm_s390_get_cmma_bits()
2356 mmap_read_unlock(kvm->mm); in kvm_s390_get_cmma_bits()
2358 if (kvm->arch.migration_mode) in kvm_s390_get_cmma_bits()
2359 args->remaining = atomic64_read(&kvm->arch.cmma_dirty_pages); in kvm_s390_get_cmma_bits()
2375 static int kvm_s390_set_cmma_bits(struct kvm *kvm, in kvm_s390_set_cmma_bits() argument
2384 if (!kvm->arch.use_cmma) in kvm_s390_set_cmma_bits()
2406 mmap_read_lock(kvm->mm); in kvm_s390_set_cmma_bits()
2407 srcu_idx = srcu_read_lock(&kvm->srcu); in kvm_s390_set_cmma_bits()
2409 hva = gfn_to_hva(kvm, args->start_gfn + i); in kvm_s390_set_cmma_bits()
2418 set_pgste_bits(kvm->mm, hva, mask, pgstev); in kvm_s390_set_cmma_bits()
2420 srcu_read_unlock(&kvm->srcu, srcu_idx); in kvm_s390_set_cmma_bits()
2421 mmap_read_unlock(kvm->mm); in kvm_s390_set_cmma_bits()
2423 if (!kvm->mm->context.uses_cmm) { in kvm_s390_set_cmma_bits()
2424 mmap_write_lock(kvm->mm); in kvm_s390_set_cmma_bits()
2425 kvm->mm->context.uses_cmm = 1; in kvm_s390_set_cmma_bits()
2426 mmap_write_unlock(kvm->mm); in kvm_s390_set_cmma_bits()
2446 int kvm_s390_cpus_from_pv(struct kvm *kvm, u16 *rc, u16 *rrc) in kvm_s390_cpus_from_pv() argument
2461 kvm_for_each_vcpu(i, vcpu, kvm) { in kvm_s390_cpus_from_pv()
2472 kvm_s390_gisa_enable(kvm); in kvm_s390_cpus_from_pv()
2487 static int kvm_s390_cpus_to_pv(struct kvm *kvm, u16 *rc, u16 *rrc) in kvm_s390_cpus_to_pv() argument
2497 kvm_s390_gisa_disable(kvm); in kvm_s390_cpus_to_pv()
2499 kvm_for_each_vcpu(i, vcpu, kvm) { in kvm_s390_cpus_to_pv()
2507 kvm_s390_cpus_from_pv(kvm, &dummy, &dummy); in kvm_s390_cpus_to_pv()
2558 static int kvm_s390_pv_dmp(struct kvm *kvm, struct kvm_pv_cmd *cmd, in kvm_s390_pv_dmp() argument
2566 if (kvm->arch.pv.dumping) in kvm_s390_pv_dmp()
2573 kvm_s390_vcpu_block_all(kvm); in kvm_s390_pv_dmp()
2575 r = uv_cmd_nodata(kvm_s390_pv_get_handle(kvm), in kvm_s390_pv_dmp()
2577 KVM_UV_EVENT(kvm, 3, "PROTVIRT DUMP INIT: rc %x rrc %x", in kvm_s390_pv_dmp()
2580 kvm->arch.pv.dumping = true; in kvm_s390_pv_dmp()
2582 kvm_s390_vcpu_unblock_all(kvm); in kvm_s390_pv_dmp()
2588 if (!kvm->arch.pv.dumping) in kvm_s390_pv_dmp()
2596 r = kvm_s390_pv_dump_stor_state(kvm, result_buff, &dmp.gaddr, dmp.buff_len, in kvm_s390_pv_dmp()
2601 if (!kvm->arch.pv.dumping) in kvm_s390_pv_dmp()
2608 r = kvm_s390_pv_dump_complete(kvm, result_buff, in kvm_s390_pv_dmp()
2620 static int kvm_s390_handle_pv(struct kvm *kvm, struct kvm_pv_cmd *cmd) in kvm_s390_handle_pv() argument
2628 mutex_lock(&kvm->lock); in kvm_s390_handle_pv()
2633 if (kvm_s390_pv_is_protected(kvm)) in kvm_s390_handle_pv()
2640 r = sca_switch_to_extended(kvm); in kvm_s390_handle_pv()
2648 r = kvm_s390_pv_init_vm(kvm, &cmd->rc, &cmd->rrc); in kvm_s390_handle_pv()
2652 r = kvm_s390_cpus_to_pv(kvm, &cmd->rc, &cmd->rrc); in kvm_s390_handle_pv()
2654 kvm_s390_pv_deinit_vm(kvm, &dummy, &dummy); in kvm_s390_handle_pv()
2657 set_bit(IRQ_PEND_EXT_SERVICE, &kvm->arch.float_int.masked_irqs); in kvm_s390_handle_pv()
2662 if (!kvm_s390_pv_is_protected(kvm) || !async_destroy) in kvm_s390_handle_pv()
2665 r = kvm_s390_cpus_from_pv(kvm, &cmd->rc, &cmd->rrc); in kvm_s390_handle_pv()
2673 r = kvm_s390_pv_set_aside(kvm, &cmd->rc, &cmd->rrc); in kvm_s390_handle_pv()
2676 clear_bit(IRQ_PEND_EXT_SERVICE, &kvm->arch.float_int.masked_irqs); in kvm_s390_handle_pv()
2683 r = kvm_s390_pv_deinit_aside_vm(kvm, &cmd->rc, &cmd->rrc); in kvm_s390_handle_pv()
2687 if (!kvm_s390_pv_is_protected(kvm)) in kvm_s390_handle_pv()
2690 r = kvm_s390_cpus_from_pv(kvm, &cmd->rc, &cmd->rrc); in kvm_s390_handle_pv()
2698 r = kvm_s390_pv_deinit_cleanup_all(kvm, &cmd->rc, &cmd->rrc); in kvm_s390_handle_pv()
2701 clear_bit(IRQ_PEND_EXT_SERVICE, &kvm->arch.float_int.masked_irqs); in kvm_s390_handle_pv()
2709 if (!kvm_s390_pv_is_protected(kvm)) in kvm_s390_handle_pv()
2729 r = kvm_s390_pv_set_sec_parms(kvm, hdr, parms.length, in kvm_s390_handle_pv()
2739 if (!kvm_s390_pv_is_protected(kvm) || !mm_is_protected(kvm->mm)) in kvm_s390_handle_pv()
2746 r = kvm_s390_pv_unpack(kvm, unp.addr, unp.size, unp.tweak, in kvm_s390_handle_pv()
2752 if (!kvm_s390_pv_is_protected(kvm)) in kvm_s390_handle_pv()
2755 r = uv_cmd_nodata(kvm_s390_pv_get_handle(kvm), in kvm_s390_handle_pv()
2757 KVM_UV_EVENT(kvm, 3, "PROTVIRT VERIFY: rc %x rrc %x", cmd->rc, in kvm_s390_handle_pv()
2763 if (!kvm_s390_pv_is_protected(kvm)) in kvm_s390_handle_pv()
2766 r = uv_cmd_nodata(kvm_s390_pv_get_handle(kvm), in kvm_s390_handle_pv()
2768 KVM_UV_EVENT(kvm, 3, "PROTVIRT PREP RESET: rc %x rrc %x", in kvm_s390_handle_pv()
2774 if (!kvm_s390_pv_is_protected(kvm)) in kvm_s390_handle_pv()
2777 r = uv_cmd_nodata(kvm_s390_pv_get_handle(kvm), in kvm_s390_handle_pv()
2779 KVM_UV_EVENT(kvm, 3, "PROTVIRT UNSHARE: rc %x rrc %x", in kvm_s390_handle_pv()
2827 if (!kvm_s390_pv_is_protected(kvm)) in kvm_s390_handle_pv()
2834 r = kvm_s390_pv_dmp(kvm, cmd, dmp); in kvm_s390_handle_pv()
2849 mutex_unlock(&kvm->lock); in kvm_s390_handle_pv()
2869 static int kvm_s390_vm_mem_op_abs(struct kvm *kvm, struct kvm_s390_mem_op *mop) in kvm_s390_vm_mem_op_abs() argument
2887 srcu_idx = srcu_read_lock(&kvm->srcu); in kvm_s390_vm_mem_op_abs()
2889 if (!kvm_is_gpa_in_memslot(kvm, mop->gaddr)) { in kvm_s390_vm_mem_op_abs()
2896 r = check_gpa_range(kvm, mop->gaddr, mop->size, acc_mode, mop->key); in kvm_s390_vm_mem_op_abs()
2900 r = access_guest_abs_with_key(kvm, mop->gaddr, tmpbuf, in kvm_s390_vm_mem_op_abs()
2911 r = access_guest_abs_with_key(kvm, mop->gaddr, tmpbuf, in kvm_s390_vm_mem_op_abs()
2916 srcu_read_unlock(&kvm->srcu, srcu_idx); in kvm_s390_vm_mem_op_abs()
2922 static int kvm_s390_vm_mem_op_cmpxchg(struct kvm *kvm, struct kvm_s390_mem_op *mop) in kvm_s390_vm_mem_op_cmpxchg() argument
2949 srcu_idx = srcu_read_lock(&kvm->srcu); in kvm_s390_vm_mem_op_cmpxchg()
2951 if (!kvm_is_gpa_in_memslot(kvm, mop->gaddr)) { in kvm_s390_vm_mem_op_cmpxchg()
2956 r = cmpxchg_guest_abs_with_key(kvm, mop->gaddr, mop->size, &old.quad, in kvm_s390_vm_mem_op_cmpxchg()
2962 srcu_read_unlock(&kvm->srcu, srcu_idx); in kvm_s390_vm_mem_op_cmpxchg()
2966 static int kvm_s390_vm_mem_op(struct kvm *kvm, struct kvm_s390_mem_op *mop) in kvm_s390_vm_mem_op() argument
2977 if (kvm_s390_pv_get_handle(kvm)) in kvm_s390_vm_mem_op()
2983 return kvm_s390_vm_mem_op_abs(kvm, mop); in kvm_s390_vm_mem_op()
2985 return kvm_s390_vm_mem_op_cmpxchg(kvm, mop); in kvm_s390_vm_mem_op()
2993 struct kvm *kvm = filp->private_data; in kvm_arch_vm_ioctl() local
3005 r = kvm_s390_inject_vm(kvm, &s390int); in kvm_arch_vm_ioctl()
3010 if (kvm->arch.use_irqchip) in kvm_arch_vm_ioctl()
3018 r = kvm_s390_vm_set_attr(kvm, &attr); in kvm_arch_vm_ioctl()
3025 r = kvm_s390_vm_get_attr(kvm, &attr); in kvm_arch_vm_ioctl()
3032 r = kvm_s390_vm_has_attr(kvm, &attr); in kvm_arch_vm_ioctl()
3042 r = kvm_s390_get_skeys(kvm, &args); in kvm_arch_vm_ioctl()
3052 r = kvm_s390_set_skeys(kvm, &args); in kvm_arch_vm_ioctl()
3061 mutex_lock(&kvm->slots_lock); in kvm_arch_vm_ioctl()
3062 r = kvm_s390_get_cmma_bits(kvm, &args); in kvm_arch_vm_ioctl()
3063 mutex_unlock(&kvm->slots_lock); in kvm_arch_vm_ioctl()
3077 mutex_lock(&kvm->slots_lock); in kvm_arch_vm_ioctl()
3078 r = kvm_s390_set_cmma_bits(kvm, &args); in kvm_arch_vm_ioctl()
3079 mutex_unlock(&kvm->slots_lock); in kvm_arch_vm_ioctl()
3086 kvm_s390_set_user_cpu_state_ctrl(kvm); in kvm_arch_vm_ioctl()
3101 r = kvm_s390_handle_pv(kvm, &args); in kvm_arch_vm_ioctl()
3112 r = kvm_s390_vm_mem_op(kvm, &mem_op); in kvm_arch_vm_ioctl()
3127 r = kvm_s390_pci_zpci_op(kvm, &args); in kvm_arch_vm_ioctl()
3157 static void kvm_s390_set_crycb_format(struct kvm *kvm) in kvm_s390_set_crycb_format() argument
3159 kvm->arch.crypto.crycbd = virt_to_phys(kvm->arch.crypto.crycb); in kvm_s390_set_crycb_format()
3162 kvm->arch.crypto.crycbd &= ~(CRYCB_FORMAT_MASK); in kvm_s390_set_crycb_format()
3165 if (!test_kvm_facility(kvm, 76)) in kvm_s390_set_crycb_format()
3169 kvm->arch.crypto.crycbd |= CRYCB_FORMAT2; in kvm_s390_set_crycb_format()
3171 kvm->arch.crypto.crycbd |= CRYCB_FORMAT1; in kvm_s390_set_crycb_format()
3189 void kvm_arch_crypto_set_masks(struct kvm *kvm, unsigned long *apm, in kvm_arch_crypto_set_masks() argument
3192 struct kvm_s390_crypto_cb *crycb = kvm->arch.crypto.crycb; in kvm_arch_crypto_set_masks()
3194 kvm_s390_vcpu_block_all(kvm); in kvm_arch_crypto_set_masks()
3196 switch (kvm->arch.crypto.crycbd & CRYCB_FORMAT_MASK) { in kvm_arch_crypto_set_masks()
3199 VM_EVENT(kvm, 3, "SET CRYCB: apm %016lx %016lx %016lx %016lx", in kvm_arch_crypto_set_masks()
3202 VM_EVENT(kvm, 3, "SET CRYCB: aqm %016lx %016lx %016lx %016lx", in kvm_arch_crypto_set_masks()
3205 VM_EVENT(kvm, 3, "SET CRYCB: adm %016lx %016lx %016lx %016lx", in kvm_arch_crypto_set_masks()
3213 VM_EVENT(kvm, 3, "SET CRYCB: apm %016lx aqm %04x adm %04x", in kvm_arch_crypto_set_masks()
3222 kvm_s390_sync_request_broadcast(kvm, KVM_REQ_VSIE_RESTART); in kvm_arch_crypto_set_masks()
3223 kvm_s390_vcpu_unblock_all(kvm); in kvm_arch_crypto_set_masks()
3239 void kvm_arch_crypto_clear_masks(struct kvm *kvm) in kvm_arch_crypto_clear_masks() argument
3241 kvm_s390_vcpu_block_all(kvm); in kvm_arch_crypto_clear_masks()
3243 memset(&kvm->arch.crypto.crycb->apcb0, 0, in kvm_arch_crypto_clear_masks()
3244 sizeof(kvm->arch.crypto.crycb->apcb0)); in kvm_arch_crypto_clear_masks()
3245 memset(&kvm->arch.crypto.crycb->apcb1, 0, in kvm_arch_crypto_clear_masks()
3246 sizeof(kvm->arch.crypto.crycb->apcb1)); in kvm_arch_crypto_clear_masks()
3248 VM_EVENT(kvm, 3, "%s", "CLR CRYCB:"); in kvm_arch_crypto_clear_masks()
3250 kvm_s390_sync_request_broadcast(kvm, KVM_REQ_VSIE_RESTART); in kvm_arch_crypto_clear_masks()
3251 kvm_s390_vcpu_unblock_all(kvm); in kvm_arch_crypto_clear_masks()
3264 static void kvm_s390_crypto_init(struct kvm *kvm) in kvm_s390_crypto_init() argument
3266 kvm->arch.crypto.crycb = &kvm->arch.sie_page2->crycb; in kvm_s390_crypto_init()
3267 kvm_s390_set_crycb_format(kvm); in kvm_s390_crypto_init()
3268 init_rwsem(&kvm->arch.crypto.pqap_hook_rwsem); in kvm_s390_crypto_init()
3270 if (!test_kvm_facility(kvm, 76)) in kvm_s390_crypto_init()
3274 kvm->arch.crypto.aes_kw = 1; in kvm_s390_crypto_init()
3275 kvm->arch.crypto.dea_kw = 1; in kvm_s390_crypto_init()
3276 get_random_bytes(kvm->arch.crypto.crycb->aes_wrapping_key_mask, in kvm_s390_crypto_init()
3277 sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask)); in kvm_s390_crypto_init()
3278 get_random_bytes(kvm->arch.crypto.crycb->dea_wrapping_key_mask, in kvm_s390_crypto_init()
3279 sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask)); in kvm_s390_crypto_init()
3282 static void sca_dispose(struct kvm *kvm) in sca_dispose() argument
3284 if (kvm->arch.use_esca) in sca_dispose()
3285 free_pages_exact(kvm->arch.sca, sizeof(struct esca_block)); in sca_dispose()
3287 free_page((unsigned long)(kvm->arch.sca)); in sca_dispose()
3288 kvm->arch.sca = NULL; in sca_dispose()
3291 void kvm_arch_free_vm(struct kvm *kvm) in kvm_arch_free_vm() argument
3294 kvm_s390_pci_clear_list(kvm); in kvm_arch_free_vm()
3296 __kvm_arch_free_vm(kvm); in kvm_arch_free_vm()
3299 int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) in kvm_arch_init_vm() argument
3325 rwlock_init(&kvm->arch.sca_lock); in kvm_arch_init_vm()
3327 kvm->arch.sca = (struct bsca_block *) get_zeroed_page(alloc_flags); in kvm_arch_init_vm()
3328 if (!kvm->arch.sca) in kvm_arch_init_vm()
3334 kvm->arch.sca = (struct bsca_block *) in kvm_arch_init_vm()
3335 ((char *) kvm->arch.sca + sca_offset); in kvm_arch_init_vm()
3340 kvm->arch.dbf = debug_register(debug_name, 32, 1, 7 * sizeof(long)); in kvm_arch_init_vm()
3341 if (!kvm->arch.dbf) in kvm_arch_init_vm()
3345 kvm->arch.sie_page2 = in kvm_arch_init_vm()
3347 if (!kvm->arch.sie_page2) in kvm_arch_init_vm()
3350 kvm->arch.sie_page2->kvm = kvm; in kvm_arch_init_vm()
3351 kvm->arch.model.fac_list = kvm->arch.sie_page2->fac_list; in kvm_arch_init_vm()
3354 kvm->arch.model.fac_mask[i] = stfle_fac_list[i] & in kvm_arch_init_vm()
3357 kvm->arch.model.fac_list[i] = stfle_fac_list[i] & in kvm_arch_init_vm()
3360 kvm->arch.model.subfuncs = kvm_s390_available_subfunc; in kvm_arch_init_vm()
3363 set_kvm_facility(kvm->arch.model.fac_mask, 138); in kvm_arch_init_vm()
3364 set_kvm_facility(kvm->arch.model.fac_list, 138); in kvm_arch_init_vm()
3366 set_kvm_facility(kvm->arch.model.fac_mask, 74); in kvm_arch_init_vm()
3367 set_kvm_facility(kvm->arch.model.fac_list, 74); in kvm_arch_init_vm()
3369 set_kvm_facility(kvm->arch.model.fac_mask, 147); in kvm_arch_init_vm()
3370 set_kvm_facility(kvm->arch.model.fac_list, 147); in kvm_arch_init_vm()
3374 set_kvm_facility(kvm->arch.model.fac_mask, 65); in kvm_arch_init_vm()
3376 kvm->arch.model.cpuid = kvm_s390_get_initial_cpuid(); in kvm_arch_init_vm()
3377 kvm->arch.model.ibc = sclp.ibc & 0x0fff; in kvm_arch_init_vm()
3379 kvm->arch.model.uv_feat_guest.feat = 0; in kvm_arch_init_vm()
3381 kvm_s390_crypto_init(kvm); in kvm_arch_init_vm()
3384 mutex_lock(&kvm->lock); in kvm_arch_init_vm()
3385 kvm_s390_pci_init_list(kvm); in kvm_arch_init_vm()
3386 kvm_s390_vcpu_pci_enable_interp(kvm); in kvm_arch_init_vm()
3387 mutex_unlock(&kvm->lock); in kvm_arch_init_vm()
3390 mutex_init(&kvm->arch.float_int.ais_lock); in kvm_arch_init_vm()
3391 spin_lock_init(&kvm->arch.float_int.lock); in kvm_arch_init_vm()
3393 INIT_LIST_HEAD(&kvm->arch.float_int.lists[i]); in kvm_arch_init_vm()
3394 init_waitqueue_head(&kvm->arch.ipte_wq); in kvm_arch_init_vm()
3395 mutex_init(&kvm->arch.ipte_mutex); in kvm_arch_init_vm()
3397 debug_register_view(kvm->arch.dbf, &debug_sprintf_view); in kvm_arch_init_vm()
3398 VM_EVENT(kvm, 3, "vm created with type %lu", type); in kvm_arch_init_vm()
3401 kvm->arch.gmap = NULL; in kvm_arch_init_vm()
3402 kvm->arch.mem_limit = KVM_S390_NO_MEM_LIMIT; in kvm_arch_init_vm()
3405 kvm->arch.mem_limit = TASK_SIZE_MAX; in kvm_arch_init_vm()
3407 kvm->arch.mem_limit = min_t(unsigned long, TASK_SIZE_MAX, in kvm_arch_init_vm()
3409 kvm->arch.gmap = gmap_create(current->mm, kvm->arch.mem_limit - 1); in kvm_arch_init_vm()
3410 if (!kvm->arch.gmap) in kvm_arch_init_vm()
3412 kvm->arch.gmap->private = kvm; in kvm_arch_init_vm()
3413 kvm->arch.gmap->pfault_enabled = 0; in kvm_arch_init_vm()
3416 kvm->arch.use_pfmfi = sclp.has_pfmfi; in kvm_arch_init_vm()
3417 kvm->arch.use_skf = sclp.has_skey; in kvm_arch_init_vm()
3418 spin_lock_init(&kvm->arch.start_stop_lock); in kvm_arch_init_vm()
3419 kvm_s390_vsie_init(kvm); in kvm_arch_init_vm()
3421 kvm_s390_gisa_init(kvm); in kvm_arch_init_vm()
3422 INIT_LIST_HEAD(&kvm->arch.pv.need_cleanup); in kvm_arch_init_vm()
3423 kvm->arch.pv.set_aside = NULL; in kvm_arch_init_vm()
3424 KVM_EVENT(3, "vm 0x%pK created by pid %u", kvm, current->pid); in kvm_arch_init_vm()
3428 free_page((unsigned long)kvm->arch.sie_page2); in kvm_arch_init_vm()
3429 debug_unregister(kvm->arch.dbf); in kvm_arch_init_vm()
3430 sca_dispose(kvm); in kvm_arch_init_vm()
3443 if (!kvm_is_ucontrol(vcpu->kvm)) in kvm_arch_vcpu_destroy()
3445 kvm_s390_update_topology_change_report(vcpu->kvm, 1); in kvm_arch_vcpu_destroy()
3447 if (kvm_is_ucontrol(vcpu->kvm)) in kvm_arch_vcpu_destroy()
3450 if (vcpu->kvm->arch.use_cmma) in kvm_arch_vcpu_destroy()
3458 void kvm_arch_destroy_vm(struct kvm *kvm) in kvm_arch_destroy_vm() argument
3462 kvm_destroy_vcpus(kvm); in kvm_arch_destroy_vm()
3463 sca_dispose(kvm); in kvm_arch_destroy_vm()
3464 kvm_s390_gisa_destroy(kvm); in kvm_arch_destroy_vm()
3470 kvm_s390_pv_deinit_cleanup_all(kvm, &rc, &rrc); in kvm_arch_destroy_vm()
3477 if (kvm->arch.pv.mmu_notifier.ops) in kvm_arch_destroy_vm()
3478 mmu_notifier_unregister(&kvm->arch.pv.mmu_notifier, kvm->mm); in kvm_arch_destroy_vm()
3480 debug_unregister(kvm->arch.dbf); in kvm_arch_destroy_vm()
3481 free_page((unsigned long)kvm->arch.sie_page2); in kvm_arch_destroy_vm()
3482 if (!kvm_is_ucontrol(kvm)) in kvm_arch_destroy_vm()
3483 gmap_remove(kvm->arch.gmap); in kvm_arch_destroy_vm()
3484 kvm_s390_destroy_adapters(kvm); in kvm_arch_destroy_vm()
3485 kvm_s390_clear_float_irqs(kvm); in kvm_arch_destroy_vm()
3486 kvm_s390_vsie_destroy(kvm); in kvm_arch_destroy_vm()
3487 KVM_EVENT(3, "vm 0x%pK destroyed", kvm); in kvm_arch_destroy_vm()
3496 vcpu->arch.gmap->private = vcpu->kvm; in __kvm_ucontrol_vcpu_init()
3505 read_lock(&vcpu->kvm->arch.sca_lock); in sca_del_vcpu()
3506 if (vcpu->kvm->arch.use_esca) { in sca_del_vcpu()
3507 struct esca_block *sca = vcpu->kvm->arch.sca; in sca_del_vcpu()
3512 struct bsca_block *sca = vcpu->kvm->arch.sca; in sca_del_vcpu()
3517 read_unlock(&vcpu->kvm->arch.sca_lock); in sca_del_vcpu()
3523 phys_addr_t sca_phys = virt_to_phys(vcpu->kvm->arch.sca); in sca_add_vcpu()
3530 read_lock(&vcpu->kvm->arch.sca_lock); in sca_add_vcpu()
3531 if (vcpu->kvm->arch.use_esca) { in sca_add_vcpu()
3532 struct esca_block *sca = vcpu->kvm->arch.sca; in sca_add_vcpu()
3541 struct bsca_block *sca = vcpu->kvm->arch.sca; in sca_add_vcpu()
3549 read_unlock(&vcpu->kvm->arch.sca_lock); in sca_add_vcpu()
3570 static int sca_switch_to_extended(struct kvm *kvm) in sca_switch_to_extended() argument
3572 struct bsca_block *old_sca = kvm->arch.sca; in sca_switch_to_extended()
3579 if (kvm->arch.use_esca) in sca_switch_to_extended()
3590 kvm_s390_vcpu_block_all(kvm); in sca_switch_to_extended()
3591 write_lock(&kvm->arch.sca_lock); in sca_switch_to_extended()
3595 kvm_for_each_vcpu(vcpu_idx, vcpu, kvm) { in sca_switch_to_extended()
3600 kvm->arch.sca = new_sca; in sca_switch_to_extended()
3601 kvm->arch.use_esca = 1; in sca_switch_to_extended()
3603 write_unlock(&kvm->arch.sca_lock); in sca_switch_to_extended()
3604 kvm_s390_vcpu_unblock_all(kvm); in sca_switch_to_extended()
3608 VM_EVENT(kvm, 2, "Switched to ESCA (0x%pK -> 0x%pK)", in sca_switch_to_extended()
3609 old_sca, kvm->arch.sca); in sca_switch_to_extended()
3613 static int sca_can_add_vcpu(struct kvm *kvm, unsigned int id) in sca_can_add_vcpu() argument
3627 rc = kvm->arch.use_esca ? 0 : sca_switch_to_extended(kvm); in sca_can_add_vcpu()
3742 mutex_lock(&vcpu->kvm->lock); in kvm_arch_vcpu_postcreate()
3744 vcpu->arch.sie_block->epoch = vcpu->kvm->arch.epoch; in kvm_arch_vcpu_postcreate()
3745 vcpu->arch.sie_block->epdx = vcpu->kvm->arch.epdx; in kvm_arch_vcpu_postcreate()
3747 mutex_unlock(&vcpu->kvm->lock); in kvm_arch_vcpu_postcreate()
3748 if (!kvm_is_ucontrol(vcpu->kvm)) { in kvm_arch_vcpu_postcreate()
3749 vcpu->arch.gmap = vcpu->kvm->arch.gmap; in kvm_arch_vcpu_postcreate()
3752 if (test_kvm_facility(vcpu->kvm, 74) || vcpu->kvm->arch.user_instr0) in kvm_arch_vcpu_postcreate()
3758 static bool kvm_has_pckmo_subfunc(struct kvm *kvm, unsigned long nr) in kvm_has_pckmo_subfunc() argument
3760 if (test_bit_inv(nr, (unsigned long *)&kvm->arch.model.subfuncs.pckmo) && in kvm_has_pckmo_subfunc()
3766 static bool kvm_has_pckmo_ecc(struct kvm *kvm) in kvm_has_pckmo_ecc() argument
3769 return kvm_has_pckmo_subfunc(kvm, 32) || in kvm_has_pckmo_ecc()
3770 kvm_has_pckmo_subfunc(kvm, 33) || in kvm_has_pckmo_ecc()
3771 kvm_has_pckmo_subfunc(kvm, 34) || in kvm_has_pckmo_ecc()
3772 kvm_has_pckmo_subfunc(kvm, 40) || in kvm_has_pckmo_ecc()
3773 kvm_has_pckmo_subfunc(kvm, 41); in kvm_has_pckmo_ecc()
3783 if (!vcpu->kvm->arch.crypto.apie && !test_kvm_facility(vcpu->kvm, 76)) in kvm_s390_vcpu_crypto_setup()
3786 vcpu->arch.sie_block->crycbd = vcpu->kvm->arch.crypto.crycbd; in kvm_s390_vcpu_crypto_setup()
3791 if (vcpu->kvm->arch.crypto.apie) in kvm_s390_vcpu_crypto_setup()
3795 if (vcpu->kvm->arch.crypto.aes_kw) { in kvm_s390_vcpu_crypto_setup()
3798 if (kvm_has_pckmo_ecc(vcpu->kvm)) in kvm_s390_vcpu_crypto_setup()
3802 if (vcpu->kvm->arch.crypto.dea_kw) in kvm_s390_vcpu_crypto_setup()
3825 struct kvm_s390_cpu_model *model = &vcpu->kvm->arch.model; in kvm_s390_vcpu_setup_model()
3828 if (test_kvm_facility(vcpu->kvm, 7)) in kvm_s390_vcpu_setup_model()
3841 if (test_kvm_facility(vcpu->kvm, 78)) in kvm_s390_vcpu_setup()
3843 else if (test_kvm_facility(vcpu->kvm, 8)) in kvm_s390_vcpu_setup()
3851 if (test_kvm_facility(vcpu->kvm, 9)) in kvm_s390_vcpu_setup()
3853 if (test_kvm_facility(vcpu->kvm, 11)) in kvm_s390_vcpu_setup()
3855 if (test_kvm_facility(vcpu->kvm, 73)) in kvm_s390_vcpu_setup()
3857 if (!kvm_is_ucontrol(vcpu->kvm)) in kvm_s390_vcpu_setup()
3860 if (test_kvm_facility(vcpu->kvm, 8) && vcpu->kvm->arch.use_pfmfi) in kvm_s390_vcpu_setup()
3862 if (test_kvm_facility(vcpu->kvm, 130)) in kvm_s390_vcpu_setup()
3873 if (test_kvm_facility(vcpu->kvm, 129)) { in kvm_s390_vcpu_setup()
3877 if (test_kvm_facility(vcpu->kvm, 139)) in kvm_s390_vcpu_setup()
3879 if (test_kvm_facility(vcpu->kvm, 156)) in kvm_s390_vcpu_setup()
3894 if (vcpu->kvm->arch.use_cmma) { in kvm_s390_vcpu_setup()
3908 mutex_lock(&vcpu->kvm->lock); in kvm_s390_vcpu_setup()
3909 if (kvm_s390_pv_is_protected(vcpu->kvm)) { in kvm_s390_vcpu_setup()
3914 mutex_unlock(&vcpu->kvm->lock); in kvm_s390_vcpu_setup()
3919 int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id) in kvm_arch_vcpu_precreate() argument
3921 if (!kvm_is_ucontrol(kvm) && !sca_can_add_vcpu(kvm, id)) in kvm_arch_vcpu_precreate()
3945 vcpu->arch.sie_block->gd = kvm_s390_get_gisa_desc(vcpu->kvm); in kvm_arch_vcpu_create()
3959 if (test_kvm_facility(vcpu->kvm, 64)) in kvm_arch_vcpu_create()
3961 if (test_kvm_facility(vcpu->kvm, 82)) in kvm_arch_vcpu_create()
3963 if (test_kvm_facility(vcpu->kvm, 133)) in kvm_arch_vcpu_create()
3965 if (test_kvm_facility(vcpu->kvm, 156)) in kvm_arch_vcpu_create()
3975 if (kvm_is_ucontrol(vcpu->kvm)) { in kvm_arch_vcpu_create()
3981 VM_EVENT(vcpu->kvm, 3, "create cpu %d at 0x%pK, sie block at 0x%pK", in kvm_arch_vcpu_create()
3989 kvm_s390_update_topology_change_report(vcpu->kvm, 1); in kvm_arch_vcpu_create()
3993 if (kvm_is_ucontrol(vcpu->kvm)) in kvm_arch_vcpu_create()
4002 clear_bit(vcpu->vcpu_idx, vcpu->kvm->arch.gisa_int.kicked_mask); in kvm_arch_vcpu_runnable()
4061 struct kvm *kvm = gmap->private; in kvm_gmap_notifier() local
4073 kvm_for_each_vcpu(i, vcpu, kvm) { in kvm_gmap_notifier()
4211 if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm)) in kvm_arch_vcpu_ioctl_normal_reset()
4436 kvm_s390_set_user_cpu_state_ctrl(vcpu->kvm); in kvm_arch_vcpu_ioctl_set_mpstate()
4533 if ((vcpu->kvm->arch.use_cmma) && in kvm_s390_handle_requests()
4534 (vcpu->kvm->mm->context.uses_cmm)) in kvm_s390_handle_requests()
4545 static void __kvm_s390_set_tod_clock(struct kvm *kvm, const struct kvm_s390_vm_tod_clock *gtod) in __kvm_s390_set_tod_clock() argument
4555 kvm->arch.epoch = gtod->tod - clk.tod; in __kvm_s390_set_tod_clock()
4556 kvm->arch.epdx = 0; in __kvm_s390_set_tod_clock()
4557 if (test_kvm_facility(kvm, 139)) { in __kvm_s390_set_tod_clock()
4558 kvm->arch.epdx = gtod->epoch_idx - clk.ei; in __kvm_s390_set_tod_clock()
4559 if (kvm->arch.epoch > gtod->tod) in __kvm_s390_set_tod_clock()
4560 kvm->arch.epdx -= 1; in __kvm_s390_set_tod_clock()
4563 kvm_s390_vcpu_block_all(kvm); in __kvm_s390_set_tod_clock()
4564 kvm_for_each_vcpu(i, vcpu, kvm) { in __kvm_s390_set_tod_clock()
4565 vcpu->arch.sie_block->epoch = kvm->arch.epoch; in __kvm_s390_set_tod_clock()
4566 vcpu->arch.sie_block->epdx = kvm->arch.epdx; in __kvm_s390_set_tod_clock()
4569 kvm_s390_vcpu_unblock_all(kvm); in __kvm_s390_set_tod_clock()
4573 int kvm_s390_try_set_tod_clock(struct kvm *kvm, const struct kvm_s390_vm_tod_clock *gtod) in kvm_s390_try_set_tod_clock() argument
4575 if (!mutex_trylock(&kvm->lock)) in kvm_s390_try_set_tod_clock()
4577 __kvm_s390_set_tod_clock(kvm, gtod); in kvm_s390_try_set_tod_clock()
4578 mutex_unlock(&kvm->lock); in kvm_s390_try_set_tod_clock()
4611 WARN_ON_ONCE(kvm_s390_inject_vm(vcpu->kvm, &inti)); in __kvm_inject_pfault_token()
4665 hva = gfn_to_hva(vcpu->kvm, gpa_to_gfn(current->thread.gmap_addr)); in kvm_arch_setup_async_pf()
4690 if (!kvm_is_ucontrol(vcpu->kvm)) { in vcpu_pre_run()
4705 clear_bit(vcpu->vcpu_idx, vcpu->kvm->arch.gisa_int.kicked_mask); in vcpu_pre_run()
4788 } else if (kvm_is_ucontrol(vcpu->kvm)) { in vcpu_post_run()
4899 test_kvm_facility(vcpu->kvm, 64) && in sync_regs_fmt2()
4910 test_kvm_facility(vcpu->kvm, 133) && in sync_regs_fmt2()
4919 test_kvm_facility(vcpu->kvm, 82)) { in sync_regs_fmt2()
5037 if (vcpu->kvm->arch.pv.dumping) in kvm_arch_vcpu_ioctl_run()
5061 if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm)) { in kvm_arch_vcpu_ioctl_run()
5181 static void __disable_ibs_on_all_vcpus(struct kvm *kvm) in __disable_ibs_on_all_vcpus() argument
5186 kvm_for_each_vcpu(i, vcpu, kvm) { in __disable_ibs_on_all_vcpus()
5208 spin_lock(&vcpu->kvm->arch.start_stop_lock); in kvm_s390_vcpu_start()
5209 online_vcpus = atomic_read(&vcpu->kvm->online_vcpus); in kvm_s390_vcpu_start()
5215 spin_unlock(&vcpu->kvm->arch.start_stop_lock); in kvm_s390_vcpu_start()
5221 if (!is_vcpu_stopped(kvm_get_vcpu(vcpu->kvm, i))) in kvm_s390_vcpu_start()
5234 __disable_ibs_on_all_vcpus(vcpu->kvm); in kvm_s390_vcpu_start()
5250 spin_unlock(&vcpu->kvm->arch.start_stop_lock); in kvm_s390_vcpu_start()
5264 spin_lock(&vcpu->kvm->arch.start_stop_lock); in kvm_s390_vcpu_stop()
5265 online_vcpus = atomic_read(&vcpu->kvm->online_vcpus); in kvm_s390_vcpu_stop()
5271 spin_unlock(&vcpu->kvm->arch.start_stop_lock); in kvm_s390_vcpu_stop()
5288 struct kvm_vcpu *tmp = kvm_get_vcpu(vcpu->kvm, i); in kvm_s390_vcpu_stop()
5304 spin_unlock(&vcpu->kvm->arch.start_stop_lock); in kvm_s390_vcpu_stop()
5318 if (!vcpu->kvm->arch.css_support) { in kvm_vcpu_ioctl_enable_cap()
5319 vcpu->kvm->arch.css_support = 1; in kvm_vcpu_ioctl_enable_cap()
5320 VM_EVENT(vcpu->kvm, 3, "%s", "ENABLE: CSS support"); in kvm_vcpu_ioctl_enable_cap()
5321 trace_kvm_s390_enable_css(vcpu->kvm); in kvm_vcpu_ioctl_enable_cap()
5425 srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); in kvm_s390_vcpu_memsida_op()
5441 srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx); in kvm_s390_vcpu_memsida_op()
5498 if (!vcpu->kvm->arch.pv.dumping) in kvm_s390_handle_pv_vcpu_dump()
5545 idx = srcu_read_lock(&vcpu->kvm->srcu); in kvm_arch_vcpu_ioctl()
5547 srcu_read_unlock(&vcpu->kvm->srcu, idx); in kvm_arch_vcpu_ioctl()
5613 if (!kvm_is_ucontrol(vcpu->kvm)) { in kvm_arch_vcpu_ioctl()
5630 if (!kvm_is_ucontrol(vcpu->kvm)) { in kvm_arch_vcpu_ioctl()
5735 && (kvm_is_ucontrol(vcpu->kvm))) { in kvm_arch_vcpu_fault()
5744 bool kvm_arch_irqchip_in_kernel(struct kvm *kvm) in kvm_arch_irqchip_in_kernel() argument
5750 int kvm_arch_prepare_memory_region(struct kvm *kvm, in kvm_arch_prepare_memory_region() argument
5757 if (kvm_is_ucontrol(kvm)) in kvm_arch_prepare_memory_region()
5761 if (kvm_s390_pv_get_handle(kvm)) in kvm_arch_prepare_memory_region()
5779 if ((new->base_gfn * PAGE_SIZE) + size > kvm->arch.mem_limit) in kvm_arch_prepare_memory_region()
5783 if (!kvm->arch.migration_mode) in kvm_arch_prepare_memory_region()
5796 WARN(kvm_s390_vm_stop_migration(kvm), in kvm_arch_prepare_memory_region()
5802 void kvm_arch_commit_memory_region(struct kvm *kvm, in kvm_arch_commit_memory_region() argument
5811 rc = gmap_unmap_segment(kvm->arch.gmap, old->base_gfn * PAGE_SIZE, in kvm_arch_commit_memory_region()
5815 rc = gmap_unmap_segment(kvm->arch.gmap, old->base_gfn * PAGE_SIZE, in kvm_arch_commit_memory_region()
5821 rc = gmap_map_segment(kvm->arch.gmap, new->userspace_addr, in kvm_arch_commit_memory_region()