ia64/xen-unstable

changeset 6652:ef1cd7729676

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@watson.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Sep 06 15:31:34 2005 +0000 (2005-09-06)
parents 60bf463f79a8
children 158d23cbd2e6
files xen/arch/x86/vmx.c xen/arch/x86/vmx_platform.c
line diff
     1.1 --- a/xen/arch/x86/vmx.c	Tue Sep 06 09:44:58 2005 +0000
     1.2 +++ b/xen/arch/x86/vmx.c	Tue Sep 06 15:31:34 2005 +0000
     1.3 @@ -730,7 +730,7 @@ static void vmx_io_instruction(struct cp
     1.4  int
     1.5  vmx_copy(void *buf, unsigned long laddr, int size, int dir)
     1.6  {
     1.7 -    unsigned long mfn;
     1.8 +    unsigned long gpa, mfn;
     1.9      char *addr;
    1.10      int count;
    1.11  
    1.12 @@ -739,8 +739,14 @@ vmx_copy(void *buf, unsigned long laddr,
    1.13  	if (count > size)
    1.14  	    count = size;
    1.15  
    1.16 -	mfn = get_mfn_from_pfn(laddr >> PAGE_SHIFT);
    1.17 -	/* XXX check whether laddr is valid */
    1.18 +	if (vmx_paging_enabled(current)) {
    1.19 +		gpa = gva_to_gpa(laddr);
    1.20 +		mfn = get_mfn_from_pfn(gpa >> PAGE_SHIFT);
    1.21 +	} else
    1.22 +		mfn = get_mfn_from_pfn(laddr >> PAGE_SHIFT);
    1.23 +	if (mfn == INVALID_MFN)
    1.24 +		return 0;
    1.25 +
    1.26  	addr = (char *)map_domain_page(mfn) + (laddr & ~PAGE_MASK);
    1.27  
    1.28  	if (dir == VMX_COPY_IN)
     2.1 --- a/xen/arch/x86/vmx_platform.c	Tue Sep 06 09:44:58 2005 +0000
     2.2 +++ b/xen/arch/x86/vmx_platform.c	Tue Sep 06 15:31:34 2005 +0000
     2.3 @@ -583,49 +583,13 @@ static int vmx_decode(unsigned char *opc
     2.4      }
     2.5  }
     2.6  
     2.7 -/* XXX use vmx_copy instead */
     2.8  int inst_copy_from_guest(unsigned char *buf, unsigned long guest_eip, int inst_len)
     2.9  {
    2.10 -    unsigned long gpa;
    2.11 -    unsigned long mfn;
    2.12 -    unsigned char *inst_start;
    2.13 -    int remaining = 0;
    2.14 -        
    2.15 -    if ( (inst_len > MAX_INST_LEN) || (inst_len <= 0) )
    2.16 +    if (inst_len > MAX_INST_LEN || inst_len <= 0)
    2.17          return 0;
    2.18 -
    2.19 -    if ( vmx_paging_enabled(current) )
    2.20 -    {
    2.21 -        gpa = gva_to_gpa(guest_eip);
    2.22 -        mfn = get_mfn_from_pfn(gpa >> PAGE_SHIFT);
    2.23 -
    2.24 -        /* Does this cross a page boundary ? */
    2.25 -        if ( (guest_eip & PAGE_MASK) != ((guest_eip + inst_len) & PAGE_MASK) )
    2.26 -        {
    2.27 -            remaining = (guest_eip + inst_len) & ~PAGE_MASK;
    2.28 -            inst_len -= remaining;
    2.29 -        }
    2.30 -    }
    2.31 -    else
    2.32 -    {
    2.33 -        mfn = get_mfn_from_pfn(guest_eip >> PAGE_SHIFT);
    2.34 -    }
    2.35 -
    2.36 -    inst_start = map_domain_page(mfn);
    2.37 -    memcpy((char *)buf, inst_start + (guest_eip & ~PAGE_MASK), inst_len);
    2.38 -    unmap_domain_page(inst_start);
    2.39 -
    2.40 -    if ( remaining )
    2.41 -    {
    2.42 -        gpa = gva_to_gpa(guest_eip+inst_len+remaining);
    2.43 -        mfn = get_mfn_from_pfn(gpa >> PAGE_SHIFT);
    2.44 -
    2.45 -        inst_start = map_domain_page(mfn);
    2.46 -        memcpy((char *)buf+inst_len, inst_start, remaining);
    2.47 -        unmap_domain_page(inst_start);
    2.48 -    }
    2.49 -
    2.50 -    return inst_len+remaining;
    2.51 +    if (!vmx_copy(buf, guest_eip, inst_len, VMX_COPY_IN))
    2.52 +        return 0;
    2.53 +    return inst_len;
    2.54  }
    2.55  
    2.56  void send_mmio_req(unsigned char type, unsigned long gpa,