[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Reducing LOC (always a good thing) by eliminating duplicated functionality.



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID ef1cd772967698f38ebc5a351fb5c125fb565acb
# Parent  60bf463f79a85d92f55bbe42c45856fc791dd7d7
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 60bf463f79a8 -r ef1cd7729676 xen/arch/x86/vmx.c
--- a/xen/arch/x86/vmx.c        Tue Sep  6 09:44:58 2005
+++ b/xen/arch/x86/vmx.c        Tue Sep  6 15:31:34 2005
@@ -730,7 +730,7 @@
 int
 vmx_copy(void *buf, unsigned long laddr, int size, int dir)
 {
-    unsigned long mfn;
+    unsigned long gpa, mfn;
     char *addr;
     int count;
 
@@ -739,8 +739,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 60bf463f79a8 -r ef1cd7729676 xen/arch/x86/vmx_platform.c
--- a/xen/arch/x86/vmx_platform.c       Tue Sep  6 09:44:58 2005
+++ b/xen/arch/x86/vmx_platform.c       Tue Sep  6 15:31:34 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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.