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

Re: [Xen-devel] how to deal with copy_to_user returning non zero



how does it get page fault? I made sure the output buffer at the user space is properly allocated with the correct  size.

When page fault, do I have no choice but abort? It seems calling the hypercall again does not solve it.




On 7 Nov 2014, at 6:44 pm, Andrew Cooper <andrew.cooper3@xxxxxxxxxx> wrote:

On 07/11/14 10:38, Anh Dinh wrote:
I'm testing out a hypercall that takes in large data (many MB) from the user space and simply copy the data back. 

For copying in, I call xmalloc_array() for about 4MB at a time and call copy_from_user() successfully for the entire input. 

The problem is with copy_to_user() which returns non-zero values. I tried to vary the size of the data being copy, but still unable to copy the whole data back. 

What are the cause of copy_to_user() failure? I checked the source I got quite lost at the code. 

How could I make sure all data is copy back? Surely it is not a memory limitation problem, because I copy_from_user() succeeds for over 100MB. 


copy_to_user() returns non-zero if it encounters a fault while moving data, generally a pagefault.


******
long do_test_copy(long n, unsigned char *in, unsigned char *out){

This looks quite bogus.  You should have XEN_GUEST_HANDLE() for a pointer into guest memory.  A bare pointer like *in is completely wrong.

~Andrew

        unsigned char **tmp; 
        long ret;
        int m = n/(MAX_ALLOC); 
        tmp = xmalloc_array(unsigned char*,m); 

        for (int i=0; i<m; i++){
                tmp[i] = xmalloc_array(unsigned char, MAX_ALLOC); 
                copy_from_user(tmp[i],in+i*MAX_ALLOC,MAX_ALLOC); 
        }
        
        for (int i=0; i<m; i++){
                if (tmp[i]){
                        ret = copy_to_user(out+i*MAX_ALLOC,tmp[i],MAX_ALLOC);                 
                        xfree(tmp[i]); 
                }
        }
        xfree(tmp);
        return 0;       
}
****



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

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