ia64/xen-unstable

changeset 18350:6fc154f0827e

x86 hvm: Fix binary arithmetic in hvmemul_linear_to_phys().

PAGE_SIZE - (x & ~PAGE_MASK) is not equivalent to -x & ~PAGE_MASK

Also the early goto could be removed.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Aug 20 14:43:52 2008 +0100 (2008-08-20)
parents 4939ce665161
children daf1193bcd11
files xen/arch/x86/hvm/emulate.c
line diff
     1.1 --- a/xen/arch/x86/hvm/emulate.c	Wed Aug 20 10:14:26 2008 +0100
     1.2 +++ b/xen/arch/x86/hvm/emulate.c	Wed Aug 20 14:43:52 2008 +0100
     1.3 @@ -207,7 +207,7 @@ static int hvmemul_linear_to_phys(
     1.4      struct hvm_emulate_ctxt *hvmemul_ctxt)
     1.5  {
     1.6      struct vcpu *curr = current;
     1.7 -    unsigned long pfn, npfn, done, todo, i;
     1.8 +    unsigned long pfn, npfn, done, todo, i, offset = addr & ~PAGE_MASK;
     1.9      int reverse;
    1.10  
    1.11      /*
    1.12 @@ -223,12 +223,10 @@ static int hvmemul_linear_to_phys(
    1.13          return X86EMUL_OKAY;
    1.14      }
    1.15  
    1.16 -    *paddr = addr & ~PAGE_MASK;
    1.17 -
    1.18      /* Reverse mode if this is a backwards multi-iteration string operation. */
    1.19      reverse = (hvmemul_ctxt->ctxt.regs->eflags & X86_EFLAGS_DF) && (*reps > 1);
    1.20  
    1.21 -    if ( reverse && ((-addr & ~PAGE_MASK) < bytes_per_rep) )
    1.22 +    if ( reverse && ((PAGE_SIZE - offset) < bytes_per_rep) )
    1.23      {
    1.24          /* Do page-straddling first iteration forwards via recursion. */
    1.25          paddr_t _paddr;
    1.26 @@ -245,12 +243,8 @@ static int hvmemul_linear_to_phys(
    1.27          return X86EMUL_EXCEPTION;
    1.28      }
    1.29  
    1.30 -    /* If the range does not straddle a page boundary then we're done. */
    1.31 -    done = reverse ? bytes_per_rep + (addr & ~PAGE_MASK) : -addr & ~PAGE_MASK;
    1.32 +    done = reverse ? bytes_per_rep + offset : PAGE_SIZE - offset;
    1.33      todo = *reps * bytes_per_rep;
    1.34 -    if ( done >= todo )
    1.35 -        goto done;
    1.36 -
    1.37      for ( i = 1; done < todo; i++ )
    1.38      {
    1.39          /* Get the next PFN in the range. */
    1.40 @@ -276,8 +270,7 @@ static int hvmemul_linear_to_phys(
    1.41          done += PAGE_SIZE;
    1.42      }
    1.43  
    1.44 - done:
    1.45 -    *paddr |= (paddr_t)pfn << PAGE_SHIFT;
    1.46 +    *paddr = ((paddr_t)pfn << PAGE_SHIFT) | offset;
    1.47      return X86EMUL_OKAY;
    1.48  }
    1.49