]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/s390/kvm/intercept.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/jk/spufs
[linux-2.6-omap-h63xx.git] / arch / s390 / kvm / intercept.c
index e757230b982cddaaad2cb18025da13b5ec1f5bfe..349581a2610344f23c1af6873dc57d6c23761b47 100644 (file)
 #include <asm/kvm_host.h>
 
 #include "kvm-s390.h"
+#include "gaccess.h"
+
+static int handle_lctg(struct kvm_vcpu *vcpu)
+{
+       int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
+       int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
+       int base2 = vcpu->arch.sie_block->ipb >> 28;
+       int disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) +
+                       ((vcpu->arch.sie_block->ipb & 0xff00) << 4);
+       u64 useraddr;
+       int reg, rc;
+
+       vcpu->stat.instruction_lctg++;
+       if ((vcpu->arch.sie_block->ipb & 0xff) != 0x2f)
+               return -ENOTSUPP;
+
+       useraddr = disp2;
+       if (base2)
+               useraddr += vcpu->arch.guest_gprs[base2];
+
+       reg = reg1;
+
+       VCPU_EVENT(vcpu, 5, "lctg r1:%x, r3:%x,b2:%x,d2:%x", reg1, reg3, base2,
+                  disp2);
+
+       do {
+               rc = get_guest_u64(vcpu, useraddr,
+                                  &vcpu->arch.sie_block->gcr[reg]);
+               if (rc == -EFAULT) {
+                       kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
+                       break;
+               }
+               useraddr += 8;
+               if (reg == reg3)
+                       break;
+               reg = (reg + 1) % 16;
+       } while (1);
+       return 0;
+}
+
+static int handle_lctl(struct kvm_vcpu *vcpu)
+{
+       int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
+       int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
+       int base2 = vcpu->arch.sie_block->ipb >> 28;
+       int disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
+       u64 useraddr;
+       u32 val = 0;
+       int reg, rc;
+
+       vcpu->stat.instruction_lctl++;
+
+       useraddr = disp2;
+       if (base2)
+               useraddr += vcpu->arch.guest_gprs[base2];
+
+       VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x,b2:%x,d2:%x", reg1, reg3, base2,
+                  disp2);
+
+       reg = reg1;
+       do {
+               rc = get_guest_u32(vcpu, useraddr, &val);
+               if (rc == -EFAULT) {
+                       kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
+                       break;
+               }
+               vcpu->arch.sie_block->gcr[reg] &= 0xffffffff00000000ul;
+               vcpu->arch.sie_block->gcr[reg] |= val;
+               useraddr += 4;
+               if (reg == reg3)
+                       break;
+               reg = (reg + 1) % 16;
+       } while (1);
+       return 0;
+}
+
+static intercept_handler_t instruction_handlers[256] = {
+       [0x83] = kvm_s390_handle_diag,
+       [0xae] = kvm_s390_handle_sigp,
+       [0xb2] = kvm_s390_handle_priv,
+       [0xb7] = handle_lctl,
+       [0xeb] = handle_lctg,
+};
 
 static int handle_noop(struct kvm_vcpu *vcpu)
 {
@@ -36,10 +119,27 @@ static int handle_noop(struct kvm_vcpu *vcpu)
 
 static int handle_stop(struct kvm_vcpu *vcpu)
 {
+       int rc;
+
        vcpu->stat.exit_stop_request++;
-       VCPU_EVENT(vcpu, 3, "%s", "cpu stopped");
        atomic_clear_mask(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
-       return -ENOTSUPP;
+       spin_lock_bh(&vcpu->arch.local_int.lock);
+       if (vcpu->arch.local_int.action_bits & ACTION_STORE_ON_STOP) {
+               vcpu->arch.local_int.action_bits &= ~ACTION_STORE_ON_STOP;
+               rc = __kvm_s390_vcpu_store_status(vcpu,
+                                                 KVM_S390_STORE_STATUS_NOADDR);
+               if (rc >= 0)
+                       rc = -ENOTSUPP;
+       }
+
+       if (vcpu->arch.local_int.action_bits & ACTION_STOP_ON_STOP) {
+               vcpu->arch.local_int.action_bits &= ~ACTION_STOP_ON_STOP;
+               VCPU_EVENT(vcpu, 3, "%s", "cpu stopped");
+               rc = -ENOTSUPP;
+       } else
+               rc = 0;
+       spin_unlock_bh(&vcpu->arch.local_int.lock);
+       return rc;
 }
 
 static int handle_validity(struct kvm_vcpu *vcpu)
@@ -58,10 +158,46 @@ static int handle_validity(struct kvm_vcpu *vcpu)
        return -ENOTSUPP;
 }
 
+static int handle_instruction(struct kvm_vcpu *vcpu)
+{
+       intercept_handler_t handler;
+
+       vcpu->stat.exit_instruction++;
+       handler = instruction_handlers[vcpu->arch.sie_block->ipa >> 8];
+       if (handler)
+               return handler(vcpu);
+       return -ENOTSUPP;
+}
+
+static int handle_prog(struct kvm_vcpu *vcpu)
+{
+       vcpu->stat.exit_program_interruption++;
+       return kvm_s390_inject_program_int(vcpu, vcpu->arch.sie_block->iprcc);
+}
+
+static int handle_instruction_and_prog(struct kvm_vcpu *vcpu)
+{
+       int rc, rc2;
+
+       vcpu->stat.exit_instr_and_program++;
+       rc = handle_instruction(vcpu);
+       rc2 = handle_prog(vcpu);
+
+       if (rc == -ENOTSUPP)
+               vcpu->arch.sie_block->icptcode = 0x04;
+       if (rc)
+               return rc;
+       return rc2;
+}
+
 static const intercept_handler_t intercept_funcs[0x48 >> 2] = {
        [0x00 >> 2] = handle_noop,
+       [0x04 >> 2] = handle_instruction,
+       [0x08 >> 2] = handle_prog,
+       [0x0C >> 2] = handle_instruction_and_prog,
        [0x10 >> 2] = handle_noop,
        [0x14 >> 2] = handle_noop,
+       [0x1C >> 2] = kvm_s390_handle_wait,
        [0x20 >> 2] = handle_validity,
        [0x28 >> 2] = handle_stop,
 };