WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] x86 hvm: Fix binary arithmetic in hvmemul

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] x86 hvm: Fix binary arithmetic in hvmemul_linear_to_phys().
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 20 Aug 2008 06:50:10 -0700
Delivery-date: Wed, 20 Aug 2008 06:49:57 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1219239832 -3600
# Node ID 6fc154f0827ebc925e0a730b69e90f4f1ef9c3f4
# Parent  4939ce66516194953e47b6a0c7f9465b591bda00
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@xxxxxxxxxx>
---
 xen/arch/x86/hvm/emulate.c |   15 ++++-----------
 1 files changed, 4 insertions(+), 11 deletions(-)

diff -r 4939ce665161 -r 6fc154f0827e xen/arch/x86/hvm/emulate.c
--- a/xen/arch/x86/hvm/emulate.c        Wed Aug 20 10:14:26 2008 +0100
+++ b/xen/arch/x86/hvm/emulate.c        Wed Aug 20 14:43:52 2008 +0100
@@ -207,7 +207,7 @@ static int hvmemul_linear_to_phys(
     struct hvm_emulate_ctxt *hvmemul_ctxt)
 {
     struct vcpu *curr = current;
-    unsigned long pfn, npfn, done, todo, i;
+    unsigned long pfn, npfn, done, todo, i, offset = addr & ~PAGE_MASK;
     int reverse;
 
     /*
@@ -223,12 +223,10 @@ static int hvmemul_linear_to_phys(
         return X86EMUL_OKAY;
     }
 
-    *paddr = addr & ~PAGE_MASK;
-
     /* Reverse mode if this is a backwards multi-iteration string operation. */
     reverse = (hvmemul_ctxt->ctxt.regs->eflags & X86_EFLAGS_DF) && (*reps > 1);
 
-    if ( reverse && ((-addr & ~PAGE_MASK) < bytes_per_rep) )
+    if ( reverse && ((PAGE_SIZE - offset) < bytes_per_rep) )
     {
         /* Do page-straddling first iteration forwards via recursion. */
         paddr_t _paddr;
@@ -245,12 +243,8 @@ static int hvmemul_linear_to_phys(
         return X86EMUL_EXCEPTION;
     }
 
-    /* If the range does not straddle a page boundary then we're done. */
-    done = reverse ? bytes_per_rep + (addr & ~PAGE_MASK) : -addr & ~PAGE_MASK;
+    done = reverse ? bytes_per_rep + offset : PAGE_SIZE - offset;
     todo = *reps * bytes_per_rep;
-    if ( done >= todo )
-        goto done;
-
     for ( i = 1; done < todo; i++ )
     {
         /* Get the next PFN in the range. */
@@ -276,8 +270,7 @@ static int hvmemul_linear_to_phys(
         done += PAGE_SIZE;
     }
 
- done:
-    *paddr |= (paddr_t)pfn << PAGE_SHIFT;
+    *paddr = ((paddr_t)pfn << PAGE_SHIFT) | offset;
     return X86EMUL_OKAY;
 }
     

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] x86 hvm: Fix binary arithmetic in hvmemul_linear_to_phys()., Xen patchbot-unstable <=