KVM: s390: further fixes for -next
cover KVM: s390: further fixes for -next
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(-)
Signature · 1 line
1.8.2.2
PATCH 1/7 KVM: s390: Renamed PGM_PRIVILEGED_OPERATION
From: Thomas Huth <[email protected]>
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.
--- 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(-)
arch/s390/include/asm/kvm_host.h +1 -1
@@ -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
arch/s390/kvm/priv.c +7 -9
@@ -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,
arch/s390/kvm/sigp.c +1 -2
@@ -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);
Signature · 1 line
1.8.2.2
PATCH 2/7 KVM: s390: Privileged operation check for TPROT
In reply to Cornelia HuckFrom: Thomas Huth <[email protected]>
TPROT is a privileged instruction and thus should generate a privileged operation exception when the problem state bit is not cleared in the PSW.
--- arch/s390/kvm/priv.c | 3 +++ 1 file changed, 3 insertions(+)
arch/s390/kvm/priv.c +3 -0
@@ -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:
Signature · 1 line
1.8.2.2
PATCH 3/7 KVM: s390: Privileged operation checks moved to instruction handlers
In reply to Cornelia HuckFrom: Thomas Huth <[email protected]>
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.
--- arch/s390/kvm/priv.c | 63 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 24 deletions(-)
arch/s390/kvm/priv.c +39 -24
@@ -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);
Signature · 1 line
1.8.2.2
PATCH 4/7 KVM: s390: Check for PSTATE when handling DIAGNOSE
In reply to Cornelia HuckFrom: Thomas Huth <[email protected]>
DIAGNOSE is a privileged instruction and thus we must make sure that we are in supervisor mode before taking any other actions.
--- arch/s390/kvm/diag.c | 3 +++ 1 file changed, 3 insertions(+)
arch/s390/kvm/diag.c +3 -0
@@ -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 :
Signature · 1 line
1.8.2.2
PATCH 5/7 KVM: s390: Check for access exceptions during TPI
In reply to Cornelia HuckFrom: Thomas Huth <[email protected]>
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.
--- arch/s390/kvm/priv.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/s390/kvm/priv.c +4 -3
@@ -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
Signature · 1 line
1.8.2.2
PATCH 6/7 KVM: s390: Reworked LCTL and LCTLG instructions
In reply to Cornelia HuckFrom: Thomas Huth <[email protected]>
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.
--- 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(-)
arch/s390/kvm/intercept.c +2 -83
@@ -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)
arch/s390/kvm/kvm-s390.h +2 -1
@@ -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);
arch/s390/kvm/priv.c +77 -1
88 lines not on this page · raw message
Signature · 1 line
1.8.2.2
PATCH 7/7 KVM: s390: Fixed priority of execution in STSI
In reply to Cornelia HuckFrom: Thomas Huth <[email protected]>
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.
--- arch/s390/kvm/priv.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
arch/s390/kvm/priv.c +16 -7
@@ -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 )) {
Signature · 1 line
1.8.2.2
Il 20/06/2013 17:21, Cornelia Huck ha scritto:
Quoted 16 lines
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: RenamedPGM_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
Quoted 8 lines
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