KVM: s390: pfmf: fix end address calculation
authorDavid Hildenbrand <dahi@linux.vnet.ibm.com>
Wed, 13 Apr 2016 08:09:47 +0000 (10:09 +0200)
committerChristian Borntraeger <borntraeger@de.ibm.com>
Fri, 10 Jun 2016 10:07:28 +0000 (12:07 +0200)
The current calculation is wrong if absolute != real address. Let's just
calculate the start address for 4k frames upfront. Otherwise, the
calculated end address will be wrong, resulting in wrong memory
location/storage keys getting touched.

To keep low-address protection working (using the effective address),
we have to move the check.

Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
arch/s390/kvm/priv.c

index c6deed782c615cebb6417f440da3ed4bcbf6d6a6..bfba98302ca0352703b85b7aef42cf82cee2c4a5 100644 (file)
@@ -682,8 +682,15 @@ static int handle_pfmf(struct kvm_vcpu *vcpu)
        start = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK;
        start = kvm_s390_logical_to_effective(vcpu, start);
 
+       if (vcpu->run->s.regs.gprs[reg1] & PFMF_CF) {
+               if (kvm_s390_check_low_addr_prot_real(vcpu, start))
+                       return kvm_s390_inject_prog_irq(vcpu, &vcpu->arch.pgm);
+       }
+
        switch (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) {
        case 0x00000000:
+               /* only 4k frames specify a real address */
+               start = kvm_s390_real_to_abs(vcpu, start);
                end = (start + (1UL << 12)) & ~((1UL << 12) - 1);
                break;
        case 0x00001000:
@@ -701,20 +708,11 @@ static int handle_pfmf(struct kvm_vcpu *vcpu)
                return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
        }
 
-       if (vcpu->run->s.regs.gprs[reg1] & PFMF_CF) {
-               if (kvm_s390_check_low_addr_prot_real(vcpu, start))
-                       return kvm_s390_inject_prog_irq(vcpu, &vcpu->arch.pgm);
-       }
-
        while (start < end) {
-               unsigned long useraddr, abs_addr;
+               unsigned long useraddr;
 
                /* Translate guest address to host address */
-               if ((vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) == 0)
-                       abs_addr = kvm_s390_real_to_abs(vcpu, start);
-               else
-                       abs_addr = start;
-               useraddr = gfn_to_hva(vcpu->kvm, gpa_to_gfn(abs_addr));
+               useraddr = gfn_to_hva(vcpu->kvm, gpa_to_gfn(start));
                if (kvm_is_error_hva(useraddr))
                        return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);