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-devel

[Xen-devel] [PATCH] vmx-copy_from_guest.patch

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] vmx-copy_from_guest.patch
From: Leendert van Doorn <leendert@xxxxxxxxxxxxxx>
Date: Tue, 06 Sep 2005 04:23:11 -0400
Cc: arun.sharma@xxxxxxxxx, Ian Pratt <Ian.Pratt@xxxxxxxxxxxx>
Delivery-date: Tue, 06 Sep 2005 13:20:23 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Organization: IBM T.J. Watson Research Center
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Reducing LOC (always a good thing) by eliminating duplicated functionality.
vmx_platform.c/inst_copy_from_guest() now uses vmx_copy. Also shored up
vmx_copy to handle copies when paging is enabled and improved its error
handling.

Signed-Off-By: Leendert van Doorn <leendert@xxxxxxxxxxxxxx>

diff -r 23d8580d56b0 xen/arch/x86/vmx.c
--- a/xen/arch/x86/vmx.c        Fri Sep  2 18:23:57 2005
+++ b/xen/arch/x86/vmx.c        Mon Sep  5 13:43:59 2005
@@ -729,7 +735,7 @@
 int
 vmx_copy(void *buf, unsigned long laddr, int size, int dir)
 {
-    unsigned long mfn;
+    unsigned long gpa, mfn;
     char *addr;
     int count;
 
@@ -738,8 +744,14 @@
        if (count > size)
            count = size;
 
-       mfn = get_mfn_from_pfn(laddr >> PAGE_SHIFT);
-       /* XXX check whether laddr is valid */
+       if (vmx_paging_enabled(current)) {
+               gpa = gva_to_gpa(laddr);
+               mfn = get_mfn_from_pfn(gpa >> PAGE_SHIFT);
+       } else
+               mfn = get_mfn_from_pfn(laddr >> PAGE_SHIFT);
+       if (mfn == INVALID_MFN)
+               return 0;
+
        addr = (char *)map_domain_page(mfn) + (laddr & ~PAGE_MASK);
 
        if (dir == VMX_COPY_IN)
diff -r 23d8580d56b0 xen/arch/x86/vmx_platform.c
--- a/xen/arch/x86/vmx_platform.c       Fri Sep  2 18:23:57 2005
+++ b/xen/arch/x86/vmx_platform.c       Mon Sep  5 13:43:59 2005
@@ -583,49 +583,13 @@
     }
 }
 
-/* XXX use vmx_copy instead */
 int inst_copy_from_guest(unsigned char *buf, unsigned long guest_eip, int 
inst_len)
 {
-    unsigned long gpa;
-    unsigned long mfn;
-    unsigned char *inst_start;
-    int remaining = 0;
-        
-    if ( (inst_len > MAX_INST_LEN) || (inst_len <= 0) )
+    if (inst_len > MAX_INST_LEN || inst_len <= 0)
         return 0;
-
-    if ( vmx_paging_enabled(current) )
-    {
-        gpa = gva_to_gpa(guest_eip);
-        mfn = get_mfn_from_pfn(gpa >> PAGE_SHIFT);
-
-        /* Does this cross a page boundary ? */
-        if ( (guest_eip & PAGE_MASK) != ((guest_eip + inst_len) & PAGE_MASK) )
-        {
-            remaining = (guest_eip + inst_len) & ~PAGE_MASK;
-            inst_len -= remaining;
-        }
-    }
-    else
-    {
-        mfn = get_mfn_from_pfn(guest_eip >> PAGE_SHIFT);
-    }
-
-    inst_start = map_domain_page(mfn);
-    memcpy((char *)buf, inst_start + (guest_eip & ~PAGE_MASK), inst_len);
-    unmap_domain_page(inst_start);
-
-    if ( remaining )
-    {
-        gpa = gva_to_gpa(guest_eip+inst_len+remaining);
-        mfn = get_mfn_from_pfn(gpa >> PAGE_SHIFT);
-
-        inst_start = map_domain_page(mfn);
-        memcpy((char *)buf+inst_len, inst_start, remaining);
-        unmap_domain_page(inst_start);
-    }
-
-    return inst_len+remaining;
+    if (!vmx_copy(buf, guest_eip, inst_len, VMX_COPY_IN))
+        return 0;
+    return inst_len;
 }
 
 void send_mmio_req(unsigned char type, unsigned long gpa, 

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

<Prev in Thread] Current Thread [Next in Thread>