Date: 17 May 2012 11:20
Subject: Re: Writing to userspace memory in kernel mode
To:
asbj...@gmail.comAsbjørn Thegler wrote:
>
> We found your answer to our question below very helpful. If you have time,
> we would be very grateful if you could elaborate a bit.
May I ask why this conversation has to be private?
In case it was merely hitting the wrong button, I do not oppose to this
post being public, in fact I would prefer.
> More specifically, what parts of the MINIX architecture causes this limitation?
VM, not kernel, handles the management of mapping of memory; so it is VM
which allocate such memory mappings; but kernel address space is fixed
before VM even starts: this is a chicken-and-egg problem.
The "obvious" solution is to specialize a part of kernel address space
and pretends (in VM) that part is to be available for sharing purpose:
this looks like to me creating a new ad-hoc kind of memory mapping
(MMAP_NEW_KERNEL_HACK); I do not see the difference between such a hack
and the already existing mechanism like /dev/kmem or the statistical
profile buffer, and I fail to see the benefit to adhere to the POSIX or
4BSD models of memory mapping here, particularly when MINIX already has
several missing features in this area already.
> We are slightly puzzled as to how the kernel reads messages from servers if
> virtual memory addresses are not valid within the kernel.
Ok, this is slightly different. Besides having access to any part of the
physical memory using "raw" copy procedures, kernel has its own
organized address space; selected content of this address space can be
"exported" to other processes (using e.g. sys_getinfo, or even the old
/dev/kmem device but it blurs the organization); and fixed-size messages
are "imported" into that address space as part of the IPC mechanism.
Conceptually I cannot consider as equivalent: while kernel might gain
access to any part of the physical memory, it is not supposed to be
aware of what kind of memory (as managed by VM) it is, which virtual
address, whether it is shared or not, code or data, or more importantly
here, present or not.
When you look at the basic message copying, core kernel (proc.c) is not
aware of the details of the virtual memory address of it, nor does it
care (look at copy_msg_from_user in klib.S): it just uses the values in
place. This is quite different when for example in the system "task",
additional data from the sending process are needed to perform the work:
here the code has to resolve the virtual address of the paramter to
fetch, and therefore uses data_copy() hence virtual_copy(), which
emulates the pagination process and has quite more overhead; using a
shared memory mapping would avoid that overhead, but it would be adding
a new feature to the kernel architecture.
Antoine