kvm-s390.c (4e9816d012dbc28dc89559261c6ffbf8ffc440dd) kvm-s390.c (0759d0681cae279e77ebb4b76175e330360b01d9)
1/*
2 * hosting zSeries kernel virtual machines
3 *
4 * Copyright IBM Corp. 2008, 2009
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License (version 2 only)
8 * as published by the Free Software Foundation.

--- 153 unchanged lines hidden (view full) ---

162 case KVM_CAP_ONE_REG:
163 case KVM_CAP_ENABLE_CAP:
164 case KVM_CAP_S390_CSS_SUPPORT:
165 case KVM_CAP_IRQFD:
166 case KVM_CAP_IOEVENTFD:
167 case KVM_CAP_DEVICE_CTRL:
168 case KVM_CAP_ENABLE_CAP_VM:
169 case KVM_CAP_VM_ATTRIBUTES:
1/*
2 * hosting zSeries kernel virtual machines
3 *
4 * Copyright IBM Corp. 2008, 2009
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License (version 2 only)
8 * as published by the Free Software Foundation.

--- 153 unchanged lines hidden (view full) ---

162 case KVM_CAP_ONE_REG:
163 case KVM_CAP_ENABLE_CAP:
164 case KVM_CAP_S390_CSS_SUPPORT:
165 case KVM_CAP_IRQFD:
166 case KVM_CAP_IOEVENTFD:
167 case KVM_CAP_DEVICE_CTRL:
168 case KVM_CAP_ENABLE_CAP_VM:
169 case KVM_CAP_VM_ATTRIBUTES:
170 case KVM_CAP_MP_STATE:
170 r = 1;
171 break;
172 case KVM_CAP_NR_VCPUS:
173 case KVM_CAP_MAX_VCPUS:
174 r = KVM_MAX_VCPUS;
175 break;
176 case KVM_CAP_NR_MEMSLOTS:
177 r = KVM_USER_MEM_SLOTS;

--- 412 unchanged lines hidden (view full) ---

590 vcpu->arch.sie_block->gcr[0] = 0xE0UL;
591 vcpu->arch.sie_block->gcr[14] = 0xC2000000UL;
592 vcpu->arch.guest_fpregs.fpc = 0;
593 asm volatile("lfpc %0" : : "Q" (vcpu->arch.guest_fpregs.fpc));
594 vcpu->arch.sie_block->gbea = 1;
595 vcpu->arch.sie_block->pp = 0;
596 vcpu->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
597 kvm_clear_async_pf_completion_queue(vcpu);
171 r = 1;
172 break;
173 case KVM_CAP_NR_VCPUS:
174 case KVM_CAP_MAX_VCPUS:
175 r = KVM_MAX_VCPUS;
176 break;
177 case KVM_CAP_NR_MEMSLOTS:
178 r = KVM_USER_MEM_SLOTS;

--- 412 unchanged lines hidden (view full) ---

591 vcpu->arch.sie_block->gcr[0] = 0xE0UL;
592 vcpu->arch.sie_block->gcr[14] = 0xC2000000UL;
593 vcpu->arch.guest_fpregs.fpc = 0;
594 asm volatile("lfpc %0" : : "Q" (vcpu->arch.guest_fpregs.fpc));
595 vcpu->arch.sie_block->gbea = 1;
596 vcpu->arch.sie_block->pp = 0;
597 vcpu->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
598 kvm_clear_async_pf_completion_queue(vcpu);
598 kvm_s390_vcpu_stop(vcpu);
599 if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm))
600 kvm_s390_vcpu_stop(vcpu);
599 kvm_s390_clear_local_irqs(vcpu);
600}
601
602int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
603{
604 return 0;
605}
606

--- 314 unchanged lines hidden (view full) ---

921 fpu->fpc = vcpu->arch.guest_fpregs.fpc;
922 return 0;
923}
924
925static int kvm_arch_vcpu_ioctl_set_initial_psw(struct kvm_vcpu *vcpu, psw_t psw)
926{
927 int rc = 0;
928
601 kvm_s390_clear_local_irqs(vcpu);
602}
603
604int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
605{
606 return 0;
607}
608

--- 314 unchanged lines hidden (view full) ---

923 fpu->fpc = vcpu->arch.guest_fpregs.fpc;
924 return 0;
925}
926
927static int kvm_arch_vcpu_ioctl_set_initial_psw(struct kvm_vcpu *vcpu, psw_t psw)
928{
929 int rc = 0;
930
929 if (!(atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_STOPPED))
931 if (!is_vcpu_stopped(vcpu))
930 rc = -EBUSY;
931 else {
932 vcpu->run->psw_mask = psw.mask;
933 vcpu->run->psw_addr = psw.addr;
934 }
935 return rc;
936}
937

--- 37 unchanged lines hidden (view full) ---

975 }
976
977 return rc;
978}
979
980int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
981 struct kvm_mp_state *mp_state)
982{
932 rc = -EBUSY;
933 else {
934 vcpu->run->psw_mask = psw.mask;
935 vcpu->run->psw_addr = psw.addr;
936 }
937 return rc;
938}
939

--- 37 unchanged lines hidden (view full) ---

977 }
978
979 return rc;
980}
981
982int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
983 struct kvm_mp_state *mp_state)
984{
983 return -EINVAL; /* not implemented yet */
985 /* CHECK_STOP and LOAD are not supported yet */
986 return is_vcpu_stopped(vcpu) ? KVM_MP_STATE_STOPPED :
987 KVM_MP_STATE_OPERATING;
984}
985
986int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
987 struct kvm_mp_state *mp_state)
988{
988}
989
990int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
991 struct kvm_mp_state *mp_state)
992{
989 return -EINVAL; /* not implemented yet */
993 int rc = 0;
994
995 /* user space knows about this interface - let it control the state */
996 vcpu->kvm->arch.user_cpu_state_ctrl = 1;
997
998 switch (mp_state->mp_state) {
999 case KVM_MP_STATE_STOPPED:
1000 kvm_s390_vcpu_stop(vcpu);
1001 break;
1002 case KVM_MP_STATE_OPERATING:
1003 kvm_s390_vcpu_start(vcpu);
1004 break;
1005 case KVM_MP_STATE_LOAD:
1006 case KVM_MP_STATE_CHECK_STOP:
1007 /* fall through - CHECK_STOP and LOAD are not supported yet */
1008 default:
1009 rc = -ENXIO;
1010 }
1011
1012 return rc;
990}
991
992bool kvm_s390_cmma_enabled(struct kvm *kvm)
993{
994 if (!MACHINE_IS_LPAR)
995 return false;
996 /* only enable for z10 and later */
997 if (!MACHINE_HAS_EDAT1)

--- 42 unchanged lines hidden (view full) ---

1040 if (ibs_enabled(vcpu)) {
1041 trace_kvm_s390_enable_disable_ibs(vcpu->vcpu_id, 0);
1042 atomic_clear_mask(CPUSTAT_IBS,
1043 &vcpu->arch.sie_block->cpuflags);
1044 }
1045 goto retry;
1046 }
1047
1013}
1014
1015bool kvm_s390_cmma_enabled(struct kvm *kvm)
1016{
1017 if (!MACHINE_IS_LPAR)
1018 return false;
1019 /* only enable for z10 and later */
1020 if (!MACHINE_HAS_EDAT1)

--- 42 unchanged lines hidden (view full) ---

1063 if (ibs_enabled(vcpu)) {
1064 trace_kvm_s390_enable_disable_ibs(vcpu->vcpu_id, 0);
1065 atomic_clear_mask(CPUSTAT_IBS,
1066 &vcpu->arch.sie_block->cpuflags);
1067 }
1068 goto retry;
1069 }
1070
1071 /* nothing to do, just clear the request */
1072 clear_bit(KVM_REQ_UNHALT, &vcpu->requests);
1073
1048 return 0;
1049}
1050
1051/**
1052 * kvm_arch_fault_in_page - fault-in guest page if necessary
1053 * @vcpu: The corresponding virtual cpu
1054 * @gpa: Guest physical address
1055 * @writable: Whether the page should be writable or not

--- 223 unchanged lines hidden (view full) ---

1279 if (guestdbg_exit_pending(vcpu)) {
1280 kvm_s390_prepare_debug_exit(vcpu);
1281 return 0;
1282 }
1283
1284 if (vcpu->sigset_active)
1285 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
1286
1074 return 0;
1075}
1076
1077/**
1078 * kvm_arch_fault_in_page - fault-in guest page if necessary
1079 * @vcpu: The corresponding virtual cpu
1080 * @gpa: Guest physical address
1081 * @writable: Whether the page should be writable or not

--- 223 unchanged lines hidden (view full) ---

1305 if (guestdbg_exit_pending(vcpu)) {
1306 kvm_s390_prepare_debug_exit(vcpu);
1307 return 0;
1308 }
1309
1310 if (vcpu->sigset_active)
1311 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
1312
1287 kvm_s390_vcpu_start(vcpu);
1313 if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm)) {
1314 kvm_s390_vcpu_start(vcpu);
1315 } else if (is_vcpu_stopped(vcpu)) {
1316 pr_err_ratelimited("kvm-s390: can't run stopped vcpu %d\n",
1317 vcpu->vcpu_id);
1318 return -EINVAL;
1319 }
1288
1289 switch (kvm_run->exit_reason) {
1290 case KVM_EXIT_S390_SIEIC:
1291 case KVM_EXIT_UNKNOWN:
1292 case KVM_EXIT_INTR:
1293 case KVM_EXIT_S390_RESET:
1294 case KVM_EXIT_S390_UCONTROL:
1295 case KVM_EXIT_S390_TSCH:

--- 112 unchanged lines hidden (view full) ---

1408 */
1409 save_fp_ctl(&vcpu->arch.guest_fpregs.fpc);
1410 save_fp_regs(vcpu->arch.guest_fpregs.fprs);
1411 save_access_regs(vcpu->run->s.regs.acrs);
1412
1413 return kvm_s390_store_status_unloaded(vcpu, addr);
1414}
1415
1320
1321 switch (kvm_run->exit_reason) {
1322 case KVM_EXIT_S390_SIEIC:
1323 case KVM_EXIT_UNKNOWN:
1324 case KVM_EXIT_INTR:
1325 case KVM_EXIT_S390_RESET:
1326 case KVM_EXIT_S390_UCONTROL:
1327 case KVM_EXIT_S390_TSCH:

--- 112 unchanged lines hidden (view full) ---

1440 */
1441 save_fp_ctl(&vcpu->arch.guest_fpregs.fpc);
1442 save_fp_regs(vcpu->arch.guest_fpregs.fprs);
1443 save_access_regs(vcpu->run->s.regs.acrs);
1444
1445 return kvm_s390_store_status_unloaded(vcpu, addr);
1446}
1447
1416static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu)
1417{
1418 return atomic_read(&(vcpu)->arch.sie_block->cpuflags) & CPUSTAT_STOPPED;
1419}
1420
1421static void __disable_ibs_on_vcpu(struct kvm_vcpu *vcpu)
1422{
1423 kvm_check_request(KVM_REQ_ENABLE_IBS, vcpu);
1424 kvm_make_request(KVM_REQ_DISABLE_IBS, vcpu);
1425 exit_sie_sync(vcpu);
1426}
1427
1428static void __disable_ibs_on_all_vcpus(struct kvm *kvm)

--- 60 unchanged lines hidden (view full) ---

1489 if (is_vcpu_stopped(vcpu))
1490 return;
1491
1492 trace_kvm_s390_vcpu_start_stop(vcpu->vcpu_id, 0);
1493 /* Only one cpu at a time may enter/leave the STOPPED state. */
1494 spin_lock_bh(&vcpu->kvm->arch.start_stop_lock);
1495 online_vcpus = atomic_read(&vcpu->kvm->online_vcpus);
1496
1448static void __disable_ibs_on_vcpu(struct kvm_vcpu *vcpu)
1449{
1450 kvm_check_request(KVM_REQ_ENABLE_IBS, vcpu);
1451 kvm_make_request(KVM_REQ_DISABLE_IBS, vcpu);
1452 exit_sie_sync(vcpu);
1453}
1454
1455static void __disable_ibs_on_all_vcpus(struct kvm *kvm)

--- 60 unchanged lines hidden (view full) ---

1516 if (is_vcpu_stopped(vcpu))
1517 return;
1518
1519 trace_kvm_s390_vcpu_start_stop(vcpu->vcpu_id, 0);
1520 /* Only one cpu at a time may enter/leave the STOPPED state. */
1521 spin_lock_bh(&vcpu->kvm->arch.start_stop_lock);
1522 online_vcpus = atomic_read(&vcpu->kvm->online_vcpus);
1523
1524 /* Need to lock access to action_bits to avoid a SIGP race condition */
1525 spin_lock_bh(&vcpu->arch.local_int.lock);
1497 atomic_set_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags);
1526 atomic_set_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags);
1527
1528 /* SIGP STOP and SIGP STOP AND STORE STATUS has been fully processed */
1529 vcpu->arch.local_int.action_bits &=
1530 ~(ACTION_STOP_ON_STOP | ACTION_STORE_ON_STOP);
1531 spin_unlock_bh(&vcpu->arch.local_int.lock);
1532
1498 __disable_ibs_on_vcpu(vcpu);
1499
1500 for (i = 0; i < online_vcpus; i++) {
1501 if (!is_vcpu_stopped(vcpu->kvm->vcpus[i])) {
1502 started_vcpus++;
1503 started_vcpu = vcpu->kvm->vcpus[i];
1504 }
1505 }

--- 262 unchanged lines hidden ---
1533 __disable_ibs_on_vcpu(vcpu);
1534
1535 for (i = 0; i < online_vcpus; i++) {
1536 if (!is_vcpu_stopped(vcpu->kvm->vcpus[i])) {
1537 started_vcpus++;
1538 started_vcpu = vcpu->kvm->vcpus[i];
1539 }
1540 }

--- 262 unchanged lines hidden ---