2 * 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>
16 #include <asm/virtio-ccw.h>
19 #include "trace-s390.h"
21 static int diag_release_pages(struct kvm_vcpu
*vcpu
)
23 unsigned long start
, end
;
24 unsigned long prefix
= vcpu
->arch
.sie_block
->prefix
;
26 start
= vcpu
->run
->s
.regs
.gprs
[(vcpu
->arch
.sie_block
->ipa
& 0xf0) >> 4];
27 end
= vcpu
->run
->s
.regs
.gprs
[vcpu
->arch
.sie_block
->ipa
& 0xf] + 4096;
29 if (start
& ~PAGE_MASK
|| end
& ~PAGE_MASK
|| start
> end
30 || start
< 2 * PAGE_SIZE
)
31 return kvm_s390_inject_program_int(vcpu
, PGM_SPECIFICATION
);
33 VCPU_EVENT(vcpu
, 5, "diag release pages %lX %lX", start
, end
);
34 vcpu
->stat
.diagnose_10
++;
36 /* we checked for start > end above */
37 if (end
< prefix
|| start
>= prefix
+ 2 * PAGE_SIZE
) {
38 gmap_discard(start
, end
, vcpu
->arch
.gmap
);
41 gmap_discard(start
, prefix
, vcpu
->arch
.gmap
);
43 gmap_discard(prefix
+ 2 * PAGE_SIZE
,
44 end
, vcpu
->arch
.gmap
);
49 static int __diag_time_slice_end(struct kvm_vcpu
*vcpu
)
51 VCPU_EVENT(vcpu
, 5, "%s", "diag time slice end");
52 vcpu
->stat
.diagnose_44
++;
53 kvm_vcpu_on_spin(vcpu
);
57 static int __diag_time_slice_end_directed(struct kvm_vcpu
*vcpu
)
59 struct kvm
*kvm
= vcpu
->kvm
;
60 struct kvm_vcpu
*tcpu
;
64 tid
= vcpu
->run
->s
.regs
.gprs
[(vcpu
->arch
.sie_block
->ipa
& 0xf0) >> 4];
65 vcpu
->stat
.diagnose_9c
++;
66 VCPU_EVENT(vcpu
, 5, "diag time slice end directed to %d", tid
);
68 if (tid
== vcpu
->vcpu_id
)
71 kvm_for_each_vcpu(i
, tcpu
, kvm
)
72 if (tcpu
->vcpu_id
== tid
) {
73 kvm_vcpu_yield_to(tcpu
);
80 static int __diag_ipl_functions(struct kvm_vcpu
*vcpu
)
82 unsigned int reg
= vcpu
->arch
.sie_block
->ipa
& 0xf;
83 unsigned long subcode
= vcpu
->run
->s
.regs
.gprs
[reg
] & 0xffff;
85 VCPU_EVENT(vcpu
, 5, "diag ipl functions, subcode %lx", subcode
);
88 vcpu
->run
->s390_reset_flags
= KVM_S390_RESET_CLEAR
;
91 vcpu
->run
->s390_reset_flags
= 0;
97 atomic_set_mask(CPUSTAT_STOPPED
, &vcpu
->arch
.sie_block
->cpuflags
);
98 vcpu
->run
->s390_reset_flags
|= KVM_S390_RESET_SUBSYSTEM
;
99 vcpu
->run
->s390_reset_flags
|= KVM_S390_RESET_IPL
;
100 vcpu
->run
->s390_reset_flags
|= KVM_S390_RESET_CPU_INIT
;
101 vcpu
->run
->exit_reason
= KVM_EXIT_S390_RESET
;
102 VCPU_EVENT(vcpu
, 3, "requesting userspace resets %llx",
103 vcpu
->run
->s390_reset_flags
);
104 trace_kvm_s390_request_resets(vcpu
->run
->s390_reset_flags
);
108 static int __diag_virtio_hypercall(struct kvm_vcpu
*vcpu
)
112 /* No virtio-ccw notification? Get out quickly. */
113 if (!vcpu
->kvm
->arch
.css_support
||
114 (vcpu
->run
->s
.regs
.gprs
[1] != KVM_S390_VIRTIO_CCW_NOTIFY
))
117 idx
= srcu_read_lock(&vcpu
->kvm
->srcu
);
119 * The layout is as follows:
120 * - gpr 2 contains the subchannel id (passed as addr)
121 * - gpr 3 contains the virtqueue index (passed as datamatch)
123 ret
= kvm_io_bus_write(vcpu
->kvm
, KVM_VIRTIO_CCW_NOTIFY_BUS
,
124 vcpu
->run
->s
.regs
.gprs
[2],
125 8, &vcpu
->run
->s
.regs
.gprs
[3]);
126 srcu_read_unlock(&vcpu
->kvm
->srcu
, idx
);
127 /* kvm_io_bus_write returns -EOPNOTSUPP if it found no match. */
128 return ret
< 0 ? ret
: 0;
131 int kvm_s390_handle_diag(struct kvm_vcpu
*vcpu
)
133 int code
= (vcpu
->arch
.sie_block
->ipb
& 0xfff0000) >> 16;
135 trace_kvm_s390_handle_diag(vcpu
, code
);
138 return diag_release_pages(vcpu
);
140 return __diag_time_slice_end(vcpu
);
142 return __diag_time_slice_end_directed(vcpu
);
144 return __diag_ipl_functions(vcpu
);
146 return __diag_virtio_hypercall(vcpu
);