2008-03-25 20:47:31 +03:00
|
|
|
/*
|
2012-07-20 13:15:04 +04:00
|
|
|
* handling interprocessor communication
|
2008-03-25 20:47:31 +03:00
|
|
|
*
|
2013-11-21 19:01:48 +04:00
|
|
|
* Copyright IBM Corp. 2008, 2013
|
2008-03-25 20:47:31 +03:00
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Author(s): Carsten Otte <cotte@de.ibm.com>
|
|
|
|
* Christian Borntraeger <borntraeger@de.ibm.com>
|
2009-05-20 17:34:55 +04:00
|
|
|
* Christian Ehrhardt <ehrhardt@de.ibm.com>
|
2008-03-25 20:47:31 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kvm.h>
|
|
|
|
#include <linux/kvm_host.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2012-06-04 14:55:15 +04:00
|
|
|
#include <asm/sigp.h>
|
2008-03-25 20:47:31 +03:00
|
|
|
#include "gaccess.h"
|
|
|
|
#include "kvm-s390.h"
|
2012-07-23 19:20:29 +04:00
|
|
|
#include "trace.h"
|
2008-03-25 20:47:31 +03:00
|
|
|
|
2014-03-19 19:59:39 +04:00
|
|
|
static int __sigp_sense(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu,
|
2012-01-11 14:20:32 +04:00
|
|
|
u64 *reg)
|
2008-03-25 20:47:31 +03:00
|
|
|
{
|
2014-02-25 18:36:45 +04:00
|
|
|
struct kvm_s390_local_interrupt *li;
|
|
|
|
int cpuflags;
|
2008-03-25 20:47:31 +03:00
|
|
|
int rc;
|
2014-10-14 17:29:30 +04:00
|
|
|
int ext_call_pending;
|
2008-03-25 20:47:31 +03:00
|
|
|
|
2014-02-25 18:36:45 +04:00
|
|
|
li = &dst_vcpu->arch.local_int;
|
|
|
|
|
|
|
|
cpuflags = atomic_read(li->cpuflags);
|
2014-10-14 17:29:30 +04:00
|
|
|
ext_call_pending = kvm_s390_ext_call_pending(dst_vcpu);
|
|
|
|
if (!(cpuflags & CPUSTAT_STOPPED) && !ext_call_pending)
|
2012-06-26 18:06:41 +04:00
|
|
|
rc = SIGP_CC_ORDER_CODE_ACCEPTED;
|
|
|
|
else {
|
2008-03-25 20:47:31 +03:00
|
|
|
*reg &= 0xffffffff00000000UL;
|
2014-10-14 17:29:30 +04:00
|
|
|
if (ext_call_pending)
|
2012-06-26 18:06:41 +04:00
|
|
|
*reg |= SIGP_STATUS_EXT_CALL_PENDING;
|
2014-02-25 18:36:45 +04:00
|
|
|
if (cpuflags & CPUSTAT_STOPPED)
|
2012-06-26 18:06:41 +04:00
|
|
|
*reg |= SIGP_STATUS_STOPPED;
|
2012-06-26 18:06:40 +04:00
|
|
|
rc = SIGP_CC_STATUS_STORED;
|
2008-03-25 20:47:31 +03:00
|
|
|
}
|
|
|
|
|
2014-03-19 19:59:39 +04:00
|
|
|
VCPU_EVENT(vcpu, 4, "sensed status of cpu %x rc %x", dst_vcpu->vcpu_id,
|
|
|
|
rc);
|
2008-03-25 20:47:31 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-06-06 12:24:15 +04:00
|
|
|
static int __inject_sigp_emergency(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_vcpu *dst_vcpu)
|
2008-03-25 20:47:31 +03:00
|
|
|
{
|
2014-07-29 17:11:49 +04:00
|
|
|
struct kvm_s390_irq irq = {
|
2014-05-14 19:14:46 +04:00
|
|
|
.type = KVM_S390_INT_EMERGENCY,
|
2014-07-29 17:11:49 +04:00
|
|
|
.u.emerg.code = vcpu->vcpu_id,
|
2014-05-14 19:14:46 +04:00
|
|
|
};
|
|
|
|
int rc = 0;
|
2008-03-25 20:47:31 +03:00
|
|
|
|
2014-07-29 17:11:49 +04:00
|
|
|
rc = kvm_s390_inject_vcpu(dst_vcpu, &irq);
|
2014-05-14 19:14:46 +04:00
|
|
|
if (!rc)
|
2014-03-19 19:59:39 +04:00
|
|
|
VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x",
|
|
|
|
dst_vcpu->vcpu_id);
|
2008-03-25 20:47:31 +03:00
|
|
|
|
2014-05-14 19:14:46 +04:00
|
|
|
return rc ? rc : SIGP_CC_ORDER_CODE_ACCEPTED;
|
2011-10-18 14:27:15 +04:00
|
|
|
}
|
|
|
|
|
2014-06-06 12:24:15 +04:00
|
|
|
static int __sigp_emergency(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu)
|
|
|
|
{
|
|
|
|
return __inject_sigp_emergency(vcpu, dst_vcpu);
|
|
|
|
}
|
|
|
|
|
2014-03-19 19:59:39 +04:00
|
|
|
static int __sigp_conditional_emergency(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_vcpu *dst_vcpu,
|
2013-11-21 19:01:48 +04:00
|
|
|
u16 asn, u64 *reg)
|
|
|
|
{
|
|
|
|
const u64 psw_int_mask = PSW_MASK_IO | PSW_MASK_EXT;
|
|
|
|
u16 p_asn, s_asn;
|
|
|
|
psw_t *psw;
|
|
|
|
u32 flags;
|
|
|
|
|
|
|
|
flags = atomic_read(&dst_vcpu->arch.sie_block->cpuflags);
|
|
|
|
psw = &dst_vcpu->arch.sie_block->gpsw;
|
|
|
|
p_asn = dst_vcpu->arch.sie_block->gcr[4] & 0xffff; /* Primary ASN */
|
|
|
|
s_asn = dst_vcpu->arch.sie_block->gcr[3] & 0xffff; /* Secondary ASN */
|
|
|
|
|
2014-06-06 12:24:15 +04:00
|
|
|
/* Inject the emergency signal? */
|
2013-11-21 19:01:48 +04:00
|
|
|
if (!(flags & CPUSTAT_STOPPED)
|
|
|
|
|| (psw->mask & psw_int_mask) != psw_int_mask
|
|
|
|
|| ((flags & CPUSTAT_WAIT) && psw->addr != 0)
|
|
|
|
|| (!(flags & CPUSTAT_WAIT) && (asn == p_asn || asn == s_asn))) {
|
2014-06-06 12:24:15 +04:00
|
|
|
return __inject_sigp_emergency(vcpu, dst_vcpu);
|
2013-11-21 19:01:48 +04:00
|
|
|
} else {
|
|
|
|
*reg &= 0xffffffff00000000UL;
|
|
|
|
*reg |= SIGP_STATUS_INCORRECT_STATE;
|
|
|
|
return SIGP_CC_STATUS_STORED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 19:59:39 +04:00
|
|
|
static int __sigp_external_call(struct kvm_vcpu *vcpu,
|
2014-10-14 17:29:30 +04:00
|
|
|
struct kvm_vcpu *dst_vcpu, u64 *reg)
|
2011-10-18 14:27:15 +04:00
|
|
|
{
|
2014-07-29 17:11:49 +04:00
|
|
|
struct kvm_s390_irq irq = {
|
2014-05-14 19:14:46 +04:00
|
|
|
.type = KVM_S390_INT_EXTERNAL_CALL,
|
2014-07-29 17:11:49 +04:00
|
|
|
.u.extcall.code = vcpu->vcpu_id,
|
2014-05-14 19:14:46 +04:00
|
|
|
};
|
|
|
|
int rc;
|
2011-10-18 14:27:15 +04:00
|
|
|
|
2014-07-29 17:11:49 +04:00
|
|
|
rc = kvm_s390_inject_vcpu(dst_vcpu, &irq);
|
2014-10-14 17:29:30 +04:00
|
|
|
if (rc == -EBUSY) {
|
|
|
|
*reg &= 0xffffffff00000000UL;
|
|
|
|
*reg |= SIGP_STATUS_EXT_CALL_PENDING;
|
|
|
|
return SIGP_CC_STATUS_STORED;
|
|
|
|
} else if (rc == 0) {
|
2014-03-19 19:59:39 +04:00
|
|
|
VCPU_EVENT(vcpu, 4, "sent sigp ext call to cpu %x",
|
|
|
|
dst_vcpu->vcpu_id);
|
2014-10-14 17:29:30 +04:00
|
|
|
}
|
2011-10-18 14:27:15 +04:00
|
|
|
|
2014-05-14 19:14:46 +04:00
|
|
|
return rc ? rc : SIGP_CC_ORDER_CODE_ACCEPTED;
|
2008-03-25 20:47:31 +03:00
|
|
|
}
|
|
|
|
|
2014-06-06 12:25:09 +04:00
|
|
|
static int __sigp_stop(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu)
|
2009-05-20 17:34:55 +04:00
|
|
|
{
|
2014-10-15 18:48:53 +04:00
|
|
|
struct kvm_s390_irq irq = {
|
|
|
|
.type = KVM_S390_SIGP_STOP,
|
|
|
|
};
|
2009-05-20 17:34:55 +04:00
|
|
|
int rc;
|
|
|
|
|
2014-10-15 18:48:53 +04:00
|
|
|
rc = kvm_s390_inject_vcpu(dst_vcpu, &irq);
|
|
|
|
if (rc == -EBUSY)
|
|
|
|
rc = SIGP_CC_BUSY;
|
|
|
|
else if (rc == 0)
|
|
|
|
VCPU_EVENT(vcpu, 4, "sent sigp stop to cpu %x",
|
|
|
|
dst_vcpu->vcpu_id);
|
2013-11-06 18:46:33 +04:00
|
|
|
|
2014-06-06 12:25:09 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __sigp_stop_and_store_status(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_vcpu *dst_vcpu, u64 *reg)
|
|
|
|
{
|
2014-10-15 18:48:53 +04:00
|
|
|
struct kvm_s390_irq irq = {
|
|
|
|
.type = KVM_S390_SIGP_STOP,
|
|
|
|
.u.stop.flags = KVM_S390_STOP_FLAG_STORE_STATUS,
|
|
|
|
};
|
2014-06-06 12:25:09 +04:00
|
|
|
int rc;
|
|
|
|
|
2014-10-15 18:48:53 +04:00
|
|
|
rc = kvm_s390_inject_vcpu(dst_vcpu, &irq);
|
|
|
|
if (rc == -EBUSY)
|
|
|
|
rc = SIGP_CC_BUSY;
|
|
|
|
else if (rc == 0)
|
|
|
|
VCPU_EVENT(vcpu, 4, "sent sigp stop and store status to cpu %x",
|
|
|
|
dst_vcpu->vcpu_id);
|
2013-11-06 18:46:33 +04:00
|
|
|
|
2008-03-25 20:47:31 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __sigp_set_arch(struct kvm_vcpu *vcpu, u32 parameter)
|
|
|
|
{
|
|
|
|
int rc;
|
2013-10-07 19:11:48 +04:00
|
|
|
unsigned int i;
|
|
|
|
struct kvm_vcpu *v;
|
2008-03-25 20:47:31 +03:00
|
|
|
|
|
|
|
switch (parameter & 0xff) {
|
|
|
|
case 0:
|
2012-06-26 18:06:40 +04:00
|
|
|
rc = SIGP_CC_NOT_OPERATIONAL;
|
2008-03-25 20:47:31 +03:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2013-10-07 19:11:48 +04:00
|
|
|
kvm_for_each_vcpu(i, v, vcpu->kvm) {
|
|
|
|
v->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
|
|
|
|
kvm_clear_async_pf_completion_queue(v);
|
|
|
|
}
|
|
|
|
|
2012-06-26 18:06:40 +04:00
|
|
|
rc = SIGP_CC_ORDER_CODE_ACCEPTED;
|
2008-03-25 20:47:31 +03:00
|
|
|
break;
|
|
|
|
default:
|
2010-02-27 00:37:41 +03:00
|
|
|
rc = -EOPNOTSUPP;
|
2008-03-25 20:47:31 +03:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-03-19 19:59:39 +04:00
|
|
|
static int __sigp_set_prefix(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu,
|
|
|
|
u32 address, u64 *reg)
|
2008-03-25 20:47:31 +03:00
|
|
|
{
|
2014-10-14 11:44:55 +04:00
|
|
|
struct kvm_s390_irq irq = {
|
|
|
|
.type = KVM_S390_SIGP_SET_PREFIX,
|
|
|
|
.u.prefix.address = address & 0x7fffe000u,
|
|
|
|
};
|
2008-03-25 20:47:31 +03:00
|
|
|
int rc;
|
|
|
|
|
2014-01-01 19:47:12 +04:00
|
|
|
/*
|
|
|
|
* Make sure the new value is valid memory. We only need to check the
|
|
|
|
* first page, since address is 8k aligned and memory pieces are always
|
|
|
|
* at least 1MB aligned and have at least a size of 1MB.
|
|
|
|
*/
|
2014-10-14 11:44:55 +04:00
|
|
|
if (kvm_is_error_gpa(vcpu->kvm, irq.u.prefix.address)) {
|
2012-06-26 18:06:39 +04:00
|
|
|
*reg &= 0xffffffff00000000UL;
|
2012-06-04 14:55:15 +04:00
|
|
|
*reg |= SIGP_STATUS_INVALID_PARAMETER;
|
2012-06-26 18:06:40 +04:00
|
|
|
return SIGP_CC_STATUS_STORED;
|
2008-03-25 20:47:31 +03:00
|
|
|
}
|
|
|
|
|
2014-10-14 11:44:55 +04:00
|
|
|
rc = kvm_s390_inject_vcpu(dst_vcpu, &irq);
|
|
|
|
if (rc == -EBUSY) {
|
2012-06-26 18:06:39 +04:00
|
|
|
*reg &= 0xffffffff00000000UL;
|
|
|
|
*reg |= SIGP_STATUS_INCORRECT_STATE;
|
2014-10-14 11:44:55 +04:00
|
|
|
return SIGP_CC_STATUS_STORED;
|
|
|
|
} else if (rc == 0) {
|
|
|
|
VCPU_EVENT(vcpu, 4, "set prefix of cpu %02x to %x",
|
|
|
|
dst_vcpu->vcpu_id, irq.u.prefix.address);
|
2008-03-25 20:47:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-03-19 19:59:39 +04:00
|
|
|
static int __sigp_store_status_at_addr(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_vcpu *dst_vcpu,
|
|
|
|
u32 addr, u64 *reg)
|
2013-11-13 23:48:51 +04:00
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
flags = atomic_read(dst_vcpu->arch.local_int.cpuflags);
|
|
|
|
if (!(flags & CPUSTAT_STOPPED)) {
|
|
|
|
*reg &= 0xffffffff00000000UL;
|
|
|
|
*reg |= SIGP_STATUS_INCORRECT_STATE;
|
|
|
|
return SIGP_CC_STATUS_STORED;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr &= 0x7ffffe00;
|
|
|
|
rc = kvm_s390_store_status_unloaded(dst_vcpu, addr);
|
|
|
|
if (rc == -EFAULT) {
|
|
|
|
*reg &= 0xffffffff00000000UL;
|
|
|
|
*reg |= SIGP_STATUS_INVALID_PARAMETER;
|
|
|
|
rc = SIGP_CC_STATUS_STORED;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-03-19 19:59:39 +04:00
|
|
|
static int __sigp_sense_running(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_vcpu *dst_vcpu, u64 *reg)
|
2011-11-17 14:00:42 +04:00
|
|
|
{
|
2014-02-25 18:36:45 +04:00
|
|
|
struct kvm_s390_local_interrupt *li;
|
2011-11-17 14:00:42 +04:00
|
|
|
int rc;
|
|
|
|
|
2014-02-25 18:36:45 +04:00
|
|
|
li = &dst_vcpu->arch.local_int;
|
|
|
|
if (atomic_read(li->cpuflags) & CPUSTAT_RUNNING) {
|
|
|
|
/* running */
|
|
|
|
rc = SIGP_CC_ORDER_CODE_ACCEPTED;
|
|
|
|
} else {
|
|
|
|
/* not running */
|
|
|
|
*reg &= 0xffffffff00000000UL;
|
|
|
|
*reg |= SIGP_STATUS_NOT_RUNNING;
|
|
|
|
rc = SIGP_CC_STATUS_STORED;
|
2011-11-17 14:00:42 +04:00
|
|
|
}
|
|
|
|
|
2014-03-19 19:59:39 +04:00
|
|
|
VCPU_EVENT(vcpu, 4, "sensed running status of cpu %x rc %x",
|
|
|
|
dst_vcpu->vcpu_id, rc);
|
2011-11-17 14:00:42 +04:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-05-23 14:22:56 +04:00
|
|
|
static int __prepare_sigp_re_start(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_vcpu *dst_vcpu, u8 order_code)
|
2012-02-08 11:28:29 +04:00
|
|
|
{
|
2014-03-19 19:59:39 +04:00
|
|
|
struct kvm_s390_local_interrupt *li = &dst_vcpu->arch.local_int;
|
2014-05-23 14:22:56 +04:00
|
|
|
/* handle (RE)START in user space */
|
|
|
|
int rc = -EOPNOTSUPP;
|
2012-02-08 11:28:29 +04:00
|
|
|
|
2014-10-15 18:48:53 +04:00
|
|
|
/* make sure we don't race with STOP irq injection */
|
2014-05-16 12:23:53 +04:00
|
|
|
spin_lock(&li->lock);
|
2014-10-15 18:48:53 +04:00
|
|
|
if (kvm_s390_is_stop_irq_pending(dst_vcpu))
|
2012-06-26 18:06:40 +04:00
|
|
|
rc = SIGP_CC_BUSY;
|
2014-05-16 12:23:53 +04:00
|
|
|
spin_unlock(&li->lock);
|
2014-02-25 18:36:45 +04:00
|
|
|
|
2012-02-08 11:28:29 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-05-23 14:22:56 +04:00
|
|
|
static int __prepare_sigp_cpu_reset(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_vcpu *dst_vcpu, u8 order_code)
|
|
|
|
{
|
|
|
|
/* handle (INITIAL) CPU RESET in user space */
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __prepare_sigp_unknown(struct kvm_vcpu *vcpu,
|
|
|
|
struct kvm_vcpu *dst_vcpu)
|
|
|
|
{
|
|
|
|
/* handle unknown orders in user space */
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2014-03-19 17:57:49 +04:00
|
|
|
static int handle_sigp_dst(struct kvm_vcpu *vcpu, u8 order_code,
|
|
|
|
u16 cpu_addr, u32 parameter, u64 *status_reg)
|
2008-03-25 20:47:31 +03:00
|
|
|
{
|
|
|
|
int rc;
|
2014-03-19 19:59:39 +04:00
|
|
|
struct kvm_vcpu *dst_vcpu;
|
|
|
|
|
|
|
|
if (cpu_addr >= KVM_MAX_VCPUS)
|
|
|
|
return SIGP_CC_NOT_OPERATIONAL;
|
|
|
|
|
|
|
|
dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
|
|
|
|
if (!dst_vcpu)
|
|
|
|
return SIGP_CC_NOT_OPERATIONAL;
|
2008-03-25 20:47:31 +03:00
|
|
|
|
|
|
|
switch (order_code) {
|
|
|
|
case SIGP_SENSE:
|
|
|
|
vcpu->stat.instruction_sigp_sense++;
|
2014-03-19 19:59:39 +04:00
|
|
|
rc = __sigp_sense(vcpu, dst_vcpu, status_reg);
|
2008-03-25 20:47:31 +03:00
|
|
|
break;
|
2011-10-18 14:27:15 +04:00
|
|
|
case SIGP_EXTERNAL_CALL:
|
|
|
|
vcpu->stat.instruction_sigp_external_call++;
|
2014-10-14 17:29:30 +04:00
|
|
|
rc = __sigp_external_call(vcpu, dst_vcpu, status_reg);
|
2011-10-18 14:27:15 +04:00
|
|
|
break;
|
2012-06-04 14:55:15 +04:00
|
|
|
case SIGP_EMERGENCY_SIGNAL:
|
2008-03-25 20:47:31 +03:00
|
|
|
vcpu->stat.instruction_sigp_emergency++;
|
2014-03-19 19:59:39 +04:00
|
|
|
rc = __sigp_emergency(vcpu, dst_vcpu);
|
2008-03-25 20:47:31 +03:00
|
|
|
break;
|
|
|
|
case SIGP_STOP:
|
|
|
|
vcpu->stat.instruction_sigp_stop++;
|
2014-06-06 12:25:09 +04:00
|
|
|
rc = __sigp_stop(vcpu, dst_vcpu);
|
2008-03-25 20:47:31 +03:00
|
|
|
break;
|
2012-06-04 14:55:15 +04:00
|
|
|
case SIGP_STOP_AND_STORE_STATUS:
|
2014-05-23 14:25:11 +04:00
|
|
|
vcpu->stat.instruction_sigp_stop_store_status++;
|
2014-06-06 12:25:09 +04:00
|
|
|
rc = __sigp_stop_and_store_status(vcpu, dst_vcpu, status_reg);
|
2008-03-25 20:47:31 +03:00
|
|
|
break;
|
2013-11-13 23:48:51 +04:00
|
|
|
case SIGP_STORE_STATUS_AT_ADDRESS:
|
2014-05-23 14:25:11 +04:00
|
|
|
vcpu->stat.instruction_sigp_store_status++;
|
2014-03-19 19:59:39 +04:00
|
|
|
rc = __sigp_store_status_at_addr(vcpu, dst_vcpu, parameter,
|
2014-03-19 17:57:49 +04:00
|
|
|
status_reg);
|
2008-03-25 20:47:31 +03:00
|
|
|
break;
|
|
|
|
case SIGP_SET_PREFIX:
|
|
|
|
vcpu->stat.instruction_sigp_prefix++;
|
2014-03-19 19:59:39 +04:00
|
|
|
rc = __sigp_set_prefix(vcpu, dst_vcpu, parameter, status_reg);
|
2008-03-25 20:47:31 +03:00
|
|
|
break;
|
2013-11-21 19:01:48 +04:00
|
|
|
case SIGP_COND_EMERGENCY_SIGNAL:
|
2014-05-23 14:25:11 +04:00
|
|
|
vcpu->stat.instruction_sigp_cond_emergency++;
|
2014-03-19 19:59:39 +04:00
|
|
|
rc = __sigp_conditional_emergency(vcpu, dst_vcpu, parameter,
|
2014-03-19 17:57:49 +04:00
|
|
|
status_reg);
|
2013-11-21 19:01:48 +04:00
|
|
|
break;
|
2011-11-17 14:00:42 +04:00
|
|
|
case SIGP_SENSE_RUNNING:
|
|
|
|
vcpu->stat.instruction_sigp_sense_running++;
|
2014-03-19 19:59:39 +04:00
|
|
|
rc = __sigp_sense_running(vcpu, dst_vcpu, status_reg);
|
2011-11-17 14:00:42 +04:00
|
|
|
break;
|
2013-12-03 15:54:55 +04:00
|
|
|
case SIGP_START:
|
2014-05-23 14:25:11 +04:00
|
|
|
vcpu->stat.instruction_sigp_start++;
|
2014-05-23 14:22:56 +04:00
|
|
|
rc = __prepare_sigp_re_start(vcpu, dst_vcpu, order_code);
|
2013-12-03 15:54:55 +04:00
|
|
|
break;
|
2008-03-25 20:47:31 +03:00
|
|
|
case SIGP_RESTART:
|
|
|
|
vcpu->stat.instruction_sigp_restart++;
|
2014-05-23 14:22:56 +04:00
|
|
|
rc = __prepare_sigp_re_start(vcpu, dst_vcpu, order_code);
|
|
|
|
break;
|
|
|
|
case SIGP_INITIAL_CPU_RESET:
|
2014-05-23 14:25:11 +04:00
|
|
|
vcpu->stat.instruction_sigp_init_cpu_reset++;
|
2014-05-23 14:22:56 +04:00
|
|
|
rc = __prepare_sigp_cpu_reset(vcpu, dst_vcpu, order_code);
|
|
|
|
break;
|
|
|
|
case SIGP_CPU_RESET:
|
2014-05-23 14:25:11 +04:00
|
|
|
vcpu->stat.instruction_sigp_cpu_reset++;
|
2014-05-23 14:22:56 +04:00
|
|
|
rc = __prepare_sigp_cpu_reset(vcpu, dst_vcpu, order_code);
|
2013-11-27 14:47:10 +04:00
|
|
|
break;
|
2008-03-25 20:47:31 +03:00
|
|
|
default:
|
2014-05-23 14:25:11 +04:00
|
|
|
vcpu->stat.instruction_sigp_unknown++;
|
2014-05-23 14:22:56 +04:00
|
|
|
rc = __prepare_sigp_unknown(vcpu, dst_vcpu);
|
2014-03-19 17:57:49 +04:00
|
|
|
}
|
|
|
|
|
2014-05-23 14:22:56 +04:00
|
|
|
if (rc == -EOPNOTSUPP)
|
|
|
|
VCPU_EVENT(vcpu, 4,
|
|
|
|
"sigp order %u -> cpu %x: handled in user space",
|
|
|
|
order_code, dst_vcpu->vcpu_id);
|
|
|
|
|
2014-03-19 17:57:49 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-10-09 16:10:13 +04:00
|
|
|
static int handle_sigp_order_in_user_space(struct kvm_vcpu *vcpu, u8 order_code)
|
|
|
|
{
|
|
|
|
if (!vcpu->kvm->arch.user_sigp)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (order_code) {
|
|
|
|
case SIGP_SENSE:
|
|
|
|
case SIGP_EXTERNAL_CALL:
|
|
|
|
case SIGP_EMERGENCY_SIGNAL:
|
|
|
|
case SIGP_COND_EMERGENCY_SIGNAL:
|
|
|
|
case SIGP_SENSE_RUNNING:
|
|
|
|
return 0;
|
|
|
|
/* update counters as we're directly dropping to user space */
|
|
|
|
case SIGP_STOP:
|
|
|
|
vcpu->stat.instruction_sigp_stop++;
|
|
|
|
break;
|
|
|
|
case SIGP_STOP_AND_STORE_STATUS:
|
|
|
|
vcpu->stat.instruction_sigp_stop_store_status++;
|
|
|
|
break;
|
|
|
|
case SIGP_STORE_STATUS_AT_ADDRESS:
|
|
|
|
vcpu->stat.instruction_sigp_store_status++;
|
|
|
|
break;
|
|
|
|
case SIGP_SET_PREFIX:
|
|
|
|
vcpu->stat.instruction_sigp_prefix++;
|
|
|
|
break;
|
|
|
|
case SIGP_START:
|
|
|
|
vcpu->stat.instruction_sigp_start++;
|
|
|
|
break;
|
|
|
|
case SIGP_RESTART:
|
|
|
|
vcpu->stat.instruction_sigp_restart++;
|
|
|
|
break;
|
|
|
|
case SIGP_INITIAL_CPU_RESET:
|
|
|
|
vcpu->stat.instruction_sigp_init_cpu_reset++;
|
|
|
|
break;
|
|
|
|
case SIGP_CPU_RESET:
|
|
|
|
vcpu->stat.instruction_sigp_cpu_reset++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
vcpu->stat.instruction_sigp_unknown++;
|
|
|
|
}
|
|
|
|
|
|
|
|
VCPU_EVENT(vcpu, 4, "sigp order %u: completely handled in user space",
|
|
|
|
order_code);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-03-19 17:57:49 +04:00
|
|
|
int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu)
|
|
|
|
{
|
|
|
|
int r1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
|
|
|
|
int r3 = vcpu->arch.sie_block->ipa & 0x000f;
|
|
|
|
u32 parameter;
|
|
|
|
u16 cpu_addr = vcpu->run->s.regs.gprs[r3];
|
|
|
|
u8 order_code;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* sigp in userspace can exit */
|
|
|
|
if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
|
|
|
|
return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
|
|
|
|
|
|
|
|
order_code = kvm_s390_get_base_disp_rs(vcpu);
|
2014-10-09 16:10:13 +04:00
|
|
|
if (handle_sigp_order_in_user_space(vcpu, order_code))
|
|
|
|
return -EOPNOTSUPP;
|
2014-03-19 17:57:49 +04:00
|
|
|
|
|
|
|
if (r1 % 2)
|
|
|
|
parameter = vcpu->run->s.regs.gprs[r1];
|
|
|
|
else
|
|
|
|
parameter = vcpu->run->s.regs.gprs[r1 + 1];
|
|
|
|
|
|
|
|
trace_kvm_s390_handle_sigp(vcpu, order_code, cpu_addr, parameter);
|
|
|
|
switch (order_code) {
|
|
|
|
case SIGP_SET_ARCHITECTURE:
|
|
|
|
vcpu->stat.instruction_sigp_arch++;
|
|
|
|
rc = __sigp_set_arch(vcpu, parameter);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rc = handle_sigp_dst(vcpu, order_code, cpu_addr,
|
|
|
|
parameter,
|
|
|
|
&vcpu->run->s.regs.gprs[r1]);
|
2008-03-25 20:47:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
2013-11-26 15:27:16 +04:00
|
|
|
kvm_s390_set_psw_cc(vcpu, rc);
|
2008-03-25 20:47:31 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2014-02-21 11:59:59 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle SIGP partial execution interception.
|
|
|
|
*
|
|
|
|
* This interception will occur at the source cpu when a source cpu sends an
|
|
|
|
* external call to a target cpu and the target cpu has the WAIT bit set in
|
|
|
|
* its cpuflags. Interception will occurr after the interrupt indicator bits at
|
|
|
|
* the target cpu have been set. All error cases will lead to instruction
|
|
|
|
* interception, therefore nothing is to be checked or prepared.
|
|
|
|
*/
|
|
|
|
int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu)
|
|
|
|
{
|
|
|
|
int r3 = vcpu->arch.sie_block->ipa & 0x000f;
|
|
|
|
u16 cpu_addr = vcpu->run->s.regs.gprs[r3];
|
|
|
|
struct kvm_vcpu *dest_vcpu;
|
|
|
|
u8 order_code = kvm_s390_get_base_disp_rs(vcpu);
|
|
|
|
|
|
|
|
trace_kvm_s390_handle_sigp_pei(vcpu, order_code, cpu_addr);
|
|
|
|
|
|
|
|
if (order_code == SIGP_EXTERNAL_CALL) {
|
|
|
|
dest_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
|
|
|
|
BUG_ON(dest_vcpu == NULL);
|
|
|
|
|
2014-05-16 13:59:46 +04:00
|
|
|
kvm_s390_vcpu_wakeup(dest_vcpu);
|
2014-02-21 11:59:59 +04:00
|
|
|
kvm_s390_set_psw_cc(vcpu, SIGP_CC_ORDER_CODE_ACCEPTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|