stop_machine: reimplement using cpu_stop
[safe/jmp/linux-2.6] / arch / s390 / kvm / intercept.c
index 349581a..3ddc308 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * intercept.c - in-kernel handling for sie intercepts
  *
- * Copyright IBM Corp. 2008
+ * Copyright IBM Corp. 2008,2009
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License (version 2 only)
@@ -20,7 +20,7 @@
 #include "kvm-s390.h"
 #include "gaccess.h"
 
-static int handle_lctg(struct kvm_vcpu *vcpu)
+static int handle_lctlg(struct kvm_vcpu *vcpu)
 {
        int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
        int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
@@ -30,17 +30,20 @@ static int handle_lctg(struct kvm_vcpu *vcpu)
        u64 useraddr;
        int reg, rc;
 
-       vcpu->stat.instruction_lctg++;
+       vcpu->stat.instruction_lctlg++;
        if ((vcpu->arch.sie_block->ipb & 0xff) != 0x2f)
-               return -ENOTSUPP;
+               return -EOPNOTSUPP;
 
        useraddr = disp2;
        if (base2)
                useraddr += vcpu->arch.guest_gprs[base2];
 
+       if (useraddr & 7)
+               return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+
        reg = reg1;
 
-       VCPU_EVENT(vcpu, 5, "lctg r1:%x, r3:%x,b2:%x,d2:%x", reg1, reg3, base2,
+       VCPU_EVENT(vcpu, 5, "lctlg r1:%x, r3:%x,b2:%x,d2:%x", reg1, reg3, base2,
                   disp2);
 
        do {
@@ -74,6 +77,9 @@ static int handle_lctl(struct kvm_vcpu *vcpu)
        if (base2)
                useraddr += vcpu->arch.guest_gprs[base2];
 
+       if (useraddr & 3)
+               return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+
        VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x,b2:%x,d2:%x", reg1, reg3, base2,
                   disp2);
 
@@ -97,14 +103,17 @@ static int handle_lctl(struct kvm_vcpu *vcpu)
 static intercept_handler_t instruction_handlers[256] = {
        [0x83] = kvm_s390_handle_diag,
        [0xae] = kvm_s390_handle_sigp,
-       [0xb2] = kvm_s390_handle_priv,
+       [0xb2] = kvm_s390_handle_b2,
        [0xb7] = handle_lctl,
-       [0xeb] = handle_lctg,
+       [0xeb] = handle_lctlg,
 };
 
 static int handle_noop(struct kvm_vcpu *vcpu)
 {
        switch (vcpu->arch.sie_block->icptcode) {
+       case 0x0:
+               vcpu->stat.exit_null++;
+               break;
        case 0x10:
                vcpu->stat.exit_external_request++;
                break;
@@ -119,7 +128,7 @@ static int handle_noop(struct kvm_vcpu *vcpu)
 
 static int handle_stop(struct kvm_vcpu *vcpu)
 {
-       int rc;
+       int rc = 0;
 
        vcpu->stat.exit_stop_request++;
        atomic_clear_mask(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
@@ -129,15 +138,21 @@ static int handle_stop(struct kvm_vcpu *vcpu)
                rc = __kvm_s390_vcpu_store_status(vcpu,
                                                  KVM_S390_STORE_STATUS_NOADDR);
                if (rc >= 0)
-                       rc = -ENOTSUPP;
+                       rc = -EOPNOTSUPP;
+       }
+
+       if (vcpu->arch.local_int.action_bits & ACTION_RELOADVCPU_ON_STOP) {
+               vcpu->arch.local_int.action_bits &= ~ACTION_RELOADVCPU_ON_STOP;
+               rc = SIE_INTERCEPT_RERUNVCPU;
+               vcpu->run->exit_reason = KVM_EXIT_INTR;
        }
 
        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;
+               rc = -EOPNOTSUPP;
+       }
+
        spin_unlock_bh(&vcpu->arch.local_int.lock);
        return rc;
 }
@@ -145,17 +160,25 @@ static int handle_stop(struct kvm_vcpu *vcpu)
 static int handle_validity(struct kvm_vcpu *vcpu)
 {
        int viwhy = vcpu->arch.sie_block->ipb >> 16;
+       int rc;
+
        vcpu->stat.exit_validity++;
-       if (viwhy == 0x37) {
-               fault_in_pages_writeable((char __user *)
-                                        vcpu->kvm->arch.guest_origin +
-                                        vcpu->arch.sie_block->prefix,
-                                        PAGE_SIZE);
-               return 0;
-       }
-       VCPU_EVENT(vcpu, 2, "unhandled validity intercept code %d",
-                  viwhy);
-       return -ENOTSUPP;
+       if ((viwhy == 0x37) && (vcpu->arch.sie_block->prefix
+               <= kvm_s390_vcpu_get_memsize(vcpu) - 2*PAGE_SIZE)) {
+               rc = fault_in_pages_writeable((char __user *)
+                        vcpu->arch.sie_block->gmsor +
+                        vcpu->arch.sie_block->prefix,
+                        2*PAGE_SIZE);
+               if (rc)
+                       /* user will receive sigsegv, exit to user */
+                       rc = -EOPNOTSUPP;
+       } else
+               rc = -EOPNOTSUPP;
+
+       if (rc)
+               VCPU_EVENT(vcpu, 2, "unhandled validity intercept code %d",
+                          viwhy);
+       return rc;
 }
 
 static int handle_instruction(struct kvm_vcpu *vcpu)
@@ -166,7 +189,7 @@ static int handle_instruction(struct kvm_vcpu *vcpu)
        handler = instruction_handlers[vcpu->arch.sie_block->ipa >> 8];
        if (handler)
                return handler(vcpu);
-       return -ENOTSUPP;
+       return -EOPNOTSUPP;
 }
 
 static int handle_prog(struct kvm_vcpu *vcpu)
@@ -183,14 +206,14 @@ static int handle_instruction_and_prog(struct kvm_vcpu *vcpu)
        rc = handle_instruction(vcpu);
        rc2 = handle_prog(vcpu);
 
-       if (rc == -ENOTSUPP)
+       if (rc == -EOPNOTSUPP)
                vcpu->arch.sie_block->icptcode = 0x04;
        if (rc)
                return rc;
        return rc2;
 }
 
-static const intercept_handler_t intercept_funcs[0x48 >> 2] = {
+static const intercept_handler_t intercept_funcs[] = {
        [0x00 >> 2] = handle_noop,
        [0x04 >> 2] = handle_instruction,
        [0x08 >> 2] = handle_prog,
@@ -207,10 +230,10 @@ int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
        intercept_handler_t func;
        u8 code = vcpu->arch.sie_block->icptcode;
 
-       if (code & 3 || code > 0x48)
-               return -ENOTSUPP;
+       if (code & 3 || (code >> 2) >= ARRAY_SIZE(intercept_funcs))
+               return -EOPNOTSUPP;
        func = intercept_funcs[code >> 2];
        if (func)
                return func(vcpu);
-       return -ENOTSUPP;
+       return -EOPNOTSUPP;
 }