* [PATCH 0/7] KVM: s390: further fixes for -next
@ 2013-06-20 15:21 Cornelia Huck
2013-06-20 15:21 ` [PATCH 1/7] KVM: s390: Renamed PGM_PRIVILEGED_OPERATION Cornelia Huck
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Cornelia Huck @ 2013-06-20 15:21 UTC (permalink / raw)
To: Gleb Natapov, Paolo Bonzini
Cc: Christian Borntraeger, Heiko Carstens, Martin Schwidefsky, KVM,
linux-s390
Hi,
some more fixes for kvm-next, bringing our handling of intercepted
instructions more into line with what is actually architectured.
Please apply.
Thomas Huth (7):
KVM: s390: Renamed PGM_PRIVILEGED_OPERATION
KVM: s390: Privileged operation check for TPROT
KVM: s390: Privileged operation checks moved to instruction handlers
KVM: s390: Check for PSTATE when handling DIAGNOSE
KVM: s390: Check for access exceptions during TPI
KVM: s390: Reworked LCTL and LCTLG instructions
KVM: s390: Fixed priority of execution in STSI
arch/s390/include/asm/kvm_host.h | 2 +-
arch/s390/kvm/diag.c | 3 +
arch/s390/kvm/intercept.c | 85 +-----------------
arch/s390/kvm/kvm-s390.h | 3 +-
arch/s390/kvm/priv.c | 184 ++++++++++++++++++++++++++++++---------
arch/s390/kvm/sigp.c | 3 +-
6 files changed, 152 insertions(+), 128 deletions(-)
--
1.8.2.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/7] KVM: s390: Renamed PGM_PRIVILEGED_OPERATION
2013-06-20 15:21 [PATCH 0/7] KVM: s390: further fixes for -next Cornelia Huck
@ 2013-06-20 15:21 ` Cornelia Huck
2013-06-20 15:22 ` [PATCH 2/7] KVM: s390: Privileged operation check for TPROT Cornelia Huck
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Cornelia Huck @ 2013-06-20 15:21 UTC (permalink / raw)
To: Gleb Natapov, Paolo Bonzini
Cc: Christian Borntraeger, Heiko Carstens, Martin Schwidefsky, KVM,
linux-s390, Thomas Huth
From: Thomas Huth <thuth@linux.vnet.ibm.com>
Renamed the PGM_PRIVILEGED_OPERATION define to PGM_PRIVILEGED_OP since this
define was way longer than the other PGM_* defines and caused the code often
to exceed the 80 columns limit when not split to multiple lines.
Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
arch/s390/include/asm/kvm_host.h | 2 +-
arch/s390/kvm/priv.c | 16 +++++++---------
arch/s390/kvm/sigp.c | 3 +--
3 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 4339069..3238d40 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -175,7 +175,7 @@ struct kvm_s390_ext_info {
};
#define PGM_OPERATION 0x01
-#define PGM_PRIVILEGED_OPERATION 0x02
+#define PGM_PRIVILEGED_OP 0x02
#define PGM_EXECUTE 0x03
#define PGM_PROTECTION 0x04
#define PGM_ADDRESSING 0x05
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index a0c63d7..a21e014 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -259,8 +259,8 @@ int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
u64 addr;
if (gpsw->mask & PSW_MASK_PSTATE)
- return kvm_s390_inject_program_int(vcpu,
- PGM_PRIVILEGED_OPERATION);
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
addr = kvm_s390_get_base_disp_s(vcpu);
if (addr & 7)
return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
@@ -446,7 +446,7 @@ int kvm_s390_handle_b2(struct kvm_vcpu *vcpu)
if (handler) {
if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
return kvm_s390_inject_program_int(vcpu,
- PGM_PRIVILEGED_OPERATION);
+ PGM_PRIVILEGED_OP);
else
return handler(vcpu);
}
@@ -493,7 +493,7 @@ static int handle_pfmf(struct kvm_vcpu *vcpu)
return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
- return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OPERATION);
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
if (vcpu->run->s.regs.gprs[reg1] & PFMF_RESERVED)
return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
@@ -564,7 +564,7 @@ int kvm_s390_handle_b9(struct kvm_vcpu *vcpu)
if ((handler != handle_epsw) &&
(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE))
return kvm_s390_inject_program_int(vcpu,
- PGM_PRIVILEGED_OPERATION);
+ PGM_PRIVILEGED_OP);
else
return handler(vcpu);
}
@@ -581,8 +581,7 @@ int kvm_s390_handle_priv_eb(struct kvm_vcpu *vcpu)
/* All eb instructions that end up here are privileged. */
if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
- return kvm_s390_inject_program_int(vcpu,
- PGM_PRIVILEGED_OPERATION);
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff];
if (handler)
return handler(vcpu);
@@ -642,8 +641,7 @@ static int handle_sckpf(struct kvm_vcpu *vcpu)
u32 value;
if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
- return kvm_s390_inject_program_int(vcpu,
- PGM_PRIVILEGED_OPERATION);
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000)
return kvm_s390_inject_program_int(vcpu,
diff --git a/arch/s390/kvm/sigp.c b/arch/s390/kvm/sigp.c
index 033c864..bec398c 100644
--- a/arch/s390/kvm/sigp.c
+++ b/arch/s390/kvm/sigp.c
@@ -333,8 +333,7 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu)
/* sigp in userspace can exit */
if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
- return kvm_s390_inject_program_int(vcpu,
- PGM_PRIVILEGED_OPERATION);
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
order_code = kvm_s390_get_base_disp_rs(vcpu);
--
1.8.2.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/7] KVM: s390: Privileged operation check for TPROT
2013-06-20 15:21 [PATCH 0/7] KVM: s390: further fixes for -next Cornelia Huck
2013-06-20 15:21 ` [PATCH 1/7] KVM: s390: Renamed PGM_PRIVILEGED_OPERATION Cornelia Huck
@ 2013-06-20 15:22 ` Cornelia Huck
2013-06-20 15:22 ` [PATCH 3/7] KVM: s390: Privileged operation checks moved to instruction handlers Cornelia Huck
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Cornelia Huck @ 2013-06-20 15:22 UTC (permalink / raw)
To: Gleb Natapov, Paolo Bonzini
Cc: Christian Borntraeger, Heiko Carstens, Martin Schwidefsky, KVM,
linux-s390, Thomas Huth
From: Thomas Huth <thuth@linux.vnet.ibm.com>
TPROT is a privileged instruction and thus should generate a privileged
operation exception when the problem state bit is not cleared in the PSW.
Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
arch/s390/kvm/priv.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index a21e014..04dc4a1 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -596,6 +596,9 @@ static int handle_tprot(struct kvm_vcpu *vcpu)
vcpu->stat.instruction_tprot++;
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
kvm_s390_get_base_disp_sse(vcpu, &address1, &address2);
/* we only handle the Linux memory detection case:
--
1.8.2.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/7] KVM: s390: Privileged operation checks moved to instruction handlers
2013-06-20 15:21 [PATCH 0/7] KVM: s390: further fixes for -next Cornelia Huck
2013-06-20 15:21 ` [PATCH 1/7] KVM: s390: Renamed PGM_PRIVILEGED_OPERATION Cornelia Huck
2013-06-20 15:22 ` [PATCH 2/7] KVM: s390: Privileged operation check for TPROT Cornelia Huck
@ 2013-06-20 15:22 ` Cornelia Huck
2013-06-20 15:22 ` [PATCH 4/7] KVM: s390: Check for PSTATE when handling DIAGNOSE Cornelia Huck
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Cornelia Huck @ 2013-06-20 15:22 UTC (permalink / raw)
To: Gleb Natapov, Paolo Bonzini
Cc: Christian Borntraeger, Heiko Carstens, Martin Schwidefsky, KVM,
linux-s390, Thomas Huth
From: Thomas Huth <thuth@linux.vnet.ibm.com>
We need more fine-grained control about the point in time when we check
for privileged instructions, since the exceptions that can happen during
an instruction have a well-defined priority. For example, for the PFMF
instruction, the check for PGM_PRIVILEGED_OP must happen after the check
for PGM_OPERATION since the latter has a higher precedence - thus the
check for privileged operation must not be done in kvm_s390_handle_b9()
already.
Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
arch/s390/kvm/priv.c | 63 ++++++++++++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 24 deletions(-)
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 04dc4a1..0b19e22 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -37,6 +37,9 @@ static int handle_set_prefix(struct kvm_vcpu *vcpu)
vcpu->stat.instruction_spx++;
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
operand2 = kvm_s390_get_base_disp_s(vcpu);
/* must be word boundary */
@@ -68,6 +71,9 @@ static int handle_store_prefix(struct kvm_vcpu *vcpu)
vcpu->stat.instruction_stpx++;
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
operand2 = kvm_s390_get_base_disp_s(vcpu);
/* must be word boundary */
@@ -92,6 +98,9 @@ static int handle_store_cpu_address(struct kvm_vcpu *vcpu)
vcpu->stat.instruction_stap++;
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
useraddr = kvm_s390_get_base_disp_s(vcpu);
if (useraddr & 1)
@@ -108,6 +117,10 @@ static int handle_store_cpu_address(struct kvm_vcpu *vcpu)
static int handle_skey(struct kvm_vcpu *vcpu)
{
vcpu->stat.instruction_storage_key++;
+
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
vcpu->arch.sie_block->gpsw.addr =
__rewind_psw(vcpu->arch.sie_block->gpsw, 4);
VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation");
@@ -186,6 +199,9 @@ static int handle_io_inst(struct kvm_vcpu *vcpu)
{
VCPU_EVENT(vcpu, 4, "%s", "I/O instruction");
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
if (vcpu->kvm->arch.css_support) {
/*
* Most I/O instructions will be handled by userspace.
@@ -214,6 +230,10 @@ static int handle_stfl(struct kvm_vcpu *vcpu)
int rc;
vcpu->stat.instruction_stfl++;
+
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
/* only pass the facility bits, which we can handle */
facility_list = S390_lowcore.stfl_fac_list & 0xff82fff3;
@@ -282,6 +302,9 @@ static int handle_lpswe(struct kvm_vcpu *vcpu)
psw_t new_psw;
u64 addr;
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
addr = kvm_s390_get_base_disp_s(vcpu);
if (addr & 7)
return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
@@ -300,6 +323,9 @@ static int handle_stidp(struct kvm_vcpu *vcpu)
vcpu->stat.instruction_stidp++;
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
operand2 = kvm_s390_get_base_disp_s(vcpu);
if (operand2 & 7)
@@ -355,6 +381,9 @@ static int handle_stsi(struct kvm_vcpu *vcpu)
vcpu->stat.instruction_stsi++;
VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2);
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
operand2 = kvm_s390_get_base_disp_s(vcpu);
if (operand2 & 0xfff && fc > 0)
@@ -436,20 +465,14 @@ int kvm_s390_handle_b2(struct kvm_vcpu *vcpu)
intercept_handler_t handler;
/*
- * a lot of B2 instructions are priviledged. We first check for
- * the privileged ones, that we can handle in the kernel. If the
- * kernel can handle this instruction, we check for the problem
- * state bit and (a) handle the instruction or (b) send a code 2
- * program check.
- * Anything else goes to userspace.*/
+ * A lot of B2 instructions are priviledged. Here we check for
+ * the privileged ones, that we can handle in the kernel.
+ * Anything else goes to userspace.
+ */
handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
- if (handler) {
- if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
- return kvm_s390_inject_program_int(vcpu,
- PGM_PRIVILEGED_OP);
- else
- return handler(vcpu);
- }
+ if (handler)
+ return handler(vcpu);
+
return -EOPNOTSUPP;
}
@@ -560,14 +583,9 @@ int kvm_s390_handle_b9(struct kvm_vcpu *vcpu)
/* This is handled just as for the B2 instructions. */
handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
- if (handler) {
- if ((handler != handle_epsw) &&
- (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE))
- return kvm_s390_inject_program_int(vcpu,
- PGM_PRIVILEGED_OP);
- else
- return handler(vcpu);
- }
+ if (handler)
+ return handler(vcpu);
+
return -EOPNOTSUPP;
}
@@ -579,9 +597,6 @@ int kvm_s390_handle_priv_eb(struct kvm_vcpu *vcpu)
{
intercept_handler_t handler;
- /* All eb instructions that end up here are privileged. */
- if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
- return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff];
if (handler)
return handler(vcpu);
--
1.8.2.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/7] KVM: s390: Check for PSTATE when handling DIAGNOSE
2013-06-20 15:21 [PATCH 0/7] KVM: s390: further fixes for -next Cornelia Huck
` (2 preceding siblings ...)
2013-06-20 15:22 ` [PATCH 3/7] KVM: s390: Privileged operation checks moved to instruction handlers Cornelia Huck
@ 2013-06-20 15:22 ` Cornelia Huck
2013-06-20 15:22 ` [PATCH 5/7] KVM: s390: Check for access exceptions during TPI Cornelia Huck
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Cornelia Huck @ 2013-06-20 15:22 UTC (permalink / raw)
To: Gleb Natapov, Paolo Bonzini
Cc: Christian Borntraeger, Heiko Carstens, Martin Schwidefsky, KVM,
linux-s390, Thomas Huth
From: Thomas Huth <thuth@linux.vnet.ibm.com>
DIAGNOSE is a privileged instruction and thus we must make sure that we are
in supervisor mode before taking any other actions.
Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
arch/s390/kvm/diag.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
index 1c01a99..3074475 100644
--- a/arch/s390/kvm/diag.c
+++ b/arch/s390/kvm/diag.c
@@ -132,6 +132,9 @@ int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
{
int code = (vcpu->arch.sie_block->ipb & 0xfff0000) >> 16;
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
trace_kvm_s390_handle_diag(vcpu, code);
switch (code) {
case 0x10:
--
1.8.2.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/7] KVM: s390: Check for access exceptions during TPI
2013-06-20 15:21 [PATCH 0/7] KVM: s390: further fixes for -next Cornelia Huck
` (3 preceding siblings ...)
2013-06-20 15:22 ` [PATCH 4/7] KVM: s390: Check for PSTATE when handling DIAGNOSE Cornelia Huck
@ 2013-06-20 15:22 ` Cornelia Huck
2013-06-20 15:22 ` [PATCH 6/7] KVM: s390: Reworked LCTL and LCTLG instructions Cornelia Huck
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Cornelia Huck @ 2013-06-20 15:22 UTC (permalink / raw)
To: Gleb Natapov, Paolo Bonzini
Cc: Christian Borntraeger, Heiko Carstens, Martin Schwidefsky, KVM,
linux-s390, Thomas Huth
From: Thomas Huth <thuth@linux.vnet.ibm.com>
When a guest calls the TPI instruction, the second operand address could
point to an invalid location. In this case the problem should be signaled
to the guest by throwing an access exception.
Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
arch/s390/kvm/priv.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 0b19e22..4b8fb6c 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -146,9 +146,10 @@ static int handle_tpi(struct kvm_vcpu *vcpu)
* Store the two-word I/O interruption code into the
* provided area.
*/
- put_guest(vcpu, inti->io.subchannel_id, (u16 __user *) addr);
- put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *) (addr + 2));
- put_guest(vcpu, inti->io.io_int_parm, (u32 __user *) (addr + 4));
+ if (put_guest(vcpu, inti->io.subchannel_id, (u16 __user *)addr)
+ || put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *)(addr + 2))
+ || put_guest(vcpu, inti->io.io_int_parm, (u32 __user *)(addr + 4)))
+ return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
} else {
/*
* Store the three-word I/O interruption code into
--
1.8.2.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/7] KVM: s390: Reworked LCTL and LCTLG instructions
2013-06-20 15:21 [PATCH 0/7] KVM: s390: further fixes for -next Cornelia Huck
` (4 preceding siblings ...)
2013-06-20 15:22 ` [PATCH 5/7] KVM: s390: Check for access exceptions during TPI Cornelia Huck
@ 2013-06-20 15:22 ` Cornelia Huck
2013-06-20 15:22 ` [PATCH 7/7] KVM: s390: Fixed priority of execution in STSI Cornelia Huck
2013-06-20 21:33 ` [PATCH 0/7] KVM: s390: further fixes for -next Paolo Bonzini
7 siblings, 0 replies; 9+ messages in thread
From: Cornelia Huck @ 2013-06-20 15:22 UTC (permalink / raw)
To: Gleb Natapov, Paolo Bonzini
Cc: Christian Borntraeger, Heiko Carstens, Martin Schwidefsky, KVM,
linux-s390, Thomas Huth
From: Thomas Huth <thuth@linux.vnet.ibm.com>
LCTL and LCTLG are also privileged instructions, thus there is no need for
treating them separately from the other instructions in priv.c. So this
patch moves these two instructions to priv.c, adds a check for supervisor
state and simplifies the "handle_eb" instruction decoding by merging the
two eb_handlers jump tables from intercept.c and priv.c into one table only.
Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
arch/s390/kvm/intercept.c | 85 ++---------------------------------------------
arch/s390/kvm/kvm-s390.h | 3 +-
arch/s390/kvm/priv.c | 78 ++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 81 insertions(+), 85 deletions(-)
diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c
index f0b8be0..5ee56e5 100644
--- a/arch/s390/kvm/intercept.c
+++ b/arch/s390/kvm/intercept.c
@@ -22,87 +22,6 @@
#include "trace.h"
#include "trace-s390.h"
-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;
- u64 useraddr;
- int reg, rc;
-
- vcpu->stat.instruction_lctlg++;
-
- useraddr = kvm_s390_get_base_disp_rsy(vcpu);
-
- if (useraddr & 7)
- return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
-
- reg = reg1;
-
- VCPU_EVENT(vcpu, 5, "lctlg r1:%x, r3:%x, addr:%llx", reg1, reg3,
- useraddr);
- trace_kvm_s390_handle_lctl(vcpu, 1, reg1, reg3, useraddr);
-
- do {
- rc = get_guest(vcpu, vcpu->arch.sie_block->gcr[reg],
- (u64 __user *) useraddr);
- if (rc)
- return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
- 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;
- u64 useraddr;
- u32 val = 0;
- int reg, rc;
-
- vcpu->stat.instruction_lctl++;
-
- useraddr = kvm_s390_get_base_disp_rs(vcpu);
-
- if (useraddr & 3)
- return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
-
- VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x, addr:%llx", reg1, reg3,
- useraddr);
- trace_kvm_s390_handle_lctl(vcpu, 0, reg1, reg3, useraddr);
-
- reg = reg1;
- do {
- rc = get_guest(vcpu, val, (u32 __user *) useraddr);
- if (rc)
- return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
- 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 const intercept_handler_t eb_handlers[256] = {
- [0x2f] = handle_lctlg,
- [0x8a] = kvm_s390_handle_priv_eb,
-};
-
-static int handle_eb(struct kvm_vcpu *vcpu)
-{
- intercept_handler_t handler;
-
- handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff];
- if (handler)
- return handler(vcpu);
- return -EOPNOTSUPP;
-}
static const intercept_handler_t instruction_handlers[256] = {
[0x01] = kvm_s390_handle_01,
@@ -110,10 +29,10 @@ static const intercept_handler_t instruction_handlers[256] = {
[0x83] = kvm_s390_handle_diag,
[0xae] = kvm_s390_handle_sigp,
[0xb2] = kvm_s390_handle_b2,
- [0xb7] = handle_lctl,
+ [0xb7] = kvm_s390_handle_lctl,
[0xb9] = kvm_s390_handle_b9,
[0xe5] = kvm_s390_handle_e5,
- [0xeb] = handle_eb,
+ [0xeb] = kvm_s390_handle_eb,
};
static int handle_noop(struct kvm_vcpu *vcpu)
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index 15795b8..028ca9f 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -132,7 +132,8 @@ int kvm_s390_handle_e5(struct kvm_vcpu *vcpu);
int kvm_s390_handle_01(struct kvm_vcpu *vcpu);
int kvm_s390_handle_b9(struct kvm_vcpu *vcpu);
int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu);
-int kvm_s390_handle_priv_eb(struct kvm_vcpu *vcpu);
+int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu);
+int kvm_s390_handle_eb(struct kvm_vcpu *vcpu);
/* implemented in sigp.c */
int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu);
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 4b8fb6c..c7603f5 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -590,11 +590,87 @@ int kvm_s390_handle_b9(struct kvm_vcpu *vcpu)
return -EOPNOTSUPP;
}
+int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu)
+{
+ int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
+ int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
+ u64 useraddr;
+ u32 val = 0;
+ int reg, rc;
+
+ vcpu->stat.instruction_lctl++;
+
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
+ useraddr = kvm_s390_get_base_disp_rs(vcpu);
+
+ if (useraddr & 3)
+ return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+
+ VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x, addr:%llx", reg1, reg3,
+ useraddr);
+ trace_kvm_s390_handle_lctl(vcpu, 0, reg1, reg3, useraddr);
+
+ reg = reg1;
+ do {
+ rc = get_guest(vcpu, val, (u32 __user *) useraddr);
+ if (rc)
+ return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
+ 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 int handle_lctlg(struct kvm_vcpu *vcpu)
+{
+ int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
+ int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
+ u64 useraddr;
+ int reg, rc;
+
+ vcpu->stat.instruction_lctlg++;
+
+ if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
+ return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
+
+ useraddr = kvm_s390_get_base_disp_rsy(vcpu);
+
+ if (useraddr & 7)
+ return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+
+ reg = reg1;
+
+ VCPU_EVENT(vcpu, 5, "lctlg r1:%x, r3:%x, addr:%llx", reg1, reg3,
+ useraddr);
+ trace_kvm_s390_handle_lctl(vcpu, 1, reg1, reg3, useraddr);
+
+ do {
+ rc = get_guest(vcpu, vcpu->arch.sie_block->gcr[reg],
+ (u64 __user *) useraddr);
+ if (rc)
+ return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
+ useraddr += 8;
+ if (reg == reg3)
+ break;
+ reg = (reg + 1) % 16;
+ } while (1);
+
+ return 0;
+}
+
static const intercept_handler_t eb_handlers[256] = {
+ [0x2f] = handle_lctlg,
[0x8a] = handle_io_inst,
};
-int kvm_s390_handle_priv_eb(struct kvm_vcpu *vcpu)
+int kvm_s390_handle_eb(struct kvm_vcpu *vcpu)
{
intercept_handler_t handler;
--
1.8.2.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 7/7] KVM: s390: Fixed priority of execution in STSI
2013-06-20 15:21 [PATCH 0/7] KVM: s390: further fixes for -next Cornelia Huck
` (5 preceding siblings ...)
2013-06-20 15:22 ` [PATCH 6/7] KVM: s390: Reworked LCTL and LCTLG instructions Cornelia Huck
@ 2013-06-20 15:22 ` Cornelia Huck
2013-06-20 21:33 ` [PATCH 0/7] KVM: s390: further fixes for -next Paolo Bonzini
7 siblings, 0 replies; 9+ messages in thread
From: Cornelia Huck @ 2013-06-20 15:22 UTC (permalink / raw)
To: Gleb Natapov, Paolo Bonzini
Cc: Christian Borntraeger, Heiko Carstens, Martin Schwidefsky, KVM,
linux-s390, Thomas Huth
From: Thomas Huth <thuth@linux.vnet.ibm.com>
Added some missing validity checks for the operands and fixed the
priority of exceptions for some function codes according to the
"Principles of Operation" document.
Signed-off-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
arch/s390/kvm/priv.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index c7603f5..0da3e6e 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -385,16 +385,27 @@ static int handle_stsi(struct kvm_vcpu *vcpu)
if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
- operand2 = kvm_s390_get_base_disp_s(vcpu);
+ if (fc > 3) {
+ vcpu->arch.sie_block->gpsw.mask |= 3ul << 44; /* cc 3 */
+ return 0;
+ }
- if (operand2 & 0xfff && fc > 0)
+ if (vcpu->run->s.regs.gprs[0] & 0x0fffff00
+ || vcpu->run->s.regs.gprs[1] & 0xffff0000)
return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
- switch (fc) {
- case 0:
+ if (fc == 0) {
vcpu->run->s.regs.gprs[0] = 3 << 28;
- vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
+ vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); /* cc 0 */
return 0;
+ }
+
+ operand2 = kvm_s390_get_base_disp_s(vcpu);
+
+ if (operand2 & 0xfff)
+ return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
+
+ switch (fc) {
case 1: /* same handling for 1 and 2 */
case 2:
mem = get_zeroed_page(GFP_KERNEL);
@@ -411,8 +422,6 @@ static int handle_stsi(struct kvm_vcpu *vcpu)
goto out_no_data;
handle_stsi_3_2_2(vcpu, (void *) mem);
break;
- default:
- goto out_no_data;
}
if (copy_to_guest_absolute(vcpu, operand2, (void *) mem, PAGE_SIZE)) {
--
1.8.2.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 0/7] KVM: s390: further fixes for -next
2013-06-20 15:21 [PATCH 0/7] KVM: s390: further fixes for -next Cornelia Huck
` (6 preceding siblings ...)
2013-06-20 15:22 ` [PATCH 7/7] KVM: s390: Fixed priority of execution in STSI Cornelia Huck
@ 2013-06-20 21:33 ` Paolo Bonzini
7 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2013-06-20 21:33 UTC (permalink / raw)
To: Cornelia Huck
Cc: Gleb Natapov, Christian Borntraeger, Heiko Carstens,
Martin Schwidefsky, KVM, linux-s390
Il 20/06/2013 17:21, Cornelia Huck ha scritto:
> Hi,
>
> some more fixes for kvm-next, bringing our handling of intercepted
> instructions more into line with what is actually architectured.
>
> Please apply.
>
> Thomas Huth (7):
> KVM: s390: Renamed PGM_PRIVILEGED_OPERATION
> KVM: s390: Privileged operation check for TPROT
> KVM: s390: Privileged operation checks moved to instruction handlers
> KVM: s390: Check for PSTATE when handling DIAGNOSE
> KVM: s390: Check for access exceptions during TPI
> KVM: s390: Reworked LCTL and LCTLG instructions
> KVM: s390: Fixed priority of execution in STSI
>
> arch/s390/include/asm/kvm_host.h | 2 +-
> arch/s390/kvm/diag.c | 3 +
> arch/s390/kvm/intercept.c | 85 +-----------------
> arch/s390/kvm/kvm-s390.h | 3 +-
> arch/s390/kvm/priv.c | 184 ++++++++++++++++++++++++++++++---------
> arch/s390/kvm/sigp.c | 3 +-
> 6 files changed, 152 insertions(+), 128 deletions(-)
>
Applied to next, thanks.
Paolo
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2013-06-20 21:33 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-20 15:21 [PATCH 0/7] KVM: s390: further fixes for -next Cornelia Huck
2013-06-20 15:21 ` [PATCH 1/7] KVM: s390: Renamed PGM_PRIVILEGED_OPERATION Cornelia Huck
2013-06-20 15:22 ` [PATCH 2/7] KVM: s390: Privileged operation check for TPROT Cornelia Huck
2013-06-20 15:22 ` [PATCH 3/7] KVM: s390: Privileged operation checks moved to instruction handlers Cornelia Huck
2013-06-20 15:22 ` [PATCH 4/7] KVM: s390: Check for PSTATE when handling DIAGNOSE Cornelia Huck
2013-06-20 15:22 ` [PATCH 5/7] KVM: s390: Check for access exceptions during TPI Cornelia Huck
2013-06-20 15:22 ` [PATCH 6/7] KVM: s390: Reworked LCTL and LCTLG instructions Cornelia Huck
2013-06-20 15:22 ` [PATCH 7/7] KVM: s390: Fixed priority of execution in STSI Cornelia Huck
2013-06-20 21:33 ` [PATCH 0/7] KVM: s390: further fixes for -next Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox