KVM: s390: sie intercept handling
[linux-2.6/linux-2.6-openrd.git] / arch / s390 / kvm / intercept.c
blobe757230b982cddaaad2cb18025da13b5ec1f5bfe
1 /*
2 * intercept.c - in-kernel handling for sie intercepts
4 * Copyright IBM Corp. 2008
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_host.h>
15 #include <linux/errno.h>
16 #include <linux/pagemap.h>
18 #include <asm/kvm_host.h>
20 #include "kvm-s390.h"
22 static int handle_noop(struct kvm_vcpu *vcpu)
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 */
34 return 0;
37 static int handle_stop(struct kvm_vcpu *vcpu)
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;
45 static int handle_validity(struct kvm_vcpu *vcpu)
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;
56 VCPU_EVENT(vcpu, 2, "unhandled validity intercept code %d",
57 viwhy);
58 return -ENOTSUPP;
61 static 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,
69 int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
71 intercept_handler_t func;
72 u8 code = vcpu->arch.sie_block->icptcode;
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;