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

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

To: "Leendert van Doorn" <leendert@xxxxxxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: RE: [Xen-devel] [PATCH] vmx-copy_from_guest.patch
From: "Ling, Xiaofeng" <xiaofeng.ling@xxxxxxxxx>
Date: Tue, 6 Sep 2005 22:41:43 +0800
Cc: "Sharma, Arun" <arun.sharma@xxxxxxxxx>, Ian Pratt <Ian.Pratt@xxxxxxxxxxxx>
Delivery-date: Tue, 06 Sep 2005 14:39:43 +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>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcWy5hUYfNf/It7+Ro283hVnXEJtMgACK0xAAAAyzRA=
Thread-topic: [Xen-devel] [PATCH] vmx-copy_from_guest.patch
Ling, Xiaofeng <> wrote:
> seems current vmx_copy can not deal with copy over page boundary?
> so remove inst_copy_from_guest will cause problem.
> 
> Leendert van Doorn <> wrote:
The following code is I used to deal with hypercall parameters in vmx.
It has no limit with copy length and page boundary.

static inline void*  map_domain_vaddr(void * guest_vaddr, unsigned long len)
{
    unsigned long gpa, mfn;
    void * vstart;
    
    gpa = gva_to_gpa((unsigned long)guest_vaddr);
    mfn = get_mfn_from_pfn(gpa>>PAGE_SHIFT);
    vstart = (void *)map_domain_page(mfn) + 
           ((unsigned long)guest_vaddr & (PAGE_SIZE - 1));

    return vstart;
}

unsigned long
copy_from_guest(void *to, const void __user *from, unsigned long n)
{
    void *hfrom;    
    unsigned long ncopy;
    int nleft;
    ncopy = (((unsigned long)from  + PAGE_SIZE) & PAGE_MASK) - 
            (unsigned long)from;
    ncopy = ncopy > n ? n : ncopy;  

    for(nleft = n; nleft > 0; ncopy = nleft > PAGE_SIZE ? PAGE_SIZE : nleft) 
    {
        hfrom = map_domain_vaddr((void*)from, ncopy);
        if(hfrom) 
        {
            memcpy(to, hfrom, ncopy);
            unmap_domain_page((void*)hfrom); 
        }
        else 
        {
            printk("error!, copy from guest map error, from:%p, ncopy:%ld\n", 
                   from, ncopy);
             return nleft;
        }
        nleft -= ncopy;
        from += ncopy;
        to += ncopy;
    }
    return nleft;
}

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

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