Re: Writing on Proccess Address Space

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

 





On Tue, 16 Aug 2005, Jan Hudec wrote:

On Tue, Aug 16, 2005 at 19:04:10 +0200, Arjan van de Ven wrote:
On Tue, 2005-08-16 at 19:14 +0300, Stavros Passas wrote:
Hi All,

I working on a kernel module and I have been a little bit comfused with
Linux memory manager.

When a user opens the device,the module stores somewhere user's
active_mm pointer.We can assume that only one user can open the device
at the same time. When a interrupt comes to my handler, I want to write
some data to a page of the user. The interrupt handler has the
destination address,and the length of the data that must be copied and
of course the data. The problem is that the destination address is from
address space of the user. At first,through user's active_mm, I find if
the user have access to the memory region that device must write. AFAIK
I cannot use copy_to_user function, or something like this, because
these functions can used only from the user proccess.

So the question is how to "convert" the destination memory address to
interrupt handler address space, so the handler can write the data to
the correct place.


an interrupt handler has no address space.
Also.. what if the memory in userspace is actually swapped out?
Sure,I must care about this ,it will be the next big problem.


you just can't do this in linux; you need to do this from user context;
and wake that user context up from the irq.

Saying "process context" would be a bit clearer here, as it really runs in
kernel, either inside a syscall or in a kernel thread.
If it necessary to write the data from the user space,
it will be a good tactic to create a thread
only for waiting when the data will be arrive?


Actually there are two ways to read a device file and these determine the
solution:

1) The device is read via read syscall.

   In this case, the irq must place the data in a buffer in kernel memory
   and, if registered, wake up the process if waiting in poll or in read.

   When the process is awoken it will issue/continue a read, which will do
   the actual copy_to_user from it's file_operations->read.

The problem is that the user program mustn't make any call to receive
the data. May be it must be notified somehow when the reception is completed,but not before of that.

2) The device is read via mmap.

   In this case, the irq places the data in a buffer in kernel memory
   exactly as before. It also should wake up the process if it is waiting
   (it probably should have some means of waiting for the data).

   Now there is _no_ copy_to_user, since the buffer is visible in the
   process. The mmap method you would implement here would attach the buffer
   where the data is placed into address space of the calling process.

The data is stored on a buffer from a source, which can be for example
a network device, and I want to make as less as possible copies
to the destination address.

In neither case you should save process' active_mm anywhere. Manipulating
process' memory should only ever happen in that process context, or, as in
the later case, in a shared buffer set up with mmap.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@xxxxxx>

Thanks anyway for the answers,
They was very useful :)

--
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