aboutsummaryrefslogtreecommitdiffstats
path: root/arch/s390/kvm
diff options
context:
space:
mode:
authorHeiko Carstens <heiko.carstens@de.ibm.com>2013-03-25 12:22:52 -0400
committerGleb Natapov <gleb@redhat.com>2013-04-02 09:14:36 -0400
commit3736b874a39a1df2a94186c357aabeb6a7d7d4f6 (patch)
treed1f52792219577767ca33a4c0aa0211ef6e836da /arch/s390/kvm
parent6fd0fcc93b1eaf82911782de5c7aa35c174bf620 (diff)
KVM: s390: make if statements in lpsw/lpswe handlers readable
Being unable to parse the 5- and 8-line if statements I had to split them to be able to make any sense of them and verify that they match the architecture. So change the code since I guess that other people will also have a hard time parsing such long conditional statements with line breaks. Introduce a common is_valid_psw() function which does all the checks needed. In case of lpsw (64 bit psw -> 128 bit psw conversion) it will do some not needed additional checks, since a couple of bits can't be set anyway, but that doesn't hurt. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Gleb Natapov <gleb@redhat.com>
Diffstat (limited to 'arch/s390/kvm')
-rw-r--r--arch/s390/kvm/priv.c58
1 files changed, 24 insertions, 34 deletions
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 9d32c56fb02c..05d186c21eca 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -258,68 +258,58 @@ static void handle_new_psw(struct kvm_vcpu *vcpu)
258#define PSW_ADDR_24 0x0000000000ffffffUL 258#define PSW_ADDR_24 0x0000000000ffffffUL
259#define PSW_ADDR_31 0x000000007fffffffUL 259#define PSW_ADDR_31 0x000000007fffffffUL
260 260
261static int is_valid_psw(psw_t *psw) {
262 if (psw->mask & PSW_MASK_UNASSIGNED)
263 return 0;
264 if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_BA) {
265 if (psw->addr & ~PSW_ADDR_31)
266 return 0;
267 }
268 if (!(psw->mask & PSW_MASK_ADDR_MODE) && (psw->addr & ~PSW_ADDR_24))
269 return 0;
270 if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_EA)
271 return 0;
272 return 1;
273}
274
261int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu) 275int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
262{ 276{
263 u64 addr; 277 psw_t *gpsw = &vcpu->arch.sie_block->gpsw;
264 psw_compat_t new_psw; 278 psw_compat_t new_psw;
279 u64 addr;
265 280
266 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) 281 if (gpsw->mask & PSW_MASK_PSTATE)
267 return kvm_s390_inject_program_int(vcpu, 282 return kvm_s390_inject_program_int(vcpu,
268 PGM_PRIVILEGED_OPERATION); 283 PGM_PRIVILEGED_OPERATION);
269
270 addr = kvm_s390_get_base_disp_s(vcpu); 284 addr = kvm_s390_get_base_disp_s(vcpu);
271
272 if (addr & 7) 285 if (addr & 7)
273 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); 286 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
274
275 if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw))) 287 if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw)))
276 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); 288 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
277
278 if (!(new_psw.mask & PSW32_MASK_BASE)) 289 if (!(new_psw.mask & PSW32_MASK_BASE))
279 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); 290 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
280 291 gpsw->mask = (new_psw.mask & ~PSW32_MASK_BASE) << 32;
281 vcpu->arch.sie_block->gpsw.mask = 292 gpsw->mask |= new_psw.addr & PSW32_ADDR_AMODE;
282 (new_psw.mask & ~PSW32_MASK_BASE) << 32; 293 gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE;
283 vcpu->arch.sie_block->gpsw.mask |= new_psw.addr & PSW32_ADDR_AMODE; 294 if (!is_valid_psw(gpsw))
284 vcpu->arch.sie_block->gpsw.addr = new_psw.addr & ~PSW32_ADDR_AMODE;
285
286 if ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_UNASSIGNED) ||
287 (!(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) &&
288 (vcpu->arch.sie_block->gpsw.addr & ~PSW_ADDR_24)) ||
289 ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) ==
290 PSW_MASK_EA))
291 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); 295 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
292
293 handle_new_psw(vcpu); 296 handle_new_psw(vcpu);
294 return 0; 297 return 0;
295} 298}
296 299
297static int handle_lpswe(struct kvm_vcpu *vcpu) 300static int handle_lpswe(struct kvm_vcpu *vcpu)
298{ 301{
299 u64 addr;
300 psw_t new_psw; 302 psw_t new_psw;
303 u64 addr;
301 304
302 addr = kvm_s390_get_base_disp_s(vcpu); 305 addr = kvm_s390_get_base_disp_s(vcpu);
303
304 if (addr & 7) 306 if (addr & 7)
305 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); 307 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
306
307 if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw))) 308 if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw)))
308 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); 309 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
309 310 vcpu->arch.sie_block->gpsw = new_psw;
310 vcpu->arch.sie_block->gpsw.mask = new_psw.mask; 311 if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
311 vcpu->arch.sie_block->gpsw.addr = new_psw.addr;
312
313 if ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_UNASSIGNED) ||
314 (((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) ==
315 PSW_MASK_BA) &&
316 (vcpu->arch.sie_block->gpsw.addr & ~PSW_ADDR_31)) ||
317 (!(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) &&
318 (vcpu->arch.sie_block->gpsw.addr & ~PSW_ADDR_24)) ||
319 ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) ==
320 PSW_MASK_EA))
321 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); 312 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
322
323 handle_new_psw(vcpu); 313 handle_new_psw(vcpu);
324 return 0; 314 return 0;
325} 315}