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

RE: [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


 


Rackspace

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