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"
38 /* #define DEBUG_KVM */
41 #define dprintf(fmt, ...) \
42 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
44 #define dprintf(fmt, ...) \
48 #define IPA0_DIAG 0x8300
49 #define IPA0_SIGP 0xae00
50 #define IPA0_B2 0xb200
51 #define IPA0_B9 0xb900
52 #define IPA0_EB 0xeb00
54 #define PRIV_SCLP_CALL 0x20
55 #define PRIV_CSCH 0x30
56 #define PRIV_HSCH 0x31
57 #define PRIV_MSCH 0x32
58 #define PRIV_SSCH 0x33
59 #define PRIV_STSCH 0x34
60 #define PRIV_TSCH 0x35
63 #define PRIV_RSCH 0x38
64 #define PRIV_STCRW 0x39
65 #define PRIV_STCPS 0x3a
66 #define PRIV_RCHP 0x3b
67 #define PRIV_SCHM 0x3c
68 #define PRIV_CHSC 0x5f
69 #define PRIV_SIGA 0x74
70 #define PRIV_XSCH 0x76
71 #define PRIV_SQBS 0x8a
72 #define PRIV_EQBS 0x9c
73 #define DIAG_KVM_HYPERCALL 0x500
74 #define DIAG_KVM_BREAKPOINT 0x501
76 #define ICPT_INSTRUCTION 0x04
77 #define ICPT_WAITPSW 0x1c
78 #define ICPT_SOFT_INTERCEPT 0x24
79 #define ICPT_CPU_STOP 0x28
82 #define SIGP_RESTART 0x06
83 #define SIGP_INITIAL_CPU_RESET 0x0b
84 #define SIGP_STORE_STATUS_ADDR 0x0e
85 #define SIGP_SET_ARCH 0x12
87 const KVMCapabilityInfo kvm_arch_required_capabilities
[] = {
91 static int cap_sync_regs
;
93 int kvm_arch_init(KVMState
*s
)
95 cap_sync_regs
= kvm_check_extension(s
, KVM_CAP_SYNC_REGS
);
99 unsigned long kvm_arch_vcpu_id(CPUState
*cpu
)
101 return cpu
->cpu_index
;
104 int kvm_arch_init_vcpu(CPUState
*cpu
)
106 /* nothing todo yet */
110 void kvm_arch_reset_vcpu(CPUState
*cpu
)
112 /* The initial reset call is needed here to reset in-kernel
113 * vcpu data that we can't access directly from QEMU
114 * (i.e. with older kernels which don't support sync_regs/ONE_REG).
115 * Before this ioctl cpu_synchronize_state() is called in common kvm
117 if (kvm_vcpu_ioctl(cpu
, KVM_S390_INITIAL_RESET
, NULL
)) {
118 perror("Can't reset vcpu\n");
122 int kvm_arch_put_registers(CPUState
*cs
, int level
)
124 S390CPU
*cpu
= S390_CPU(cs
);
125 CPUS390XState
*env
= &cpu
->env
;
126 struct kvm_one_reg reg
;
127 struct kvm_sregs sregs
;
128 struct kvm_regs regs
;
132 /* always save the PSW and the GPRS*/
133 cs
->kvm_run
->psw_addr
= env
->psw
.addr
;
134 cs
->kvm_run
->psw_mask
= env
->psw
.mask
;
136 if (cap_sync_regs
&& cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_GPRS
) {
137 for (i
= 0; i
< 16; i
++) {
138 cs
->kvm_run
->s
.regs
.gprs
[i
] = env
->regs
[i
];
139 cs
->kvm_run
->kvm_dirty_regs
|= KVM_SYNC_GPRS
;
142 for (i
= 0; i
< 16; i
++) {
143 regs
.gprs
[i
] = env
->regs
[i
];
145 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_REGS
, ®s
);
151 if (env
->runtime_reg_dirty_mask
== KVM_S390_RUNTIME_DIRTY_FULL
) {
152 reg
.id
= KVM_REG_S390_CPU_TIMER
;
153 reg
.addr
= (__u64
)&(env
->cputm
);
154 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_ONE_REG
, ®
);
159 reg
.id
= KVM_REG_S390_CLOCK_COMP
;
160 reg
.addr
= (__u64
)&(env
->ckc
);
161 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_ONE_REG
, ®
);
166 reg
.id
= KVM_REG_S390_TODPR
;
167 reg
.addr
= (__u64
)&(env
->todpr
);
168 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_ONE_REG
, ®
);
173 env
->runtime_reg_dirty_mask
= KVM_S390_RUNTIME_DIRTY_NONE
;
175 /* Do we need to save more than that? */
176 if (level
== KVM_PUT_RUNTIME_STATE
) {
181 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_ACRS
&&
182 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_CRS
) {
183 for (i
= 0; i
< 16; i
++) {
184 cs
->kvm_run
->s
.regs
.acrs
[i
] = env
->aregs
[i
];
185 cs
->kvm_run
->s
.regs
.crs
[i
] = env
->cregs
[i
];
187 cs
->kvm_run
->kvm_dirty_regs
|= KVM_SYNC_ACRS
;
188 cs
->kvm_run
->kvm_dirty_regs
|= KVM_SYNC_CRS
;
190 for (i
= 0; i
< 16; i
++) {
191 sregs
.acrs
[i
] = env
->aregs
[i
];
192 sregs
.crs
[i
] = env
->cregs
[i
];
194 ret
= kvm_vcpu_ioctl(cs
, KVM_SET_SREGS
, &sregs
);
200 /* Finally the prefix */
201 if (cap_sync_regs
&& cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_PREFIX
) {
202 cs
->kvm_run
->s
.regs
.prefix
= env
->psa
;
203 cs
->kvm_run
->kvm_dirty_regs
|= KVM_SYNC_PREFIX
;
205 /* prefix is only supported via sync regs */
210 int kvm_arch_get_registers(CPUState
*cs
)
212 S390CPU
*cpu
= S390_CPU(cs
);
213 CPUS390XState
*env
= &cpu
->env
;
214 struct kvm_one_reg reg
;
217 r
= kvm_s390_get_registers_partial(cs
);
222 reg
.id
= KVM_REG_S390_CPU_TIMER
;
223 reg
.addr
= (__u64
)&(env
->cputm
);
224 r
= kvm_vcpu_ioctl(cs
, KVM_GET_ONE_REG
, ®
);
229 reg
.id
= KVM_REG_S390_CLOCK_COMP
;
230 reg
.addr
= (__u64
)&(env
->ckc
);
231 r
= kvm_vcpu_ioctl(cs
, KVM_GET_ONE_REG
, ®
);
236 reg
.id
= KVM_REG_S390_TODPR
;
237 reg
.addr
= (__u64
)&(env
->todpr
);
238 r
= kvm_vcpu_ioctl(cs
, KVM_GET_ONE_REG
, ®
);
243 env
->runtime_reg_dirty_mask
= KVM_S390_RUNTIME_DIRTY_FULL
;
247 int kvm_s390_get_registers_partial(CPUState
*cs
)
249 S390CPU
*cpu
= S390_CPU(cs
);
250 CPUS390XState
*env
= &cpu
->env
;
251 struct kvm_sregs sregs
;
252 struct kvm_regs regs
;
256 if (env
->runtime_reg_dirty_mask
) {
261 env
->psw
.addr
= cs
->kvm_run
->psw_addr
;
262 env
->psw
.mask
= cs
->kvm_run
->psw_mask
;
265 if (cap_sync_regs
&& cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_GPRS
) {
266 for (i
= 0; i
< 16; i
++) {
267 env
->regs
[i
] = cs
->kvm_run
->s
.regs
.gprs
[i
];
270 ret
= kvm_vcpu_ioctl(cs
, KVM_GET_REGS
, ®s
);
274 for (i
= 0; i
< 16; i
++) {
275 env
->regs
[i
] = regs
.gprs
[i
];
279 /* The ACRS and CRS */
281 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_ACRS
&&
282 cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_CRS
) {
283 for (i
= 0; i
< 16; i
++) {
284 env
->aregs
[i
] = cs
->kvm_run
->s
.regs
.acrs
[i
];
285 env
->cregs
[i
] = cs
->kvm_run
->s
.regs
.crs
[i
];
288 ret
= kvm_vcpu_ioctl(cs
, KVM_GET_SREGS
, &sregs
);
292 for (i
= 0; i
< 16; i
++) {
293 env
->aregs
[i
] = sregs
.acrs
[i
];
294 env
->cregs
[i
] = sregs
.crs
[i
];
298 /* Finally the prefix */
299 if (cap_sync_regs
&& cs
->kvm_run
->kvm_valid_regs
& KVM_SYNC_PREFIX
) {
300 env
->psa
= cs
->kvm_run
->s
.regs
.prefix
;
302 /* no prefix without sync regs */
305 env
->runtime_reg_dirty_mask
= KVM_S390_RUNTIME_DIRTY_PARTIAL
;
310 * Legacy layout for s390:
311 * Older S390 KVM requires the topmost vma of the RAM to be
312 * smaller than an system defined value, which is at least 256GB.
313 * Larger systems have larger values. We put the guest between
314 * the end of data segment (system break) and this value. We
315 * use 32GB as a base to have enough room for the system break
316 * to grow. We also have to use MAP parameters that avoid
317 * read-only mapping of guest pages.
319 static void *legacy_s390_alloc(ram_addr_t size
)
323 mem
= mmap((void *) 0x800000000ULL
, size
,
324 PROT_EXEC
|PROT_READ
|PROT_WRITE
,
325 MAP_SHARED
| MAP_ANONYMOUS
| MAP_FIXED
, -1, 0);
326 if (mem
== MAP_FAILED
) {
327 fprintf(stderr
, "Allocating RAM failed\n");
333 void *kvm_arch_vmalloc(ram_addr_t size
)
335 /* Can we use the standard allocation ? */
336 if (kvm_check_extension(kvm_state
, KVM_CAP_S390_GMAP
) &&
337 kvm_check_extension(kvm_state
, KVM_CAP_S390_COW
)) {
340 return legacy_s390_alloc(size
);
344 int kvm_arch_insert_sw_breakpoint(CPUState
*cs
, struct kvm_sw_breakpoint
*bp
)
346 S390CPU
*cpu
= S390_CPU(cs
);
347 CPUS390XState
*env
= &cpu
->env
;
348 static const uint8_t diag_501
[] = {0x83, 0x24, 0x05, 0x01};
350 if (cpu_memory_rw_debug(env
, bp
->pc
, (uint8_t *)&bp
->saved_insn
, 4, 0) ||
351 cpu_memory_rw_debug(env
, bp
->pc
, (uint8_t *)diag_501
, 4, 1)) {
357 int kvm_arch_remove_sw_breakpoint(CPUState
*cs
, struct kvm_sw_breakpoint
*bp
)
359 S390CPU
*cpu
= S390_CPU(cs
);
360 CPUS390XState
*env
= &cpu
->env
;
362 static const uint8_t diag_501
[] = {0x83, 0x24, 0x05, 0x01};
364 if (cpu_memory_rw_debug(env
, bp
->pc
, t
, 4, 0)) {
366 } else if (memcmp(t
, diag_501
, 4)) {
368 } else if (cpu_memory_rw_debug(env
, bp
->pc
, (uint8_t *)&bp
->saved_insn
, 1, 1)) {
375 void kvm_arch_pre_run(CPUState
*cpu
, struct kvm_run
*run
)
379 void kvm_arch_post_run(CPUState
*cpu
, struct kvm_run
*run
)
383 int kvm_arch_process_async_events(CPUState
*cs
)
388 void kvm_s390_interrupt_internal(S390CPU
*cpu
, int type
, uint32_t parm
,
389 uint64_t parm64
, int vm
)
391 CPUState
*cs
= CPU(cpu
);
392 struct kvm_s390_interrupt kvmint
;
395 if (!cs
->kvm_state
) {
401 kvmint
.parm64
= parm64
;
404 r
= kvm_vm_ioctl(cs
->kvm_state
, KVM_S390_INTERRUPT
, &kvmint
);
406 r
= kvm_vcpu_ioctl(cs
, KVM_S390_INTERRUPT
, &kvmint
);
410 fprintf(stderr
, "KVM failed to inject interrupt\n");
415 void kvm_s390_virtio_irq(S390CPU
*cpu
, int config_change
, uint64_t token
)
417 kvm_s390_interrupt_internal(cpu
, KVM_S390_INT_VIRTIO
, config_change
,
421 void kvm_s390_interrupt(S390CPU
*cpu
, int type
, uint32_t code
)
423 kvm_s390_interrupt_internal(cpu
, type
, code
, 0, 0);
426 static void enter_pgmcheck(S390CPU
*cpu
, uint16_t code
)
428 kvm_s390_interrupt(cpu
, KVM_S390_PROGRAM_INT
, code
);
431 static inline void setcc(S390CPU
*cpu
, uint64_t cc
)
433 CPUS390XState
*env
= &cpu
->env
;
434 CPUState
*cs
= CPU(cpu
);
436 cs
->kvm_run
->psw_mask
&= ~(3ull << 44);
437 cs
->kvm_run
->psw_mask
|= (cc
& 3) << 44;
439 env
->psw
.mask
&= ~(3ul << 44);
440 env
->psw
.mask
|= (cc
& 3) << 44;
443 static int kvm_sclp_service_call(S390CPU
*cpu
, struct kvm_run
*run
,
446 CPUS390XState
*env
= &cpu
->env
;
451 cpu_synchronize_state(env
);
452 sccb
= env
->regs
[ipbh0
& 0xf];
453 code
= env
->regs
[(ipbh0
& 0xf0) >> 4];
455 r
= sclp_service_call(sccb
, code
);
457 enter_pgmcheck(cpu
, -r
);
464 static int kvm_handle_css_inst(S390CPU
*cpu
, struct kvm_run
*run
,
465 uint8_t ipa0
, uint8_t ipa1
, uint8_t ipb
)
469 CPUS390XState
*env
= &cpu
->env
;
470 CPUState
*cs
= ENV_GET_CPU(env
);
473 /* Not handled for now. */
477 kvm_s390_get_registers_partial(cs
);
478 cs
->kvm_vcpu_dirty
= true;
482 r
= ioinst_handle_xsch(env
, env
->regs
[1]);
485 r
= ioinst_handle_csch(env
, env
->regs
[1]);
488 r
= ioinst_handle_hsch(env
, env
->regs
[1]);
491 r
= ioinst_handle_msch(env
, env
->regs
[1], run
->s390_sieic
.ipb
);
494 r
= ioinst_handle_ssch(env
, env
->regs
[1], run
->s390_sieic
.ipb
);
497 r
= ioinst_handle_stcrw(env
, run
->s390_sieic
.ipb
);
500 r
= ioinst_handle_stsch(env
, env
->regs
[1], run
->s390_sieic
.ipb
);
503 /* We should only get tsch via KVM_EXIT_S390_TSCH. */
504 fprintf(stderr
, "Spurious tsch intercept\n");
507 r
= ioinst_handle_chsc(env
, run
->s390_sieic
.ipb
);
510 /* This should have been handled by kvm already. */
511 fprintf(stderr
, "Spurious tpi intercept\n");
515 r
= ioinst_handle_schm(env
, env
->regs
[1], env
->regs
[2],
516 run
->s390_sieic
.ipb
);
519 r
= ioinst_handle_rsch(env
, env
->regs
[1]);
522 r
= ioinst_handle_rchp(env
, env
->regs
[1]);
525 /* We do not provide this instruction, it is suppressed. */
531 r
= ioinst_handle_sal(env
, env
->regs
[1]);
549 static int is_ioinst(uint8_t ipa0
, uint8_t ipa1
, uint8_t ipb
)
552 uint16_t ipa
= (ipa0
<< 8) | ipa1
;
555 case IPA0_B2
| PRIV_CSCH
:
556 case IPA0_B2
| PRIV_HSCH
:
557 case IPA0_B2
| PRIV_MSCH
:
558 case IPA0_B2
| PRIV_SSCH
:
559 case IPA0_B2
| PRIV_STSCH
:
560 case IPA0_B2
| PRIV_TPI
:
561 case IPA0_B2
| PRIV_SAL
:
562 case IPA0_B2
| PRIV_RSCH
:
563 case IPA0_B2
| PRIV_STCRW
:
564 case IPA0_B2
| PRIV_STCPS
:
565 case IPA0_B2
| PRIV_RCHP
:
566 case IPA0_B2
| PRIV_SCHM
:
567 case IPA0_B2
| PRIV_CHSC
:
568 case IPA0_B2
| PRIV_SIGA
:
569 case IPA0_B2
| PRIV_XSCH
:
570 case IPA0_B9
| PRIV_EQBS
:
571 case IPA0_EB
| PRIV_SQBS
:
579 static int handle_priv(S390CPU
*cpu
, struct kvm_run
*run
,
580 uint8_t ipa0
, uint8_t ipa1
)
583 uint16_t ipbh0
= (run
->s390_sieic
.ipb
& 0xffff0000) >> 16;
584 uint8_t ipb
= run
->s390_sieic
.ipb
& 0xff;
586 dprintf("KVM: PRIV: %d\n", ipa1
);
589 r
= kvm_sclp_service_call(cpu
, run
, ipbh0
);
592 if (is_ioinst(ipa0
, ipa1
, ipb
)) {
593 r
= kvm_handle_css_inst(cpu
, run
, ipa0
, ipa1
, ipb
);
599 dprintf("KVM: unknown PRIV: 0x%x\n", ipa1
);
608 static int handle_hypercall(CPUS390XState
*env
, struct kvm_run
*run
)
610 CPUState
*cs
= ENV_GET_CPU(env
);
612 kvm_s390_get_registers_partial(cs
);
613 cs
->kvm_vcpu_dirty
= true;
614 env
->regs
[2] = s390_virtio_hypercall(env
);
619 static int handle_diag(CPUS390XState
*env
, struct kvm_run
*run
, int ipb_code
)
624 case DIAG_KVM_HYPERCALL
:
625 r
= handle_hypercall(env
, run
);
627 case DIAG_KVM_BREAKPOINT
:
631 dprintf("KVM: unknown DIAG: 0x%x\n", ipb_code
);
639 static int s390_cpu_restart(S390CPU
*cpu
)
641 kvm_s390_interrupt(cpu
, KVM_S390_RESTART
, 0);
642 s390_add_running_cpu(cpu
);
643 qemu_cpu_kick(CPU(cpu
));
644 dprintf("DONE: SIGP cpu restart: %p\n", &cpu
->env
);
648 static int s390_store_status(CPUS390XState
*env
, uint32_t parameter
)
651 fprintf(stderr
, "XXX SIGP store status\n");
655 static int s390_cpu_initial_reset(S390CPU
*cpu
)
657 CPUS390XState
*env
= &cpu
->env
;
660 s390_del_running_cpu(cpu
);
661 if (kvm_vcpu_ioctl(CPU(cpu
), KVM_S390_INITIAL_RESET
, NULL
) < 0) {
662 perror("cannot init reset vcpu");
665 /* Manually zero out all registers */
666 cpu_synchronize_state(env
);
667 for (i
= 0; i
< 16; i
++) {
671 dprintf("DONE: SIGP initial reset: %p\n", env
);
675 static int handle_sigp(S390CPU
*cpu
, struct kvm_run
*run
, uint8_t ipa1
)
677 CPUS390XState
*env
= &cpu
->env
;
684 CPUS390XState
*target_env
;
686 cpu_synchronize_state(env
);
689 order_code
= run
->s390_sieic
.ipb
>> 28;
690 if (order_code
> 0) {
691 order_code
= env
->regs
[order_code
];
693 order_code
+= (run
->s390_sieic
.ipb
& 0x0fff0000) >> 16;
696 t
= (ipa1
& 0xf0) >> 4;
701 parameter
= env
->regs
[t
] & 0x7ffffe00;
702 cpu_addr
= env
->regs
[ipa1
& 0x0f];
704 target_cpu
= s390_cpu_addr2state(cpu_addr
);
705 if (target_cpu
== NULL
) {
708 target_env
= &target_cpu
->env
;
710 switch (order_code
) {
712 r
= s390_cpu_restart(target_cpu
);
714 case SIGP_STORE_STATUS_ADDR
:
715 r
= s390_store_status(target_env
, parameter
);
718 /* make the caller panic */
720 case SIGP_INITIAL_CPU_RESET
:
721 r
= s390_cpu_initial_reset(target_cpu
);
724 fprintf(stderr
, "KVM: unknown SIGP: 0x%x\n", order_code
);
729 setcc(cpu
, r
? 3 : 0);
733 static int handle_instruction(S390CPU
*cpu
, struct kvm_run
*run
)
735 CPUS390XState
*env
= &cpu
->env
;
736 unsigned int ipa0
= (run
->s390_sieic
.ipa
& 0xff00);
737 uint8_t ipa1
= run
->s390_sieic
.ipa
& 0x00ff;
738 int ipb_code
= (run
->s390_sieic
.ipb
& 0x0fff0000) >> 16;
741 dprintf("handle_instruction 0x%x 0x%x\n", run
->s390_sieic
.ipa
, run
->s390_sieic
.ipb
);
746 r
= handle_priv(cpu
, run
, ipa0
>> 8, ipa1
);
749 r
= handle_diag(env
, run
, ipb_code
);
752 r
= handle_sigp(cpu
, run
, ipa1
);
757 enter_pgmcheck(cpu
, 0x0001);
762 static bool is_special_wait_psw(CPUState
*cs
)
765 return cs
->kvm_run
->psw_addr
== 0xfffUL
;
768 static int handle_intercept(S390CPU
*cpu
)
770 CPUState
*cs
= CPU(cpu
);
771 struct kvm_run
*run
= cs
->kvm_run
;
772 int icpt_code
= run
->s390_sieic
.icptcode
;
775 dprintf("intercept: 0x%x (at 0x%lx)\n", icpt_code
,
776 (long)cs
->kvm_run
->psw_addr
);
778 case ICPT_INSTRUCTION
:
779 r
= handle_instruction(cpu
, run
);
782 if (s390_del_running_cpu(cpu
) == 0 &&
783 is_special_wait_psw(cs
)) {
784 qemu_system_shutdown_request();
789 if (s390_del_running_cpu(cpu
) == 0) {
790 qemu_system_shutdown_request();
794 case ICPT_SOFT_INTERCEPT
:
795 fprintf(stderr
, "KVM unimplemented icpt SOFT\n");
799 fprintf(stderr
, "KVM unimplemented icpt IO\n");
803 fprintf(stderr
, "Unknown intercept code: %d\n", icpt_code
);
811 static int handle_tsch(S390CPU
*cpu
)
813 CPUS390XState
*env
= &cpu
->env
;
814 CPUState
*cs
= CPU(cpu
);
815 struct kvm_run
*run
= cs
->kvm_run
;
818 kvm_s390_get_registers_partial(cs
);
819 cs
->kvm_vcpu_dirty
= true;
821 ret
= ioinst_handle_tsch(env
, env
->regs
[1], run
->s390_tsch
.ipb
);
823 /* Success; set condition code. */
826 } else if (ret
< -1) {
829 * If an I/O interrupt had been dequeued, we have to reinject it.
831 if (run
->s390_tsch
.dequeued
) {
832 uint16_t subchannel_id
= run
->s390_tsch
.subchannel_id
;
833 uint16_t subchannel_nr
= run
->s390_tsch
.subchannel_nr
;
834 uint32_t io_int_parm
= run
->s390_tsch
.io_int_parm
;
835 uint32_t io_int_word
= run
->s390_tsch
.io_int_word
;
836 uint32_t type
= ((subchannel_id
& 0xff00) << 24) |
837 ((subchannel_id
& 0x00060) << 22) | (subchannel_nr
<< 16);
839 kvm_s390_interrupt_internal(cpu
, type
,
840 ((uint32_t)subchannel_id
<< 16)
842 ((uint64_t)io_int_parm
<< 32)
850 int kvm_arch_handle_exit(CPUState
*cs
, struct kvm_run
*run
)
852 S390CPU
*cpu
= S390_CPU(cs
);
855 switch (run
->exit_reason
) {
856 case KVM_EXIT_S390_SIEIC
:
857 ret
= handle_intercept(cpu
);
859 case KVM_EXIT_S390_RESET
:
860 qemu_system_reset_request();
862 case KVM_EXIT_S390_TSCH
:
863 ret
= handle_tsch(cpu
);
866 fprintf(stderr
, "Unknown KVM exit: %d\n", run
->exit_reason
);
871 ret
= EXCP_INTERRUPT
;
876 bool kvm_arch_stop_on_emulation_error(CPUState
*cpu
)
881 int kvm_arch_on_sigbus_vcpu(CPUState
*cpu
, int code
, void *addr
)
886 int kvm_arch_on_sigbus(int code
, void *addr
)
891 void kvm_s390_io_interrupt(S390CPU
*cpu
, uint16_t subchannel_id
,
892 uint16_t subchannel_nr
, uint32_t io_int_parm
,
893 uint32_t io_int_word
)
897 type
= ((subchannel_id
& 0xff00) << 24) |
898 ((subchannel_id
& 0x00060) << 22) | (subchannel_nr
<< 16);
899 kvm_s390_interrupt_internal(cpu
, type
,
900 ((uint32_t)subchannel_id
<< 16) | subchannel_nr
,
901 ((uint64_t)io_int_parm
<< 32) | io_int_word
, 1);
904 void kvm_s390_crw_mchk(S390CPU
*cpu
)
906 kvm_s390_interrupt_internal(cpu
, KVM_S390_MCHK
, 1 << 28,
907 0x00400f1d40330000, 1);
910 void kvm_s390_enable_css_support(S390CPU
*cpu
)
912 struct kvm_enable_cap cap
= {};
915 /* Activate host kernel channel subsystem support. */
916 cap
.cap
= KVM_CAP_S390_CSS_SUPPORT
;
917 r
= kvm_vcpu_ioctl(CPU(cpu
), KVM_ENABLE_CAP
, &cap
);