aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390/kvm/intercept.c
diff options
context:
space:
mode:
authorChristian Borntraeger <borntraeger@de.ibm.com>2008-03-25 13:47:23 -0400
committerAvi Kivity <avi@qumranet.com>2008-04-27 05:00:43 -0400
commit8f2abe6a1e525e878bdf58f68ccd146d543fde84 (patch)
tree5f52959474a16847c740fb8668ebd9d6cbc75d07 /arch/s390/kvm/intercept.c
parentb0c632db637d68ad39d9f97f452ce176253f5f4e (diff)
KVM: s390: sie intercept handling
This path introduces handling of sie intercepts in three flavors: Intercepts are either handled completely in-kernel by kvm_handle_sie_intercept(), or passed to userspace with corresponding data in struct kvm_run in case kvm_handle_sie_intercept() returns -ENOTSUPP. In case of partial execution in kernel with the need of userspace support, kvm_handle_sie_intercept() may choose to set up struct kvm_run and return -EREMOTE. The trivial intercept reasons are handled in this patch: handle_noop() just does nothing for intercepts that don't require our support at all handle_stop() is called when a cpu enters stopped state, and it drops out to userland after updating our vcpu state handle_validity() faults in the cpu lowcore if needed, or passes the request to userland Acked-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Carsten Otte <cotte@de.ibm.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'arch/s390/kvm/intercept.c')
-rw-r--r--arch/s390/kvm/intercept.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c
new file mode 100644
index 000000000000..e757230b982c
--- /dev/null
+++ b/arch/s390/kvm/intercept.c
@@ -0,0 +1,80 @@
1/*
2 * intercept.c - in-kernel handling for sie intercepts
3 *
4 * Copyright IBM Corp. 2008
5 *
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.
9 *
10 * Author(s): Carsten Otte <cotte@de.ibm.com>
11 * Christian Borntraeger <borntraeger@de.ibm.com>
12 */
13
14#include <linux/kvm_host.h>
15#include <linux/errno.h>
16#include <linux/pagemap.h>
17
18#include <asm/kvm_host.h>
19
20#include "kvm-s390.h"
21
22static int handle_noop(struct kvm_vcpu *vcpu)
23{
24 switch (vcpu->arch.sie_block->icptcode) {
25 case 0x10:
26 vcpu->stat.exit_external_request++;
27 break;
28 case 0x14:
29 vcpu->stat.exit_external_interrupt++;
30 break;
31 default:
32 break; /* nothing */
33 }
34 return 0;
35}
36
37static int handle_stop(struct kvm_vcpu *vcpu)
38{
39 vcpu->stat.exit_stop_request++;
40 VCPU_EVENT(vcpu, 3, "%s", "cpu stopped");
41 atomic_clear_mask(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
42 return -ENOTSUPP;
43}
44
45static int handle_validity(struct kvm_vcpu *vcpu)
46{
47 int viwhy = vcpu->arch.sie_block->ipb >> 16;
48 vcpu->stat.exit_validity++;
49 if (viwhy == 0x37) {
50 fault_in_pages_writeable((char __user *)
51 vcpu->kvm->arch.guest_origin +
52 vcpu->arch.sie_block->prefix,
53 PAGE_SIZE);
54 return 0;
55 }
56 VCPU_EVENT(vcpu, 2, "unhandled validity intercept code %d",
57 viwhy);
58 return -ENOTSUPP;
59}
60
61static const intercept_handler_t intercept_funcs[0x48 >> 2] = {
62 [0x00 >> 2] = handle_noop,
63 [0x10 >> 2] = handle_noop,
64 [0x14 >> 2] = handle_noop,
65 [0x20 >> 2] = handle_validity,
66 [0x28 >> 2] = handle_stop,
67};
68
69int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
70{
71 intercept_handler_t func;
72 u8 code = vcpu->arch.sie_block->icptcode;
73
74 if (code & 3 || code > 0x48)
75 return -ENOTSUPP;
76 func = intercept_funcs[code >> 2];
77 if (func)
78 return func(vcpu);
79 return -ENOTSUPP;
80}