Commit fc56eb66 authored by Heiko Carstens's avatar Heiko Carstens Committed by Christian Borntraeger

KVM: s390: fix handling of lctl[g]/stctl[g]

According to the architecture all instructions are suppressing if memory
access is prohibited due to DAT protection, unless stated otherwise for
an instruction.
The lctl[g]/stctl[g] implementations handled this incorrectly since
control register handling was done piecemeal, which means they had
terminating instead of suppressing semantics.
This patch fixes this.
Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Reviewed-by: default avatarThomas Huth <thuth@linux.vnet.ibm.com>
Reviewed-by: default avatarDavid Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: default avatarChristian Borntraeger <borntraeger@de.ibm.com>
parent 2dca485f
...@@ -762,8 +762,8 @@ int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu) ...@@ -762,8 +762,8 @@ int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu)
{ {
int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
int reg3 = vcpu->arch.sie_block->ipa & 0x000f; int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
u32 val = 0; int reg, rc, nr_regs;
int reg, rc; u32 ctl_array[16];
u64 ga; u64 ga;
vcpu->stat.instruction_lctl++; vcpu->stat.instruction_lctl++;
...@@ -779,14 +779,15 @@ int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu) ...@@ -779,14 +779,15 @@ int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu)
VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x, addr:%llx", reg1, reg3, ga); VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x, addr:%llx", reg1, reg3, ga);
trace_kvm_s390_handle_lctl(vcpu, 0, reg1, reg3, ga); trace_kvm_s390_handle_lctl(vcpu, 0, reg1, reg3, ga);
reg = reg1; nr_regs = ((reg3 - reg1) & 0xf) + 1;
do { rc = read_guest(vcpu, ga, ctl_array, nr_regs * sizeof(u32));
rc = read_guest(vcpu, ga, &val, sizeof(val));
if (rc) if (rc)
return kvm_s390_inject_prog_cond(vcpu, rc); return kvm_s390_inject_prog_cond(vcpu, rc);
reg = reg1;
nr_regs = 0;
do {
vcpu->arch.sie_block->gcr[reg] &= 0xffffffff00000000ul; vcpu->arch.sie_block->gcr[reg] &= 0xffffffff00000000ul;
vcpu->arch.sie_block->gcr[reg] |= val; vcpu->arch.sie_block->gcr[reg] |= ctl_array[nr_regs++];
ga += 4;
if (reg == reg3) if (reg == reg3)
break; break;
reg = (reg + 1) % 16; reg = (reg + 1) % 16;
...@@ -799,9 +800,9 @@ int kvm_s390_handle_stctl(struct kvm_vcpu *vcpu) ...@@ -799,9 +800,9 @@ int kvm_s390_handle_stctl(struct kvm_vcpu *vcpu)
{ {
int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
int reg3 = vcpu->arch.sie_block->ipa & 0x000f; int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
int reg, rc, nr_regs;
u32 ctl_array[16];
u64 ga; u64 ga;
u32 val;
int reg, rc;
vcpu->stat.instruction_stctl++; vcpu->stat.instruction_stctl++;
...@@ -817,26 +818,24 @@ int kvm_s390_handle_stctl(struct kvm_vcpu *vcpu) ...@@ -817,26 +818,24 @@ int kvm_s390_handle_stctl(struct kvm_vcpu *vcpu)
trace_kvm_s390_handle_stctl(vcpu, 0, reg1, reg3, ga); trace_kvm_s390_handle_stctl(vcpu, 0, reg1, reg3, ga);
reg = reg1; reg = reg1;
nr_regs = 0;
do { do {
val = vcpu->arch.sie_block->gcr[reg] & 0x00000000fffffffful; ctl_array[nr_regs++] = vcpu->arch.sie_block->gcr[reg];
rc = write_guest(vcpu, ga, &val, sizeof(val));
if (rc)
return kvm_s390_inject_prog_cond(vcpu, rc);
ga += 4;
if (reg == reg3) if (reg == reg3)
break; break;
reg = (reg + 1) % 16; reg = (reg + 1) % 16;
} while (1); } while (1);
rc = write_guest(vcpu, ga, ctl_array, nr_regs * sizeof(u32));
return 0; return rc ? kvm_s390_inject_prog_cond(vcpu, rc) : 0;
} }
static int handle_lctlg(struct kvm_vcpu *vcpu) static int handle_lctlg(struct kvm_vcpu *vcpu)
{ {
int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
int reg3 = vcpu->arch.sie_block->ipa & 0x000f; int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
u64 ga, val; int reg, rc, nr_regs;
int reg, rc; u64 ctl_array[16];
u64 ga;
vcpu->stat.instruction_lctlg++; vcpu->stat.instruction_lctlg++;
...@@ -848,17 +847,17 @@ static int handle_lctlg(struct kvm_vcpu *vcpu) ...@@ -848,17 +847,17 @@ static int handle_lctlg(struct kvm_vcpu *vcpu)
if (ga & 7) if (ga & 7)
return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
reg = reg1;
VCPU_EVENT(vcpu, 5, "lctlg r1:%x, r3:%x, addr:%llx", reg1, reg3, ga); VCPU_EVENT(vcpu, 5, "lctlg r1:%x, r3:%x, addr:%llx", reg1, reg3, ga);
trace_kvm_s390_handle_lctl(vcpu, 1, reg1, reg3, ga); trace_kvm_s390_handle_lctl(vcpu, 1, reg1, reg3, ga);
do { nr_regs = ((reg3 - reg1) & 0xf) + 1;
rc = read_guest(vcpu, ga, &val, sizeof(val)); rc = read_guest(vcpu, ga, ctl_array, nr_regs * sizeof(u64));
if (rc) if (rc)
return kvm_s390_inject_prog_cond(vcpu, rc); return kvm_s390_inject_prog_cond(vcpu, rc);
vcpu->arch.sie_block->gcr[reg] = val; reg = reg1;
ga += 8; nr_regs = 0;
do {
vcpu->arch.sie_block->gcr[reg] = ctl_array[nr_regs++];
if (reg == reg3) if (reg == reg3)
break; break;
reg = (reg + 1) % 16; reg = (reg + 1) % 16;
...@@ -871,8 +870,9 @@ static int handle_stctg(struct kvm_vcpu *vcpu) ...@@ -871,8 +870,9 @@ static int handle_stctg(struct kvm_vcpu *vcpu)
{ {
int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
int reg3 = vcpu->arch.sie_block->ipa & 0x000f; int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
u64 ga, val; int reg, rc, nr_regs;
int reg, rc; u64 ctl_array[16];
u64 ga;
vcpu->stat.instruction_stctg++; vcpu->stat.instruction_stctg++;
...@@ -884,23 +884,19 @@ static int handle_stctg(struct kvm_vcpu *vcpu) ...@@ -884,23 +884,19 @@ static int handle_stctg(struct kvm_vcpu *vcpu)
if (ga & 7) if (ga & 7)
return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
reg = reg1;
VCPU_EVENT(vcpu, 5, "stctg r1:%x, r3:%x, addr:%llx", reg1, reg3, ga); VCPU_EVENT(vcpu, 5, "stctg r1:%x, r3:%x, addr:%llx", reg1, reg3, ga);
trace_kvm_s390_handle_stctl(vcpu, 1, reg1, reg3, ga); trace_kvm_s390_handle_stctl(vcpu, 1, reg1, reg3, ga);
reg = reg1;
nr_regs = 0;
do { do {
val = vcpu->arch.sie_block->gcr[reg]; ctl_array[nr_regs++] = vcpu->arch.sie_block->gcr[reg];
rc = write_guest(vcpu, ga, &val, sizeof(val));
if (rc)
return kvm_s390_inject_prog_cond(vcpu, rc);
ga += 8;
if (reg == reg3) if (reg == reg3)
break; break;
reg = (reg + 1) % 16; reg = (reg + 1) % 16;
} while (1); } while (1);
rc = write_guest(vcpu, ga, ctl_array, nr_regs * sizeof(u64));
return 0; return rc ? kvm_s390_inject_prog_cond(vcpu, rc) : 0;
} }
static const intercept_handler_t eb_handlers[256] = { static const intercept_handler_t eb_handlers[256] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment