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"
41 /* #define DEBUG_KVM */
44 #define DPRINTF(fmt, ...) \
45 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
47 #define DPRINTF(fmt, ...) \
51 #define IPA0_DIAG 0x8300
52 #define IPA0_SIGP 0xae00
53 #define IPA0_B2 0xb200
54 #define IPA0_B9 0xb900
55 #define IPA0_EB 0xeb00
57 #define PRIV_B2_SCLP_CALL 0x20
58 #define PRIV_B2_CSCH 0x30
59 #define PRIV_B2_HSCH 0x31
60 #define PRIV_B2_MSCH 0x32
61 #define PRIV_B2_SSCH 0x33
62 #define PRIV_B2_STSCH 0x34
63 #define PRIV_B2_TSCH 0x35
64 #define PRIV_B2_TPI 0x36
65 #define PRIV_B2_SAL 0x37
66 #define PRIV_B2_RSCH 0x38
67 #define PRIV_B2_STCRW 0x39
68 #define PRIV_B2_STCPS 0x3a
69 #define PRIV_B2_RCHP 0x3b
70 #define PRIV_B2_SCHM 0x3c
71 #define PRIV_B2_CHSC 0x5f
72 #define PRIV_B2_SIGA 0x74
73 #define PRIV_B2_XSCH 0x76
75 #define PRIV_EB_SQBS 0x8a
77 #define PRIV_B9_EQBS 0x9c
79 #define DIAG_IPL 0x308
80 #define DIAG_KVM_HYPERCALL 0x500
81 #define DIAG_KVM_BREAKPOINT 0x501
83 #define ICPT_INSTRUCTION 0x04
84 #define ICPT_WAITPSW 0x1c
85 #define ICPT_SOFT_INTERCEPT 0x24
86 #define ICPT_CPU_STOP 0x28
89 const KVMCapabilityInfo kvm_arch_required_capabilities
[] = {
93 static int cap_sync_regs
;
94 static int cap_async_pf
;
96 static void *legacy_s390_alloc(size_t size
);
98 int kvm_arch_init(KVMState
*s
)
100 cap_sync_regs
= kvm_check_extension(s
, KVM_CAP_SYNC_REGS
);
101 cap_async_pf
= kvm_check_extension(s
, KVM_CAP_ASYNC_PF
);
102 if (!kvm_check_extension(s
, KVM_CAP_S390_GMAP
)
103 || !kvm_check_extension(s
, KVM_CAP_S390_COW
)) {
104 phys_mem_set_alloc(legacy_s390_alloc
);
109 unsigned long kvm_arch_vcpu_id(CPUState
*cpu
)
111 return cpu
->cpu_index
;
114 int kvm_arch_init_vcpu(CPUState
*cpu
)
116 /* nothing todo yet */
120 void kvm_arch_reset_vcpu(CPUState
*cpu
)
122 /* The initial reset call is needed here to reset in-kernel
123 * vcpu data that we can't access directly from QEMU
124 * (i.e. with older kernels which don't support sync_regs/ONE_REG).
125 * Before this ioctl cpu_synchronize_state() is called in common kvm
127 if (kvm_vcpu_ioctl(cpu
, KVM_S390_INITIAL_RESET
, NULL
)) {
128 perror("Can't reset vcpu\n");
132 int kvm_arch_put_registers(CPUState
*cs
, int level
)
134 S390CPU
*cpu
= S390_CPU(cs
);
135 CPUS390XState
*env
= &cpu
->env
;
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 r
= kvm_vcpu_ioctl(cs
, KVM_SET_REGS
, ®s
);
160 /* Do we need to save more than that? */
161 if (level
== KVM_PUT_RUNTIME_STATE
) {
166 * These ONE_REGS are not protected by a capability. As they are only
167 * necessary for migration we just trace a possible error, but don't
168 * return with an error return code.
170 kvm_set_one_reg(cs
, KVM_REG_S390_CPU_TIMER
, &env
->cputm
);
171 kvm_set_one_reg(cs
, KVM_REG_S390_CLOCK_COMP
, &env
->ckc
);
172 kvm_set_one_reg(cs
, KVM_REG_S390_TODPR
, &env
->todpr
);
173 kvm_set_one_reg(cs
, KVM_REG_S390_GBEA
, &env
->gbea
);
174 kvm_set_one_reg(cs
, KVM_REG_S390_PP
, &env
->pp
);
177 r
= kvm_set_one_reg(cs
, KVM_REG_S390_PFTOKEN
, &env
->pfault_token
);
181 r
= kvm_set_one_reg(cs
, KVM_REG_S390_PFCOMPARE
, &env
->pfault_compare
);
185 r
= kvm_set_one_reg(cs
, KVM_REG_S390_PFSELECT
, &env
->pfault_select
);
192 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_ACRS
&&
193 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_CRS
) {
194 for (i
= 0; i
< 16; i
++) {
195 cs
->kvm_run
->s
.regs
.acrs
[i
] = env
->aregs
[i
];
196 cs
->kvm_run
->s
.regs
.crs
[i
] = env
->cregs
[i
];
198 cs
->kvm_run
->kvm_dirty_regs
|= KVM_SYNC_ACRS
;
199 cs
->kvm_run
->kvm_dirty_regs
|= KVM_SYNC_CRS
;
201 for (i
= 0; i
< 16; i
++) {
202 sregs
.acrs
[i
] = env
->aregs
[i
];
203 sregs
.crs
[i
] = env
->cregs
[i
];
205 r
= kvm_vcpu_ioctl(cs
, KVM_SET_SREGS
, &sregs
);
211 /* Finally the prefix */
212 if (cap_sync_regs
&& cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_PREFIX
) {
213 cs
->kvm_run
->s
.regs
.prefix
= env
->psa
;
214 cs
->kvm_run
->kvm_dirty_regs
|= KVM_SYNC_PREFIX
;
216 /* prefix is only supported via sync regs */
221 int kvm_arch_get_registers(CPUState
*cs
)
223 S390CPU
*cpu
= S390_CPU(cs
);
224 CPUS390XState
*env
= &cpu
->env
;
225 struct kvm_sregs sregs
;
226 struct kvm_regs regs
;
230 env
->psw
.addr
= cs
->kvm_run
->psw_addr
;
231 env
->psw
.mask
= cs
->kvm_run
->psw_mask
;
234 if (cap_sync_regs
&& cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_GPRS
) {
235 for (i
= 0; i
< 16; i
++) {
236 env
->regs
[i
] = cs
->kvm_run
->s
.regs
.gprs
[i
];
239 r
= kvm_vcpu_ioctl(cs
, KVM_GET_REGS
, ®s
);
243 for (i
= 0; i
< 16; i
++) {
244 env
->regs
[i
] = regs
.gprs
[i
];
248 /* The ACRS and CRS */
250 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_ACRS
&&
251 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_CRS
) {
252 for (i
= 0; i
< 16; i
++) {
253 env
->aregs
[i
] = cs
->kvm_run
->s
.regs
.acrs
[i
];
254 env
->cregs
[i
] = cs
->kvm_run
->s
.regs
.crs
[i
];
257 r
= kvm_vcpu_ioctl(cs
, KVM_GET_SREGS
, &sregs
);
261 for (i
= 0; i
< 16; i
++) {
262 env
->aregs
[i
] = sregs
.acrs
[i
];
263 env
->cregs
[i
] = sregs
.crs
[i
];
268 if (cap_sync_regs
&& cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_PREFIX
) {
269 env
->psa
= cs
->kvm_run
->s
.regs
.prefix
;
273 * These ONE_REGS are not protected by a capability. As they are only
274 * necessary for migration we just trace a possible error, but don't
275 * return with an error return code.
277 kvm_get_one_reg(cs
, KVM_REG_S390_CPU_TIMER
, &env
->cputm
);
278 kvm_get_one_reg(cs
, KVM_REG_S390_CLOCK_COMP
, &env
->ckc
);
279 kvm_get_one_reg(cs
, KVM_REG_S390_TODPR
, &env
->todpr
);
280 kvm_get_one_reg(cs
, KVM_REG_S390_GBEA
, &env
->gbea
);
281 kvm_get_one_reg(cs
, KVM_REG_S390_PP
, &env
->pp
);
284 r
= kvm_get_one_reg(cs
, KVM_REG_S390_PFTOKEN
, &env
->pfault_token
);
288 r
= kvm_get_one_reg(cs
, KVM_REG_S390_PFCOMPARE
, &env
->pfault_compare
);
292 r
= kvm_get_one_reg(cs
, KVM_REG_S390_PFSELECT
, &env
->pfault_select
);
302 * Legacy layout for s390:
303 * Older S390 KVM requires the topmost vma of the RAM to be
304 * smaller than an system defined value, which is at least 256GB.
305 * Larger systems have larger values. We put the guest between
306 * the end of data segment (system break) and this value. We
307 * use 32GB as a base to have enough room for the system break
308 * to grow. We also have to use MAP parameters that avoid
309 * read-only mapping of guest pages.
311 static void *legacy_s390_alloc(size_t size
)
315 mem
= mmap((void *) 0x800000000ULL
, size
,
316 PROT_EXEC
|PROT_READ
|PROT_WRITE
,
317 MAP_SHARED
| MAP_ANONYMOUS
| MAP_FIXED
, -1, 0);
318 return mem
== MAP_FAILED
? NULL
: mem
;
321 int kvm_arch_insert_sw_breakpoint(CPUState
*cs
, struct kvm_sw_breakpoint
*bp
)
323 static const uint8_t diag_501
[] = {0x83, 0x24, 0x05, 0x01};
325 if (cpu_memory_rw_debug(cs
, bp
->pc
, (uint8_t *)&bp
->saved_insn
, 4, 0) ||
326 cpu_memory_rw_debug(cs
, bp
->pc
, (uint8_t *)diag_501
, 4, 1)) {
332 int kvm_arch_remove_sw_breakpoint(CPUState
*cs
, struct kvm_sw_breakpoint
*bp
)
335 static const uint8_t diag_501
[] = {0x83, 0x24, 0x05, 0x01};
337 if (cpu_memory_rw_debug(cs
, bp
->pc
, t
, 4, 0)) {
339 } else if (memcmp(t
, diag_501
, 4)) {
341 } else if (cpu_memory_rw_debug(cs
, bp
->pc
, (uint8_t *)&bp
->saved_insn
, 1, 1)) {
348 int kvm_arch_insert_hw_breakpoint(target_ulong addr
,
349 target_ulong len
, int type
)
354 int kvm_arch_remove_hw_breakpoint(target_ulong addr
,
355 target_ulong len
, int type
)
360 void kvm_arch_remove_all_hw_breakpoints(void)
364 void kvm_arch_update_guest_debug(CPUState
*cpu
, struct kvm_guest_debug
*dbg
)
368 void kvm_arch_pre_run(CPUState
*cpu
, struct kvm_run
*run
)
372 void kvm_arch_post_run(CPUState
*cpu
, struct kvm_run
*run
)
376 int kvm_arch_process_async_events(CPUState
*cs
)
381 void kvm_s390_interrupt_internal(S390CPU
*cpu
, int type
, uint32_t parm
,
382 uint64_t parm64
, int vm
)
384 CPUState
*cs
= CPU(cpu
);
385 struct kvm_s390_interrupt kvmint
;
388 if (!cs
->kvm_state
) {
394 kvmint
.parm64
= parm64
;
397 r
= kvm_vm_ioctl(cs
->kvm_state
, KVM_S390_INTERRUPT
, &kvmint
);
399 r
= kvm_vcpu_ioctl(cs
, KVM_S390_INTERRUPT
, &kvmint
);
403 fprintf(stderr
, "KVM failed to inject interrupt\n");
408 void kvm_s390_virtio_irq(S390CPU
*cpu
, int config_change
, uint64_t token
)
410 kvm_s390_interrupt_internal(cpu
, KVM_S390_INT_VIRTIO
, config_change
,
414 void kvm_s390_interrupt(S390CPU
*cpu
, int type
, uint32_t code
)
416 kvm_s390_interrupt_internal(cpu
, type
, code
, 0, 0);
419 static void enter_pgmcheck(S390CPU
*cpu
, uint16_t code
)
421 kvm_s390_interrupt(cpu
, KVM_S390_PROGRAM_INT
, code
);
424 static int kvm_sclp_service_call(S390CPU
*cpu
, struct kvm_run
*run
,
427 CPUS390XState
*env
= &cpu
->env
;
432 cpu_synchronize_state(CPU(cpu
));
433 sccb
= env
->regs
[ipbh0
& 0xf];
434 code
= env
->regs
[(ipbh0
& 0xf0) >> 4];
436 r
= sclp_service_call(env
, sccb
, code
);
438 enter_pgmcheck(cpu
, -r
);
446 static int handle_b2(S390CPU
*cpu
, struct kvm_run
*run
, uint8_t ipa1
)
448 CPUS390XState
*env
= &cpu
->env
;
450 uint16_t ipbh0
= (run
->s390_sieic
.ipb
& 0xffff0000) >> 16;
452 cpu_synchronize_state(CPU(cpu
));
456 ioinst_handle_xsch(cpu
, env
->regs
[1]);
459 ioinst_handle_csch(cpu
, env
->regs
[1]);
462 ioinst_handle_hsch(cpu
, env
->regs
[1]);
465 ioinst_handle_msch(cpu
, env
->regs
[1], run
->s390_sieic
.ipb
);
468 ioinst_handle_ssch(cpu
, env
->regs
[1], run
->s390_sieic
.ipb
);
471 ioinst_handle_stcrw(cpu
, run
->s390_sieic
.ipb
);
474 ioinst_handle_stsch(cpu
, env
->regs
[1], run
->s390_sieic
.ipb
);
477 /* We should only get tsch via KVM_EXIT_S390_TSCH. */
478 fprintf(stderr
, "Spurious tsch intercept\n");
481 ioinst_handle_chsc(cpu
, run
->s390_sieic
.ipb
);
484 /* This should have been handled by kvm already. */
485 fprintf(stderr
, "Spurious tpi intercept\n");
488 ioinst_handle_schm(cpu
, env
->regs
[1], env
->regs
[2],
489 run
->s390_sieic
.ipb
);
492 ioinst_handle_rsch(cpu
, env
->regs
[1]);
495 ioinst_handle_rchp(cpu
, env
->regs
[1]);
498 /* We do not provide this instruction, it is suppressed. */
501 ioinst_handle_sal(cpu
, env
->regs
[1]);
504 /* Not provided, set CC = 3 for subchannel not operational */
507 case PRIV_B2_SCLP_CALL
:
508 rc
= kvm_sclp_service_call(cpu
, run
, ipbh0
);
512 DPRINTF("KVM: unhandled PRIV: 0xb2%x\n", ipa1
);
519 static int handle_b9(S390CPU
*cpu
, struct kvm_run
*run
, uint8_t ipa1
)
525 /* just inject exception */
530 DPRINTF("KVM: unhandled PRIV: 0xb9%x\n", ipa1
);
537 static int handle_eb(S390CPU
*cpu
, struct kvm_run
*run
, uint8_t ipa1
)
543 /* just inject exception */
548 DPRINTF("KVM: unhandled PRIV: 0xeb%x\n", ipa1
);
555 static int handle_hypercall(S390CPU
*cpu
, struct kvm_run
*run
)
557 CPUS390XState
*env
= &cpu
->env
;
560 cpu_synchronize_state(CPU(cpu
));
561 ret
= s390_virtio_hypercall(env
);
562 if (ret
== -EINVAL
) {
563 enter_pgmcheck(cpu
, PGM_SPECIFICATION
);
570 static void kvm_handle_diag_308(S390CPU
*cpu
, struct kvm_run
*run
)
574 cpu_synchronize_state(CPU(cpu
));
575 r1
= (run
->s390_sieic
.ipa
& 0x00f0) >> 8;
576 r3
= run
->s390_sieic
.ipa
& 0x000f;
577 handle_diag_308(&cpu
->env
, r1
, r3
);
580 #define DIAG_KVM_CODE_MASK 0x000000000000ffff
582 static int handle_diag(S390CPU
*cpu
, struct kvm_run
*run
, uint32_t ipb
)
588 * For any diagnose call we support, bits 48-63 of the resulting
589 * address specify the function code; the remainder is ignored.
591 func_code
= decode_basedisp_rs(&cpu
->env
, ipb
) & DIAG_KVM_CODE_MASK
;
594 kvm_handle_diag_308(cpu
, run
);
596 case DIAG_KVM_HYPERCALL
:
597 r
= handle_hypercall(cpu
, run
);
599 case DIAG_KVM_BREAKPOINT
:
603 DPRINTF("KVM: unknown DIAG: 0x%x\n", func_code
);
611 static int kvm_s390_cpu_start(S390CPU
*cpu
)
613 s390_add_running_cpu(cpu
);
614 qemu_cpu_kick(CPU(cpu
));
615 DPRINTF("DONE: KVM cpu start: %p\n", &cpu
->env
);
619 int kvm_s390_cpu_restart(S390CPU
*cpu
)
621 kvm_s390_interrupt(cpu
, KVM_S390_RESTART
, 0);
622 s390_add_running_cpu(cpu
);
623 qemu_cpu_kick(CPU(cpu
));
624 DPRINTF("DONE: KVM cpu restart: %p\n", &cpu
->env
);
628 static void sigp_initial_cpu_reset(void *arg
)
631 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cpu
);
633 cpu_synchronize_state(cpu
);
634 scc
->initial_cpu_reset(cpu
);
637 static void sigp_cpu_reset(void *arg
)
640 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cpu
);
642 cpu_synchronize_state(cpu
);
646 #define SIGP_ORDER_MASK 0x000000ff
648 static int handle_sigp(S390CPU
*cpu
, struct kvm_run
*run
, uint8_t ipa1
)
650 CPUS390XState
*env
= &cpu
->env
;
654 uint64_t *statusreg
= &env
->regs
[ipa1
>> 4];
657 cpu_synchronize_state(CPU(cpu
));
660 order_code
= decode_basedisp_rs(env
, run
->s390_sieic
.ipb
) & SIGP_ORDER_MASK
;
662 cpu_addr
= env
->regs
[ipa1
& 0x0f];
663 target_cpu
= s390_cpu_addr2state(cpu_addr
);
664 if (target_cpu
== NULL
) {
665 cc
= 3; /* not operational */
669 switch (order_code
) {
671 cc
= kvm_s390_cpu_start(target_cpu
);
674 cc
= kvm_s390_cpu_restart(target_cpu
);
677 *statusreg
&= 0xffffffff00000000UL
;
678 *statusreg
|= SIGP_STAT_INVALID_PARAMETER
;
679 cc
= 1; /* status stored */
681 case SIGP_INITIAL_CPU_RESET
:
682 run_on_cpu(CPU(target_cpu
), sigp_initial_cpu_reset
, CPU(target_cpu
));
686 run_on_cpu(CPU(target_cpu
), sigp_cpu_reset
, CPU(target_cpu
));
690 DPRINTF("KVM: unknown SIGP: 0x%x\n", order_code
);
691 *statusreg
&= 0xffffffff00000000UL
;
692 *statusreg
|= SIGP_STAT_INVALID_ORDER
;
693 cc
= 1; /* status stored */
702 static void handle_instruction(S390CPU
*cpu
, struct kvm_run
*run
)
704 unsigned int ipa0
= (run
->s390_sieic
.ipa
& 0xff00);
705 uint8_t ipa1
= run
->s390_sieic
.ipa
& 0x00ff;
708 DPRINTF("handle_instruction 0x%x 0x%x\n",
709 run
->s390_sieic
.ipa
, run
->s390_sieic
.ipb
);
712 r
= handle_b2(cpu
, run
, ipa1
);
715 r
= handle_b9(cpu
, run
, ipa1
);
718 r
= handle_eb(cpu
, run
, ipa1
);
721 r
= handle_diag(cpu
, run
, run
->s390_sieic
.ipb
);
724 r
= handle_sigp(cpu
, run
, ipa1
);
729 enter_pgmcheck(cpu
, 0x0001);
733 static bool is_special_wait_psw(CPUState
*cs
)
736 return cs
->kvm_run
->psw_addr
== 0xfffUL
;
739 static int handle_intercept(S390CPU
*cpu
)
741 CPUState
*cs
= CPU(cpu
);
742 struct kvm_run
*run
= cs
->kvm_run
;
743 int icpt_code
= run
->s390_sieic
.icptcode
;
746 DPRINTF("intercept: 0x%x (at 0x%lx)\n", icpt_code
,
747 (long)cs
->kvm_run
->psw_addr
);
749 case ICPT_INSTRUCTION
:
750 handle_instruction(cpu
, run
);
753 /* disabled wait, since enabled wait is handled in kernel */
754 if (s390_del_running_cpu(cpu
) == 0) {
755 if (is_special_wait_psw(cs
)) {
756 qemu_system_shutdown_request();
760 data
= qobject_from_jsonf("{ 'action': %s }", "pause");
761 monitor_protocol_event(QEVENT_GUEST_PANICKED
, data
);
762 qobject_decref(data
);
763 vm_stop(RUN_STATE_GUEST_PANICKED
);
769 if (s390_del_running_cpu(cpu
) == 0) {
770 qemu_system_shutdown_request();
774 case ICPT_SOFT_INTERCEPT
:
775 fprintf(stderr
, "KVM unimplemented icpt SOFT\n");
779 fprintf(stderr
, "KVM unimplemented icpt IO\n");
783 fprintf(stderr
, "Unknown intercept code: %d\n", icpt_code
);
791 static int handle_tsch(S390CPU
*cpu
)
793 CPUS390XState
*env
= &cpu
->env
;
794 CPUState
*cs
= CPU(cpu
);
795 struct kvm_run
*run
= cs
->kvm_run
;
798 cpu_synchronize_state(cs
);
800 ret
= ioinst_handle_tsch(env
, env
->regs
[1], run
->s390_tsch
.ipb
);
802 /* Success; set condition code. */
805 } else if (ret
< -1) {
808 * If an I/O interrupt had been dequeued, we have to reinject it.
810 if (run
->s390_tsch
.dequeued
) {
811 uint16_t subchannel_id
= run
->s390_tsch
.subchannel_id
;
812 uint16_t subchannel_nr
= run
->s390_tsch
.subchannel_nr
;
813 uint32_t io_int_parm
= run
->s390_tsch
.io_int_parm
;
814 uint32_t io_int_word
= run
->s390_tsch
.io_int_word
;
815 uint32_t type
= ((subchannel_id
& 0xff00) << 24) |
816 ((subchannel_id
& 0x00060) << 22) | (subchannel_nr
<< 16);
818 kvm_s390_interrupt_internal(cpu
, type
,
819 ((uint32_t)subchannel_id
<< 16)
821 ((uint64_t)io_int_parm
<< 32)
829 static int kvm_arch_handle_debug_exit(S390CPU
*cpu
)
834 int kvm_arch_handle_exit(CPUState
*cs
, struct kvm_run
*run
)
836 S390CPU
*cpu
= S390_CPU(cs
);
839 switch (run
->exit_reason
) {
840 case KVM_EXIT_S390_SIEIC
:
841 ret
= handle_intercept(cpu
);
843 case KVM_EXIT_S390_RESET
:
844 qemu_system_reset_request();
846 case KVM_EXIT_S390_TSCH
:
847 ret
= handle_tsch(cpu
);
850 ret
= kvm_arch_handle_debug_exit(cpu
);
853 fprintf(stderr
, "Unknown KVM exit: %d\n", run
->exit_reason
);
858 ret
= EXCP_INTERRUPT
;
863 bool kvm_arch_stop_on_emulation_error(CPUState
*cpu
)
868 int kvm_arch_on_sigbus_vcpu(CPUState
*cpu
, int code
, void *addr
)
873 int kvm_arch_on_sigbus(int code
, void *addr
)
878 void kvm_s390_io_interrupt(S390CPU
*cpu
, uint16_t subchannel_id
,
879 uint16_t subchannel_nr
, uint32_t io_int_parm
,
880 uint32_t io_int_word
)
884 if (io_int_word
& IO_INT_WORD_AI
) {
885 type
= KVM_S390_INT_IO(1, 0, 0, 0);
887 type
= ((subchannel_id
& 0xff00) << 24) |
888 ((subchannel_id
& 0x00060) << 22) | (subchannel_nr
<< 16);
890 kvm_s390_interrupt_internal(cpu
, type
,
891 ((uint32_t)subchannel_id
<< 16) | subchannel_nr
,
892 ((uint64_t)io_int_parm
<< 32) | io_int_word
, 1);
895 void kvm_s390_crw_mchk(S390CPU
*cpu
)
897 kvm_s390_interrupt_internal(cpu
, KVM_S390_MCHK
, 1 << 28,
898 0x00400f1d40330000, 1);
901 void kvm_s390_enable_css_support(S390CPU
*cpu
)
905 /* Activate host kernel channel subsystem support. */
906 r
= kvm_vcpu_enable_cap(CPU(cpu
), KVM_CAP_S390_CSS_SUPPORT
, 0);
910 void kvm_arch_init_irq_routing(KVMState
*s
)
914 int kvm_s390_assign_subch_ioeventfd(EventNotifier
*notifier
, uint32_t sch
,
917 struct kvm_ioeventfd kick
= {
918 .flags
= KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY
|
919 KVM_IOEVENTFD_FLAG_DATAMATCH
,
920 .fd
= event_notifier_get_fd(notifier
),
925 if (!kvm_check_extension(kvm_state
, KVM_CAP_IOEVENTFD
)) {
929 kick
.flags
|= KVM_IOEVENTFD_FLAG_DEASSIGN
;
931 return kvm_vm_ioctl(kvm_state
, KVM_IOEVENTFD
, &kick
);