Jon, You must be tired of answering questions :) > then how does copy_from_user and copy_to_user work? (I don't know enough > assembly to understand the code in uaccess.h) Roughly this goes on: *). Check validity of vma and process memory mapping. *). Check page is available. *). Copy the data accross. Point number 2 here ( check page is available ) ... What if page is not available and there is no page table/page directory set up for this ? Does it cause a page fault ? or it make sure that there is no page fault by doing all the page table manipulation and getting the page frame for the request ( pretty much does all the jobs by a page fault handler ) ? Why is copy_to_user() required ? can it be implemented inside the page fault handler itself to take care of page faults happened addressing user memory from kernel mode when doing a simple memcpy ? In either case ( even we use copy_to_user) the process is going to be put to sleep/block if the request can'nt be met immediately. Aboo -----Original Message----- From: kernelnewbies-bounce@xxxxxxxxxxxx [mailto:kernelnewbies-bounce@xxxxxxxxxxxx] On Behalf Of Jon Masters Sent: Tuesday, October 12, 2004 7:39 AM To: Om Cc: Linux Newbies Subject: Re: copy_to/from_use query? On Mon, 11 Oct 2004 10:08:16 -0700, Om <omanakuttan@xxxxxxx> wrote: > > > > > > > > > > No, you can't. The user-space memory is not directly addressable from > > > > > kernel. What Jan Hudec means (please include quotes indicating who said what) is that the kernel code cannot necessary directly dereference a pointer in to userspace, even though it may form part of the conceptual virtual memory map as seen by the kernel. The reasons for this include the following items of note: *). Userspace memory is pageable (the kernel is not yet so) so it may not be mapped and in kernel code has to take that in to consideration. *). Userspace memory is governed by page tables which may not contain an entry for other reasons or a processor TLB might need to be loaded as part of a page fault like exception when memory is accessed on embedded CPUs (the kernel also supports pinning on some CPUs where large fixed mappings cover the kernel so it doesn't get this problem). *). Userspace memory might be in high memory so even just manually walking the process descriptor and pulling out addresses won't cut the mustard here (that's an English phrase nobody ever uses any more, but I felt like it). *). Randomly following a pointer in to userspace or implementing checks yourself is to say that you can do a better job than tested kernel access code that does sanity and security checks for you. > then how does copy_from_user and copy_to_user work? (I don't know enough > assembly to understand the code in uaccess.h) Roughly this goes on: *). Check validity of vma and process memory mapping. *). Check page is available. *). Copy the data accross. Jon. -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/ -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/