2 * QEMU S390x KVM implementation
4 * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
5 * Copyright IBM Corp. 2012
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * Contributions after 2012-10-29 are licensed under the terms of the
18 * GNU GPL, version 2 or (at your option) any later version.
20 * You should have received a copy of the GNU (Lesser) General Public
21 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
24 #include <sys/types.h>
25 #include <sys/ioctl.h>
28 #include <linux/kvm.h>
29 #include <asm/ptrace.h>
31 #include "qemu-common.h"
32 #include "qemu/timer.h"
33 #include "sysemu/sysemu.h"
34 #include "sysemu/kvm.h"
36 #include "sysemu/device_tree.h"
37 #include "qapi/qmp/qjson.h"
38 #include "monitor/monitor.h"
40 /* #define DEBUG_KVM */
43 #define DPRINTF(fmt, ...) \
44 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
46 #define DPRINTF(fmt, ...) \
50 #define IPA0_DIAG 0x8300
51 #define IPA0_SIGP 0xae00
52 #define IPA0_B2 0xb200
53 #define IPA0_B9 0xb900
54 #define IPA0_EB 0xeb00
56 #define PRIV_B2_SCLP_CALL 0x20
57 #define PRIV_B2_CSCH 0x30
58 #define PRIV_B2_HSCH 0x31
59 #define PRIV_B2_MSCH 0x32
60 #define PRIV_B2_SSCH 0x33
61 #define PRIV_B2_STSCH 0x34
62 #define PRIV_B2_TSCH 0x35
63 #define PRIV_B2_TPI 0x36
64 #define PRIV_B2_SAL 0x37
65 #define PRIV_B2_RSCH 0x38
66 #define PRIV_B2_STCRW 0x39
67 #define PRIV_B2_STCPS 0x3a
68 #define PRIV_B2_RCHP 0x3b
69 #define PRIV_B2_SCHM 0x3c
70 #define PRIV_B2_CHSC 0x5f
71 #define PRIV_B2_SIGA 0x74
72 #define PRIV_B2_XSCH 0x76
74 #define PRIV_EB_SQBS 0x8a
76 #define PRIV_B9_EQBS 0x9c
78 #define DIAG_IPL 0x308
79 #define DIAG_KVM_HYPERCALL 0x500
80 #define DIAG_KVM_BREAKPOINT 0x501
82 #define ICPT_INSTRUCTION 0x04
83 #define ICPT_WAITPSW 0x1c
84 #define ICPT_SOFT_INTERCEPT 0x24
85 #define ICPT_CPU_STOP 0x28
88 const KVMCapabilityInfo kvm_arch_required_capabilities
[] = {
92 static int cap_sync_regs
;
93 static int cap_async_pf
;
95 static void *legacy_s390_alloc(size_t size
);
97 int kvm_arch_init(KVMState
*s
)
99 cap_sync_regs
= kvm_check_extension(s
, KVM_CAP_SYNC_REGS
);
100 cap_async_pf
= kvm_check_extension(s
, KVM_CAP_ASYNC_PF
);
101 if (!kvm_check_extension(s
, KVM_CAP_S390_GMAP
)
102 || !kvm_check_extension(s
, KVM_CAP_S390_COW
)) {
103 phys_mem_set_alloc(legacy_s390_alloc
);
108 unsigned long kvm_arch_vcpu_id(CPUState
*cpu
)
110 return cpu
->cpu_index
;
113 int kvm_arch_init_vcpu(CPUState
*cpu
)
115 /* nothing todo yet */
119 void kvm_arch_reset_vcpu(CPUState
*cpu
)
121 /* The initial reset call is needed here to reset in-kernel
122 * vcpu data that we can't access directly from QEMU
123 * (i.e. with older kernels which don't support sync_regs/ONE_REG).
124 * Before this ioctl cpu_synchronize_state() is called in common kvm
126 if (kvm_vcpu_ioctl(cpu
, KVM_S390_INITIAL_RESET
, NULL
)) {
127 perror("Can't reset vcpu\n");
131 int kvm_arch_put_registers(CPUState
*cs
, int level
)
133 S390CPU
*cpu
= S390_CPU(cs
);
134 CPUS390XState
*env
= &cpu
->env
;
135 struct kvm_one_reg reg
;
136 struct kvm_sregs sregs
;
137 struct kvm_regs regs
;
141 /* always save the PSW and the GPRS*/
142 cs
->kvm_run
->psw_addr
= env
->psw
.addr
;
143 cs
->kvm_run
->psw_mask
= env
->psw
.mask
;
145 if (cap_sync_regs
&& cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_GPRS
) {
146 for (i
= 0; i
< 16; i
++) {
147 cs
->kvm_run
->s
.regs
.gprs
[i
] = env
->regs
[i
];
148 cs
->kvm_run
->kvm_dirty_regs
|= KVM_SYNC_GPRS
;
151 for (i
= 0; i
< 16; i
++) {
152 regs
.gprs
[i
] = env
->regs
[i
];
154 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_REGS
, ®s
);
160 /* Do we need to save more than that? */
161 if (level
== KVM_PUT_RUNTIME_STATE
) {
165 reg
.id
= KVM_REG_S390_CPU_TIMER
;
166 reg
.addr
= (__u64
)&(env
->cputm
);
167 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_ONE_REG
, ®
);
172 reg
.id
= KVM_REG_S390_CLOCK_COMP
;
173 reg
.addr
= (__u64
)&(env
->ckc
);
174 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_ONE_REG
, ®
);
179 reg
.id
= KVM_REG_S390_TODPR
;
180 reg
.addr
= (__u64
)&(env
->todpr
);
181 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_ONE_REG
, ®
);
187 reg
.id
= KVM_REG_S390_PFTOKEN
;
188 reg
.addr
= (__u64
)&(env
->pfault_token
);
189 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_ONE_REG
, ®
);
194 reg
.id
= KVM_REG_S390_PFCOMPARE
;
195 reg
.addr
= (__u64
)&(env
->pfault_compare
);
196 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_ONE_REG
, ®
);
201 reg
.id
= KVM_REG_S390_PFSELECT
;
202 reg
.addr
= (__u64
)&(env
->pfault_select
);
203 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_ONE_REG
, ®
);
210 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_ACRS
&&
211 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_CRS
) {
212 for (i
= 0; i
< 16; i
++) {
213 cs
->kvm_run
->s
.regs
.acrs
[i
] = env
->aregs
[i
];
214 cs
->kvm_run
->s
.regs
.crs
[i
] = env
->cregs
[i
];
216 cs
->kvm_run
->kvm_dirty_regs
|= KVM_SYNC_ACRS
;
217 cs
->kvm_run
->kvm_dirty_regs
|= KVM_SYNC_CRS
;
219 for (i
= 0; i
< 16; i
++) {
220 sregs
.acrs
[i
] = env
->aregs
[i
];
221 sregs
.crs
[i
] = env
->cregs
[i
];
223 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_SREGS
, &sregs
);
229 /* Finally the prefix */
230 if (cap_sync_regs
&& cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_PREFIX
) {
231 cs
->kvm_run
->s
.regs
.prefix
= env
->psa
;
232 cs
->kvm_run
->kvm_dirty_regs
|= KVM_SYNC_PREFIX
;
234 /* prefix is only supported via sync regs */
239 int kvm_arch_get_registers(CPUState
*cs
)
241 S390CPU
*cpu
= S390_CPU(cs
);
242 CPUS390XState
*env
= &cpu
->env
;
243 struct kvm_one_reg reg
;
244 struct kvm_sregs sregs
;
245 struct kvm_regs regs
;
249 env
->psw
.addr
= cs
->kvm_run
->psw_addr
;
250 env
->psw
.mask
= cs
->kvm_run
->psw_mask
;
253 if (cap_sync_regs
&& cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_GPRS
) {
254 for (i
= 0; i
< 16; i
++) {
255 env
->regs
[i
] = cs
->kvm_run
->s
.regs
.gprs
[i
];
258 r
= kvm_vcpu_ioctl(cs
, KVM_GET_REGS
, ®s
);
262 for (i
= 0; i
< 16; i
++) {
263 env
->regs
[i
] = regs
.gprs
[i
];
267 /* The ACRS and CRS */
269 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_ACRS
&&
270 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_CRS
) {
271 for (i
= 0; i
< 16; i
++) {
272 env
->aregs
[i
] = cs
->kvm_run
->s
.regs
.acrs
[i
];
273 env
->cregs
[i
] = cs
->kvm_run
->s
.regs
.crs
[i
];
276 r
= kvm_vcpu_ioctl(cs
, KVM_GET_SREGS
, &sregs
);
280 for (i
= 0; i
< 16; i
++) {
281 env
->aregs
[i
] = sregs
.acrs
[i
];
282 env
->cregs
[i
] = sregs
.crs
[i
];
287 if (cap_sync_regs
&& cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_PREFIX
) {
288 env
->psa
= cs
->kvm_run
->s
.regs
.prefix
;
292 reg
.id
= KVM_REG_S390_CPU_TIMER
;
293 reg
.addr
= (__u64
)&(env
->cputm
);
294 r
= kvm_vcpu_ioctl(cs
, KVM_GET_ONE_REG
, ®
);
299 reg
.id
= KVM_REG_S390_CLOCK_COMP
;
300 reg
.addr
= (__u64
)&(env
->ckc
);
301 r
= kvm_vcpu_ioctl(cs
, KVM_GET_ONE_REG
, ®
);
306 reg
.id
= KVM_REG_S390_TODPR
;
307 reg
.addr
= (__u64
)&(env
->todpr
);
308 r
= kvm_vcpu_ioctl(cs
, KVM_GET_ONE_REG
, ®
);
314 reg
.id
= KVM_REG_S390_PFTOKEN
;
315 reg
.addr
= (__u64
)&(env
->pfault_token
);
316 r
= kvm_vcpu_ioctl(cs
, KVM_GET_ONE_REG
, ®
);
321 reg
.id
= KVM_REG_S390_PFCOMPARE
;
322 reg
.addr
= (__u64
)&(env
->pfault_compare
);
323 r
= kvm_vcpu_ioctl(cs
, KVM_GET_ONE_REG
, ®
);
328 reg
.id
= KVM_REG_S390_PFSELECT
;
329 reg
.addr
= (__u64
)&(env
->pfault_select
);
330 r
= kvm_vcpu_ioctl(cs
, KVM_GET_ONE_REG
, ®
);
340 * Legacy layout for s390:
341 * Older S390 KVM requires the topmost vma of the RAM to be
342 * smaller than an system defined value, which is at least 256GB.
343 * Larger systems have larger values. We put the guest between
344 * the end of data segment (system break) and this value. We
345 * use 32GB as a base to have enough room for the system break
346 * to grow. We also have to use MAP parameters that avoid
347 * read-only mapping of guest pages.
349 static void *legacy_s390_alloc(size_t size
)
353 mem
= mmap((void *) 0x800000000ULL
, size
,
354 PROT_EXEC
|PROT_READ
|PROT_WRITE
,
355 MAP_SHARED
| MAP_ANONYMOUS
| MAP_FIXED
, -1, 0);
356 return mem
== MAP_FAILED
? NULL
: mem
;
359 int kvm_arch_insert_sw_breakpoint(CPUState
*cs
, struct kvm_sw_breakpoint
*bp
)
361 static const uint8_t diag_501
[] = {0x83, 0x24, 0x05, 0x01};
363 if (cpu_memory_rw_debug(cs
, bp
->pc
, (uint8_t *)&bp
->saved_insn
, 4, 0) ||
364 cpu_memory_rw_debug(cs
, bp
->pc
, (uint8_t *)diag_501
, 4, 1)) {
370 int kvm_arch_remove_sw_breakpoint(CPUState
*cs
, struct kvm_sw_breakpoint
*bp
)
373 static const uint8_t diag_501
[] = {0x83, 0x24, 0x05, 0x01};
375 if (cpu_memory_rw_debug(cs
, bp
->pc
, t
, 4, 0)) {
377 } else if (memcmp(t
, diag_501
, 4)) {
379 } else if (cpu_memory_rw_debug(cs
, bp
->pc
, (uint8_t *)&bp
->saved_insn
, 1, 1)) {
386 void kvm_arch_pre_run(CPUState
*cpu
, struct kvm_run
*run
)
390 void kvm_arch_post_run(CPUState
*cpu
, struct kvm_run
*run
)
394 int kvm_arch_process_async_events(CPUState
*cs
)
399 void kvm_s390_interrupt_internal(S390CPU
*cpu
, int type
, uint32_t parm
,
400 uint64_t parm64
, int vm
)
402 CPUState
*cs
= CPU(cpu
);
403 struct kvm_s390_interrupt kvmint
;
406 if (!cs
->kvm_state
) {
412 kvmint
.parm64
= parm64
;
415 r
= kvm_vm_ioctl(cs
->kvm_state
, KVM_S390_INTERRUPT
, &kvmint
);
417 r
= kvm_vcpu_ioctl(cs
, KVM_S390_INTERRUPT
, &kvmint
);
421 fprintf(stderr
, "KVM failed to inject interrupt\n");
426 void kvm_s390_virtio_irq(S390CPU
*cpu
, int config_change
, uint64_t token
)
428 kvm_s390_interrupt_internal(cpu
, KVM_S390_INT_VIRTIO
, config_change
,
432 void kvm_s390_interrupt(S390CPU
*cpu
, int type
, uint32_t code
)
434 kvm_s390_interrupt_internal(cpu
, type
, code
, 0, 0);
437 static void enter_pgmcheck(S390CPU
*cpu
, uint16_t code
)
439 kvm_s390_interrupt(cpu
, KVM_S390_PROGRAM_INT
, code
);
442 static int kvm_sclp_service_call(S390CPU
*cpu
, struct kvm_run
*run
,
445 CPUS390XState
*env
= &cpu
->env
;
450 cpu_synchronize_state(CPU(cpu
));
451 sccb
= env
->regs
[ipbh0
& 0xf];
452 code
= env
->regs
[(ipbh0
& 0xf0) >> 4];
454 r
= sclp_service_call(env
, sccb
, code
);
456 enter_pgmcheck(cpu
, -r
);
464 static int handle_b2(S390CPU
*cpu
, struct kvm_run
*run
, uint8_t ipa1
)
466 CPUS390XState
*env
= &cpu
->env
;
468 uint16_t ipbh0
= (run
->s390_sieic
.ipb
& 0xffff0000) >> 16;
470 cpu_synchronize_state(CPU(cpu
));
474 ioinst_handle_xsch(cpu
, env
->regs
[1]);
477 ioinst_handle_csch(cpu
, env
->regs
[1]);
480 ioinst_handle_hsch(cpu
, env
->regs
[1]);
483 ioinst_handle_msch(cpu
, env
->regs
[1], run
->s390_sieic
.ipb
);
486 ioinst_handle_ssch(cpu
, env
->regs
[1], run
->s390_sieic
.ipb
);
489 ioinst_handle_stcrw(cpu
, run
->s390_sieic
.ipb
);
492 ioinst_handle_stsch(cpu
, env
->regs
[1], run
->s390_sieic
.ipb
);
495 /* We should only get tsch via KVM_EXIT_S390_TSCH. */
496 fprintf(stderr
, "Spurious tsch intercept\n");
499 ioinst_handle_chsc(cpu
, run
->s390_sieic
.ipb
);
502 /* This should have been handled by kvm already. */
503 fprintf(stderr
, "Spurious tpi intercept\n");
506 ioinst_handle_schm(cpu
, env
->regs
[1], env
->regs
[2],
507 run
->s390_sieic
.ipb
);
510 ioinst_handle_rsch(cpu
, env
->regs
[1]);
513 ioinst_handle_rchp(cpu
, env
->regs
[1]);
516 /* We do not provide this instruction, it is suppressed. */
519 ioinst_handle_sal(cpu
, env
->regs
[1]);
522 /* Not provided, set CC = 3 for subchannel not operational */
525 case PRIV_B2_SCLP_CALL
:
526 rc
= kvm_sclp_service_call(cpu
, run
, ipbh0
);
530 DPRINTF("KVM: unhandled PRIV: 0xb2%x\n", ipa1
);
537 static int handle_b9(S390CPU
*cpu
, struct kvm_run
*run
, uint8_t ipa1
)
543 /* just inject exception */
548 DPRINTF("KVM: unhandled PRIV: 0xb9%x\n", ipa1
);
555 static int handle_eb(S390CPU
*cpu
, struct kvm_run
*run
, uint8_t ipa1
)
561 /* just inject exception */
566 DPRINTF("KVM: unhandled PRIV: 0xeb%x\n", ipa1
);
573 static int handle_hypercall(S390CPU
*cpu
, struct kvm_run
*run
)
575 CPUS390XState
*env
= &cpu
->env
;
578 cpu_synchronize_state(CPU(cpu
));
579 ret
= s390_virtio_hypercall(env
);
580 if (ret
== -EINVAL
) {
581 enter_pgmcheck(cpu
, PGM_SPECIFICATION
);
588 static void kvm_handle_diag_308(S390CPU
*cpu
, struct kvm_run
*run
)
592 cpu_synchronize_state(CPU(cpu
));
593 r1
= (run
->s390_sieic
.ipa
& 0x00f0) >> 8;
594 r3
= run
->s390_sieic
.ipa
& 0x000f;
595 handle_diag_308(&cpu
->env
, r1
, r3
);
598 #define DIAG_KVM_CODE_MASK 0x000000000000ffff
600 static int handle_diag(S390CPU
*cpu
, struct kvm_run
*run
, uint32_t ipb
)
606 * For any diagnose call we support, bits 48-63 of the resulting
607 * address specify the function code; the remainder is ignored.
609 func_code
= decode_basedisp_rs(&cpu
->env
, ipb
) & DIAG_KVM_CODE_MASK
;
612 kvm_handle_diag_308(cpu
, run
);
614 case DIAG_KVM_HYPERCALL
:
615 r
= handle_hypercall(cpu
, run
);
617 case DIAG_KVM_BREAKPOINT
:
621 DPRINTF("KVM: unknown DIAG: 0x%x\n", func_code
);
629 static int kvm_s390_cpu_start(S390CPU
*cpu
)
631 s390_add_running_cpu(cpu
);
632 qemu_cpu_kick(CPU(cpu
));
633 DPRINTF("DONE: KVM cpu start: %p\n", &cpu
->env
);
637 int kvm_s390_cpu_restart(S390CPU
*cpu
)
639 kvm_s390_interrupt(cpu
, KVM_S390_RESTART
, 0);
640 s390_add_running_cpu(cpu
);
641 qemu_cpu_kick(CPU(cpu
));
642 DPRINTF("DONE: KVM cpu restart: %p\n", &cpu
->env
);
646 static void sigp_initial_cpu_reset(void *arg
)
649 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cpu
);
651 cpu_synchronize_state(cpu
);
652 scc
->initial_cpu_reset(cpu
);
655 static void sigp_cpu_reset(void *arg
)
658 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cpu
);
660 cpu_synchronize_state(cpu
);
664 #define SIGP_ORDER_MASK 0x000000ff
666 static int handle_sigp(S390CPU
*cpu
, struct kvm_run
*run
, uint8_t ipa1
)
668 CPUS390XState
*env
= &cpu
->env
;
672 uint64_t *statusreg
= &env
->regs
[ipa1
>> 4];
675 cpu_synchronize_state(CPU(cpu
));
678 order_code
= decode_basedisp_rs(env
, run
->s390_sieic
.ipb
) & SIGP_ORDER_MASK
;
680 cpu_addr
= env
->regs
[ipa1
& 0x0f];
681 target_cpu
= s390_cpu_addr2state(cpu_addr
);
682 if (target_cpu
== NULL
) {
683 cc
= 3; /* not operational */
687 switch (order_code
) {
689 cc
= kvm_s390_cpu_start(target_cpu
);
692 cc
= kvm_s390_cpu_restart(target_cpu
);
695 *statusreg
&= 0xffffffff00000000UL
;
696 *statusreg
|= SIGP_STAT_INVALID_PARAMETER
;
697 cc
= 1; /* status stored */
699 case SIGP_INITIAL_CPU_RESET
:
700 run_on_cpu(CPU(target_cpu
), sigp_initial_cpu_reset
, CPU(target_cpu
));
704 run_on_cpu(CPU(target_cpu
), sigp_cpu_reset
, CPU(target_cpu
));
708 DPRINTF("KVM: unknown SIGP: 0x%x\n", order_code
);
709 *statusreg
&= 0xffffffff00000000UL
;
710 *statusreg
|= SIGP_STAT_INVALID_ORDER
;
711 cc
= 1; /* status stored */
720 static void handle_instruction(S390CPU
*cpu
, struct kvm_run
*run
)
722 unsigned int ipa0
= (run
->s390_sieic
.ipa
& 0xff00);
723 uint8_t ipa1
= run
->s390_sieic
.ipa
& 0x00ff;
726 DPRINTF("handle_instruction 0x%x 0x%x\n",
727 run
->s390_sieic
.ipa
, run
->s390_sieic
.ipb
);
730 r
= handle_b2(cpu
, run
, ipa1
);
733 r
= handle_b9(cpu
, run
, ipa1
);
736 r
= handle_eb(cpu
, run
, ipa1
);
739 r
= handle_diag(cpu
, run
, run
->s390_sieic
.ipb
);
742 r
= handle_sigp(cpu
, run
, ipa1
);
747 enter_pgmcheck(cpu
, 0x0001);
751 static bool is_special_wait_psw(CPUState
*cs
)
754 return cs
->kvm_run
->psw_addr
== 0xfffUL
;
757 static int handle_intercept(S390CPU
*cpu
)
759 CPUState
*cs
= CPU(cpu
);
760 struct kvm_run
*run
= cs
->kvm_run
;
761 int icpt_code
= run
->s390_sieic
.icptcode
;
764 DPRINTF("intercept: 0x%x (at 0x%lx)\n", icpt_code
,
765 (long)cs
->kvm_run
->psw_addr
);
767 case ICPT_INSTRUCTION
:
768 handle_instruction(cpu
, run
);
771 /* disabled wait, since enabled wait is handled in kernel */
772 if (s390_del_running_cpu(cpu
) == 0) {
773 if (is_special_wait_psw(cs
)) {
774 qemu_system_shutdown_request();
778 data
= qobject_from_jsonf("{ 'action': %s }", "pause");
779 monitor_protocol_event(QEVENT_GUEST_PANICKED
, data
);
780 qobject_decref(data
);
781 vm_stop(RUN_STATE_GUEST_PANICKED
);
787 if (s390_del_running_cpu(cpu
) == 0) {
788 qemu_system_shutdown_request();
792 case ICPT_SOFT_INTERCEPT
:
793 fprintf(stderr
, "KVM unimplemented icpt SOFT\n");
797 fprintf(stderr
, "KVM unimplemented icpt IO\n");
801 fprintf(stderr
, "Unknown intercept code: %d\n", icpt_code
);
809 static int handle_tsch(S390CPU
*cpu
)
811 CPUS390XState
*env
= &cpu
->env
;
812 CPUState
*cs
= CPU(cpu
);
813 struct kvm_run
*run
= cs
->kvm_run
;
816 cpu_synchronize_state(cs
);
818 ret
= ioinst_handle_tsch(env
, env
->regs
[1], run
->s390_tsch
.ipb
);
820 /* Success; set condition code. */
823 } else if (ret
< -1) {
826 * If an I/O interrupt had been dequeued, we have to reinject it.
828 if (run
->s390_tsch
.dequeued
) {
829 uint16_t subchannel_id
= run
->s390_tsch
.subchannel_id
;
830 uint16_t subchannel_nr
= run
->s390_tsch
.subchannel_nr
;
831 uint32_t io_int_parm
= run
->s390_tsch
.io_int_parm
;
832 uint32_t io_int_word
= run
->s390_tsch
.io_int_word
;
833 uint32_t type
= ((subchannel_id
& 0xff00) << 24) |
834 ((subchannel_id
& 0x00060) << 22) | (subchannel_nr
<< 16);
836 kvm_s390_interrupt_internal(cpu
, type
,
837 ((uint32_t)subchannel_id
<< 16)
839 ((uint64_t)io_int_parm
<< 32)
847 int kvm_arch_handle_exit(CPUState
*cs
, struct kvm_run
*run
)
849 S390CPU
*cpu
= S390_CPU(cs
);
852 switch (run
->exit_reason
) {
853 case KVM_EXIT_S390_SIEIC
:
854 ret
= handle_intercept(cpu
);
856 case KVM_EXIT_S390_RESET
:
857 qemu_system_reset_request();
859 case KVM_EXIT_S390_TSCH
:
860 ret
= handle_tsch(cpu
);
863 fprintf(stderr
, "Unknown KVM exit: %d\n", run
->exit_reason
);
868 ret
= EXCP_INTERRUPT
;
873 bool kvm_arch_stop_on_emulation_error(CPUState
*cpu
)
878 int kvm_arch_on_sigbus_vcpu(CPUState
*cpu
, int code
, void *addr
)
883 int kvm_arch_on_sigbus(int code
, void *addr
)
888 void kvm_s390_io_interrupt(S390CPU
*cpu
, uint16_t subchannel_id
,
889 uint16_t subchannel_nr
, uint32_t io_int_parm
,
890 uint32_t io_int_word
)
894 if (io_int_word
& IO_INT_WORD_AI
) {
895 type
= KVM_S390_INT_IO(1, 0, 0, 0);
897 type
= ((subchannel_id
& 0xff00) << 24) |
898 ((subchannel_id
& 0x00060) << 22) | (subchannel_nr
<< 16);
900 kvm_s390_interrupt_internal(cpu
, type
,
901 ((uint32_t)subchannel_id
<< 16) | subchannel_nr
,
902 ((uint64_t)io_int_parm
<< 32) | io_int_word
, 1);
905 void kvm_s390_crw_mchk(S390CPU
*cpu
)
907 kvm_s390_interrupt_internal(cpu
, KVM_S390_MCHK
, 1 << 28,
908 0x00400f1d40330000, 1);
911 void kvm_s390_enable_css_support(S390CPU
*cpu
)
913 struct kvm_enable_cap cap
= {};
916 /* Activate host kernel channel subsystem support. */
917 cap
.cap
= KVM_CAP_S390_CSS_SUPPORT
;
918 r
= kvm_vcpu_ioctl(CPU(cpu
), KVM_ENABLE_CAP
, &cap
);
922 void kvm_arch_init_irq_routing(KVMState
*s
)
926 int kvm_s390_assign_subch_ioeventfd(EventNotifier
*notifier
, uint32_t sch
,
929 struct kvm_ioeventfd kick
= {
930 .flags
= KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY
|
931 KVM_IOEVENTFD_FLAG_DATAMATCH
,
932 .fd
= event_notifier_get_fd(notifier
),
937 if (!kvm_check_extension(kvm_state
, KVM_CAP_IOEVENTFD
)) {
941 kick
.flags
|= KVM_IOEVENTFD_FLAG_DEASSIGN
;
943 return kvm_vm_ioctl(kvm_state
, KVM_IOEVENTFD
, &kick
);