Re: kernel thread and copy_to_user

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

 



Thanks Robert and Dr. Michael for answering my question :)

This [copying to-user-space from kernel threads] came up in my mind,
because I was wondering about the working of Async I/O library (libaio)
from RedHat. How does it handle async reads from the kernel. I guessed
that when a poll() is done it returns immediately and a kernel thread
is created to do the async copy-to-user by the kernel. But that can't
be done!

I think I need to read the sources of libaio. They must be doing
something different. Does anybody know how its done there?

Thanks once again,
A.


--- Robert Love <rml@tech9.net> wrote:
> On Fri, 2002-12-27 at 11:23, zw wrote:
> 
> > > But I thought while doing copy_to_user() the task should have 
> > > a valid task->mm. no?
> > 
> > You mean the kernel thread, or the user task? I think you don't
> have 
> > to do anything special on your kernel thread. You kernel thread, I 
> > think, basically waiting there for a pointer from user space. Then 
> > you call copy_to_user() in your kernel thread. That's it. I think.
> 
> Think about what devnetfs is asking.
> 
> The function is prototyped as copy_to_user(to, from, len) where to
> and
> from are pointers.
> 
> If current->mm is invalid, then exactly whose "from" are you copying
> to?  Remember, Linux is a virtual memory operating system: there can
> be
> many mappings at the same address.
> 
> Likewise, with copy_from_user(), without a valid ->mm from where
> exactly
> are you copying from?
> 
> The functions pull the to/from user addresses from the loaded user
> address space.  Without a user address space, these functions do not
> work.  Nor could they.
> 
> In short, to answer the original question, kernel threads cannot copy
> from user-space since they have no user-space.  If you want to get
> data
> into and out of a kernel thread, expose an interface (procfs, sysfs,
> syscall, device file, etc.)
> 
> 	Robert Love
> 



__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux