2 * diag.c - handling diagnose instructions
4 * Copyright IBM Corp. 2008,2011
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.
10 * Author(s): Carsten Otte <cotte@de.ibm.com>
11 * Christian Borntraeger <borntraeger@de.ibm.com>
14 #include <linux/kvm.h>
15 #include <linux/kvm_host.h>
18 static int diag_release_pages(struct kvm_vcpu
*vcpu
)
20 unsigned long start
, end
;
21 unsigned long prefix
= vcpu
->arch
.sie_block
->prefix
;
23 start
= vcpu
->run
->s
.regs
.gprs
[(vcpu
->arch
.sie_block
->ipa
& 0xf0) >> 4];
24 end
= vcpu
->run
->s
.regs
.gprs
[vcpu
->arch
.sie_block
->ipa
& 0xf] + 4096;
26 if (start
& ~PAGE_MASK
|| end
& ~PAGE_MASK
|| start
> end
27 || start
< 2 * PAGE_SIZE
)
28 return kvm_s390_inject_program_int(vcpu
, PGM_SPECIFICATION
);
30 VCPU_EVENT(vcpu
, 5, "diag release pages %lX %lX", start
, end
);
31 vcpu
->stat
.diagnose_10
++;
33 /* we checked for start > end above */
34 if (end
< prefix
|| start
>= prefix
+ 2 * PAGE_SIZE
) {
35 gmap_discard(start
, end
, vcpu
->arch
.gmap
);
38 gmap_discard(start
, prefix
, vcpu
->arch
.gmap
);
40 gmap_discard(prefix
+ 2 * PAGE_SIZE
,
41 end
, vcpu
->arch
.gmap
);
46 static int __diag_time_slice_end(struct kvm_vcpu
*vcpu
)
48 VCPU_EVENT(vcpu
, 5, "%s", "diag time slice end");
49 vcpu
->stat
.diagnose_44
++;
56 static int __diag_ipl_functions(struct kvm_vcpu
*vcpu
)
58 unsigned int reg
= vcpu
->arch
.sie_block
->ipa
& 0xf;
59 unsigned long subcode
= vcpu
->run
->s
.regs
.gprs
[reg
] & 0xffff;
61 VCPU_EVENT(vcpu
, 5, "diag ipl functions, subcode %lx", subcode
);
64 vcpu
->run
->s390_reset_flags
= KVM_S390_RESET_CLEAR
;
67 vcpu
->run
->s390_reset_flags
= 0;
73 atomic_set_mask(CPUSTAT_STOPPED
, &vcpu
->arch
.sie_block
->cpuflags
);
74 vcpu
->run
->s390_reset_flags
|= KVM_S390_RESET_SUBSYSTEM
;
75 vcpu
->run
->s390_reset_flags
|= KVM_S390_RESET_IPL
;
76 vcpu
->run
->s390_reset_flags
|= KVM_S390_RESET_CPU_INIT
;
77 vcpu
->run
->exit_reason
= KVM_EXIT_S390_RESET
;
78 VCPU_EVENT(vcpu
, 3, "requesting userspace resets %llx",
79 vcpu
->run
->s390_reset_flags
);
83 int kvm_s390_handle_diag(struct kvm_vcpu
*vcpu
)
85 int code
= (vcpu
->arch
.sie_block
->ipb
& 0xfff0000) >> 16;
89 return diag_release_pages(vcpu
);
91 return __diag_time_slice_end(vcpu
);
93 return __diag_ipl_functions(vcpu
);